Android驱动开发---Linux Kernel/HAL Layer/Jni Layer实例全集

栏目: Android · 发布时间: 7年前

内容简介:本人在开发Android Nfc POS之初,探索调试了一番驱动,目前在Nexus 5X 7.1.1上已经调成,之前的步骤可以参考我发的文章,Android驱动开发经验分享如下。/

本人在开发Android Nfc POS之初,探索调试了一番驱动,目前在Nexus 5X 7.1.1上已经调成,之前的步骤可以参考我发的文章,Android驱动开发经验分享如下。

1. Linux 内核驱动实例

以下均在Android Linux内核目录下操作, 在drivers目录下创建驱动目录hello

这个目下要创建3个文件,hello.c, Makefile and Kconfig

1.1 hello.c

cd drivers

mkdir hello

vim hello.c
code as follows:

/ linux kernel driver: hello.c => /dev/hello /

please find the code in the below. here skip the code to make the page clean and clear.

1.2 Makefile

Create the Makefile and add:

obj-y += hello.o

1.3 Kconfig

Create Kconfig and add:

config HELLO 
    tristate "Eric: First Android Driver"
default n
help
  This is the first Android driver.

this file is used when we make menuconfig.

1.4 Modify drivers/Makefile

Add following in the end

obj-y += hello.o

1.5 Add the driver into system configuration

Before we build the kernal, we need to config the system.

1.5.1 Modify arch/arm64/Kconfig

Add following in the end

source "drivers/hello/Kconfig"

It seems that this config not work, may be skipped.

1.5.2 Modify drivers/Kconfig

Following the menu:

menu "Device Drivers"

Please add

source "drivers/hello/Kconfig"

1.5.3 Modify drivers/Kconfig

make menuconfig

To enble the menu 'Eric: First Android Driver' in the "Device Drivers" item.

And save , then to build the linux kernel code.

2. 测试驱动

以下是需要操作的目录在AOSP目录下

2.1 create the application on externel

在external下创建hello目录

目录下将有两个文件:hello.c and Android.mk

cd external

mkdir hello

vim hello.c

/ AOSP app : ./external/hello.c =>/system/bin/hello /

Android.mk as follows:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello
LOCAL_SRC_FILES := $(call all-subdir-c-files)
include $(BUILD_EXECUTABLE)

2.2 build the application

To build the hello application

mmm external/hello/

Add it into the system.img

make snod

2.3 Test/Debug the driver hello

Before flash, we can build the AOSP again, of cource, don't forget replace the linux kernel file 'Image.gz-dtb'.

After flash into the phone, reboot the phone, and then do follows:

C:\Users\ylgi>adb devices
List of devices attached
01059f9781509a67        device

C:\Users\ylgi>adb -s 01059f9781509a67 shell
bullhead:/ $ ls

Android驱动开发---Linux Kernel/HAL Layer/Jni Layer实例全集

cd /system/bin
./hello

Android驱动开发---Linux Kernel/HAL Layer/Jni Layer实例全集

运行效果如上图,表示 Linux 驱动已经成功加载。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

菜鸟侦探挑战数据分析

菜鸟侦探挑战数据分析

[日] 石田基广 / 支鹏浩 / 人民邮电出版社 / 2017-1 / 42

本书以小说的形式展开,讲述了主人公俵太从大学文科专业毕业后进入征信所,从零开始学习数据分析的故事。书中以主人公就职的征信所所在的商业街为舞台,选取贴近生活的案例,将平均值、t检验、卡方检验、相关、回归分析、文本挖掘以及时间序列分析等数据分析的基础知识融入到了生动有趣的侦探故事中,讲解由浅入深、寓教于乐,没有深奥的理论和晦涩的术语,同时提供了大量实际数据,使用免费自由软件RStudio引领读者进一步......一起来看看 《菜鸟侦探挑战数据分析》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具