Kernel Module (Cross) Compilation


jgauthier

Still Fresh
Joined
Jan 1, 2011
Messages
3
Hey all,

I've decided for fun, and learning, to get into doing some cross compilation with the caanoo. I really wanted to learn how to several things, but one of them is kernel modules. So, brief overview. I installed x64 debian inside Virtual box, and moved all the Caanoo toolchain stuff into it.

Cross compiling seemed to be no problem. Now, I went ahead and tried a kernel module. Specifically, I have an old USB wireless thing. I wanted to see if I can make it work. So, I downloaded the Caanoo kernel (from 1.06) source, and linux-wlan-ng debian package.

I was able to get the kernel modules to compile (once I got the environment right), but I cannot load them.

I get "Unknown symbol malloc_sizes". Now, I searched through the source, and there aren't any references to this in the source. So, it implies, to me, that is expected in something local. Perhaps libraries?

Anyway. I am running the firmware for 1.5, which is still kernel 2.6.24.

Are there any suggestions? I feel like I could possibly get this to work, because I am so close.

Since kernel module development seems to be tightly integrated with the kernel itself, I almost feel like I could tweak some kernel config settings to get this to go.
Still, this is new territory for me, so I'm not sure.

Thanks!
 
I think you need to build the kernel in the crosscompiling environment to get the headerfiles. This has to be done with the exact same configuration, the kernel on the canoo is built.
 
I found in the caanoo kernel source a .configUP. I am assuming this is the proper config.
I renamed it to .config, and I was able to make the kernel, modules, everything.

I then cleaned and recompiled my driver source, but loading it on the caanoo still results in the same undefined variable.
It looks like it comes from the slab allocator.. and it's referenced in slab.c and slab.h in the kernel source.

But, I'm stuck on how to proceed :(
 
Tried mount --bind'ing /usr/lib/modules... @ your own build & running depmod? Just a shot in the dark. Good luck! :)
 
here is the .config file i've used to sucessfully cross-compile my rtl8712 wireless patched driver :
http://zx81.zx81.free.fr/public/caanoo/drivers/linux-2.6.24-pollux-config.tar.bz2

where are the source of your driver ? how did you tried to compile it ?

What i've done is to setup properly the .config file in the kernel-2.6.24-pollux folder, cross-compile the kernel and then i compile the wireless driver as follows :

make ARCH=arm CROSS_COMPILE=arm-gph-linux-gnueabi- -C /usr/local/caanoodev/linux-2.6.24-pollux/ M=/home/zx81/caanoo/dev/wifi-drivers/rtl8712_8188_8191_8192SU modules

where :
/usr/local/caanoodev/linux-2.6.24-pollux/ is the kernel source/compiled kernel

/home/zx81/caanoo/dev/wifi-drivers/rtl8712_8188_8191_8192SU is the location of the makefile of my driver
 
z,

I really appreciate your input. I dropped your config into my kernel and compiled it. Worked fine.
I then compiled my sources (http://www.linux-wlan.com -- ftp://ftp.linux-wlan.org/pub/linux-wlan-ng/)

This time, the modules loaded with the malloc_sizes error. That's fantastic! There is obviously something different between my original kernel compile, and this one.
Can you let me know where the .config came from?

This device (a prism2 usb) has two modules. p80211.ko loads. unfortuantely, prism2_usb.ko seg faults :) But, it is progress!

prism2usb_init: prism2_usb.o: 0.2.9 Loaded
prism2usb_init: dev_info is: prism2_usb
Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = c2d6c000
[00000000] *pgd=02d62031, *pte=00000000, *ppte=00000000
Internal error: Oops: 817 [#1]
Modules linked in: prism2_usb(F) p80211(F) g_ether lf1000_udc usbhid hid hcd9032 usb_stora ge libusual usbcore sd_mod scsi_mod ad7993 rtc_isl1208 rtc_core
CPU: 0 Tainted: GF (2.6.24 #107)
PC is at dev_alloc_name+0x20/0x50
LR is at register_wlandev+0x20/0x104 [p80211]
pc : [<c01746e8>] lr : [<bf08907c>] psr: 60000013
sp : c2d61d60 ip : c2d61d90 fp : c2d61d8c
r10: c4794000 r9 : c2d59460 r8 : 00000000
r7 : bf09a0a8 r6 : c2d61d60 r5 : c2df6800 r4 : c2df6400
r3 : 00000003 r2 : 20000013 r1 : bf08a208 r0 : 00000000
Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 0005317f Table: 02d6c000 DAC: 00000015
Process insmod (pid: 518, stack limit = 0xc2d60268)


I really think the scope of this is outside of this forums now, because we're getting into dirty kernel areas ;)
But, thanks for the help! This has been a good learning tool.

(BTW, i had no problems with your rt driver... just don't have one of those)

I have an acx chipset around here somewhere.. I think i will play with it next.. unfortunately, it uses hotplug to get it's non-open firmware.
 
jgauthier said:
...
This time, the modules loaded with the malloc_sizes error. That's fantastic! There is obviously something different between my original kernel compile, and this one.
Can you let me know where the .config came from?

I can't remember where i've found it, may be on this forum (on thread dealing with kernel/module compilation) or on fungp web site.

jgauthier said:
...
This device (a prism2 usb) has two modules. p80211.ko loads. unfortuantely, prism2_usb.ko seg faults :) But, it is progress!

...

I really think the scope of this is outside of this forums now, because we're getting into dirty kernel areas ;)
But, thanks for the help! This has been a good learning tool.

(BTW, i had no problems with your rt driver... just don't have one of those)

I have an acx chipset around here somewhere.. I think i will play with it next.. unfortunately, it uses hotplug to get it's non-open firmware.

For the RT driver, i've tried several version before to find the one that works with this kernel version. May be you can do the same with your module.
 
Last edited by a moderator:
Hi, I tried compiling the kernel, but I got:

Code:
TG-613 linux-2.6.24-pollux # make ARCH=arm CROSS_COMPILE=arm-gph-linux-gnueabi- -C /home/daniel/Desktop/linux-2.6.24-pollux/ M=/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0 modules
make: arm-gph-linux-gnueabi-gcc: Command not found
make: Entering directory `/home/daniel/Desktop/linux-2.6.24-pollux'

  WARNING: Symbol version dump /home/daniel/Desktop/linux-2.6.24-pollux/Module.symvers
           is missing; modules will have no dependencies and modversions.

scripts/Makefile.build:46: *** CFLAGS was changed in "/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/Makefile". Fix it to use EXTRA_CFLAGS.  Stop.
make: *** [_module_/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0] Error 2
make: Leaving directory `/home/daniel/Desktop/linux-2.6.24-pollux'
 
Com64 said:
Hi, I tried compiling the kernel, but I got:

Code:
 TG-613 linux-2.6.24-pollux # make ARCH=arm CROSS_COMPILE=arm-gph-linux-gnueabi- -C /home/daniel/Desktop/linux-2.6.24-pollux/ M=/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0 modules
 make: arm-gph-linux-gnueabi-gcc: Command not found
 make: Entering directory `/home/daniel/Desktop/linux-2.6.24-pollux'
 
   WARNING: Symbol version dump /home/daniel/Desktop/linux-2.6.24-pollux/Module.symvers
            is missing; modules will have no dependencies and modversions.
 
 scripts/Makefile.build:46: *** CFLAGS was changed in "/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/Makefile". Fix it to use EXTRA_CFLAGS.  Stop.
 make: *** [_module_/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0] Error 2
 make: Leaving directory `/home/daniel/Desktop/linux-2.6.24-pollux'

looks like he couldn't find your crosscompiler 'arm-gph-linux-gnueabi-gcc'.

lenrlad
 
Last edited by a moderator:
zx-81 said:
you need to have 'arm-gph-linux-gnueabi-gcc' in your PATH.
Okay, I've done that. Now I get this:
Code:
TG-613 daniel # make ARCH=arm CROSS_COMPILE=arm-gph-linux-gnueabi- -C /home/daniel/Desktop/linux-2.6.24-pollux/ M=/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0 modules
make: Entering directory `/home/daniel/Desktop/linux-2.6.24-pollux'

  WARNING: Symbol version dump /home/daniel/Desktop/linux-2.6.24-pollux/Module.symvers
           is missing; modules will have no dependencies and modversions.

scripts/Makefile.build:46: *** CFLAGS was changed in "/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/Makefile". Fix it to use EXTRA_CFLAGS.  Stop.
make: *** [_module_/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0] Error 2
make: Leaving directory `/home/daniel/Desktop/linux-2.6.24-pollux'

EDIT:
I've fixed that CFLAGS problem, but now I have another one:
Code:
TG-613 linux-2.6.24-pollux # make ARCH=arm CROSS_COMPILE=arm-gph-linux-gnueabi- -C /home/daniel/Desktop/linux-2.6.24-pollux/ M=/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0 modules
make: Entering directory `/home/daniel/Desktop/linux-2.6.24-pollux'

  WARNING: Symbol version dump /home/daniel/Desktop/linux-2.6.24-pollux/Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.o
In file included from /home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:38:
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rt_config.h:96:29: error: asm-i386/atomic.h: No such file or directory
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c: In function 'CMDHandler':
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1079: warning: unused variable 'pkey'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1078: warning: unused variable 'i'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c: In function 'usb_rtusb_probe':
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1770: error: implicit declaration of function 'SET_MODULE_OWNER'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1779: error: 'struct net_device' has no member named 'get_wireless_stats'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1787: error: 'struct net_device' has no member named 'weight'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1807: error: 'dev_base' undeclared (first use in this function)
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1807: error: (Each undeclared identifier is reported only once
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1807: error: for each function it appears in.)
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1807: error: 'struct net_device' has no member named 'next'
make[1]: *** [/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.o] Error 1
make: *** [_module_/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0] Error 2
make: Leaving directory `/home/daniel/Desktop/linux-2.6.24-pollux'
 
Last edited by a moderator:
Code:
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rt_config.h:96:29: error: asm-i386/atomic.h: No such file or directory

The driver tries to include a i386 processor-specific header file, which can not be found in the kernel tree because it was configured
for the ARM processor family.

Either that driver has not been ported properly to support ARM, or it is not configured correctly. Look into rt_config.h, line 96 and
see under what conditions "asm-i386/atomic.h" is included...
 
hmn said:
Code:
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rt_config.h:96:29: error: asm-i386/atomic.h: No such file or directory

The driver tries to include a i386 processor-specific header file, which can not be found in the kernel tree because it was configured
for the ARM processor family.

Either that driver has not been ported properly to support ARM, or it is not configured correctly. Look into rt_config.h, line 96 and
see under what conditions "asm-i386/atomic.h" is included...
Hm... Line 96 just says:
Code:
#include <asm-i386/atomic.h>

So I pointed it to asm-arm instead. Still get another error message, I'll have to sort that out...

Code:
TG-613 linux-2.6.24-pollux # make ARCH=arm CROSS_COMPILE=arm-gph-linux-gnueabi- -C /home/daniel/Desktop/linux-2.6.24-pollux/ M=/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0 modules
make: Entering directory `/home/daniel/Desktop/linux-2.6.24-pollux'

  WARNING: Symbol version dump /home/daniel/Desktop/linux-2.6.24-pollux/Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.o
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c: In function 'CMDHandler':
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1079: warning: unused variable 'pkey'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1078: warning: unused variable 'i'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c: In function 'usb_rtusb_probe':
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1770: error: implicit declaration of function 'SET_MODULE_OWNER'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1779: error: 'struct net_device' has no member named 'get_wireless_stats'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1787: error: 'struct net_device' has no member named 'weight'
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1807: error: 'dev_base' undeclared (first use in this function)
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1807: error: (Each undeclared identifier is reported only once
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1807: error: for each function it appears in.)
/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.c:1807: error: 'struct net_device' has no member named 'next'
make[1]: *** [/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0/rtusb_main.o] Error 1
make: *** [_module_/home/daniel/Desktop/lan/RT25USB-SRC-V2.0.8.0] Error 2
make: Leaving directory `/home/daniel/Desktop/linux-2.6.24-pollux'

Line 1770:
Code:
	SET_MODULE_OWNER(pAdapter->net);
Line 1779:
Code:
	netdev->get_wireless_stats = RTUSB_get_wireless_stats;
Line 1787:
Code:
	pAdapter->net->weight = 64;
Line 1807:
Code:
			for (device = dev_base; device != NULL; device = device->next)
 
Last edited by a moderator:
I think you should forget about that RT driver package... it seems to be ancient! There is a driver for RT2xxx in the kernel tree. That one should be much easier to get to work...
 
hmn said:
I think you should forget about that RT driver package... it seems to be ancient! There is a driver for RT2xxx in the kernel tree. That one should be much easier to get to work...
Edit:
Sweet! I downloaded a Linux driver from here:
http://sourceforge.net/projects/rt2400/files/Final%20software%20release/rt2570-legacy-final-cvs/rt2570-cvs-daily.tar.gz/download

Then I compiled it, and it worked. I can't wait to try it out.
Edit: I'm having trouble getting it onto my Caanoo's internal memory. It's read-only.
 
Last edited by a moderator:
EDIT: Posted this too late, but still might be helpful :)

Starting with zx-81's .config, start the configuration menu:
Code:
.../linux-2.6.24-pollux$ make menuconfig CROSS_COMPILE=arm-gph-linux-gnueabi-
In "Device Drivers/Network device support/Wireless LAN" set "Ralink rt2500 usb support" to <M>.

Exit the menu and compile the modules:
Code:
.../linux-2.6.24-pollux$ make modules CROSS_COMPILE=arm-gph-linux-gnueabi-
There will be several modules of interest after compiliation, not sure if you need all of them:
Code:
./net/ieee80211/ieee80211.ko
./net/ieee80211/ieee80211_crypt.ko
./net/wireless/cfg80211.ko
./net/mac80211/mac80211.ko
./crypto/pcbc.ko
./crypto/arc4.ko
./crypto/aes_generic.ko
./crypto/ecb.ko
./drivers/net/wireless/rt2x00/rt2500usb.ko
./drivers/net/wireless/rt2x00/rt2x00lib.ko
./drivers/net/wireless/rt2x00/rt2x00usb.ko
 
hmn said:
EDIT: Posted this too late, but still might be helpful :)

Starting with zx-81's .config, start the configuration menu:
Code:
.../linux-2.6.24-pollux$ make menuconfig CROSS_COMPILE=arm-gph-linux-gnueabi-
In "Device Drivers/Network device support/Wireless LAN" set "Ralink rt2500 usb support" to <M>.

Exit the menu and compile the modules:
Code:
.../linux-2.6.24-pollux$ make modules CROSS_COMPILE=arm-gph-linux-gnueabi-
There will be several modules of interest after compiliation, not sure if you need all of them:
Code:
./net/ieee80211/ieee80211.ko
./net/ieee80211/ieee80211_crypt.ko
./net/wireless/cfg80211.ko
./net/mac80211/mac80211.ko
./crypto/pcbc.ko
./crypto/arc4.ko
./crypto/aes_generic.ko
./crypto/ecb.ko
./drivers/net/wireless/rt2x00/rt2500usb.ko
./drivers/net/wireless/rt2x00/rt2x00lib.ko
./drivers/net/wireless/rt2x00/rt2x00usb.ko
hm...
I did all that with a driver I found online, and ended up with rt2570.ko, which I then copied to my SD card, along with a script to load everything. Turns out, I've done something wrong. Anyway, I'm going to try what you just posted.
 
Last edited by a moderator:
Quote from the Sourceforge page:
As of 2009-04-23 0:00:00 UTC, this project is no longer under active development.
The Legacy Ralink drivers have permanently been deprecated in favor of the in-kernel rt2x00 drivers.

The "legacy" driver may still work though...
 
hmn said:
Quote from the Sourceforge page:
As of 2009-04-23 0:00:00 UTC, this project is no longer under active development.
The Legacy Ralink drivers have permanently been deprecated in favor of the in-kernel rt2x00 drivers.

The "legacy" driver may still work though...

EDIT:
Well, I can't get it to work. I'll try those legacy drivers as a last resort.
Code:
# /sbin/insmod /mnt/sd/stuff/rt2570.ko
# /sbin/ifconfig rausb0 up
ifconfig: SIOCSIFFLAGS: Invalid argument
# /lib/modules/2.6.24/kernel/net/wireless/tools/iwconfig rausb0 mode auto essid nelson key 7782337221abc channel auto nickname "caanoo"
Error for wireless request "Set Mode" (8B06)  : 
SET failed on device rausb0 ; Network is down.

Also, for some reason, the Caanoo slows down a LOT after doing "/sbin/insmod /mnt/sd/stuff/rt2570.ko".
 
Last edited by a moderator:
Back
Top