I have been trying to build a kernel module out of tree. So far its just a simple hello world project, but when i go to load the module with insmod
or modprobe
it tells me the module is an invalid format.
The enviroment i have been using is as follows:
- Compiler: gcc-arm-8.2-2019.01-x86_64-aarch64-linux-gnu
- Linux Kernel: git://git.toradex.com/linux-toradex.git
- branch: toradex_4.14-2.3.x-imx
Other build tools are the latest version via apt-get
I have attached the project to build my kernel module
The steps to build with my project setup:
- run
sudo ./build.sh -s <LINUX_SOURCE_DIR>
You can load it to a remote machine via:
- run
sudo ./build.sh -s <LINUX_SOURCE_DIR> -u <USERNAME> -n <NETWORK_IP> -i
Dear @BadTalent
The compiler and Kernel you’re using seem to be correct. I tried to follow your scripts and as far as I can see most of it seems legit, but I was not able to find any line where you source the toolchain correctly to run the compiler with it. The steps described here:
export ARCH=arm64
export PATH=~/gcc-linaro/bin/:$PATH
export CROSS_COMPILE=aarch64-linux-gnu-
In other words you’re not using the toolchain you actually downloaded. For me it seems like you are compiling your kernel module with the native toolchain of your host system (x84_64) and therefore you get this error of invalid format on the Arm target.
You could check now if you want to extend your scripts and make sure that you properly export the required variables to use the defined toolchain. To verify if the scripts are wrong you could also just compile the Kernel module with the regular (manual) approach described here.
Best regards
Diego
@diego_b.tx, i have set the enviroment variables and still has the same effect. i set export CROSS_COMPILE=$(pwd)/deps/gcc-linaro/bin/aarch64-linux-gnu-
i do this to avoid settings the PATH
and export ARCH=arm64
i have also now reverted and tried a couple of the other compilers → the binary of course changes a little but the format is still invalid. i feel like i a missing something obvious here.
p.s i can run the manual compile of the modules.
Hi, Perfect that you found a solution. What did you change?
@diego_b.tx
you were correct. it seems the ARCH
and CROSS_COMPILE
had not taken effect further down into the make chain.
successfully compiling and loading onto SoM