Chinaunix首页 | 论坛 | 博客
  • 博客访问: 299346
  • 博文数量: 53
  • 博客积分: 1266
  • 博客等级: 少尉
  • 技术积分: 572
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-16 16:45
文章分类

全部博文(53)

文章存档

2012年(37)

2011年(16)

分类: 嵌入式

2012-10-05 14:50:46

    在前面内核驱动加载成功后就可以尝试用程序的方式测试该驱动了。
1、进入android源代码路径(注意不是内核源代码路径)
2、cd external
3、mkdir hello
4、cd hello
5、创建hello.c

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #define DEVICE_NAME "/dev/hello"
  5. int main(int argc, char** argv)
  6. {
  7.     int fd = -1;
  8.     int val = 0;
  9.     fd = open(DEVICE_NAME, O_RDWR);
  10.     if(fd == -1) {
  11.         printf("Failed to open device %s.\n", DEVICE_NAME);
  12.         return -1;
  13.     }
  14.     
  15.     printf("Read original value:\n");
  16.     read(fd, &val, sizeof(val));
  17.     printf("%d.\n\n", val);
  18.     val = 5;
  19.     printf("Write value %d to %s.\n\n", val, DEVICE_NAME);
  20.         write(fd, &val, sizeof(val));
  21.     
  22.     printf("Read the value again:\n");
  23.         read(fd, &val, sizeof(val));
  24.         printf("%d.\n\n", val);
  25.     close(fd);
  26.     return 0;
  27. }
6、创建Android.mk

点击(此处)折叠或打开

  1. LOCAL_PATH := $(call my-dir)
  2. include $(CLEAR_VARS)
  3. LOCAL_MODULE_TAGS := optional
  4. LOCAL_MODULE := hello
  5. LOCAL_SRC_FILES := $(call all-subdir-c-files)
  6. include $(BUILD_EXECUTABLE)
7、回到android源代码根路径
8、make hello
9、make snod
10、cd 安卓源代码路径/out/target/product/generic
11、emulator -image system.img -data userdata.img -ramdisk ramdisk.img -sdcard dcard.img -kernel 安卓内核源代码路径/kernel/goldfish/arch/arm/boot/zImage -avd a_avd&
12、验证结果

点击(此处)折叠或打开

  1. adb shell
  2. cd /system/bin
  3. ./hello



阅读(1601) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~