raspberrypi / linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
Other
11.2k stars 5.02k forks source link

bookworm kernel headers for camera driver kernel module #6326

Open pbaetens opened 2 months ago

pbaetens commented 2 months ago

LINK TO FORUM: https://forums.raspberrypi.com/viewtopic.php?p=2248093#p2248093

for a custom camera driver I'm trying to build a dkms module. For sake of simplicity, let's reproduce it with the imx219 driver. basically I have a folder structure like this:

    pi@raspberrypi:~/ams_rpi_kernel/imx219/src $ tree
    .
    ├── imx219.c
    ├── imx219.dtsi
    ├── imx219-overlay.dts
    ├── Kbuild
    └── Makefile 
pi@raspberrypi:~/ams_rpi_kernel/imx219/src $ make -C /lib/modules/6.6.31+rpt-rpi-v8/build  M=$PWD CPATH=/usr/src/linux-headers-6.6.31+rpt-common-rpi/include/ 
make: Entering directory '/usr/src/linux-headers-6.6.31+rpt-rpi-v8'
  CC [M]  /home/pi/ams_rpi_kernel/imx219/src/imx219.o
make[2]: *** No rule to make target '/home/pi/ams_rpi_kernel/imx219/src/imx219-overlay.dtbo', needed by '/home/pi/ams_rpi_kernel/imx219/src/'.  Stop.
make[1]: *** [/usr/src/linux-headers-6.6.31+rpt-common-rpi/Makefile:1938: /home/pi/ams_rpi_kernel/imx219/src] Error 2
make: *** [/usr/src/linux-headers-6.6.31+rpt-common-rpi/Makefile:246: __sub-make] Error 2
make: Leaving directory '/usr/src/linux-headers-6.6.31+rpt-rpi-v8'

on older kernel versions, this command worked fine for me. (6.1.y headers + imx219.c from that kernel)


pi@raspberrypi:~/ams_rpi_kernel/imx219/src61 $ make -C /lib/modules/6.1.21-v8+/build/  M=$PWD CPATH=/usr/src/linux-headers-6.1.21-v8+/include/
make: Entering directory '/usr/src/linux-headers-6.1.21-v8+'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: gcc (Debian 10.2.1-6) 10.2.1 20210110
  You are using:           gcc (Debian 12.2.0-14) 12.2.0
  CC [M]  /home/pi/ams_rpi_kernel/imx219/src61/imx219.o
  DTCO    /home/pi/ams_rpi_kernel/imx219/src61/imx219.dtbo
  MODPOST /home/pi/ams_rpi_kernel/imx219/src61/Module.symvers
  CC [M]  /home/pi/ams_rpi_kernel/imx219/src61/imx219.mod.o
  LD [M]  /home/pi/ams_rpi_kernel/imx219/src61/imx219.ko
make: Leaving directory '/usr/src/linux-headers-6.1.21-v8+'

more info: I'm using pi4b, 64bit, bookworm. kernel 6.6.31.


pi@raspberrypi:~/ams_rpi_kernel/imx219/src $ uname -a
Linux raspberrypi 6.6.31+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux

contents of the files: Kbuild


obj-m  := imx219.o
dtbo-y += imx219.dtbo
targets += $(dtbo-y)
always  := $(dtbo-y)
always-y        := $(dtbo-y)
pbaetens commented 2 months ago

simplified version linked here: https://forums.raspberrypi.com/viewtopic.php?t=375795

pbaetens commented 2 months ago

@davidplowman any experience w this? thanks!

davidplowman commented 2 months ago

@davidplowman any experience w this? thanks!

Sorry, I'm afraid I don't know anything about this. Other folk who monitor these issues would know more.

6by9 commented 2 months ago
make[2]: *** No rule to make target '/home/pi/ams_rpi_kernel/imx219/src/imx219-overlay.dtbo', needed by '/home/pi/ams_rpi_kernel/imx219/src/'.  Stop.

The rule is at https://github.com/raspberrypi/linux/blob/rpi-6.6.y/scripts/Makefile.lib#L429-L445

For some reason that doesn't appear to have been copied through to the version in /usr/lib/linux-kbuild-6.6.47+rpt/scripts, which is part of the package linux-kbuild-6.6.47+rpt and symlinked into /usr/src/linux-headers-6.6.47+rpt-rpi-[v8|2712].

@XECDesign how is linux-kbuild-6.6.47+rpt built, and is it sourcing a stock kernel tree rather than our tree?

XECDesign commented 2 months ago

I suspect it's here somewhere, which runs without any rpi patches applied.

So yeah, I think you've hit the nail on the head and it's a packaging issue. I'm not sure what the best way of fixing it is, but I'll give it a go.

pbaetens commented 2 months ago

any quick workaround you can think of? would upgrading to a newer kernel help? @XECDesign

