I am trying to build my custom kernel module. it is compling successfully but while inserting module it is giving me error
insmod: init_module 'helloworld.ko' failed (Exec format error)
And dmesg Log shows:
version magic '3.10.0+ mod_unload ARMv7 p2v8 ' should be '3.10.0 SMP preempt mod_unload ARMv7 p2v8 '
How can I add "SMP" & "preempt" in version magic ?
Check whether CONFIG_PREEMPT and CONFIG_SMP is enabled in the kernel config of the kernel which you are using to compile your kernel module. Enable it in your kernel and then recompile your module using this config.
Related
I am trying to "make" and load the "/drivers/md/raid0.ko" module into my linux kernel but I am getting this error.
# modprobe raid0 --force-vermagic
modprobe: ERROR: could not insert 'raid0': Exec format error
dmesg
[Dec 2 15:10] raid0: version magic '5.0.0 SMP mod_unload ' should be '5.0.0-36-generic SMP mod_unload '
My kernel version is
# uname -a
Linux ubuntu1 5.0.0-36-generic #39-Ubuntu SMP Tue Nov 12 09:46:06 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
and the code from which I am trying to load is taken from the link https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.0.tar.xz
Hence the version in that is 5.0.0, without the EXTRAVERSION -36
I have tried a number of things but failed.
Setting the EXTRAVERSION using command make EXTRAVERSION=-1 modules_prepare, before building the module
Using the --force-vermagic while loading the kernel, but it fails.
Copying the Makefile firectly from /usr/lib/modules/$(uname -r)/build/Makefile before building the kernel.
I have used both make SUBDIRS=drivers/md modules and make M=drivers/md for building, but same result for both.
Need help!
force modprobe to ignore the magic str
use --force-vermagic optin
Every module contains a small string containing important information,
such as the kernel and compiler versions. If a module fails to load
and the kernel complains that the "version magic" doesn't match, you
can use this option to remove it. Naturally, this check is there for
your protection, so this using option is dangerous. This applies to
any modules inserted: both the module (or alias) on the command line
and any modules on which it
in this case modprob ignore magic str
I'm using YOCTO PROJECT to build a linux os for my embedded board.
I have a module named uleds which i want insert to my kernel so i taped this insmod command:
insmod
/lib/modules/4.14.73-linux4sam-6.0-dirty/kernel/drivers/leds/uleds.ko
But an errors comes out :
uleds: version magic '4.14.88-01445-g234c56a01768-dirty mod_unload
ARMv7 p2v8 ' should be '4.14.73-linux4sam-6.0-dirty mod_unload ARMv7
p2v8 '
uleds: version magic '4.14.88-01445-g234c56a01768-dirty mod_unload
ARMv7 p2v8 ' should be '4.14.73-linux4sam-6.0-dirty mod_unload ARMv7
p2v8 '
insmod: can't insert
'/lib/modules/4.14.73-linux4sam-6.0-dirty/kernel/drivers/leds/uleds.ko':
invalid module
What i see that my linux kernel version and the module version are not the same. My question is How can I fix this problem so I can insert the module to the kernel ?
The module is not compiled with the same version as your kernel (on the embedded device).
You need to simply compile the module with the right kernel.
You will need to find your kernel recipe in the meta of Yocto, download it (reset the repository of the downloaded kernel to the SRCREV of the recipe), then build your module.
I try to compile a go program on my Linux desktop (Linux desktop 4.10.0-28-generic #32-Ubuntu SMP Fri Jun 30 05:32:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux), go version go version go1.8.3 linux/amd64 to arm:
$ GOPATH=/home/xrfang/git/hermes/ GOARM=7 GOARCH=arm go build .
the executable is generated, but seems NOT ARMv7:
$ file hermes
hermes: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
It shows EABI5. How can I cross-compile to ARMv7? Is there anything missing on my Linux Desktop so that the cross-compile fallback to a lower ARM version?
Thanks.
I believe, it is not ARMv5. I was trying to do the same on MAC OS and 'file' command on Mac is saying v7, but the 'file' command on Linux don't. However, I do know that v7 has some good improvements and may boost the performance of your program.
But, that is out of scope of this question and you may need to dig deeper into what you're doing and why a performance improvement is expected.
All I can say is, it is compiled for v7.
I have a router Asus RT-AC68R with 32GB memory pen mounted to /opt. On it is installed entware including all the tools to build programs natively on the platform ARMv7. Router use TomatoUSB firmware.
I wrote a program to support the module based on the chip FT245 connected via USB to the router. The program compiled on Linux x86_64 and it works correctly on a standard Linux PC. It was - of course - necessary installing library supplied by the manufacturer (FTDI). The manufacturer provides these libraries for various platforms, including the ARMv7 versions soft and hard float. On router I installed library hard float.
These libraries are HERE
So I'm trying to compile the program, prior to the installation of the pen FTDI libraries, according to the documentation. Unfortunately, after starting the program an library error occurs.
Below the way I compile this program (named arco) and the result of running this program on my ARMv7 based router.
root#asus:/opt# gcc -Wl,-rpath=/opt/usr/local/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/usr/local/lib -O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft -l ftd2xx arco.c -o arco
root#asus:/opt# ./arco
./arco: error while loading shared libraries: /opt/usr/local/lib/libftd2xx.so: internal error
Additional information about my dev environment:
root#asus:/opt/FTDI# echo $PATH
/opt/bin:/opt/sbin:/opt/bin:/opt/sbin:/bin:/usr/bin:/sbin:/usr/sbin:/home/root:/mmc/sbin:/mmc/bin:/mmc/usr/sbin:/mmc/usr/bin:/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin:
root#asus:/opt/FTDI# echo $LD_LIBRARY_PATH
/lib:/usr/lib:/usr/local/lib:/opt/lib:/opt/usr/lib:/opt/include
root#asus:/opt/FTDI# opkg list-installed|grep gcc
gcc - 5.4.0-1
libgcc - 5.4.0-5
root#asus:/opt# uname -a
Linux asus 2.6.36.4brcmarm #5 SMP PREEMPT Tue Aug 16 22:49:47 CEST 2016 armv7l GNU/Linux
I am fairly new when it comes to platform ARMv7 but maybe there is something in compilation options I use:
-mfloat-abi=soft
a library installed is hard-float. I do not know if this could be the reason so expect council colleagues.
Thank you in advance for your answers!
After compiling a kernel for qemu, I get a lots of errors like listed below:
ipv6: version magic '3.18.11-hypriotos+ mod_unload modversions ARMv6 '
should be '3.18.11-hypriotos+ mod_unload modversions ARMv6 p2v8 '
Obviously my kernel and the Hypriotos kernel are somehow different. What means p2v8? And how can I enable it in my kernel?
Go and check out yourself in arch/arm/include/asm/module.h. It's added when CONFIG_ARM_PATCH_PHYS_VIRT is set. So you obviously need this config to be enabled. You can read the description of this option in arch/arm/Kconfig
Keep in mind, however, that if you're not using the same kernel sources that were used for the main kernel build, you may encounter strange problems even if your module is successfully loaded.
#define VERMAGIC_STRING \
UTS_RELEASE "4.4.76 SMP mod_unload ARMv7 p2v8 " \
MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
MODULE_ARCH_VERMAGIC
#endif