klipper-flash: derive -s/--start for stm32 boards

Passes `CONFIG_FLASH_APPLICATION_ADDRESS` to `flash_usb.py --start {address}`.
Same as Klipper's stm32 Makefile does.

Without this callers have always had to manually pass in script calls
```
klipper-flash-$mcu --start {address}
```

FWIW: atsamd boards need start address as well, but it is derived differently, and I do not have that hardware to verify against.
This commit is contained in:
Carson Full
2026-08-20 22:01:19 -05:00
parent 602e3e64f0
commit 211104570d

View File

@@ -18,13 +18,16 @@ let
with builtins;
let
lines = lib.splitString "\n" (readFile firmwareConfig);
matchLine = line: match ''${field}="([a-zA-Z0-9_]+)".*'' (lib.trim line);
matchLine = line: match ''${field}="?([a-zA-Z0-9_]+)"?.*'' (lib.trim line);
matched = lib.findFirst (line: matchLine line != null) null lines;
in
if matched != null then head (matchLine matched) else null;
matchPlatform = getConfigField "CONFIG_BOARD_DIRECTORY";
matchBoard = getConfigField "CONFIG_MCU";
matchAvrdudeProtocol = getConfigField "CONFIG_AVRDUDE_PROTOCOL";
matchFlashApplicationAddress = getConfigField "CONFIG_FLASH_APPLICATION_ADDRESS";
# Only stm32's require -s/--start (flash_stm32f4 in scripts/flash_usb.py)
flashStartAddress = if matchPlatform == "stm32" then matchFlashApplicationAddress else null;
flashUsbSupportedBoards = [
"sam3"
"sam4"
@@ -67,7 +70,9 @@ writeShellApplication {
if flashDevice != null then
if (builtins.elem matchBoard flashUsbSupportedBoards) && matchPlatform != null then
''
${klipper}/lib/scripts/flash_usb.py -t ${matchBoard} -d ${flashDevice} ${klipper-firmware}/klipper.bin "$@"
${klipper}/lib/scripts/flash_usb.py -t ${matchBoard} -d ${flashDevice}${
lib.optionalString (flashStartAddress != null) " -s ${flashStartAddress}"
} ${klipper-firmware}/klipper.bin "$@"
''
else if matchPlatform == "avr" && matchAvrdudeProtocol != null && matchBoard != null then
''