-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |