Develop lkm programs in Android emulator

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.