2022-01-02 14:14:54 +00:00
|
|
|
# From: https://github.com/letscontrolit/ESPEasy/blob/mega/tools/pio/post_esp32.py
|
|
|
|
# Thanks TD-er :)
|
|
|
|
|
2022-01-06 17:38:02 +00:00
|
|
|
# Combines separate bin files with their respective offsets into a single file
|
|
|
|
# This single file must then be flashed to an ESP32 node with 0 offset.
|
|
|
|
#
|
|
|
|
# Original implementation: Bartłomiej Zimoń (@uzi18)
|
|
|
|
#
|
|
|
|
# Special thanks to @Jason2866 for helping debug flashing to >4MB flash
|
|
|
|
# Thanks @jesserockz (esphome) for adapting to use esptool.py with merge_bin
|
|
|
|
#
|
|
|
|
# Typical layout of the generated file:
|
|
|
|
# Offset | File
|
|
|
|
# - 0x1000 | ~\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\bin\bootloader_dout_40m.bin
|
|
|
|
# - 0x8000 | ~\Tasmota\.pio\build\<env name>\partitions.bin
|
|
|
|
# - 0xe000 | ~\.platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin
|
|
|
|
# - 0x10000 | ~\Tasmota\.pio\build\<env name>/firmware.bin
|
2022-01-05 16:50:36 +00:00
|
|
|
|
2022-01-06 17:38:02 +00:00
|
|
|
Import("env")
|
2022-01-02 14:14:54 +00:00
|
|
|
|
2022-01-07 10:07:36 +00:00
|
|
|
platform = env.PioPlatform()
|
2022-01-06 22:02:59 +00:00
|
|
|
|
2022-01-07 10:07:36 +00:00
|
|
|
import sys
|
|
|
|
from os.path import join
|
2022-01-06 22:02:59 +00:00
|
|
|
|
2022-01-07 10:07:36 +00:00
|
|
|
sys.path.append(join(platform.get_package_dir("tool-esptoolpy")))
|
2022-01-06 17:38:02 +00:00
|
|
|
import esptool
|
2022-01-05 16:50:36 +00:00
|
|
|
|
2022-01-06 17:38:02 +00:00
|
|
|
def esp32_create_combined_bin(source, target, env):
|
|
|
|
#print("Generating combined binary for serial flashing")
|
2022-01-05 16:50:36 +00:00
|
|
|
|
|
|
|
# The offset from begin of the file where the app0 partition starts
|
|
|
|
# This is defined in the partition .csv file
|
2022-01-06 17:38:02 +00:00
|
|
|
app_offset = 0x10000
|
2022-01-05 16:50:36 +00:00
|
|
|
|
2022-01-05 22:14:49 +00:00
|
|
|
new_file_name = env.subst("$BUILD_DIR/${PROGNAME}.factory.bin")
|
2022-01-06 17:38:02 +00:00
|
|
|
sections = env.subst(env.get("FLASH_EXTRA_IMAGES"))
|
2022-01-05 16:50:36 +00:00
|
|
|
firmware_name = env.subst("$BUILD_DIR/${PROGNAME}.bin")
|
2022-01-06 17:38:02 +00:00
|
|
|
chip = env.get("BOARD_MCU")
|
|
|
|
flash_size = env.BoardConfig().get("upload.flash_size")
|
|
|
|
cmd = [
|
|
|
|
"--chip",
|
|
|
|
chip,
|
|
|
|
"merge_bin",
|
|
|
|
"-o",
|
|
|
|
new_file_name,
|
|
|
|
"--flash_size",
|
|
|
|
flash_size,
|
|
|
|
]
|
|
|
|
|
|
|
|
print(" Offset | File")
|
2022-01-02 14:14:54 +00:00
|
|
|
for section in sections:
|
2022-01-06 17:38:02 +00:00
|
|
|
sect_adr, sect_file = section.split(" ", 1)
|
|
|
|
print(f" - {sect_adr} | {sect_file}")
|
|
|
|
cmd += [sect_adr, sect_file]
|
2022-01-05 16:50:36 +00:00
|
|
|
|
2022-01-06 17:38:02 +00:00
|
|
|
print(f" - {hex(app_offset)} | {firmware_name}")
|
|
|
|
cmd += [hex(app_offset), firmware_name]
|
2022-01-05 16:50:36 +00:00
|
|
|
|
2022-01-06 22:20:21 +00:00
|
|
|
#print('Using esptool.py arguments: %s' % ' '.join(cmd))
|
2022-01-02 14:14:54 +00:00
|
|
|
|
2022-01-06 17:38:02 +00:00
|
|
|
esptool.main(cmd)
|
2022-01-05 16:50:36 +00:00
|
|
|
|
2022-01-02 14:14:54 +00:00
|
|
|
|
2022-01-06 17:38:02 +00:00
|
|
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", esp32_create_combined_bin)
|