NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.28k stars 13.53k forks source link

`klipper-firmware` fails to build when compiling for `avr` target #271063

Closed crabdancing closed 8 months ago

crabdancing commented 9 months ago

Describe the bug

When building for an AVR-based 3D printer, klipper-firmware fails, throwing an error during linking stage:

avr-objcopy -j '.compile_time_request' -O binary out/src/avr/i2c.o out/src/avr/i2c.o.ctr
avr-objcopy -j '.compile_time_request' -O binary out/src/avr/hard_pwm.o out/src/avr/hard_pwm.o.ctr
avr-objcopy -j '.compile_time_request' -O binary out/src/avr/watchdog.o out/src/avr/watchdog.o.ctr
avr-objcopy -j '.compile_time_request' -O binary out/src/avr/serial.o out/src/avr/serial.o.ctr
avr-objcopy -j '.compile_time_request' -O binary out/src/generic/serial_irq.o out/src/generic/serial_irq.o.ctr
  Building out/compile_time_request.o
cat  out/src/sched.o.ctr  out/src/command.o.ctr  out/src/basecmd.o.ctr  out/src/debugcmds.o.ctr  out/src/initial_pins.o.ctr  out/src/gpiocmds.o.ctr  out/sr>
python3 ./scripts/buildcommands.py -d out/klipper.dict -t "avr-gcc;avr-as;avr-ld;avr-objcopy;avr-objdump;avr-strip" out/compile_time_request.txt out/compil>
Version: ?-20231129_223440-localhost
avr-gcc -Iout/ -Isrc -Iout/board-generic/ -std=gnu11 -O2 -MD -Wall -Wold-style-definition -Wtype-limits -ffunction-sections -fdata-sections -fno-delete-nul>
  Linking out/klipper.elf
