I will like to know how do the kernel builder to compile parrot modules while compiling the kernel.
I saw a config file for 2.6.32 that has the CONFIG_PARROT modules to yes. And I know where this modules files are stored on the kernel 2.6.32 source. I want a 2.6.37 kernel builder to make this parrot modules and add them to the kernel so I can use them on a VM.
Beside adding the path to the drivers source on the Makefile and setting the CONFIG_PARROT lines to the .config file of the kernel, is there something else to do?
Related
I'm just curious if it is possible to compile a Linux kernel driver (* .ko binary) with only Linux kernel sources?
Is it inevitable to have a compiled Linux kernel to compile a Linux kernel driver?
I have source code pack which includes eCos source, GSS-3.2.1 compiler and and GCC-toolchain. I want to compile source code for MIPS32 target CPU. The host PC is Ubuntu Linux x86/64. The 'Readme' file have short instructions for building GCC 3.2.1 and eCos library.
As was specified there, in order to compile eCos, I will need to download GCC version 3.2.1 (GCC 3.2.1). In addition, there are note: "The build instructions given here are for the default GCC target platform CPU(i686-linux). This means that the library files created here can not be loaded onto a BRCM MIPS CPU."
Whereas, I want to create files specifically for Broadcom MIPS32 CPU. (BCM33xx)
So, its not clear, how to compile source code for embedded MIPS32 CPU on Linux x86/64 host PC?
Edit: Source package includes also gcc cross-compiler toolchain (gcc-toolchain.tar), containing folder tree:
/usr/local/ecos20/gnutools/mipsisa32-elf-i386-linux/
Then it's not clear does anything else is needed to compile code and all library files for MIPS32?
I've been spending the last week trying to reach one objective that i still haven't reached.
My final goal would be to cross-compile for some architectures (in this question i will take as an example only one which is MIPSLE) a couple of kernel modules that i'd like to use on my home router, by loading them at runtime with INSMOD.
My router is missing of some iptables functionalities and that's why during the kernel compilation, who compiled it decided to get rid of them.
The current kernel version is quite obsolete: Linux version 2.6.36+ by doing /proc/version
I read a lot of documentations and still i'm not sure if it possible to compile just some modules or if it's necessary to compile the whole kernel everytime (some people said that for some modules is possible and for others with more dependencies is not, is that true ?).
In this case the kernel modules i need are located in /net/ipv4/netfilter/
Since i didn't get how to compile just kernel modules in a standalone way, i decided to cross-compile the entire kernel and take the modules i needed.
So i've downloaded the proper toolchain (uclibc mipsle toolchain) and i was successfull in compiling a simple working hello world that i've executed on my router where i have an ssh shell.
So i'm sure that the toolchain i'm using it's the correct one.
Now, since i wanted to test with a recent version of kernel i've downloaded the latest ubuntu 20 with correspective kernel and i've successfully compiled it and the kernel modules that i was speaking about before, were there inside the netfilter folder in .ko format , PERFECT !
I clearly used the /boot/config_file of my host machine as .config
So, after I've downloaded the exact same kernel version that my router has (2.6.36) and I've tried to compile it with a .config file that i've found on GitHub related to a mipsle device with my same kernel version.
Here i think we have the first problem, I tried to find the .config of my device in order to have a smooth configuration but i don't have the /boot folder and in also was not in /proc.
How can i get it?
Anyway, I've used it and the compilation didn't look like failed, but these are the last lines:
CC drivers/usb/storage/usual-tables.o
LD drivers/usb/storage/usb-storage.o
LD drivers/usb/storage/built-in.o
LD drivers/usb/built-in.o
LD drivers/video/built-in.o
LD drivers/built-in.o
LD vmlinux.o
MODPOST vmlinux.o
GEN .version
CHK include/generated/compile.h
UPD include/generated/compile.h
CC init/version.o
LD init/built-in.o
LD .tmp_vmlinux1
KSYM .tmp_kallsyms1.S
AS .tmp_kallsyms1.o
LD .tmp_vmlinux2
KSYM .tmp_kallsyms2.S
AS .tmp_kallsyms2.o
LD vmlinux
SYSMAP System.map
SYSMAP .tmp_System.map
OBJCOPY arch/mips/boot/vmlinux.bin
Building modules, stage 2.
MODPOST 1 modules
CC drivers/scsi/scsi_wait_scan.mod.o
LD [M] drivers/scsi/scsi_wait_scan.ko
It says "1 Modules" but I don't understand why and inside the /net/ipv4/netfilter folder now I have .o files instead of .ko like if they've not been linked.
Since i was getting mad and I didn't know what to try more after several attempts, I've decided to use the config file of my host machine (ubuntu 2020, kernel 5.4.0.26) and the compilation was successful, with .ko files inside the folder.
The problem was that obviously they were modules compiled for x86-64 instead of MIPS and other clear "problems" related to the configuration of my x86-64 machine.
So, what i think now is that the .config I've found could be broken somehow, I also tried to disable, by adding a comment, that SCSI module, but nothing, I always get the same stuff.
And obviously between each try I always did a make distclean and make clean.
What do you suggest me to do? I won't even post all the references i've read about this stuff because i could sigsegv StackOverflow's server with that amount of data.
Thanks to everyone and sorry for the wall-post.
i'm not sure if it possible to compile just some modules or if it's necessary to compile the whole kernel every time
Well, you can compile just single modules, but compiling a module requires the kernel to be already built. Once you do that one time though, you should be able to compile other modules singularly. That is, of course, if you do not wish to embed them in the kernel itself (CONFIG_XXX=y instead of CONFIG_XXX=m). You should be able to compile only the module you want like this (assuming /path/to/linux is the directory where your already built kernel source resides):
$ cd /path/to/linux
$ cd path/to/module/folder
$ make -C /path/to/linux M=$(pwd) modules
I tried to find the .config of my device in order to have a smooth configuration but i don't have the /boot folder and it also was not in /proc. How can i get it?
Where did you look precisely? The presence of /proc/config.gz depends on CONFIG_IKCONFIG_PROC (see also here). If you cannot find the file then it's most likely because that configuration option was disabled when the kernel was built. You may try look under /boot (as you already did), or under /lib/modules/$(uname -r)/build/.config, but unfortunately there's not much else to do otherwise.
I've seen people suggest trying to run modprobe configs and then check /proc/config.gz, but that seems strange since as far as I know the kernel config shouldn't be configurable to be available as a loadable module.
What do you suggest me to do?
Well, the most important thing you want right now is to find the configuration file for your router (or a compatible one). If you cannot find that, it will be pretty hard to get everything right. You might want to search for OpenWRT versions available for your router (if any), or really anywhere else on the internet as long as you can find a suitable configuration. Include your router brand and/or model in your searches. StackOverflow can't really help you that much about this though.
You can try cross-compiling a 5.4 kernel with default config plus the module you want. For example, assuming you have the right cross-compilation toolchain ready:
cd /path/to/linux
make ARCH=mips CROSS_COMPILE=your-cross-toolchain-prefix- defconfig
make ARCH=mips CROSS_COMPILE=your-cross-toolchain-prefix- menuconfig
# ... enable the module, tune the config ...
make -j ARCH=mips CROSS_COMPILE=your-cross-toolchain-prefix-
In any case, consider the fact that jumping from a 2.6 to a 5.4 kernel is a pretty big change, and it's likely to end up breaking everything, so be sure to make a backup of your router's firmware before trying anything.
I am trying to insert a .ko kernel module into the linux running in arm processor. I built a .ko file in my desk PC which is a x86 one. How do I cross compile it to arm specs. I am new to this field.
Thanks in advance
For that you need to download the ARM compilers first. I suggest you download the compiler from http://www.linaro.org/downloads/ then set the CROSS_COMPILE environment variable to arm-linux-gcc.
set the bin directory path in PATH variable.You can do it by export PATH=$PATH:/path/to/arm/binaries/
Finally compile the code then run in ARM.
use file <filename> whether it is ARM executable or not.
For this you have to do the following steps.
Check you have cross compiler tool chain or not.
If you don't have cross compiler tool chain
you can download from one of the free ARM cross compiler from net.
You can generate your own cross tool chain using Buildroot tool. below you can get the link of Buildroot user manual.
http://buildroot.uclibc.org/downloads/manual/manual.html#_using_buildroot
Install cross tool chain in your host PC.
Export the cross tool chain path in your host PC using export command.
Change the make file of the kernel module to set the compiler as CROSS_COMPILE.
Do make.
Move the .ko file to target and insert it.
I made certain modifications in hid module.
I can make it and load (insmod) it on kernel v 2.6.27.14 sucessfully
Now I am willing to load the same kernel module on kernel v 2.6.27.11
As there is no differance in the kerbel source files for both the kernel versions
I can make it sucessfully, but I cannot add / insmod in this .11 kernel version
**
ERROR: Module myhid does not exist in /proc/modules
insmod: error inserting 'myhid.ko': -1 Invalid module format
**
Regards,
You can't load a module compiled for another kernel version. That the source code of the module did not change does not mean that the binary will be the same for another kernel version. Any interface change of kernel internal APIs (even when not directly visible) will break the module...
Therefore, the kernel stays on the safe side by disallowing loading of modules that were built for another kernel version. Alternatively, you can set the MODVERSIONS configuration option when building your kernel. This will embed version information into all symbols used by your module and with luck you can load it on another kernel version.
If any interface used by your module changed, the result will be the same though.
see what "modinfo" tells you about your module:
Check that it's compiled properly, linked to the right kernel.
$ modinfo hid
filename: /lib/modules/2.6.27.7/kernel/drivers/hid/hid.ko
license: GPL
depends:
vermagic: 2.6.27.7 mod_unload 486
parm: pb_fnmode:Mode of fn key on Apple keyboards (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst) (int)
When you compile/install modules, don't forget that you have to run "depmod" (as root) to rebuild the modules dependancies before running insmod/modprobe.
Thanks ! Here is the make file . I dowload all the dependent source files for HID.O and rename them
MAKEFILE
obj-m := myhid.o
myhid-objs := my-hiddraw.o my-hid-core.o my-hid-input.o my-hid-input-quirk.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules