From 211104570d6b576bee33e4974b2eb01a3076d8fa Mon Sep 17 00:00:00 2001 From: Carson Full Date: Thu, 20 Aug 2026 22:01:19 -0500 Subject: [PATCH] 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. --- pkgs/servers/klipper/klipper-flash.nix | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkgs/servers/klipper/klipper-flash.nix b/pkgs/servers/klipper/klipper-flash.nix index f96e89af93ef..d029d2f6ddf8 100644 --- a/pkgs/servers/klipper/klipper-flash.nix +++ b/pkgs/servers/klipper/klipper-flash.nix @@ -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 ''