Linux Kernel Module development compile for other kernel - linux

I'm using LinK+ in other to develop a linux kernel module. My development machine has a Linux Mint 18 installed operating system with kernel version 4.4.xx. For testing I want to deploy the kernel module to a Debian machine(in a virtualbox) which has a kernel version 3.16.xx.
LinK+ has an option called "Compile for other kernel" (see image below)
When I press that button a dialog ask me to point to Kernel Source Location. I've downloaded kernel version 3.16.xx from https://www.kernel.org/ and then pointed to extracted files from that archive.
The output of the make command is this:
**** Build of configuration Debug for project VMDD ****
make --makefile=Makefile --directory=KERN_SRC modules
make: Entering directory '/home/george/linkProjects/VMDD/KERN_SRC'
make -C /home/george/kernels/linux-3.16.43/ M=/home/george/linkProjects/VMDD/KERN_SRC modules
make[1]: Entering directory '/home/george/kernels/linux-3.16.43'
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /home/george/linkProjects/VMDD/KERN_SRC/VMDD.o
/bin/sh: 1: ./scripts/recordmcount: not found
scripts/Makefile.build:263: recipe for target '/home/george/linkProjects/VMDD/KERN_SRC/VMDD.o' failed
make[2]: *** [/home/george/linkProjects/VMDD/KERN_SRC/VMDD.o] Error 127
Makefile:1337: recipe for target '_module_/home/george/linkProjects/VMDD/KERN_SRC' failed
make[1]: Leaving directory '/home/george/kernels/linux-3.16.43'
make[1]: *** [_module_/home/george/linkProjects/VMDD/KERN_SRC] Error 2
make: *** [modules] Error 2
Makefile:8: recipe for target 'modules' failed
make: Leaving directory '/home/george/linkProjects/VMDD/KERN_SRC'
What did I do wrong ?

I've downloaded kernel version 3.16.xx from https://www.kernel.org/ and then pointed to extracted files from that archive.
You can't compile modules for some kernel if you have only its original source. You need point IDE to configured and partially build kernel. Actually, all files needed to build modules for some kernel version are in kbuild directory of compiled kernel, installed into /lib/modules/version/kbuild. There are linux-kbuild-version (https://packages.debian.org/jessie/kernel/linux-kbuild-3.16) package with some files https://packages.debian.org/jessie/amd64/linux-kbuild-3.16/filelist and linux-headers-version (https://packages.debian.org/jessie/linux-headers-3.16.0-4-amd64) which includes Module.symvers (https://packages.debian.org/jessie/amd64/linux-headers-3.16.0-4-amd64/filelist):
/usr/src/linux-headers-3.16.0-4-amd64/Module.symvers

Related

Yum reports an error:CRITICAL:yum.cli:Config error: Error accessing file for config file:///etc/yum.conf

My environment: python3.8, gcc12.2, cmake4.3. I want to compile and install the glibc library. When I finish compiling and installing, my yum has an error
The following is the error content:
CRITICAL:yum.cli:Config error: Error accessing file for config file:///etc/yum.conf
But I obviously have /etc/yum.conf, but I still get an error
I hope to know why and get a solution, thank you
I downloaded and compiled glibc, and the installation was successful, but there was an error message after installation
collect2: error: ld returned 1 exit status
Execution of gcc failed!
The script has found some problems with your installation!
Please read the FAQ and the README file and check the following:
- Did you change the gcc specs file (necessary after upgrading from
Linux libc5)?
- Are there any symbolic links of the form libXXX.so to old libraries?
Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,
libm.so should point to the newly installed glibc file - and there should be
only one such link (check e.g. /lib and /usr/lib)
You should restart this script from your build directory after you've
fixed all problems!
Btw. the script doesn't work if you're installing GNU libc not as your
primary library!
make[1]: *** [Makefile:111: install] Error 1
make[1]: Leaving directory '/opt/glibc-2.29'
make: *** [Makefile:12:install] 错误 2
But I found on the net that this error doesn't affect anything

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.

Error while building drivers on Raspberry Pi 3 board

