测试Linux内核驱动程序
来源:互联网 发布:linux系统漏洞修复 编辑:程序博客网 时间:2024/06/07 01:19
- 综述
- 内置C可执行程序测试Linux内核驱动程序
- 创建hello目录
- 新建helloc文件
- 新建Androidmk
- 使用mmm命令进行编译
- 重新打包systemimg
- 测试
综述
在编写Linux内核驱动程序中,我们介绍了如何在Ubuntu上为Android系统编写Linux内核驱动程序。在这个名为hello的Linux内核驱动程序中,创建三个不同的文件节点来供用户空间访问,分别是传统的设备文件/dev/hello、proc系统文件/proc/hello和devfs系统属性文件/sys/class/hello/hello/val。
在这一篇文章里,我们将通过自己编写的C可执行程序来访问设备文件/dev/hello
内置C可执行程序测试Linux内核驱动程序
创建hello目录
进入到Android源代码工程的external目录,创建hello目录
新建hello.c文件
在hello目录中新建hello.c文件:
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #define DEVICE_NAME "/dev/hello" int main(int argc, char** argv) { int fd = -1; int val = 0; fd = open(DEVICE_NAME, O_RDWR); if(fd == -1) { printf("Failed to open device %s.\n", DEVICE_NAME); return -1; } printf("Read original value:\n"); read(fd, &val, sizeof(val)); printf("%d.\n\n", val); val = 5; printf("Write value %d to %s.\n\n", val, DEVICE_NAME); write(fd, &val, sizeof(val)); printf("Read the value again:\n"); read(fd, &val, sizeof(val)); printf("%d.\n\n", val); close(fd); return 0; }
这个程序的作用中,打开/dev/hello文件,然后先读出/dev/hello文件中的值,接着写入值5到/dev/hello中去,最后再次读出/dev/hello文件中的值,看看是否是我们刚才写入的值5。从/dev/hello文件读写的值实际上就是我们虚拟的硬件的寄存器val的值。
新建Android.mk
在hello目录中新建Android.mk文件:
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)
注意,BUILD_EXECUTABLE表示我们要编译的是可执行程序。
使用mmm命令进行编译
mmm ./external/hello
编译成功后,就可以在out/target/product/gerneric/system/bin目录下,看到可执行文件hello了。
重新打包system.img
make snod
这样,重新打包后的system.img文件就包含刚才编译好的hello可执行文件了
测试
运行模拟器,使用/system/bin/hello可执行程序来访问Linux内核驱动程序
“`
USER-NAME@MACHINE-NAME:~/Android$ emulator -kernel ./kernel/common/arch/arm/boot/zImage &
USER-NAME@MACHINE-NAME:~/Android$ adb shell root@android:/ # cd system/bin root@android:/system/bin # ./hello Read the original value: 0. Write value 5 to /dev/hello. Read the value again: 5.
“`
看到这个结果,就说我们编写的C可执行程序可以访问我们编写的Linux内核驱动程序了。
- 测试Linux内核驱动程序
- Android系统内置C可执行程序测试Linux内核驱动程序
- Linux内核:驱动程序
- linux 驱动程序 内核数据类型
- 编写Linux内核驱动程序
- linux内核模块和驱动程序
- Linux内核驱动程序初始化顺序
- linux-0.11内核 硬盘驱动程序
- Linux内核USB主设备驱动程序
- 第一个Linux内核驱动程序
- linux 3.6 内核驱动程序编写
- linux设备驱动程序内核机制
- 在Ubuntu上为Android系统内置C可执行程序测试Linux内核驱动程序
- 在Ubuntu上为Android系统内置C可执行程序测试Linux内核驱动程序
- 在Ubuntu上为Android系统内置C可执行程序测试Linux内核驱动程序
- 在Ubuntu上为Android系统内置C可执行程序测试Linux内核驱动程序
- 在Ubuntu上为Android系统内置C可执行程序测试Linux内核驱动程序
- 在Ubuntu上为Android系统内置C可执行程序测试Linux内核驱动程序
- [Noi2010] D1T1 能量采集 (欧拉函数)
- 第2周【项目3
- JVM内存模型及String对象内存分配
- 结构体对齐
- 初识软件测试
- 测试Linux内核驱动程序
- 链路层
- liunx 防火墙操作
- spring boot 接受ajax数组
- unbuntu 37~16.04.1 安装IDEA
- android 修改viewpage滑动速度
- 分享一下赶集网的反扒策略
- 深入理解Thread.sleep的含义
- Unity 动态修改UGUI的Image