Skip to content

Commit

Permalink
generate amj file for am32.ca
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Sep 16, 2024
1 parent d0668c1 commit a2f8eb0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ $(eval H_FILE := $(ELF_FILE:.elf=.h))
$(eval BLU_ELF_FILE := $(BIN_DIR)/$(call BOOTLOADER_UPDATE_BASENAME_VER,$(BUILD),$(PIN)).elf)
$(eval BLU_HEX_FILE := $(BLU_ELF_FILE:.elf=.hex))
$(eval BLU_DEP_FILE := $(BLU_ELF_FILE:.elf=.d))
$(eval BLU_BIN_FILE := $(BLU_ELF_FILE:.elf=.bin))
$(eval BLU_AMJ_FILE := $(BLU_ELF_FILE:.elf=.amj))
$(eval TARGET := $(call BOOTLOADER_BASENAME,$(BUILD),$(PIN)))
$(eval BLU_TARGET := $(call BOOTLOADER_UPDATE_BASENAME,$(BUILD),$(PIN)))

Expand All @@ -159,7 +161,7 @@ $(ELF_FILE): $$(SRC_$(MCU)_BL) $$(SRC_BL)
$$(QUIET)$$(CP) -f Mcu$(DSEP)$(call lc,$(MCU))$(DSEP)openocd.cfg $$(OBJ)$$(DSEP)openocd.cfg > $$(NUL)

$(H_FILE): $(BIN_FILE)
python3 bl_update/make_binheader.py $(BIN_FILE) $(H_FILE)
$$(QUIET)python3 bl_update/make_binheader.py $(BIN_FILE) $(H_FILE)

$(BLU_ELF_FILE): CFLAGS_BLU := $$(MCU_$(MCU)) $$(CFLAGS_$(MCU)) $$(CFLAGS_BASE) -DBOOTLOADER -DUSE_$(PIN) $(EXTRA_CFLAGS) -Wno-unused-variable -Wno-unused-function
$(BLU_ELF_FILE): LDFLAGS_BLU := $$(LDFLAGS_COMMON) $$(LDFLAGS_$(MCU)) -T$(xBLU_LDSCRIPT)
Expand All @@ -183,9 +185,13 @@ $(BLU_HEX_FILE): $$(BLU_ELF_FILE)
$$(QUIET)$(xOBJCOPY) -O binary $$(<) $$(@:.hex=.bin)
$$(QUIET)$(xOBJCOPY) $$(<) -O ihex $$(@:.bin=.hex)

$(BLU_AMJ_FILE): $$(BLU_HEX_FILE)
$$(QUIET)echo Generating $(notdir $$@)
$$(QUIET)python3 bl_update/make_amj.py --type bl_update --githash $(shell git rev-parse HEAD) $(BLU_HEX_FILE) $(BLU_AMJ_FILE)

$(TARGET): $$(HEX_FILE)

$(BLU_TARGET): $$(BLU_HEX_FILE)
$(BLU_TARGET): $$(BLU_AMJ_FILE)

# add to list
ALL_BUILDS := $(ALL_BUILDS) $(TARGET)
Expand Down
46 changes: 46 additions & 0 deletions bl_update/make_amj.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
'''
Create an AM32 amj file from a *.hex firmware firmware for bootloader update image
'''

import argparse
import json
import base64
import os
import sys

parser = argparse.ArgumentParser(description='make_amj')

parser.add_argument('hex')
parser.add_argument('amj')
parser.add_argument("--type", default="bl_update")
parser.add_argument("--githash", default="unknown")

args = parser.parse_args()

img = open(args.hex, 'rb').read()

bname = os.path.basename(args.hex)
a = bname.split("_")
if len(a) != 6 or a[0] != 'AM32' or a[2] != 'BL' or a[3] != "UPDATER" or not a[5].endswith(".hex"):
print("Bad hex file name")
sys.exit(1)
MCU = a[1]
PIN = a[4]
VER = a[5][:-4]
if not MCU in ['F031', 'F051', 'G071', 'E230', 'F415', 'F421', 'G431', 'L431', 'V203']:
print(f"Bad MCU {MCU}")
sys.exit(1)

d = {
"type": args.type,
"mcuType": MCU,
"pin": PIN,
"githash": args.githash,
"version": VER,
"hex": base64.b64encode(img).decode('utf-8'),
}

f = open(args.amj, "w")
f.write(json.dumps(d, indent=4))
f.close()

0 comments on commit a2f8eb0

Please sign in to comment.