2024-05-22 02:02:09 +00:00
|
|
|
# trunk-ignore-all(ruff/F821)
|
|
|
|
# trunk-ignore-all(flake8/F821): For SConstruct imports
|
2021-04-16 02:35:10 +00:00
|
|
|
import sys
|
2022-09-29 15:04:56 +00:00
|
|
|
from os.path import join
|
2024-05-16 00:37:35 +00:00
|
|
|
|
2021-04-16 02:59:46 +00:00
|
|
|
from readprops import readProps
|
2021-04-16 02:35:10 +00:00
|
|
|
|
2022-09-29 15:04:56 +00:00
|
|
|
Import("env")
|
|
|
|
platform = env.PioPlatform()
|
|
|
|
|
2024-05-16 00:37:35 +00:00
|
|
|
|
2022-09-29 15:04:56 +00:00
|
|
|
def esp32_create_combined_bin(source, target, env):
|
|
|
|
# this sub is borrowed from ESPEasy build toolchain. It's licensed under GPL V3
|
|
|
|
# https://github.com/letscontrolit/ESPEasy/blob/mega/tools/pio/post_esp32.py
|
|
|
|
print("Generating combined binary for serial flashing")
|
|
|
|
|
|
|
|
app_offset = 0x10000
|
|
|
|
|
|
|
|
new_file_name = env.subst("$BUILD_DIR/${PROGNAME}.factory.bin")
|
|
|
|
sections = env.subst(env.get("FLASH_EXTRA_IMAGES"))
|
|
|
|
firmware_name = env.subst("$BUILD_DIR/${PROGNAME}.bin")
|
|
|
|
chip = env.get("BOARD_MCU")
|
|
|
|
flash_size = env.BoardConfig().get("upload.flash_size")
|
2024-05-16 00:37:35 +00:00
|
|
|
flash_freq = env.BoardConfig().get("build.f_flash", "40m")
|
|
|
|
flash_freq = flash_freq.replace("000000L", "m")
|
2022-09-29 15:04:56 +00:00
|
|
|
flash_mode = env.BoardConfig().get("build.flash_mode", "dio")
|
|
|
|
memory_type = env.BoardConfig().get("build.arduino.memory_type", "qio_qspi")
|
|
|
|
if flash_mode == "qio" or flash_mode == "qout":
|
|
|
|
flash_mode = "dio"
|
|
|
|
if memory_type == "opi_opi" or memory_type == "opi_qspi":
|
|
|
|
flash_mode = "dout"
|
|
|
|
cmd = [
|
|
|
|
"--chip",
|
|
|
|
chip,
|
|
|
|
"merge_bin",
|
|
|
|
"-o",
|
|
|
|
new_file_name,
|
|
|
|
"--flash_mode",
|
|
|
|
flash_mode,
|
|
|
|
"--flash_freq",
|
|
|
|
flash_freq,
|
|
|
|
"--flash_size",
|
|
|
|
flash_size,
|
|
|
|
]
|
|
|
|
|
|
|
|
print(" Offset | File")
|
|
|
|
for section in sections:
|
|
|
|
sect_adr, sect_file = section.split(" ", 1)
|
|
|
|
print(f" - {sect_adr} | {sect_file}")
|
|
|
|
cmd += [sect_adr, sect_file]
|
|
|
|
|
|
|
|
print(f" - {hex(app_offset)} | {firmware_name}")
|
|
|
|
cmd += [hex(app_offset), firmware_name]
|
|
|
|
|
2024-05-16 00:37:35 +00:00
|
|
|
print("Using esptool.py arguments: %s" % " ".join(cmd))
|
2022-09-29 15:04:56 +00:00
|
|
|
|
|
|
|
esptool.main(cmd)
|
|
|
|
|
2024-05-16 00:37:35 +00:00
|
|
|
|
|
|
|
if platform.name == "espressif32":
|
2022-09-29 19:23:01 +00:00
|
|
|
sys.path.append(join(platform.get_package_dir("tool-esptoolpy")))
|
|
|
|
import esptool
|
2024-05-16 00:37:35 +00:00
|
|
|
|
|
|
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", esp32_create_combined_bin)
|
2024-05-30 15:59:10 +00:00
|
|
|
|
|
|
|
esp32_kind = env.GetProjectOption("custom_esp32_kind")
|
|
|
|
if esp32_kind == "esp32":
|
|
|
|
# Free up some IRAM by removing auxiliary SPI flash chip drivers.
|
|
|
|
# Wrapped stub symbols are defined in src/platform/esp32/iram-quirk.c.
|
|
|
|
env.Append(
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-Wl,--wrap=esp_flash_chip_gd",
|
|
|
|
"-Wl,--wrap=esp_flash_chip_issi",
|
|
|
|
"-Wl,--wrap=esp_flash_chip_winbond",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
# For newer ESP32 targets, using newlib nano works better.
|
|
|
|
env.Append(LINKFLAGS=["--specs=nano.specs", "-u", "_printf_float"])
|
2022-09-29 15:04:56 +00:00
|
|
|
|
2021-04-16 02:35:10 +00:00
|
|
|
Import("projenv")
|
|
|
|
|
2020-12-10 05:17:43 +00:00
|
|
|
prefsLoc = projenv["PROJECT_DIR"] + "/version.properties"
|
2021-05-03 01:50:06 +00:00
|
|
|
verObj = readProps(prefsLoc)
|
2024-05-16 00:37:35 +00:00
|
|
|
print("Using meshtastic platformio-custom.py, firmware version " + verObj["long"])
|
2020-12-10 03:28:15 +00:00
|
|
|
|
|
|
|
# General options that are passed to the C and C++ compilers
|
2024-05-16 00:37:35 +00:00
|
|
|
projenv.Append(
|
|
|
|
CCFLAGS=[
|
|
|
|
"-DAPP_VERSION=" + verObj["long"],
|
|
|
|
"-DAPP_VERSION_SHORT=" + verObj["short"],
|
|
|
|
]
|
|
|
|
)
|