本人在开发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 */
/create the device file: /sys/class/hello/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*/