From d8980ae0d4231c11b1ad5ce168dc5a774a5c8466 Mon Sep 17 00:00:00 2001 From: ZanzyTHEbar Date: Mon, 27 Feb 2023 14:21:01 +0000 Subject: [PATCH] feat: merge binaries --- ESP/.gitignore | 1 + ESP/tools/createzip.py | 47 +++++++++++++++++++++++++++++++++++++++-- ESP/tools/customname.py | 13 +++++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/ESP/.gitignore b/ESP/.gitignore index fa0c169..42f485b 100644 --- a/ESP/.gitignore +++ b/ESP/.gitignore @@ -4,3 +4,4 @@ build/ *.log /tools/firmware_name.txt /tools/version.txt +/tools/_pycache_/ diff --git a/ESP/tools/createzip.py b/ESP/tools/createzip.py index 01a2723..d79c527 100644 --- a/ESP/tools/createzip.py +++ b/ESP/tools/createzip.py @@ -37,10 +37,44 @@ def createZip(source, target, env): file_name = "./build/{0}/{1}.zip".format( str(env["PIOENV"]), env["PROGNAME"] ) + + my_flags = env.ParseFlags(env["BUILD_FLAGS"]) + defines = dict() + for x in my_flags.get("CPPDEFINES"): + if type(x) is tuple: + (k, v) = x + defines[k] = v + elif type(x) is list: + k = x[0] + v = x[1] + defines[k] = v + else: + defines[x] = "" # empty value + + # print("Project: %s" % defines) + # strip quotes needed for shell escaping + s = lambda x: x.replace('"', "") + s = lambda x: x.replace("'", "") + with ZipFile(file_name, "w") as archive: print('\nCreating "' + archive.filename + '"', end="\n") parts = [] + + name = "OpenIris" + version = s(defines.get("PIO_SRC_TAG")) + new_install_prompt_erase = "true" + + """ + python esptool.py --chip ESP32 merge_bin -o merged-firmware.bin --flash_mode dio --flash_freq 40m --flash_size 4MB + 0x1000 bootloader.bin 0x8000 partitions.bin 0xe000 boot.bin 0x10000 OpenIris-v1.3.0-esp32AIThinker-8229a3a-master.bin + """ + env.Execute( + "$PYTHONEXE $PROJECT_PACKAGES_DIR/tool-esptoolpy/esptool.py --chip ESP32 merge_bin -o merged-firmware.bin --flash_mode dio --flash_freq 40m --flash_size 4MB %s" + % (partition.join(" ")) + ) + for [offset, path] in partitions: + filename = basename(path) archive.write(path, filename) partition = { @@ -48,9 +82,17 @@ def createZip(source, target, env): "offset": int(offset, 16), } parts.append(partition) + manifest = { - "chipFamily": "ESP32", - "parts": parts, + "builds": [ + { + "name": name, + "version": version, + "new_install_prompt_erase": new_install_prompt_erase, + "chipFamily": "ESP32", + "parts": parts, + } + ] } archive.writestr("manifest.json", json.dumps(manifest)) sys.stdout.write(RESET) @@ -63,4 +105,5 @@ def createZip(source, target, env): print("CI build not detected, skipping zip creation") sys.stdout.write(RESET) + env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", createZip) diff --git a/ESP/tools/customname.py b/ESP/tools/customname.py index e8e7445..b8be567 100644 --- a/ESP/tools/customname.py +++ b/ESP/tools/customname.py @@ -78,8 +78,6 @@ def handleGit(): def customName(project, version, commit, branch): - # Dump global construction environment (for debug purpose) - # print(env.Dump()) my_flags = env.ParseFlags(env["BUILD_FLAGS"]) defines = dict() @@ -133,6 +131,12 @@ def customName(project, version, commit, branch): try: flags = env["BUILD_FLAGS"] my_flags = env.ParseFlags(flags) + + # Dump global construction environment (for debug purpose) + # write env.Dump() to a file + #with open("env_dump.txt", "w") as f: + # f.write(env.Dump()) + handleGit() except ValueError as ex: # look for apostrophes and warn the user @@ -140,4 +144,7 @@ except ValueError as ex: print( "[Warning]: Apostrophes are not allowed in the build flags. Please remove them from the \033[;1m\033[1;36m`user-config.ini` \033[1;31mfile and try again." ) - raise Exception("Could not parse BUILD_FLAGS - Possible apostrophy used in user configuration", ex) + raise Exception( + "Could not parse BUILD_FLAGS - Possible apostrophy used in user configuration", + ex, + )