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 ''