Skip to content

Commit

Permalink
Added ESP32 firmware merging
Browse files Browse the repository at this point in the history
  • Loading branch information
foorschtbar committed Oct 9, 2023
1 parent 4afdd2d commit 248ac3f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/merge.py
Original file line number Diff line number Diff line change
@@ -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... +++")
6 changes: 5 additions & 1 deletion .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 248ac3f

Please sign in to comment.