XECDesign commented 2 months ago

I believe I have a fix which should be in the next apt kernel update. It also makes the linux-source package match what's actually shipped.

XECDesign commented 1 month ago

@pbaetens Does everything work as expected with the latest packages?

pbaetens commented 1 month ago

now this error pops up..

pi@raspberry5:~/ams_rpi_kernel/imx219 $ make -C /lib/modules/6.6.51+rpt-rpi-v8/build  M=$PWD CPATH=/usr/src/linux-headers-6.6.51+rpt-common-rpi/include/
make: Entering directory '/usr/src/linux-headers-6.6.51+rpt-rpi-v8'
  DTCO    /home/pi/ams_rpi_kernel/imx219/imx219.dtbo
/bin/sh: 1: ./scripts/dtc/dtc: not found
make[2]: *** [/usr/src/linux-headers-6.6.51+rpt-common-rpi/scripts/Makefile.lib:445: /home/pi/ams_rpi_kernel/imx219/imx219.dtbo] Error 127
make[1]: *** [/usr/src/linux-headers-6.6.51+rpt-common-rpi/Makefile:1946: /home/pi/ams_rpi_kernel/imx219] Error 2
make: *** [/usr/src/linux-headers-6.6.51+rpt-common-rpi/Makefile:246: __sub-make] Error 2
make: Leaving directory '/usr/src/linux-headers-6.6.51+rpt-rpi-v8'
pelwell commented 1 month ago

You'll need to run a make ARCH=arm64 dtbs at least once.

pbaetens commented 1 month ago

You'll need to run a make ARCH=arm64 dtbs at least once.

thanks. Do you have a guide somewhere? In which folder should I run this command? or you probably mean compile the whole kernel according to the raspberry pi docs?

pelwell commented 1 month ago

Do you have a guide somewhere?

There is a full kernel compilation guide here: https://www.raspberrypi.com/documentation/computers/linux_kernel.html#building However, it doesn't cover the use of DKMS - it's not really used or supported here.

In which folder should I run this command?

The command would normally be run in the root of the kernel source tree, but I think you don't have one of those in a DKMS scenario. Looking in the gutted source directory (/usr/src/linux-headers-6.6.51+rpt-common-rpi/include/, in your case), there is no scripts/dtc, let alone scripts/dtc/dtc, leading me to think that DKMS does not support the building of dtbs or overlays.

pbaetens commented 1 month ago

in fact I can just recompile the full kernel each time, but when making small changes to a driver, it is nice if I can only recompile that driver instead of the whole kernel.

the DTC folder does exist, but only for this 6.1.21 headers for some reason..

pi@raspberry5:/usr/src $ find . -type d -name 'dtc'
./linux-headers-6.1.21-v8+/scripts/dtc
pi@raspberry5:/usr/src $ ls -l
total 48
drwxr-xr-x  4 root root 4096 Jan 31  2024 linux-headers-6.1.0-rpi8-common-rpi
drwxr-xr-x  4 root root 4096 Jan 31  2024 linux-headers-6.1.0-rpi8-rpi-2712
drwxr-xr-x  4 root root 4096 Jan 31  2024 linux-headers-6.1.0-rpi8-rpi-v8
drwxr-xr-x 25 root root 4096 Feb  2  2024 linux-headers-6.1.21-v8+
drwxr-xr-x  4 root root 4096 Aug 26 13:35 linux-headers-6.6.31+rpt-common-rpi
drwxr-xr-x  4 root root 4096 Aug 26 16:28 linux-headers-6.6.31+rpt-rpi-2712
drwxr-xr-x  4 root root 4096 Aug 26 13:35 linux-headers-6.6.31+rpt-rpi-v8
drwxr-xr-x  4 root root 4096 Oct  7 11:23 linux-headers-6.6.51+rpt-common-rpi
drwxr-xr-x  4 root root 4096 Oct  7 11:23 linux-headers-6.6.51+rpt-rpi-2712
drwxr-xr-x  4 root root 4096 Oct  7 11:23 linux-headers-6.6.51+rpt-rpi-v8
lrwxrwxrwx  1 root root   23 Jan 25  2024 linux-kbuild-6.1 -> ../lib/linux-kbuild-6.1
lrwxrwxrwx  1 root root   30 May 29 16:04 linux-kbuild-6.6.31+rpt -> ../lib/linux-kbuild-6.6.31+rpt
lrwxrwxrwx  1 root root   30 Oct  1 15:05 linux-kbuild-6.6.51+rpt -> ../lib/linux-kbuild-6.6.51+rpt
drwxr-xr-x  4 root root 4096 Jan 31  2024 python3.11
drwxr-xr-x  3 root root 4096 Jan 31  2024 sense-hat
XECDesign commented 1 month ago

Do you have a link to the driver you're compiling?