From 248ac3fbf65ef70a38e178febc458343b0b009bc Mon Sep 17 00:00:00 2001 From: foorschtbar Date: Mon, 9 Oct 2023 22:05:09 +0200 Subject: [PATCH] Added ESP32 firmware merging --- .github/merge.py | 64 +++++++++++++++++++++++++ .github/workflows/build-and-release.yml | 6 ++- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 .github/merge.py diff --git a/.github/merge.py b/.github/merge.py new file mode 100644 index 0000000..ea268fe --- /dev/null +++ b/.github/merge.py @@ -0,0 +1,64 @@ +import os +import shutil +import subprocess + +root_dir = '.pio/build' +boot_app0_path = os.path.join(os.path.expanduser("~"),".platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin") + +print("+++ Starting merging... +++") + +# Check if the boot_app0.bin file exists +if not os.path.isfile(boot_app0_path): + print(f"boot_app0.bin not found at {boot_app0_path}") + exit(1) + +# Check if the root directory exists +if not os.path.isdir(root_dir): + print(f"Root directory {root_dir} not found") + exit(1) + +# Iterate over all items in the root directory +for item in os.listdir(root_dir): + item_path = os.path.join(root_dir, item) + + # Check if the item is a directory and its name starts with "esp32" + if os.path.isdir(item_path) and item.lower().startswith("esp32"): + print(f"Found an 'esp32' directory: {item_path}") + + # Check if the directory contains a file which begins with "firmware" + firmware_path = "" + for file in os.listdir(item_path): + if file.lower().startswith("firmware") and file.lower().endswith(".bin") and "combined" not in file.lower(): + firmware_path = os.path.join(item_path, file) + directory_path, filename_with_extension = os.path.split(firmware_path) + filename, file_extension = os.path.splitext(filename_with_extension) + print(f"> Found a 'firmware' file: {firmware_path}") + + # build new filename + firmware_combined_path = os.path.join(directory_path, filename + ".combined" + file_extension) + + # copy boot_app0.bin + print(f"> Copying boot_app0.bin to {item_path}...") + shutil.copy(boot_app0_path, item_path) + + # merge firmware + print(f"> Merging firmware to {firmware_combined_path}...") + command = f"python -m esptool --chip esp32 merge_bin -o {firmware_combined_path} --flash_mode dio --flash_freq 40m --flash_size 4MB 0x1000 {item_path}/bootloader.bin 0x8000 {item_path}/partitions.bin 0xe000 {item_path}/boot_app0.bin 0x10000 {firmware_path}" + return_code = subprocess.call(command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if return_code != 0: + print(f"> Merging failed with return code {return_code}.") + break + else: + print("> Merging successful") + + # remove unmerged firmware + print(f"> Removing unmerged firmware {firmware_path}...") + os.remove(firmware_path) + + print("> Done") + break + + if firmware_path == "": + print("> No firmware file for merging found") + +print("+++ Merging done... +++") \ No newline at end of file diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index c24342e..2ca566c 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -74,11 +74,15 @@ jobs: - name: Install pio and its dependencies 🔧 run: | python -m pip install --upgrade pip - pip install --upgrade platformio + pip install --upgrade platformio esptool - name: Run PlatformIO build on selected platforms 🏗️ run: platformio run -e ESP8266_generic -e ESP8266_nodemcuv2 -e ESP32_generic -e ESP32_d1_mini32 -e ESP8266_d1_mini -e ESP32_ulanzi + - name: Merge ESP32 firmware to single binaries 🔧 + run: | + python .github/merge.py + - name: Upload build artifacts 💾 uses: actions/upload-artifact@v3 with: