Can't figure out how to compile Linux kernel module - linux

I have been trying to figure out how to compile a kernel module. I started with http://www.tldp.org/LDP/lkmpg/2.6/lkmpg.pdf to learn. I then found Compiling a kernel module, header problems, makefile problems to get my makefile going. After running make. I get the following output:
Building target module 2.6 kernel.
PLEASE IGNORE THE "Overriding SUBDIRS" WARNING
make -C /lib/modules/2.6.32-431.el6.i686/build SUBDIRS=/root/kerntest/hello modules
make[1]: Entering directory `/usr/src/kernels/2.6.32-431.20.3.el6.i686'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/usr/src/kernels/2.6.32-431.20.3.el6.i686'
I see the .ko file, but don't see any kernel messages showing the module was activated. I also checked in /lib/modules/2.6.32-431.20.3.el6.i686/extra but there is nothing there. I also tried 'dmesg' and 'lsmod' but didn't see it.
Can anyone point me in the right direction?
I am trying this on CentOS 6.5

You need to actually load the module into the kernel after compiling by using insmod or modprobe :)

Related

error message "-mrecord-mcount" when cross-compile out of kernel module

I'm trying to build an out-of-kernel module and cross-compile it.
So, I'm working on VM, Ubuntu, and I upgraded the running kernel to 5.15.6.
Now, I'm trying to cross-compile my very simple "Hello world" module.
Its Makefile is simply:
obj-m += yanivModule.o
and the building command is:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -C /lib/modules/5.15.6/build/ M=$PWD modules
and I keep running into this error message:
arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-mrecord-mcount’; did you mean ‘-frecord-marker=4’?
Does anyone know what "-mrecord-mcount" means how to fix it?
I tried to disable the "CONFIG_FTRACE_MCOUNT_RECORD" and "CONFIG_HAVE_FTRACE_MCOUNT_RECORD" configuration flag as I read somewhere it might be related (and by name it actually might be), but it didn't solve the error.
I'm kind of lost here since in the tutorial video I'm following, it's done with no issues at all.
Update:
I managed to fix the issue, but I'm not sure why it got fixed that way, and why the way I described before didn't work.
I downloaded the kernel of beaglebone board from github:
https://github.com/beagleboard/linux/tree/5.10
and then built it using:
make ARCH=arm bb.org_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- C /home/.../beaglebone-linux-5.10/ M=$PWD modules
and only then, building the module, when -C is the new downloaded kernel tree - has succeeded with no issues.
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -C /home/.../beaglebone-linux-5.10/ M=$PWD modules
So now, I'm left with 2 questions:
What, step fixed the issue and what was missing from the previous way I tried? was it using the bb.org_defconfig configuration file?
Why this bb.org_defconfig configuration file is missing from the latest Linux kernel source tree?

Problems building driver on Linux kernel 5.8.x

I'm working with a Linux driver that is building on v5.7.x kernels but not on the latest v5.8.x releases.
To summarise, most of the driver is pre-built and the kernel interface is built on the target. This involves a make -f Kbuild command.
Having checked all of the relevant kernel interface files for any changes that would affect us, normally the driver would just build as usual on a new kernel. However, this time we get the following error:
make[2]: *** [scripts/Makefile.modpost:111: /path/to/source/Module.symvers] Error 1
make[1]: *** [Makefile:1669: modules] Error 2
make[1]: Leaving directory '/usr/src/kernels/5.8.0-1.el8.elrepo.x86_64'
make: *** [Kbuild:26: default] Error 2
This is from CentOS 8.1, but the same error has been seen on Ubuntu 20.04.
I am no expert on this so interpreting these errors is a bit difficult. I have tried building with the KBUILD_VERBOSE flag and it doesn't really provide any useful information, other than the build succeeding until this point.
On previous kernels the Module.symvers file would be created but empty. On 5.8 this file is not created at all presumably due to this error. As a result, the .ko file is not created.
Finally, if we drop in the source files rather than the pre-built .o files the build does succeed. These .o files are built with a very old version of GCC (4.4.7) but we have also tried building with a much newer version (8.3.1), the same version as the target machine.
I would appreciate suggestions for things to check. Let me know if any other details would help.
Edit:
I ran make on Makefile.modpost manually and got the following output:
sudo make -f ./scripts/Makefile.modpost
WARNING: Symbol version dump "vmlinux.symvers" is missing.
Modules may not have dependencies or modversions.
make -f /scripts/Makefile.modfinal
make[1]: Entering directory '/usr/src/linux-headers-5.8.0-050800-generic'
make[1]: /scripts/Makefile.modfinal: No such file or directory
make[1]: *** No rule to make target '/scripts/Makefile.modfinal'. Stop.
make[1]: Leaving directory '/usr/src/linux-headers-5.8.0-050800-generic'
make: *** [scripts/Makefile.modpost:117: __modpost] Error 2
I am answering my own question in case it helps anyone else with this problem. Although it has never been an issue in the past, we've always had a warning that the corresponding .o.cmd file was not present for our .o_shipped files. This appears to be important in kernel 5.8 onwards and my fix was to add a touch command to the Kbuild file (i.e. "touch .driver.o.cmd"). This does not remove the warning but it allows the driver to build as normal.

Arch Linux: make - no such file or directory

I have a problem by compiling a driver (WLAN-dongle Edimax ac600).
I´m using an Archlinux on my raspberry-pi and want to install my dongle for 5Ghz. During comiling the driver I get this message. I tried to install the linux-headers without success. (in other threads it will be a solution)
Here is my output of make:
[root#raspberry_pi_1 rtl8812AU]# make make ARCH=arm CROSS_COMPILE= -C
/lib/modules/4.9.43-1-ARCH/build M=/root/rtl8812AU modules make[1]:
*** /lib/modules/4.9.43-1-ARCH/build: No such file or directory. Stop. make: *** [Makefile:1576: modules] Error 2
I found out that my pi has a two-arch...-directories:
4.9.43-1-ARCH/
4.9.51-1-ARCH/
Only the second one has the build directory...
How can I fix the problem?!
thanks a lot,
a Linux noob...
[Reputation is too low to post comment]
Use uname -r to make sure which version of the kernel you use.
If it's 4.9.43 : you have newer version of the kernel and this confuse your installer. You should reboot on the 51 one
If it's 4.9.51 : You messed up your installation step and are trying to compile for an old target. You should review the compilation process and change every mention of the 4.9.43 to 4.9.51 since it's the version you use.
If you upgrade your kernel, you may have to rebuild the thing again (You may like to have script in the future ;) ) with the new kernel version.

Recipe for target 'curve25519-donna-c64.o" failed

I have a problem trying to compile a library. I am using curve25519-donna to generate key pairs. I have already downloaded the library and unzipped the file, but my problem is with the compilation.
I have changed my directory to curve25519-donna-1.3 and this is the code I tried to use the compile the library:
env CC='gcc -02' make
And this was the outcome.
Makefile:23 recipe for target 'curve25519-donna-c64.o' failed
make: *** [curve25519-donna-c64.o] Error 1
I am running on a Raspberry pi OS, am I missing some gcc's that I need to install in this operating system?
I've upgraded and updated but I am still having problems with this. Any help will be much appreciated, thanks!!

Can I use Linux kernel image even after this build failure

I am new to Linux Kernel and trying to build my first Kernel image, I am building from 3.4.28 Linux Kernel on i686 Architecture for 32 bit.
After one and half hours of build process, I got the following errors
BUILD arcarch/x86/boot/compressedh/x86/boot/bzImage
Setup is 16540 bytes (padded to 16896 bytes).
System is 4667 kB
CRC c2376a1f
Kernel: arch/x86/boot/bzImage is ready (#1)
Building modules, stage 2.
MODPOST 3508 modules
ERROR: "__sync_fetch_and_and_4" [drivers/staging/line6/line6usb.ko] undefined!
ERROR: "__sync_fetch_and_or_4" [drivers/staging/line6/line6usb.ko] undefined!
WARNING: modpost: Found 28 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
make[1]: *** [__modpost] Error 1
make: *** [modules] Error 2
But if I go and look in the "arch/x86/boot/compressed" directory, I find vmlinux.bin image with ELF header.
I wanted to know can I use this vmlinux binary for my purpose or is a complete successful build required to make this binary fully functional.
As long as nothing relies on the kernel module line6usb.ko or any modules built after it you are likely ok.
My answer is also same as JimR; the kernel module line6usb.ko is not so much important module. Firstly disable this module by first running mrproper then after make menuconfig.
In the menuconfig find the driver in drivers staging and disable it. Later again cross compile the kernel.
disable the module in kernel configuration.
by choosing like this
device drivers ----
staging drivers

Resources