2022-03-21 16:50:08 +00:00
|
|
|
{ lib
|
|
|
|
, writeShellApplication
|
|
|
|
, gnumake
|
|
|
|
, pkgsCross
|
|
|
|
, klipper
|
|
|
|
, klipper-firmware
|
|
|
|
, python2
|
|
|
|
, avrdude
|
|
|
|
, stm32flash
|
|
|
|
, mcu ? "mcu"
|
|
|
|
, flashDevice ? "/dev/null"
|
2022-03-21 20:04:23 +00:00
|
|
|
, firmwareConfig ? ./simulator.cfg
|
2022-03-21 16:50:08 +00:00
|
|
|
}:
|
|
|
|
let
|
2022-03-21 20:04:23 +00:00
|
|
|
isNotSupported = with builtins; isNull (match ''^.*CONFIG_BOARD_DIRECTORY="(avr|stm32|lpc176x)".*$'' (readFile firmwareConfig));
|
|
|
|
isNotStm = with builtins; isNull (match ''^.*CONFIG_BOARD_DIRECTORY="(stm32)".*$'' (readFile firmwareConfig));
|
2022-03-21 16:50:08 +00:00
|
|
|
in
|
|
|
|
writeShellApplication {
|
|
|
|
name = "klipper-flash-${mcu}";
|
|
|
|
runtimeInputs = [
|
|
|
|
python2
|
|
|
|
avrdude
|
|
|
|
stm32flash
|
|
|
|
pkgsCross.avr.stdenv.cc
|
2022-03-21 20:04:23 +00:00
|
|
|
gnumake
|
2022-03-21 16:50:08 +00:00
|
|
|
];
|
|
|
|
text = ''
|
|
|
|
NOT_SUPPORTED=${lib.boolToString isNotSupported}
|
|
|
|
NOT_STM=${lib.boolToString isNotStm}
|
|
|
|
if $NOT_SUPPORTED; then
|
|
|
|
printf "Flashing Klipper firmware to your board is not supported yet.\n"
|
|
|
|
printf "Please use the compiled firmware at ${klipper-firmware} and flash it using the tools provided for your microcontroller."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if $NOT_STM; then
|
2022-03-21 20:04:23 +00:00
|
|
|
make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" flash
|
2022-03-21 16:50:08 +00:00
|
|
|
else
|
2022-03-21 20:04:23 +00:00
|
|
|
make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" serialflash
|
2022-03-21 16:50:08 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
}
|