When lkm is installed with insmod in Android emulator, an error is reported, for example:
# Insmod hello. Ko
Insmod: init_module 'hello. Ko 'failed (function not implemented)
This is because the Kernel used by the emulator In the android SDK disables the lkm loading function. To develop and debug lkm in emulator, you must re-compile the kernel by yourself. The compilation method can refer to http://linuxclues.blogspot.com/2010/05/build-compile-linux-kernel-android.html.
NOTE: If it is compiled in Mac OS X, make may encounter the following errors:
Hostcc scripts/MoD/mk_elfconfig
Scripts/MoD/mk_elfconfig.c: 4: 17: Error: elf. h: no such file or directory
This is because the Mac include file lacks an elf. h
From the Internet (e.g.: http://www.rockbox.org/tracker/9006? GetFile = 16683) download a file in the scripts/MoD directory, and modify the MOD directory to reference two elf. H files.
The new compiled kernel is assumed to be zimage. We recommend that you add the-show-kernel switch when starting emulator, so that the information output by lkm using printk () can be output to the console for debugging. Example: emulator-kernel zimage-show-kernel-AVD <AVD Name>
Write a simple hello World to test it:
# Include <Linux/init. h> <br/> # include <Linux/module. h> <br/> module_license ("dual BSD/GPL"); <br/> static int hello_init (void) <br/>{< br/> printk (kern_info "Hello, world/N"); <br/> return 0; <br/>}< br/> static void hello_exit (void) <br/>{< br/> printk (kern_info "Goodbye, cruel world/N "); <br/>}< br/> module_init (hello_init); <br/> module_exit (hello_exit); <br/>
Cross-compiled makefile:
Kerneldir: =/users/quaful/documents/projects/360/kernel/<br/> pwd: = $ (shell PWD) <br/> arch = arm <br/> cross_compile =/developer/android-ndk-r4b/build/prebuilt/darwin-x86/arm-eabi-4.4.0/bin/ARM-Eabi-<br/> cc = $ (cross_compile) GCC <br/> LD = $ (cross_compile) LD <br/> obj-M: = hello. O <br/> modules: <br/> $ (make)-C $ (kerneldir) arch =$ (ARCH) cross_compile =$ (cross_compile) m =$ (PWD) modules <br/> clean: <br/> RM *. O *. ko *. mod. C *. markers *. order *. symvers <br/>
Upload the compiled hello. Ko to your mobile phone and run the following command:
Insmod hello. Ko
The result of printk is displayed in the console output of the kernel.