zoukankan      html  css  js  c++  java
  • Android简单驱动示例

    Android 简单驱动示例

    下面介绍在Android手机上添加简单的驱动示例程序

    1新建驱动程序

    新建程序文件hello.c

    (1) hello.c的路径如下:

    drivers/char/hello.c

    (2) hello.c的内容如下:

     1 #include <linux/init.h>
     2 #include <linux/module.h>
     3 
     4 static int __init hello_init(void)
     5 {
     6     printk("%s\n", __FUNCTION__);
     7     return 0;
     8 }
     9 
    10 static void __exit hello_exit(void)
    11 {
    12     printk("%s\n", __FUNCTION__);
    13 }
    14 
    15 module_init(hello_init);
    16 module_exit(hello_exit);
    View Code

    2修改配置文件

    修改配置文件drivers/char/Kconfig,添加以下内容:

    1 config HELLO
    2     tristate "skywang's hello driver"
    3     default m

    修改配置文件drivers/char/ Makefile,添加以下内容:

    1 obj-$(CONFIG_HELLO) += hello.o

    3编译

    执行make menuconfig,并将hello.c以.ko文件(模块)的方式编译到kernel中。如下图:

    编译生成ko文件,路径如下:

    drivers/char/hello.ko

     

    4 加载/卸载模块

    由于上面的驱动Android系统对应的驱动,因此下面讲解通过adb将驱动模块推送到内核中后再装载/卸载。

    (1)将驱动模块导入到Android系统中,通过下面的命令:

    #adb push hello.ko /system/

    (2)进入到Android系统中,通过以下命令:

    #adb shell

    (3)切换到Android系统的system目录,通过以下命令:

    #cd system

    (4) 加载模块,通过以下命令:

    # insmod hello.ko

    说明:此时输入以下打印信息,

    # hello_init

    (5)卸载模块,通过以下命令:

    # rmmod hello.ko

    说明:此时输入以下打印信息,

    # hello_exit

  • 相关阅读:
    Python xrange与range的区别返回的结果不一样
    matlab画立方体
    python查询数据类型
    Ubuntu下安装微信(electronic-wechat)
    python判断数组中是否有重复元素
    python构建数组
    Numpy中np.max(即np.amax)的用法
    你不知道C#只带有 get 访问器的属性是只读属性?
    Windows 平台安装配置 MongoDB
    一日一技:Ocelot网关使用IdentityServer4认证
  • 原文地址:https://www.cnblogs.com/skywang12345/p/AndroidDriver_Hello.html
Copyright © 2011-2022 走看看