A hello program for the Android Kernel module compilation method and test results in the simulator

Source: Internet
Author: User

Hello module Source:

#include <linux/init.h>

#include <linux/module.h>

static int hello_init (void)

{

PRINTK (Kern_alert "hello,world\n");

return 0;

}

static void Hello_exit (void)

{

PRINTK (Kern_alert "Goodbye, cruel world\n");

}

Module_init (Hello_init);

Module_exit (Hello_exit);

Compile Hello.ko module Makefile code:

Obj-m: = hello.o

All

Make Arch=arm extra_cflags= "-d_config_arm_-fno-pic"-C $ (Kdir) m=$ (PWD) modules

Clean

$ (make)-C $ (Kdir) m=$ (PWD) Cleanhe

Make Hello.ko function:

Make cross_compile=arm-linux-androideabi-kdir=/opt/hackandroid/goldfish_0228

Note:kdir is kernel path. What ' s kernel path??? Please refer to:http://blog.csdn.net/yygydjkthh/article/details/20172023

Tested on Android emulator:

Run Android Emulator:

EMULATOR-AVD Android4.2.2-kernel Arch/arm/boot/zimage

Push Hello.ko to Emulator:

testhello$ ADB push hello.ko/data/local

kb/s (2648 bytes in 0.042s)

Note:what is Zimage?  How get the Zimage??? Please refer to:http://blog.csdn.net/yygydjkthh/article/details/20172023

testhello$ adb shell

root@android:/# CD data/local/

Root@android:/data/local # ls

Hello.ko

Root@android:/data/local # Insmod Hello.ko

Root@android:/data/local # Dmesg-c

<1>hello,world

Root@android:/data/local # Lsmod

Hello 702 0-live 0x00000000 (PO)

Root@android:/data/local # Rmmod Hello

Root@android:/data/local # Dmesg-c

<1>goodbye, Cruel World

Root@android:/data/local # Lsmod

Root@android:/data/local #

<1>hello,world

So, that ' s OK, good night: _).

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.