kernel driver external modules not building completely
Asked Answered
T

2

5

I'm adding an external driver module to an android Gingerbread kernel (works similar to Linux). I've done it before and it worked but I have a problem this time. I follow the recipe found in O'Reilly "Linux Device Drivers 3rd edition" which is:

in the local Makefile, you add those statements:

   obj-m := GobiNet.o  
   GobiNet-objs :=  GobiUSBNet.o QMIDevice.o QMI.o  

In human language it means build me a GobiNet.ko from GobiUSBNet.c + QMIDevice.c + QMI.c.

This is for the case where the makefile is called when building the whole kernel. I'm cross-compiling on a Ubuntu x86-64bit for an ARM-EABI system (Cortex-A8).

Somehow, the build system understands what I want since it says during compile time:

/home/sylvain/Projects/android_gingerbread_realv210_ver_1_0/kernel  
   CHK     include/linux/version.h  
   CHK     include/generated/utsrelease.h  
make[1]: `include/generated/mach-types.h' is up to date.  
   CALL    scripts/checksyscalls.sh  
   CHK     include/generated/compile.h  
   LD      drivers/cell/OptionGobiNet/built-in.o  
   CC [M]  drivers/cell/OptionGobiNet/GobiUSBNet.o  
   CC [M]  drivers/cell/OptionGobiNet/QMIDevice.o  
   CC [M]  drivers/cell/OptionGobiNet/QMI.o  
   LD [M]  drivers/cell/OptionGobiNet/GobiNet.o  
   Kernel: arch/arm/boot/Image is ready  
   SHIPPED arch/arm/boot/compressed/lib1funcs.S  
   AS      arch/arm/boot/compressed/lib1funcs.o  
   LD      arch/arm/boot/compressed/vmlinux  
   OBJCOPY arch/arm/boot/zImage  
   Kernel: arch/arm/boot/zImage is ready       
   Building modules, stage 2.  
   MODPOST 5 modules  
ERROR: "usbnet_suspend" [drivers/cell/OptionGobiNet/GobiNet.ko] undefined!  
ERROR: "usbnet_resume" [drivers/cell/OptionGobiNet/GobiNet.ko] undefined!  
ERROR: "usbnet_disconnect" [drivers/cell/OptionGobiNet/GobiNet.ko] undefined!  
ERROR: "usbnet_probe" [drivers/cell/OptionGobiNet/GobiNet.ko] undefined!  
make[1]: *** [__modpost] Error 1  
make: *** [modules] Error 2   

It also generates the typical "GobiNet.mod.c" and "GobiNet.o" that is generated when you want the driver as a module but it doesn't complete with the "GobiNet.ko" I would expect. I ran a "find -name *.ko" in the home directory and "GobiNet.ko" is nowhere to but found.

I also looked on the WEB and in the kernel/documentation/kbuild/*.txt. There is about 3 ways to do it. I chose the one described above because all the environment variables are set within the top build script and I don't compile native but I cross compile. Anyway, the other ".ko" in the kernel tree are generated so the build script should be good to generate the ".ko" modules.

Any idea what makes this process start but not finish with the ".ko" file?

Trow answered 18/10, 2011 at 19:14 Comment(0)
T
9

I found the solution. I really misunderstood the error messages and how ".ko" modules interact with the kernel. An external module resolves externals (at least some) at compile/link time not at run time. This is why I get the 4 "ERRORS".

That said, my "GobiNet" is looking for external symbols not present in my Kernel set-up. A few quick greps allowed me to find it needed "drivers/net/usb/usbnet.c". This required CONFIG_USBNET = y to be set in the ".config" file (set through "make xconfig"). Hope it can help someone else.

EDIT: To answer the question about "a few quick greps". What I meant is I search all the source files containing the missing names. It will tell me what file defines that symbol. Then, I can find what variable should be set to "y" to include it in the compile. Here is an example:

grep -r --include="*.c" "usbnet_probe"

You execute that in the terminal from the folder you want to search from and down recursively (-r option). grep is extremely useful to find text in large amount of files. I often don't remember the specific but a quick Google search gives you how to perform some very tricky searches you never thought could be done so easily.

Trow answered 19/10, 2011 at 13:24 Comment(2)
I got some error: aml_unregister_fe_drv ite9133_fe.ko undefinedBak
Can you please explain what you mean with "A few quick greps"? Did you follow a system or how did you determine where to seach?Gyroscope
A
1

Another possibility is that the function is defined but not exported somehow ( like you write your own new function but forgot to export, or some merge issue). The fix is then add a line like

EXPORT_SYMBOL_GPL(some_new_func);

Anorexia answered 21/6, 2021 at 23:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.