Adding only one driver to linux kernel - linux-kernel

I know that on the internet I can find same information about "adding one driver to linux kernel" but I can not get it working.
I need to compile an ADV7800driver. It is based on adv7180 driver code.
I put my driver file (adv7800.c) into /linux_source_folder/drivers/media/platform/mxc/capture folder. I also add
adv7800_converter-objs := adv7800.o
obj-$(CONFIG_MXC_ADV7800_CONVERTER)+=adv7800_converter.o
in makefile in the same folder and add information in Kconfigfile.
Then I go back to /linux_source_folder and do sudo make menuconfig and set adv7800 as a module and save config. Then sudo make defconfig, then sudo make -j4 modules (now waiting about 2 hours) and then sudo make modules install.
As a result I can see every module which I configure in menuconfig but I can not see my own module (only .c file exists).
How can I do this correctly and how can I build only this one module without building others (to same much time) ?

I do not remember exactly what happens in terms of instructions executed, but the idea of defconfig is to set a default configuration for a given architecture/platform.
If, as you said, you run sudo make defconfig after you configure your module to be compiled, most likely you loose your configuration. The defconfig should be executed first (once) and then you customize the configuration.
Regarding the compilation of a single module, I point you to an old answer
How to "make" existing Linux kernel module driver after modifying the driver source code.
One note: you should not use sudo to compile

Related

Modifications not taken into account when recompiling linux kernel sources

