编写C程序快速测试硬件驱动:
在Android 源码根目录下的external文件夹创建driver_test文件夹:
cd external
mkdir driver_test
cd driver_test
创建Android.mk:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_MODULE := driver_test LOCAL_SRC_FILES := driver_test.c include $(BUILD_EXECUTABLE)创建driver_test.c:
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> int main(int argc, char *argv[]) { int fd; int val=0; fd=open("/dev/AdrIO",O_RDWR); if(fd<0) { printf("open device failed !\n"); exit(1); } else { printf("open success ! \n"); } write(fd,argv[1],1); close(fd); return 0; }回到Android源码根目录:make driver_test
最初可能会提示错误:
host c++: libhost <= build/libs/host/pseudolocalize.cpp/bin/bash: g++: 未找到命令
make: ***[out/host/linux-x86/obj/STATIC_LIBRARIES/libhost_intermediates/pseudolocalize.o] 错误 127
解决:
sudo -i
aptitude install g++
安装完成后再执行:make driver_test
最终编译完成:
Install: out/target/product/generic/system/lib/libm.so Install: out/target/product/generic/system/bin/driver_test将out/target/product/generic/system/bin/driver_test拷贝到AM335X文件系统中,启动Android
运行:
./driver_test 1 (这时D1亮)
./driver_test 0 (这时D1灭)
测试成功,利用此方法可以快速测试android下的linux内核驱动
Android 从硬件到应用:一步一步向上爬 2 -- 运行 C 程序测试硬件驱动
原文地址:http://blog.csdn.net/wu20093346/article/details/41871467