mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-08 05:31:25 +00:00
![geeksville](/assets/img/avatar_default.png)
* Automatically generate .uf2 files (which are often used by nrf52 bootloaders for installing app loads) anytime we generate a new hex file. This tool takes very little time to run and it is handy for development * Remove an old custom target I had tried to add to autogen uf2 files (that never worked) Build output now looks like: $ pio run --environment tracker-t1000-e Processing tracker-t1000-e (board: tracker-t1000-e; platform: platformio/nordicnrf52@^10.5.0; framework: arduino) ... Generating UF2 file Converting to uf2, output size: 1395200, start address: 0x27000 Wrote 1395200 bytes to /home/kevinh/development/meshtastic/firmware/.pio/build/tracker-t1000-e/firmware.uf2 Building .pio/build/tracker-t1000-e/firmware.zip Zip created at .pio/build/tracker-t1000-e/firmware.zip =================================================================================== [SUCCESS] Took 9.33 seconds =================================================================================== Environment Status Duration --------------- -------- ------------ tracker-t1000-e SUCCESS 00:00:09.327 =================================================================================== 1 succeeded in 00:00:09.327 =================================================================================== Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
98 lines
3.2 KiB
Python
98 lines
3.2 KiB
Python
# trunk-ignore-all(ruff/F821)
|
|
# trunk-ignore-all(flake8/F821): For SConstruct imports
|
|
import sys
|
|
from os.path import join
|
|
|
|
from readprops import readProps
|
|
|
|
Import("env")
|
|
platform = env.PioPlatform()
|
|
|
|
|
|
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")
|
|
flash_freq = env.BoardConfig().get("build.f_flash", "40m")
|
|
flash_freq = flash_freq.replace("000000L", "m")
|
|
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]
|
|
|
|
print("Using esptool.py arguments: %s" % " ".join(cmd))
|
|
|
|
esptool.main(cmd)
|
|
|
|
|
|
if platform.name == "espressif32":
|
|
sys.path.append(join(platform.get_package_dir("tool-esptoolpy")))
|
|
import esptool
|
|
|
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", esp32_create_combined_bin)
|
|
|
|
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"])
|
|
|
|
if platform.name == "nordicnrf52":
|
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex",
|
|
env.VerboseAction(f"python ./bin/uf2conv.py $BUILD_DIR/firmware.hex -c -f 0xADA52840 -o $BUILD_DIR/firmware.uf2",
|
|
"Generating UF2 file"))
|
|
|
|
Import("projenv")
|
|
|
|
prefsLoc = projenv["PROJECT_DIR"] + "/version.properties"
|
|
verObj = readProps(prefsLoc)
|
|
print("Using meshtastic platformio-custom.py, firmware version " + verObj["long"])
|
|
|
|
# General options that are passed to the C and C++ compilers
|
|
projenv.Append(
|
|
CCFLAGS=[
|
|
"-DAPP_VERSION=" + verObj["long"],
|
|
"-DAPP_VERSION_SHORT=" + verObj["short"],
|
|
]
|
|
) |