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 ...
随机推荐
- GDAL 遥感图像处理后的数据保存为图像文件的实现方法
在遥感图像处理中,GDAL库不仅能读取和处理大部分的遥感图像数据,而且还能够实现图像处理后将数据保存为图像的功能. 本文就详细介绍如何将内存中的图像数据保存为.tif格式. 首先,遥感数据处理完,保存 ...
- 国内市场上 Android 手机屏幕分辨率的比例情况如何?
http://www.zhihu.com/question/19587205 根据友盟发布的<友盟国内Android数据报告>,前六名分别是: 800×480,32.4% 480×320, ...
- 阿里云 通过YUM源安装nginx
阿里云centOS-6.3-64位通过YUM源安装nginx 第一步:在 /etc/yum.repos.d/ 目录下,建立名叫nginx.repo的软件源配置文件. 文件 nginx.repo 的 ...
- mssql中sp_executesql的用法
上图:
- MySQL 服务无法启动。 服务没有报告任何错误。 请键入 NET HELPMSG 3534 以获得更多的帮助。
网上搜了下,看到有几种解决方法,本人综合了一下,作为记录 第一步 有一部分人成功了 在安装根目录创建data文件夹 第二步 有一部分人成功了 D:\Program Files\mysql\bin> ...
- hdu1251在词典里统计前缀出现的个数
banana band bee absolute acm ba b band abc #include<iostream> using namespace std; //数据结构 s ...
- web app变革之rem(手机屏幕实现全适配)
以往web移动适配,常规写法是:media only screen @media only screen and (min-device-width: 320px){ //针对iPhone 3 } @ ...
- 从抽象谈起(三):AOP编程和ASP.NET MVC
AOP(Aspect oriented programming)面向切面编程.说成切面不容易理解,代码哪里有切面?又不是三维物体.概念不管,我们从其思想来理解这个名词吧. AOP的主要思想是把相同.相 ...
- mshadow笔记
矩阵维度表示和正常相反. a[2][3],行2列3,a.shape.shape_[0]=3,a.shape.shape_[1]=2. pred.Resize( Shape2( batch_size, ...
- [PaPaPa][需求说明书][V2.0]
前 言 大家好,我是“今晚打老虎”. 什么? 你问我为什么这次亮字号了? 还不是因为哥太出名了,即使我不亮你们也知道是我写的了. 自从发布了V1.0版本之后.群里又进来好多人.30K大大分发的任务 ...