I am having some issues cross-compiling a module for the Raspberry Pi 4.
The compiler used is: aarch64-linux-gnu-.
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.
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.
Related
I'm doing some experiment on rpi4, and trying to reproduce this kernel module from github https://github.com/sysprog21/dont-trace on my rpi4. I encounter this problem:
make -C /lib/modules/`uname -r`/build M=/home/ubuntu/dont-trace modules
make[1]: Entering directory '/usr/src/linux-headers-5.15.65-rt49-preemptrt-full-raspi'
warning: the compiler differs from the one used to build the kernel
The kernel was built by: aarch64-linux-gnu-gcc (Debian 10.2.1-6) 10.2.1 20210110
You are using: gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
CC [M] /home/ubuntu/dont-trace/dont_trace.o
/bin/sh: 1: scripts/basic/fixdep: Exec format error
make[2]: *** [scripts/Makefile.build:289: /home/ubuntu/dont-trace/dont_trace.o] Error 126
make[2]: *** Deleting file '/home/ubuntu/dont-trace/dont_trace.o'
make[1]: *** [Makefile:1896: /home/ubuntu/dont-trace] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.65-rt49-preemptrt-full-raspi'
make: *** [Makefile:7: all] Error 2
The kernel here is cross-compiled from x86 server and do show above. I was wondering how to solve this problem & what's the root cause. I can make it on x86 server. It should be something fundamental knowledge I don't understand. Thks!
it seems work this time
My solution might be a bit workaround, but it works. I follow the clues /bin/sh: 1: scripts/basic/fixdep: Exec format error. So I copy the source code to local raspberry pi, and make modules_prepare to construct complete /scripts, then move it into /lib/modules/`uname -r\`/build. It remain the gcc version warning, but work properly.
I'm using a make file to compile a kernel for an arm/Xilinx platform.
I'm setting an env variable CROSS_COMPILE which the make file will then use.
I'm trying to use a cross compiler, which is present on my system, called arm-xilinx-linux-gnueabi-gcc by setting the env var in the following ways;
export CROSS_COMPILE=/opt/Xilinx/SDK/2015.2/gnu/arm/lin/bin/arm-xilinx-linux-gnueabi-
export CROSS_COMPILE=arm-xilinx-linux-gnueabi-
The make file should append gcc.
The error given for both is
make: /opt/Xilinx/SDK/2015.2/gnu/arm/lin/bin/arm-xilinx-linux-gnueabi-gcc: Command not found
scripts/kconfig/conf --silentoldconfig Kconfig
make: /opt/Xilinx/SDK/2015.2/gnu/arm/lin/bin/arm-xilinx-linux-gnueabi-gcc: Command not found
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
CC kernel/bounds.s
/bin/sh: 1: /opt/Xilinx/SDK/2015.2/gnu/arm/lin/bin/arm-xilinx-linux-gnueabi-gcc: not found
make[1]: *** [kernel/bounds.s] Error 127
make: *** [prepare0] Error 2
It works with other arm cross compilers but this one.
Why is this?
According answers you gave in comments, you are trying to run a 32bits executable on a 64bits host platform.
So, if your are on Ubuntu check this answer from askubuntu.
I'm trying to compile a Linux kernel for my FriendlyARM, but I'm getting this error:
kevin#kevin-VirtualBox:~/Desktop/FriendlyARM/linux-2.6.38-friendlyarm-newgccpatched$ make
make: arm-linux-gcc: Command not found
CHK include/linux/version.h
CHK include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
CC kernel/bounds.s
/bin/sh: 1: arm-linux-gcc: not found
make[1]: *** [kernel/bounds.s] Error 127
make: *** [prepare0] Error 2
kevin#kevin-VirtualBox:~/Desktop/FriendlyARM/linux-2.6.38-friendlyarm-newgccpatched$
Is there an easy way to resolve this?
I have never done this before, therefore, if I'm asking a stupid question, please forgive me.
Firstly, you need to have arm cross compiler toolchain. For example arm-none-linux-gnueabi. You can download it here
When you have successfully installed the toolchain follow below steps to compile the kernel.
cd to kernel directory
execute
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- defconfig
EDIT: Solved it, check my comment below.
I'm trying to compile a kernel with make O=$BUILD
Where build is the build path: BUILD=~/lab/build
But then I get this error:
*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
make[3]: *** [silentoldconfig] Error 1
make[2]: *** [silentoldconfig] Error 2
make[1]: *** No rule to make target `include/config/auto.conf', needed by`include/config/kernel.release'. Stop.
Before I compiled I used the old config file for the new kernel by copying it to my kernel folder:
cp -vi /boot/config-3.13.0-45-generic .config
and then i ran:
make oldconfig
and entered all defaults.
How can I fix the error?
I got it to compile now by doing
make O=$BUILD oldconfig and also by doing a make mrproper in my kernel directory, and then running make O=$BUILD again.
I'm trying to build LLVM and clang on my machine (Ubuntu 12.04). I followed the instructions on http://clang.llvm.org/get_started.html up to step 6 (build LLVM and clang). When I make, I get a whole load of warnings about potentially incompatibly plugin versions (to do with dragonegg?). But the whole thing fails with these messages:
llvm[2]: Linking Debug+Asserts executable llvm-tblgen
/usr/bin/ld: /home/peter/llvm/build/Debug+Asserts/bin/llvm-tblgen: hidden symbol `llvm::Type::~Type()' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
make[2]: *** [/home/peter/llvm/build/Debug+Asserts/bin/llvm-tblgen] Error 1
make[2]: Leaving directory `/home/peter/llvm/build/utils/TableGen'
make[1]: *** [TableGen/.makeall] Error 2
make[1]: Leaving directory `/home/peter/llvm/build/utils'
make: *** [all] Error 1
So any help you could give me would be really helpful.
Thanks
I ended up deleting the llvm folder and checking everything out again, and it worked, so I'm just putting it down to bad timing.
You may want to use the existing LLVM packages, as provided by your distributions.
This askubuntu question about LLVM 3.1 could be relevant.
And you should at least do apt-get build-dep llvm-3.1-dev to ensure all dependencies are available.
You could also ask help on some LLVM related mailing list.