I am using Raspberry Pi 3 Model B Rev 1.2 with kernel 4.4.50-v7+ & facing issue while building drivers. Please find below error that I am facing
make[1]: *** /lib/modules/4.4.50-v7+/build: No such file or directory. Stop.
Makefile:149: recipe for target 'build_driver' failed
make: *** [build_driver] Error 2
Can someone help me to resolve this issue?
Your first line mentions why you are getting the error
make[1]: *** /lib/modules/4.4.50-v7+/build: No such file or directory.
It seems that the path /lib/modules/4.4.50-v7+/build does not exist. This may be because you have not installed kernel headers for the kernel for which you are building the driver. You can also change the Makefile of your driver to point it to the linux kernel source directory for which you are building the driver.

Compiling error - Kernel source for Raspberry Pi

I am trying to build a Linux kernel version rpi-4.14 for Raspberry Pi on Linux system.
The build is done with cross compiler arm-linux-gnueabihf with the configuration bcm2709_defconfig.
I'm running the command:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
But I get the following error:
arch/arm/boot/dts/overlays/midi-uart0-overlay.dts:4:39: fatal error: dt-bindings/clock/bcm2835.h: No such file or directory
compilation terminated.
scripts/Makefile.lib:328: recipe for target 'arch/arm/boot/dts/overlays/midi-uart0.dtbo' failed
make[2]: *** [arch/arm/boot/dts/overlays/midi-uart0.dtbo] Error 1
scripts/Makefile.build:587: recipe for target 'arch/arm/boot/dts/overlays' failed
make[1]: *** [arch/arm/boot/dts/overlays] Error 2
arch/arm/Makefile:350: recipe for target 'dtbs' failed
make: *** [dtbs] Error 2
The file dt-bindings/clock/bcm2835.h is in place, so I do not really know what the problem is.
The error is telling you that there is a file missing.
arch/arm/boot/dts/overlays/midi-uart0-overlay.dts:4:39: fatal error: dt-bindings/clock/bcm2835.h: No such file or directory
Check if the directory exists, look for the file you need and change the directory in the Makefile.
In my case it was an erroneous symbolic link under arch/arm/boot/dts/include. The kernel sources have been packed/unpacked by 7z, maybe that was an issue.
Solved it via
ln -s ~/kernel-building/linux-raspberrypi-kernel_1.20170703-2/include/dt-bindings arch/arm/boot/dts/include/dt-bindings
Trying to link in relative to the current directory did not work.

error when building 32-bit linux kernel on 64-bit linux host

I am trying to build 32-bit linux kernel 2.6.9 on a 64-bit linux host with 2.6.9 (same version). Did some google search and tried the following:
step 1) make ARCH=i386 CFLAGS=-m32 menuconfig
step 2) make ARCH=i386 CFLAGS=-m32
Step 1 was okay. But step 2 got the following errors. What did I do wrong?
make ARCH=i386 CFLAGS=-m32
< snip >
In file included from include/asm/smp.h:18,
from include/linux/smp.h:17,
from include/linux/sched.h:23,
from arch/i386/kernel/asm-offsets.c:7:
include/asm/mpspec.h:6:25: mach_mpspec.h: No such file or directory
In file included from include/asm/smp.h:18,
from include/linux/smp.h:17,
from include/linux/sched.h:23,
from arch/i386/kernel/asm-offsets.c:7:
include/asm/mpspec.h:8: error: `MAX_MP_BUSSES' undeclared here (not in a function)
include/asm/mpspec.h:22: error: `MAX_IRQ_SOURCES' undeclared here (not in a function)
In file included from include/linux/smp.h:17,
from include/linux/sched.h:23,
from arch/i386/kernel/asm-offsets.c:7:
include/asm/smp.h:72:26: mach_apicdef.h: No such file or directory
make[1]: *** [arch/i386/kernel/asm-offsets.s] Error 1
make: *** [arch/i386/kernel/asm-offsets.s] Error 2
The make ARCH=i386 should be sufficient assuming you have everything required by the build installed on the machine. I use this almost daily to build i386 on a "ubuntu 12.04".
If you have built a 64-bit kernel previously, you should have everything, and it's possible that you need to "make clean" or even "make mrproper" [save your .config somewhere safe for the latter], because I know for example asm_offsets.s will be different between 32 and 64-bit.

Resources