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
Related
I need to perform MITM attack on a router, which is embedded linux system and its architecture is ARM. The linux kernel is 2.4.24. By MITM attack I mean intercept the packet, reedit it and send it forward. I want to use netfilter. But when I try to cross compile the LKM, I encountered plenty of problems.
As usual, a LKM Makefile is as below:
obj-m+=hello.o
KDIR = /lib/modules/$(shell uname -r)/build
all:
make -C $(KDIR) M=$(shell pwd) modules
clean:
make -C $(KDIR) M=$(shell pwd) clean
I downloaded linux kernel 2.4.24. But when it comes to the cross compile environment, the problems arise.
How to set KDIR path? The Path where linux_kernel_2.4.24.tar.gz is extracted? Do I need to cross-compile the kernel first? How?
Firstly, I set KDIR to the path of linux_kernel_2.4.24, then make, the error is "The present kernel configuration has modules disabled". By now I have not successfully make menuconfig this verion of kernel.
Secondly, I try to cross-compile on CentOS 5.4 32bit, whose kernel is 2.6.18. When I add CC=arm-linux-gcc to Makefile and set KDIR as /lib/modules/$(shell uname -r)/build, the result says "there is no arm...".
Can anyone specify how to compile LKM of the old version kernel on the latest linux? And how to cross-compile ARM version of LKM?
How to set KDIR path? The Path where linux_kernel_2.4.24.tar.gz is extracted?
Yes, just as you normally would for any other kind of module, KDIR needs to point to the built kernel source root.
Do I need to cross-compile the kernel first? How?
Yes you do. You do this by:
Downloading/compiling/installing the correct cross-compilation toolchain. For example, on Debian to get an ARM cross-compilation toolchain I can do sudo apt install binutils-arm-linux-gnueabi, which will install all the binaries you normally have in binutils with the prefix arm-linux-gnueabi- (e.g. arm-linux-gnueabi-gcc, arm-linux-gnueabi-objdump, etc...). You need all of the binutils, not only gcc.
Setting ARCH= to your desired target architecture, for example ARCH=arm.
Setting CROSS_COMPILE= to your cross-compilation toolchain prefix, for example CROSS_COMPILE=arm-linux-. This also works if you want to use a downloaded toolchain as you can specify CROSS_COMPILE=/path/to/toolchain/ assuming this directory contains all the needed executables.
Getting a valid config for the target system. If you have a .config on the system you can use that one (simply copy it from the target system into KDIR/.config) and then update it with make menuconfig.
Building with make all or whatever other target you need.
I have a Makefile made by following this example:
cross compile kernel module
I built a 4.14 Linux kernel from an older Xilinx source, and then built a out-of-kernel module with that script, pointing it to the said 4.14 kernel sources, and filling in the blanks for my particular platform architecture.
That worked.
(It's based on this code, if that matters: dma-proxy.c)
Now I need a newer version, and got Xilinx sources with a kernel named 5.6.0-rc1.
(--branch "zynqmp-soc-for-v5.7" from here)
Building that kernel also worked fine.
If I now use a scrubbed clean directory (incl. hidden files) with my module source code and that Makefile again, pointing to the newer kernel sources, it does neither produce a .ko file nor an error message.
All I get is:
make ARCH=arm64 CROSS_COMPILE="aarch64-linux-gnu-" -C /home/sk/src/XILINX/linux-xlnx SUBDIRS=/home/sk/src/XILINX/dma-proxy/driver modules
make[1]: Entering directory '/home/sk/src/XILINX/linux-xlnx'
CALL scripts/checksyscalls.sh
CALL scripts/atomic/check-atomics.sh
MODPOST 28 modules
make[1]: Leaving directory '/home/sk/src/XILINX/linux-xlnx'
No .ko file in my folder as it was before when building with 4.14, and it doesn't list actually compiling anything.
I find it curious that it says "MODPOST 28 modules", whereas with pointing it to kernel 4.14, it expectedly says "1 modules"
Has anything changed between 4.14 and 5.x that would cause this?
Mkay, here is the suggested makefile template by the tutorial I referenced in the question:
PWD := $(shell pwd)
obj-m += hello.o
all:
make ARCH=arm CROSS_COMPILE=$(CROSS) -C $(KERNEL) SUBDIRS=$(PWD) modules
clean:
make -C $(KERNEL) SUBDIRS=$(PWD) clean
Turns out that if I replace SUBDIRS=$(PWD) with M=$(PWD), it works. Now if I google explicitly for that M variable in conjunction with building kernel modules, I do find text that show it that way. But the net is also littered with examples using SUBDIRS, and it worked for me with a fairly recent kernel (4.14).
Then I did find references hinting at this being an old way of doing it, like from here:
make -C $KDIR SUBDIRS=$PWD
Same as M=. The SUBDIRS= syntax is kept for backwards compatibility.
In fact, this seems to be really old, like, kernel 2.6.7 old. Unfortunately, fairly recent tutorials show the old way.
I am looking into cross compiling a kernel module for an ARM linux. I have my toolchain installed.
But there's something I am not quite getting from various how-tos.
The module I want to build is gadgetfs.
The kernel version on my host is 3.5.0-34-generic while
on the target it's 3.6.9-0.1
Now what kernel sources or headers do I actually need to download and install, and where?
I downloaded linux-3.6.9.tar.bz2 from kernel.org and extracted it.
In drivers/usb/gadget/ there's a Makefile and according to this site I need to append these lines to it, then run make:
KDIR := /lib/modules/`uname -r`/build
PWD := `pwd`
obj-m := dummy_hcd.o gadgetfs.o
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
But what do i have to replace uname -r with? Cause this would give me my host's kernel version. But my target version is different. Where is the /lib/modules/3.6.9 folder?
CROSS_COMPILE and ARCH is both set.
You need to cross compile (or download pre-compiled) matching version of Linux for your target on your host machine with right configuration since Linux doesn't have a stable binary API. Host's kernel version is not relevant.
After having target build available on your host you can build a module via
make -C kernel_build_dir M=`pwd` ARCH=arm CROSS_COMPILE=<...> modules
under that module's directory.
I'm trying to cross compile a helloworld kernel module with specifications:
host: intel x86 32 bit, linux-3.0.0
target: ARM machine (Parrot AR.Drone), linux-2.6.27.47
I'm using the makefile:
PWD := $(shell pwd)
obj-m := test.o
all:
$(MAKE) -C /path/to/kernel M=$(PWD) CROSS_COMPILE=arm-none-linux-gnueabi- ARCH=arm modules
Where arm-none-linux-gnueabi- is the prefix of the arm toolchain.
As kernel, I tried using a clone from git://github.com/CyanogenMod/cm-kernel.git as kernel. This is a 2.6 kernel fork. Using this kernel, compilation was successfull. When trying to insert the module, it gives the error:
invalid module format
Which, sadly, says very little.
Thanks to the hint of Eugene to use dmesg, I found the error:
version magic '2.6.37.6 mod_unload modversions ARMv5 ' should be '2.6.27.47-parrot preempt mod_unload ARMv5 '
Conclusion: when compiling a kernel module, not only versions need to match, but also some config-parameters. My problem was solved by using the right version and editing the configuration.
If you don't want to reconfigure everything, a quick (ugly) fix is to edit include/generated/autoconf.h
my ugly fix is modifing script file
"scripts/setlocalversion"
170 if test "${LOCALVERSION+set}" != "set"; then
171 scm=$(scm_version --short)
172 # res="$res${scm:++}"
173 res="${res}"
174 fi
Hi, everyone.. I did found simple soulution.
just modify envirionment vairable
export LOCALVERSION=
that's all
out of sheer curiosity I tried compiling a 2.6.0 kernel on my slackware machine.
root#darkstar:/home/linux-2.6.0# uname -a
Linux darkstar 2.6.37.6-smp #2 SMP Sat Apr 9 23:39:07 CDT 2011 i686 Intel(R) Core(TM)2 Duo CPU P8600 # 2.40GHz GenuineIntel GNU/Linux
When I try compiling I get :-
root#darkstar:/home/linux-2.6.0# make menuconfig
HOSTCC scripts/fixdep
scripts/fixdep.c: In function 'traps':
scripts/fixdep.c:359:2: warning: dereferencing type-punned pointer will break strict-aliasing rules
scripts/fixdep.c:361:4: warning: dereferencing type-punned pointer will break strict-aliasing rules
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/mconf.o
scripts/kconfig/mconf.c:91:21: error: static declaration of 'current_menu' follows non-static declaration
scripts/kconfig/lkc.h:63:21: note: previous declaration of 'current_menu' was here
make[1]: *** [scripts/kconfig/mconf.o] Error 1
make: *** [menuconfig] Error 2
Some hints on what im doing wrong? Thanks!
How are you doing this to start with?
Typically, you download the latest kernel from kernel.org, copy the tarball to /usr/src, then:
1. tar -zxvvf linux-2.6.xxxx.tar.gz
2. ln -nsf linux-2.6.xxxx linux # ie: Update the "/usr/src/linux" symbolic link to
# point to the new kernel source directory
3. make menuconfig # or make xconfig
4. make modules # Build the kernel modules
5. make modules_install # Install the previously built modules for the
# new kernel
6. make bzImage # Create the boot image
At this point, DO NOT run make install. Most guides say to do this, but this is WRONG! Instead, copy the newly created bzImage file to /boot (ie: find -name bzImage /usr/src/linux, then cp to /boot), then edit your LILO configuration file (edit /etc/lilo.conf, and when done, run lilo), then reboot your system (ie: init 6 or shutdown -r now), and try out the new kernel.
The whole point of skipping the make install step is because it overwrites/replaces your existing kernel. The steps I described above allow you to have the new kernel and your existing kernel both installed and runnable in parallel. If the new kernel is broken or your left out an important option, you can still fall back to your existing stable/working kernel without the need for a boot/recovery CD/DVD.
If I recall well i think you are missing the ncurses libraries. Those are needed to create the interface with menuconfig.
Try a to do a make xconfig from an X session and see if it works.
if that is the case then the ncurses libs are definitely missing.
check with:
ls /var/log/packages/ncurses*
to see if installed