klipper-firmware: Fix IFD error and minor refactoring

This commit is contained in:
Van Tuan Vo 2022-03-21 21:04:23 +01:00
parent 72871a3596
commit c49f15e87b
No known key found for this signature in database
GPG Key ID: 7C96B1B77958A566
5 changed files with 15 additions and 24 deletions

View File

@ -153,6 +153,7 @@ in
mcu = lib.strings.sanitizeDerivationName mcu;
klipper-firmware = firmware;
flashDevice = cfg.settings."${mcu}".serial;
firmwareConfig = cfg.firmware."${mcu}".firmwareConfig;
})
firmwares;
in

View File

@ -49,18 +49,14 @@
mkdir -p $out
cp ./.config $out/config
cp -r out/* $out
if ${lib.boolToString (!isNull flashDevice)}; then
make FLASH_DEVICE=${toString flashDevice} OUT=$out/ KCONFIG_CONFIG=$out/config flash
fi
'';
'' + lib.optionalString (flashDevice != null) "make FLASH_DEVICE=${toString flashDevice} OUT=$out/ KCONFIG_CONFIG=$out/config flash";
dontFixup = true;
meta = {
meta = with lib; {
inherit (klipper.meta) homepage license;
description = "Firmware part of Klipper";
maintainers = with lib.maintainers; [ vtuan10 ];
platforms = lib.platforms.linux;
maintainers = with maintainers; [ vtuan10 ];
platforms = platforms.linux;
};
}

View File

@ -9,11 +9,11 @@
, stm32flash
, mcu ? "mcu"
, flashDevice ? "/dev/null"
, firmwareConfig ? ./simulator.cfg
}:
let
firmwareConfig = builtins.readFile "${klipper-firmware}/config";
isNotSupported = with builtins; isNull (match ''^.*CONFIG_BOARD_DIRECTORY="(avr|stm32|lpc176x)".*$'' firmwareConfig);
isNotStm = with builtins; isNull (match ''^.*CONFIG_BOARD_DIRECTORY="(stm32)".*$'' firmwareConfig);
isNotSupported = with builtins; isNull (match ''^.*CONFIG_BOARD_DIRECTORY="(avr|stm32|lpc176x)".*$'' (readFile firmwareConfig));
isNotStm = with builtins; isNull (match ''^.*CONFIG_BOARD_DIRECTORY="(stm32)".*$'' (readFile firmwareConfig));
in
writeShellApplication {
name = "klipper-flash-${mcu}";
@ -22,6 +22,7 @@ writeShellApplication {
avrdude
stm32flash
pkgsCross.avr.stdenv.cc
gnumake
];
text = ''
NOT_SUPPORTED=${lib.boolToString isNotSupported}
@ -31,12 +32,10 @@ writeShellApplication {
printf "Please use the compiled firmware at ${klipper-firmware} and flash it using the tools provided for your microcontroller."
exit 1
fi
pushd ${klipper.src}
if $NOT_STM; then
${gnumake}/bin/make FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" flash
make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" flash
else
${gnumake}/bin/make FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" serialflash
make -C ${klipper.src} FLASH_DEVICE="${toString flashDevice}" OUT="${klipper-firmware}/" KCONFIG_CONFIG="${klipper-firmware}/config" serialflash
fi
popd
'';
}

View File

@ -8,13 +8,12 @@
runtimeInputs = [
python2
pkgsCross.avr.stdenv.cc
gnumake
];
text = ''
CURRENT_DIR=$(pwd)
TMP=$(mktemp -d)
pushd ${klipper.src}
${gnumake}/bin/make OUT="$TMP" KCONFIG_CONFIG="$CURRENT_DIR/config" menuconfig
popd
make -C ${klipper.src} OUT="$TMP" KCONFIG_CONFIG="$CURRENT_DIR/config" menuconfig
rm -rf "$TMP" config.old
printf "\nYour firmware configuration for klipper:\n\n"
cat config

View File

@ -3422,13 +3422,9 @@ with pkgs;
klipper = callPackage ../servers/klipper { };
klipper-firmware = callPackage ../servers/klipper/klipper-firmware.nix {
inherit libusb1;
};
klipper-firmware = callPackage ../servers/klipper/klipper-firmware.nix { };
klipper-flash = callPackage ../servers/klipper/klipper-flash.nix {
inherit klipper-firmware;
};
klipper-flash = callPackage ../servers/klipper/klipper-flash.nix { };
klipper-genconf = callPackage ../servers/klipper/klipper-genconf.nix { };