ok6410 android driver(3)
This article discusses the Makefile and how to port the module to different platform (localhost and arm).
1、localhost
My localhost system is debian wheezy.
If you would like to set up the environment for user-mode, you can follow the website :
http://www.cnblogs.com/plinx/p/3149216.html
Acturely, we could also just use the $(shell uname -r) kernel version in our system.
The different between these two is which command we need to enter for 'make'.
//user-mode
$ make
//$(shell uname -r)
$ sudo make
Here is the Makefile :
obj-m := word_count1.o
obj-m += word_count2.o KDIR := /lib/modules/$(shell uname -r)/build
#KDIR := /home/linx/Android/forlinx/android2.3_kernel_v1.
PWD := $(shell pwd)
#ARCH := arm
#CROSS := arm-linux- modules:
$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS) -C $(KDIR) M=$(PWD) modules allclean:
rm -f *.o *.ko *.mod.c *.mod.o
clean:
rm -f *.o *.mod.c *.mod.o .PHONY : allclean
.PHONY : clean
If you would like to use the kernel you compile for device driver, just correct the $(shell uname -r) to your directory.
In the word_count2.c(in previous article), we create a miscdevice(a character divice).
Device driver provides a mechanism rather than policy.
To the word_count2.c, we know we could do 'write and read' on the miscdevice 'wordcount2'.
Two ways to test the device driver :
(1) shell communicate
I write the command in a test2.sh file :
#!/bin/sh devpath="/dev/wordcount2" echo ">> Insmoding word_count2.ko"
sudo insmod word_count1.ko
if [ -c "$devpath" ]; then
echo ">> Writting to wordcount..."
echo ">> The world count program." > $devpath
echo ""
echo ">> Reading the wordcount..."
sudo cat /dev/wordcount2 echo "------------------------"
sudo rmmod word_count2
echo ">> Rmmoding word_count2.ko" echo ""
echo "----/var/log/syslog-----"
sudo dmesg | grep word | tail -n
echo "------------------------"
echo "" else
echo ">> The word count modules doesn't exits."
fi
(2) user program communicate
The following is the ftest.c :
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h> int main(int argc, char *argv[])
{
int testdev;
int ret;
int num = ;
unsigned char buf[]; testdev = open("/dev/wordcount2", O_RDWR); if(testdev == -) {
printf("Can not open file.\n");
return ;
} if(argc > ) {
printf("Strings : %s.\n", argv[]);
write(testdev, argv[], strlen(argv[]));
} read(testdev, buf, ); num = ((int)buf[]) << | \
((int)buf[]) << | \
((int)buf[]) << | \
((int)buf[]); printf("Word Byte : 0x%d%d%d%dH\n", buf[], buf[], buf[], buf[]);
printf("word count: %d\n", num); close(testdev);
return ;
}
I also write the command in a test3.sh file too :
#!/bin/sh devpath="/dev/wordcount2"
echo ">> Insmod the wordcount2..."
sudo insmod word_count2.ko
if [ -c "$devpath" ]; then
echo ""
echo ">> ./ftest \"test string 1 2 3\""
echo ""
./ftest wordcount2 "test string 1 2 3"
sudo rmmod word_count2
echo ">> Rmmoding word_count2.ko" echo ""
echo "----- /var/log/syslog ------"
sudo dmesg | grep word | tail -n
echo "----------------------------"
else
echo ">> $devpath doesn't exits"
fi
2、ok6410-android
If we want to compile the device drive into an ARM platform, we have to get this :
(1) cross compiler
arm-linux- (the compiler support on the cd of forlinx)
or arm-eabi- (the compiler support on the google android source code)
(2) source code compiled on arm platform
Here I got two piece of kernel-source code :
Android-2.3_kernel (support by forlinx)
goldfish-2.6.29_kernel (support by google)
Then we just need to correct the Makefile path.
After tested, we know :
(1) the module works properly with two cross compiler and Android-2.3_kernel.
(2) the module doesn't work on the goldfish-2.6.29_kernel.
TIPS :
When rmmod, there may wanning :
rmmod : chdir(/lib/modules): No such file or directory
[Fix]
Copy the file to /lib/modules/$(uname -r)/
If there is not this directory, create it.
3、goldfish emulator
The same with ok6410 except two different :
(1) No need to create the directory /lib/modules/$(uname -r)/
we can insmod and rmmod in any directory
(2) When we configure the kernel, we should use the goldfish_armv7_defconfig and enable 'Enable loadable module support' and his subproject.
ok6410 android driver(3)的更多相关文章
- ok6410 android driver(5)
Test the android driver by JNI (Java Native Interface), In the third article, we know how to compile ...
- ok6410 android driver(11)
This essay, I go to a deeply studying to android HAL device driver program. According to the android ...
- ok6410 android driver(9)
In this essay, I will write the JNI to test our leds device. If you don't know how to create a jni p ...
- ok6410 android driver(8)
In the past, we know how to create and run a simple character device driver on pc, goldfish and ok64 ...
- ok6410 android driver(12)
In this essay, I will talk about how to write the service libraries. TIPS : I won't discuss the name ...
- ok6410 android driver(10)
From this essay, we go to a new discussion "Android Hardware Abstraction Layer". In this e ...
- ok6410 android driver(7)
This article talk about how to test device driver on JNI. There are two ways to test the device driv ...
- ok6410 android driver(6)
This is a short essay about the mistakes in compiling ok6410 android-2.3 source codes. If there is n ...
- ok6410 android driver(1)
target system : Android (OK6410) host system : Debian Wheezy AMD64 1.Set up android system in ok6410 ...
随机推荐
- activemq安装与简单消息发送接收实例
安装环境:Activemq5.11.1, jdk1.7(activemq5.11.1版本需要jdk升级到1.7),虚拟机: 192.168.147.131 [root@localhost softwa ...
- [玩转微信平台]XML的格式化- 如何去掉XML 文档头和命名空间
前言 系统要求能够回复微信用户发过来的文本消息.实现中使用的实体对象进行XML的序列化的方式来实现XML消息. 微信平台的回复例子 http://mp.weixin.qq.com/wiki/14/ ...
- Linux 求文件交集 差集等
使用comm命令 假设两个文件FILE1和FILE2用集合A和B表示,FILE1内容如下: a b c e d a FILE2内容如下: c d a c 基本上有两个方法,一个是comm命令,一个是g ...
- Android 5.1 AOSP 源码获取
本文已同步更新至:http://dxjia.cn/2015/08/android-aosp-code-sync/ Android 5.1源码开放有一个多月啦,但由于城墙的关系,每次想着更新最新源码学习 ...
- C# 代码转化为Java代码
http://www.tangiblesoftwaresolutions.com/Free_Editions.html Install Instant C# (converts VB.NET code ...
- IOS RSA 加密方式
采用RSA加密方式,主要是生成公钥和私钥,公钥用来加密,私钥用来解密,至于其中如何实现的,网上有很多原理. 参见如下: https://github.com/jslim89/RSA-objc PS: ...
- GNU风格 ARM汇编语法指南
汇编源程序一般用于系统最基本的初始化:初始化堆栈指针.设置页表.操作 ARM的协处理器等.这些初始化工作完成后就可以跳转到C代码main函数中执行. 1. GNU汇编语言语句格式 任何Linux汇编 ...
- Spark源码系列(四)图解作业生命周期
这一章我们探索了Spark作业的运行过程,但是没把整个过程描绘出来,好,跟着我走吧,let you know! 我们先回顾一下这个图,Driver Program是我们写的那个程序,它的核心是Spar ...
- ALTER SEQUENCE 修改序列解决唯一约束冲突 unique constraint violated
背景 自增序列会遇到也会遇到唯一约束冲突吗?是的,最常见的情况就是数据迁移之后,导致数据最大值超过序列值. 软件开发中不遇到些出乎意料的问题,总感觉不太够劲. 修改序列(ALTER SEQUENCE) ...
- HDU 3999 The order of a Tree
The order of a Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...