avr-gcc  out/src/sched.o  out/src/command.o  out/src/basecmd.o  out/src/debugcmds.o  out/src/initial_pins.o  out/src/gpiocmds.o  out/src/stepper.o  out/src>
/nix/store/7mkdi5cvi1r58lv4k5xbgxria1lzd39z-avr-binutils-2.40/bin/avr-ld: out/src/spicmds.o: in function `spidev_transfer':
/build/source/src/spicmds.c:96: undefined reference to `spi_software_prepare'
/nix/store/7mkdi5cvi1r58lv4k5xbgxria1lzd39z-avr-binutils-2.40/bin/avr-ld: /build/source/src/spicmds.c:104: undefined reference to `spi_software_transfer'
/nix/store/7mkdi5cvi1r58lv4k5xbgxria1lzd39z-avr-binutils-2.40/bin/avr-ld: /build/source/src/spicmds.c:104: undefined reference to `spi_software_transfer'
/nix/store/7mkdi5cvi1r58lv4k5xbgxria1lzd39z-avr-binutils-2.40/bin/avr-ld: out/src/i2ccmds.o: in function `command_i2c_write':
/build/source/src/i2ccmds.c:61: undefined reference to `i2c_software_write'
/nix/store/7mkdi5cvi1r58lv4k5xbgxria1lzd39z-avr-binutils-2.40/bin/avr-ld: out/src/i2ccmds.o: in function `command_i2c_read':
/build/source/src/i2ccmds.c:78: undefined reference to `i2c_software_read'
/nix/store/7mkdi5cvi1r58lv4k5xbgxria1lzd39z-avr-binutils-2.40/bin/avr-ld: out/src/i2ccmds.o: in function `command_i2c_modify_bits':
/build/source/src/i2ccmds.c:111: undefined reference to `i2c_software_write'
/nix/store/7mkdi5cvi1r58lv4k5xbgxria1lzd39z-avr-binutils-2.40/bin/avr-ld: /build/source/src/i2ccmds.c:101: undefined reference to `i2c_software_read'
collect2: error: ld returned 1 exit status
make: *** [Makefile:72: out/klipper.elf] Error 1

Steps To Reproduce

Attempt to build klipper-firmware with the following klipper.cfg passed in for firmwareConfig:

# CONFIG_LOW_LEVEL_OPTIONS is not set
CONFIG_MACH_AVR=y
# CONFIG_MACH_ATSAM is not set
# CONFIG_MACH_ATSAMD is not set
# CONFIG_MACH_LPC176X is not set
# CONFIG_MACH_STM32 is not set
# CONFIG_MACH_HC32F460 is not set
# CONFIG_MACH_RP2040 is not set
# CONFIG_MACH_PRU is not set
# CONFIG_MACH_AR100 is not set
# CONFIG_MACH_LINUX is not set
# CONFIG_MACH_SIMU is not set
CONFIG_AVR_SELECT=y
CONFIG_BOARD_DIRECTORY="avr"
# CONFIG_MACH_atmega2560 is not set
# CONFIG_MACH_atmega1280 is not set
# CONFIG_MACH_at90usb1286 is not set
# CONFIG_MACH_at90usb646 is not set
# CONFIG_MACH_atmega32u4 is not set
CONFIG_MACH_atmega1284p=y
# CONFIG_MACH_atmega644p is not set
# CONFIG_MACH_atmega328p is not set
# CONFIG_MACH_atmega328 is not set
# CONFIG_MACH_atmega168 is not set
CONFIG_MCU="atmega1284p"
CONFIG_AVRDUDE_PROTOCOL="arduino"
CONFIG_CLOCK_FREQ=16000000
CONFIG_AVR_CLKPR=-1
CONFIG_AVR_STACK_SIZE=256
CONFIG_AVR_WATCHDOG=y
CONFIG_SERIAL=y
CONFIG_SERIAL_BAUD_U2X=y
CONFIG_SERIAL_PORT=0
CONFIG_SERIAL_BAUD=250000
CONFIG_USB_VENDOR_ID=0x1d50
CONFIG_USB_DEVICE_ID=0x614e
CONFIG_USB_SERIAL_NUMBER="12345"
CONFIG_CANBUS_FREQUENCY=500000
CONFIG_HAVE_GPIO=y
CONFIG_HAVE_GPIO_ADC=y
CONFIG_HAVE_GPIO_SPI=y
CONFIG_HAVE_GPIO_I2C=y
CONFIG_HAVE_GPIO_HARD_PWM=y
CONFIG_HAVE_GPIO_BITBANGING=y
CONFIG_HAVE_STRICT_TIMING=y
CONFIG_INLINE_STEPPER_HACK=y

Expected behavior

The expression should build successfully for Ender 3v2 (board 1.1.4).

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

Notify maintainers

@vtuan10

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

system: "x86_64-linux", multi-user?: yes, version: nix-env (Nix) 2.18.1, nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Priorities

Add a :+1: reaction to issues you find important.

vtuan10 commented 9 months ago

Seems like you are using an outdated config. Can you please rerun klipper-genconf and try again?

crabdancing commented 8 months ago

How does it look outdated? I tried rerunning with klipper-genconf from a recent nixpkgs, with the same settings (ATMEGA1284, with everything else set to default), and it gave me what looks to be basically the same thing:

# CONFIG_LOW_LEVEL_OPTIONS is not set
CONFIG_MACH_AVR=y
# CONFIG_MACH_ATSAM is not set
# CONFIG_MACH_ATSAMD is not set
# CONFIG_MACH_LPC176X is not set
# CONFIG_MACH_STM32 is not set
# CONFIG_MACH_HC32F460 is not set
# CONFIG_MACH_RP2040 is not set
# CONFIG_MACH_PRU is not set
# CONFIG_MACH_AR100 is not set
# CONFIG_MACH_LINUX is not set
# CONFIG_MACH_SIMU is not set
CONFIG_AVR_SELECT=y
CONFIG_BOARD_DIRECTORY="avr"
# CONFIG_MACH_atmega2560 is not set
# CONFIG_MACH_atmega1280 is not set
# CONFIG_MACH_at90usb1286 is not set
# CONFIG_MACH_at90usb646 is not set
# CONFIG_MACH_atmega32u4 is not set
CONFIG_MACH_atmega1284p=y
# CONFIG_MACH_atmega644p is not set
# CONFIG_MACH_atmega328p is not set
# CONFIG_MACH_atmega328 is not set
# CONFIG_MACH_atmega168 is not set
CONFIG_MCU="atmega1284p"
CONFIG_AVRDUDE_PROTOCOL="arduino"
CONFIG_CLOCK_FREQ=16000000
CONFIG_AVR_CLKPR=-1
CONFIG_AVR_STACK_SIZE=256
CONFIG_AVR_WATCHDOG=y
CONFIG_SERIAL=y
CONFIG_SERIAL_BAUD_U2X=y
CONFIG_SERIAL_PORT=0
CONFIG_SERIAL_BAUD=250000
CONFIG_USB_VENDOR_ID=0x1d50
CONFIG_USB_DEVICE_ID=0x614e
CONFIG_USB_SERIAL_NUMBER="12345"
CONFIG_CANBUS_FREQUENCY=500000
CONFIG_HAVE_GPIO=y
CONFIG_HAVE_GPIO_ADC=y
CONFIG_HAVE_GPIO_SPI=y
CONFIG_HAVE_GPIO_I2C=y
CONFIG_HAVE_GPIO_HARD_PWM=y
CONFIG_HAVE_GPIO_BITBANGING=y
CONFIG_HAVE_STRICT_TIMING=y
CONFIG_INLINE_STEPPER_HACK=y

Edit: diff shows the output to have not changed since the last time this utility was run.

Edit 2: tried with klipper-genconf from a recent master version of nixpkgs, (8cfef6986adfb599ba379ae53c9f5631ecd2fd9c) with the same result.

vtuan10 commented 8 months ago

When I run klipper-genconf for ATMEGA1284 I get:

# CONFIG_LOW_LEVEL_OPTIONS is not set
CONFIG_MACH_AVR=y
# CONFIG_MACH_ATSAM is not set
# CONFIG_MACH_ATSAMD is not set
# CONFIG_MACH_LPC176X is not set
# CONFIG_MACH_STM32 is not set
# CONFIG_MACH_HC32F460 is not set
# CONFIG_MACH_RP2040 is not set
# CONFIG_MACH_PRU is not set
# CONFIG_MACH_AR100 is not set
# CONFIG_MACH_LINUX is not set
# CONFIG_MACH_SIMU is not set
CONFIG_AVR_SELECT=y
CONFIG_BOARD_DIRECTORY="avr"
# CONFIG_MACH_atmega2560 is not set
# CONFIG_MACH_atmega1280 is not set
# CONFIG_MACH_at90usb1286 is not set
# CONFIG_MACH_at90usb646 is not set
# CONFIG_MACH_atmega32u4 is not set
CONFIG_MACH_atmega1284p=y
# CONFIG_MACH_atmega644p is not set
# CONFIG_MACH_atmega328p is not set
# CONFIG_MACH_atmega328 is not set
# CONFIG_MACH_atmega168 is not set
CONFIG_MCU="atmega1284p"
CONFIG_AVRDUDE_PROTOCOL="arduino"
CONFIG_CLOCK_FREQ=16000000
CONFIG_AVR_CLKPR=-1
CONFIG_AVR_STACK_SIZE=256
CONFIG_AVR_WATCHDOG=y
CONFIG_SERIAL=y
CONFIG_SERIAL_BAUD_U2X=y
CONFIG_SERIAL_PORT=0
CONFIG_SERIAL_BAUD=250000
CONFIG_USB_VENDOR_ID=0x1d50
CONFIG_USB_DEVICE_ID=0x614e
CONFIG_USB_SERIAL_NUMBER="12345"
CONFIG_WANT_GPIO_BITBANGING=y
CONFIG_WANT_DISPLAYS=y
CONFIG_WANT_SENSORS=y
CONFIG_WANT_LIS2DW=y
CONFIG_WANT_SOFTWARE_I2C=y
CONFIG_WANT_SOFTWARE_SPI=y
CONFIG_CANBUS_FREQUENCY=1000000
CONFIG_HAVE_GPIO=y
CONFIG_HAVE_GPIO_ADC=y
CONFIG_HAVE_GPIO_SPI=y
CONFIG_HAVE_GPIO_I2C=y
CONFIG_HAVE_GPIO_HARD_PWM=y
CONFIG_HAVE_STRICT_TIMING=y
CONFIG_INLINE_STEPPER_HACK=y

Your config is missing those new CONFIG_WANT_ values. It's strange, that you don't have these values if you are on a recent version. I tried it on your mentioned commit with nix shell nixpkgs/8cfef69#klipper-genconf and this generated the expected config as well.

crabdancing commented 8 months ago

OH. Yeah. So, that's totally my fault. Looks like I accidentally added the version pinning to my global overlays (all nixpkgs versions) instead of just the default one, and that propagated down my entire system derivation & dispatch system. Whoopsie. I guess the bug was too reproducible across all my systems for me to notice! :P

On another note, thank you for that nix shell nixpkgs/8cfef69#klipper-genconf command you mentioned. I wasn't aware build/shell/run would work against nixpkgs like that. For some reason, when heading with github: gives the following:

nix build github:nixpkgs/8cfef69#klipper-genconf
error:
       … while fetching the input 'github:nixpkgs/8cfef69'

       error: unable to download 'https://api.github.com/repos/nixpkgs/8cfef69/commits/HEAD': HTTP error 404

       response body:

       {
         "message": "Not Found",
         "documentation_url": "https://docs.github.com/rest/commits/commits#get-a-commit"
       }

Super weird.

vtuan10 commented 8 months ago

If you add github: to the flake reference, you need to specify owner and repository. In this case, the correct command is nix build github:NixOS/nixpkgs/8cfef69#klipper-genconf. For more information about the syntax: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#url-like-syntax

crabdancing commented 8 months ago

Oh, whoops! Thanks :)