* merge-bin.py script

This commit is contained in:
Scott Powell
2025-01-25 23:09:09 +11:00
parent 00a9e93754
commit e58d866949
2 changed files with 49 additions and 0 deletions

48
merge-bin.py Normal file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/python3
# Adds PlatformIO post-processing to merge all the ESP flash images into a single image.
import os
Import("env", "projenv")
board_config = env.BoardConfig()
firmware_bin = "${BUILD_DIR}/${PROGNAME}.bin"
merged_bin = os.environ.get("MERGED_BIN_PATH", "${BUILD_DIR}/${PROGNAME}-merged.bin")
def merge_bin_action(source, target, env):
flash_images = [
*env.Flatten(env.get("FLASH_EXTRA_IMAGES", [])),
"$ESP32_APP_OFFSET",
source[0].get_abspath(),
]
merge_cmd = " ".join(
[
'"$PYTHONEXE"',
'"$OBJCOPY"',
"--chip",
board_config.get("build.mcu", "esp32"),
"merge_bin",
"-o",
merged_bin,
"--flash_mode",
board_config.get("build.flash_mode", "dio"),
"--flash_freq",
"${__get_board_f_flash(__env__)}",
"--flash_size",
board_config.get("upload.flash_size", "4MB"),
*flash_images,
]
)
env.Execute(merge_cmd)
env.AddCustomTarget(
name="mergebin",
dependencies=firmware_bin,
actions=merge_bin_action,
title="Merge binary",
description="Build combined image",
always_build=True,
)

View File

@@ -26,6 +26,7 @@ build_src_filter = +<*.cpp> +<helpers/*.cpp>
extends = arduino_base
platform = espressif32
monitor_filters = esp32_exception_decoder
extra_scripts = merge-bin.py
build_src_filter = ${arduino_base.build_src_filter}
[Heltec_stick_lite]