Rebuild linux kernel module for another architecture - c

Suppose I have x86-64 machine with some version of Linux kernel. And I have directory with kernel sources of another version. The kernel was built for arm arch and loaded to the appropriate device.
Now I need to rebuild just one kernel module in this big directory.
I read this post and tried something like
make path/to/the/module/itself.ko
, but it build module for amd64.
When I try
make M=path/to/the/module/
it gives a bunch of arch-related C-errors.
Could someone explain how can easy use this ARM-ready environment to rebuild some kernel module?

You could try:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- M=path/to/the/module/
Also read:
Cross compiling a kernel module
gcc-arm-linux-gnueabi command not found

Related

cross Compiling ubertooth software for ARMHF

I have a software (ubertooth host ) that I need to compile on ARM, I have already compiled it on a normal Linux X64 machine and it worked. The process contains :
cmake ..
make
make install
Any help regarding how to cross compile for an armhf processor?
Linux Debian Stretch has some precompiled tools for cross compiling:
crossbuild-essential-armhf
I guess that package is the one that suit your target architecture. Firstly I would try to compile with it. Probably you need to launch the build commands with the variable CROSS_COMPILE assigned properly. Eg:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
Other option is creating your own toolchain. Have a look to this other link https://crosstool-ng.github.io/ where you can see how to create your toolchain. This toolchain is compatible with buildroot.
If it does not work, maybe this link could be useful:
http://www.jumpnowtek.com/beaglebone/BeagleBone-Systems-with-Buildroot.html
It explain how to build buildroot for beaglebone. Buildroot is a build system used for embebed systems. It is easy to integrate new modules (libraries, binaries) to be build as part of the firmware. Once you have generated your binary for your target architecture, you only have to copy the necessary files into your target system.
If you decide to build with buildroot, have a look to the documentation:
https://buildroot.org/downloads/manual/manual.html
Buildroot have support for packages based on cmake, so that, even easier if you decide for it.

Disagrees about version of symbol symbol_name after insmod

I am new in kernel programming.
For implementing my project work, I have downloaded the latest stable kernel (v4.3) from kernel.org.
Just for checking I have copied a few files from the kernel directories into my project directory. Made changes to it and inserted a few more code to it.
Then I compiled on SLES11 Linux kernel using
make -C /lib/modules/$(uname -r)/build M=$PWD modules
I have used the below makefile
obj-m := my_module.o
my_module-objs := module_main.0 other_module1.o other_module2.o other_module3.o
It compiled successfully.
But when I tried to insert into the kernel using
insmod my_sample.ko
It showed the following
disagrees about version of symbol symbol_name
You need to build your kernel module against the same version kernel you are going to run. Thus if you have kernel 4.3 sources that you have downloaded you need to compile that version of the kernel and boot with that running before trying to load your kernel.
You have two solutions then:
Download the kernel sources for the kernel you are currently running (you can install those with zypper install kernel-source on SLES or an equivalent command on other distributions.)
Compile and install the 4.3 kernel in to your operating system. If you need help with this then ask a separate question (and it probably belongs on superuser not here). Note that if kernel and glibc are tightly coupled, and it is possible that you can't run a new kernel if you have a very old C library.
The problem here is that your Kernel module is using the exported symbols of other kernel modules which in this case appears to be the linux InfiniBand RDMA stack's exported methods or symbols.
To solve the symbol version problems, copy the Module.symvers file from the
/usr/src/ofa-kernel
directory and paste it to your current working directory. Then you make your modules again. Now the insmod should work perfectly fine.
NOTE: The Module.symvers file contains information of all the kernel
module exported symbol. So by copying it to your working directory,
you are helping kbuild to know more about the used exported symbols.
And if you don't find Module.symvers or it is empty, then create one using create_Module.symvers.sh
make -C /lib/modules/$(uname -r)/build M=$PWD modules,
"$(uname -r)" shows that you are compiling against the kernel version you are running now so you should be able to insmod the module in the current kernel if you haven't changed the headers.
From your text,
"Just for checking I have copied a few files from the kernel directories into my project directory. Made changes to it and inserted a few more code to it."
If you have made modifications to the kernel source then you may need to recompile the new kernel and boot with the new updated kernel. Then you should be able to compile your kernel module with the modified headers.
Looks like you built agAinst right kernel.something to do with how your kernel is compiled. (See Config_conversions). Try --force

How to compile drivers on 3.0.32-yocto-standard

I am new to yocto and developing drivers. I got source code (alter_driver.c and Makefile) for the drivers but I don't have any idea how to compile and get altera_driver.ko file, so that I can load that drivers and use them.
The version of yocto kernel is 3.0.32-yocto-standard which I got from terminal command uname -r.
Please help me in compiling the drivers. Thank you.
I suggest you read the Yocto Kernel Development Manual (the link is to current version: you should use the one for your Yocto release). If the only thing you have is a out-of-tree module, see part 2.5.2 which explains how to create a recipe for your driver.
The short version is: make a copy of the example recipe, add your sources in the files/-directory, modify the Makefile to build your sources... but read the manual, it's pretty good.
Also, the Kernel Lab may be useful: it mostly talks about working with a full kernel but also covers an out-of-tree module example (lab 4).

How to compile a module from downloaded Linux source?

I would ultimately like to modify and compile the existing Linux USB storage driver and test it. For the first step, I wanted to compile the module as is.
I downloaded the latest Linux kernel (version 3.12) and extracted it to ~/linux-3.12.
I found the driver I wanted to compile: drivers/usb/storage, but when I ran make, I got the following error:
make: *** No targets. Stop.
I found many guides online, but none of them worked for the USB storage driver. All I want is to compile this one module and get the .ko so I can test it out.
NOTE: I'm running Ubuntu 13.04 64-bit, and uname -r outputs 3.8.0-30-generic - I'm not sure if that's the problem, but I managed to compile the whole Kernel before. I don't want to do that now because it takes an eon.
If you wanted to build the drivers/usb/storage module you would do this:
make M=drivers/usb/storage
from the root directory of the kernel tree. Before doing so, you will need to make sure that your configuration is the same as the config of the running kernel.
You can't simply take the source code for one kernel and use it to build modules for another one. The module needs to be built from the same source and with the same configuration as the kernel itself.
Basically, you need to find the source code for the Ubuntu kernel you're running. In Ubuntu, as in Debian, that can be done with 'apt-get source '. The package name is probably something like 'linux-image-3.8-2-amd64'.
Once you have the source code you need to find the configuration of your running kernel. Fortunately Ubuntu keeps that in /boot/config-3.8-....
Copy that config to your kernel source tree as .config and run 'make oldconfig'. Now you should be able to build the module (assuming it's not already built into your kernel!).

Can we only recompile a kernel module in kernel source tree?

Let's say we install a kernel 2.6.32.el6, then we download the 2.6.32.el6.src.rpm, can we just install the source and modify some module, and use make -C 2.6.32.el6.src.source.directry -M$PWD in the module directory to compile the module, then we copy into /lib/modules/2.6.32.el6/kernel/moduledirectory and the new module would work?
I try to modify kvm modules and compile it, but when I recompile the module and copy it into the directory, machine said when booting:
kvm: no symbol version for module_layout
kvm_intel: no symbol version for module_layout
Anyone knows what is wrong?
Probably linux kernel 2.6.32.el6 has been compiled with modversions but your module was compiled without it. Check if you have CONFIG_MODVERSIONS selected or deselected in your kernel config file. Compare it with /proc/.config file which is the kernel confguration file - of course if you have it.
In other words - probably your linux kernel requires that modules supports versioning, but your module doesn't provide it.

Resources