0
votes

I am having some issues cross-compiling a module for the Raspberry Pi 4.

  1. The compiler used is: aarch64-linux-gnu-.
  2. The kernel used is: linux-5.10.42

And the error during compilation is as follows:

make -C /opt/linux-5.10.42 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=/home/x/build/linux-driver-gpio-customled modules
make[1]: Entering directory '/opt/linux-5.10.42'
  CC [M]  /home/x/build/linux-driver-gpio-customled/customled.o
In file included from ./include/linux/types.h:6,
                 from ./include/linux/list.h:5,
                 from ./include/linux/module.h:12,
                 from /home/x/build/linux-driver-gpio-customled/customled.c:1:
./include/uapi/linux/types.h:5:10: fatal error: asm/types.h: No such file or directory
    5 | #include <asm/types.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.build:279: /home/x/build/linux-driver-gpio-customled/customled.o] Error 1
make[1]: *** [Makefile:1821: /home/x/build/linux-driver-gpio-customled] Error 2
make[1]: Leaving directory '/opt/linux-5.10.42'
make: *** [Makefile:5: default] Error 2

So my question is as follows: Where should this file asm/types.h come from? To my knowledge it should be included in the kernel arch/arm64/include/asm/ subdirectory. But it's not. Other architectures, namely x86 have it. Is there another way to build a module without including linux/module.h that i'm not aware of?

Any help is greatly appreciated.

1

1 Answers

0
votes

Got it!

The files are autogenerated, there is a handy make command used to prepare the build environment for out-of-tree kernel modules. What I did was run

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_prepare

inside the kernel source.

Hope this helps someone with not spending time on such a simple mistake.