I want to use the writeprotect mode of the userfaultfd feature, but it is implemented only from Linux 5.11.
I have ubuntu 20 with kernel 5.4 so I installed version 5.11 of Linux from sources, but when I reboot on the installed version, and try to use the writeprotect mode in a c user program the macros (e.g., UFFDIO_WRITEPROTECT) still appear not to be defined. And I verified that userfaultfd is not a module (doing lsmod).
In the other hand, if I make a modification for example in the scheduler just for a test (let's say in kernel/sched/core.c:context_switch) the modification are taken into account because this is in-core, but modifications for user space are not, I'm confused.
The userfaultfd.c file is in the fs/ directory of the kernel.
So please is it something that I'm missing in the compilation process (make menuconfig, make, make modules_install, make) ?
I was wrongly interpreting the error I had.
The modifications are indeed taken into account when I boot on the newly compiled kernel.
But while searching an understanding of what happens when booting on a compiled kernel, I got this:
When booting on a kernel compiled from sources, the libraries in /usr/include are not modified on the disk
If you want to overwrite them by the one modified, you should do this:
make deb-pkg //from the kernel sources directory
cd ..
sudo dpkg -i *.deb
This will install the new kernel and overwrite the headers

Unable to compile a kernel module

I am trying to build a kernel module while compiling the kernel image, by changing the config symbol value to `'m'. But I do not see any module file generated. Please let me know if I need to take some extra steps to generated a module. If I change the flag to 'y' the code works fine.
Also, in online tutorials I have seen both of the following
>insmod temp.ko
also,
>insmod temp.o
Which one is correct type for a dynamically loadable module?
For compiling loadable kernel modules in Linux tree apply the following command
make modules
.ko is the proper kernel module extension. If .o is tried with insmod, then Invalid module format error will be displayed.
if your module has dependencies to other modules, then:
make modules to build modules
make modules_install to install them
modprobe temp.ko to load temp module and it's dependencies
if your module is simple and has no dependencies, then:
make modules to build modules
cd /path/to/module
insmod temp.ko
Wasn't using modules target in make.
First, run make menuconfig, search the module you want to build using /. Next choose 'm' or 'y' depending on when you want to compile it as a part of the kernel or build it as a module.
(If you don't want to build the entire kernel and just a single module):
Next, in the linux directory (assuming you are using vanilla kernel) run the following commands which will generate the scripts and required configuration files based on your .config
make prepare
make scripts
Now simply build the module using:
make M=<path/to/module/dir>
Finally you should have a kernel object/module (.ko) in the directory if you have selected m
hope this helps.

Cross-compile Linux kernel with additional modules

I am new to cross-compilation. I have to cross-compile a Linux kernel because I intend to use a wifi module with my TS-7500 SBC (ARM processor) and it does not support it. I have the drivers for my wifi module and through internet surfing I have come to know a general procedure of cross-compilation. However I am somewhat confused on the extra module portion. Here is the information from official website of TS-7500 regarding these extra modules:
Appendix - Compiling TS-Kernel with Custom Options
In order to compile a separate kernel module and come out with a .ko file for inclusion in the already existing kernel, these are the steps to take following step 08 and ending at step 09 above. Note: Steps after step 02 are unverified/untested. They represent an accurate procedure which one would go through.
01.) Open menuconfig and modularize the kernel feature using "M". For
example, to modularize cifs.ko, one would use the arrow and Enter keys
to navigate to Filesystems -> Network File Systems -> CIFS Support.
Press "M" to modularize CIFS support into the kernel then keep hitting
"exit" until you're prompted to save changes, choose "yes".
make menuconfig
02.) Compile the kernel with the modules and copy the modules to the Linux PC
make && make modules && make modules_install
03.) Retrieve the module which was copied to the Linux PC with a command like
cp so that it can be installed into the kernel on the MiniSD card.
mkdir /mnt/miniSD4
mount /dev/sdb4 /mnt/miniSD4
cp /lib/modules/2.6.24.4/kernel/fs/cifs/cifs.ko /mnt/miniSD4
04.) Install the module into the kernel by copy and pasting from partition 4
of the card to partition 2 on the SBC.
cp -r /dev/nbd4/cifs.ko /dev/nbd2/lib/modules/2.6.24.4/kernel/fs/cifs/cifs.ko
05.) Finally, in order to use the new module, you must enable it. This can
be included in a startup script such as linuxrc.
depmod
modprobe cifs.ko
I am confused about serial 2. Can anyone explain this to me and where am I supposed to provide address of the drivers I want to install?
Thanks in advance.
I assume that by saying that your SBC does not support it, you mean that the module/driver, that you have cross-compiled, is an 'out of source tree' kernel module.
The above procedure is only for 'in-tree kernel modules'.
This leaves you with following two options.
As a result of cross-compiling the driver, you will have an *.ko file. Transfer this file to the running system using an SD card or through network. After this load the module using
insmod /path/to/module/filename.ko
This method has but one limitation. i.e If this driver/module depends on other drivers, you will have to load them first.
Include you driver in the kernel source tree and use modprobe drivername to load it along with the dependencies. modprobe is more advance than insmod in the sense that it first checks for dependencies and loads them automatically before loading the module itself.
To include the driver in you kernel's source tree see this answer.

Kernel recompiled with same config but: cpufreq: no nforce2 chipset error

I need to compile an old kernel 2.6.23 (downloaded from linuxkernels.com) in order to use it with a real time patch (it's a long story...), I installed ubuntu 10.04 which has a kernel 2.6.32-43-generic-pae.
I decided to simple copy ubuntu configuration:
cp cp /boot/config-2.6.32-43-generic-pae /usr/src/linux-2.6.23/.config
I recompile the kernel:
make menuconfig
make
make install
make modules_install
mkinitramfs -o /boot/initrd.img-2.6.23-MYVER 2.6.23-MYVER
note that in the config I make this edit: I remove the module versioning support under loadable modules section. (this step is required by the patch).
At start, I get the title error:
cpufreq: no nforce2 chipset error
how it possible, since I copied a working configuration? Maybe is because of that only flag I disable?
Not sure, but when I copy an existing .config, I run "make oldconfig" first to make sure I'm all sync'd up. Then I run make menuconfig if I want to interactively review/change any settings.

Installing Linux Kernel Modules

I usually only work on the FreeBSD kernel and it is a bit different. I get up to the stage of making and installing the modules, but how do you actually boot the kernel that you just built?
Take a look here. Essentially it's something along the lines of make menuconfig, make all, make install, make install_modules, make install_firmware, and then tweaks in grub or lilo config.
Depends on how your system is configured, but you want to copy the bzImage file somewhere your boot loader can see it, then update configs (if necessary). On my gentoo box:
#pwd is /usr/src/linux
cp arch/i386/boot/bzImage /boot/default-kernel

Resources