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 ...
随机推荐
- 寻找倒数第K个结点
#include<stdio.h> #include<iostream> using namespace std; /** * 找到链表中的倒数第k个节点 */ //定义结构体 ...
- 山寨版Quartz.Net任务统一调度框架
TaskScheduler 在日常工作中,大家都会经常遇到Win服务,在我工作的这些年中一直在使用Quartz.Net这个任务统一调度框架,也非常好用,配置简单,但是如果多个项目组的多个服务部署到一台 ...
- 每日英语:Mistrust Between U.S., Malaysia Strains Probe
Mistrust between U.S. and Malaysian air-accident investigators has hampered a multinational probe in ...
- Ubuntu server 搭建Git server
Ubuntu server 搭建Git server,git相比svn,最主要就是分布式了,每个客户端用户的本地都是一个版本管理控制器. Ubuntu server 版本为12.04 搭建步骤如下: ...
- leetCode191/201/202/136 -Number of 1 Bits/Bitwise AND of Numbers Range/Happy Number/Single Number
一:Number of 1 Bits 题目: Write a function that takes an unsigned integer and returns the number of '1' ...
- Python: 如何继承str/string?
想搞一个对象继承自str,然后存一些额外信息用来标识这个字符串,然后理所当然地重写了__init__发现跪了: class newstring(str): def __init__(self, val ...
- 【android原生态RPG游戏框架源码】
转载请注明原创地址:http://www.cnblogs.com/zisou/p/android-RPG.html 这份源码是在今年6月份写的,当时公司有一个技术部们的学习讨论的讲座,然后我自己就写了 ...
- mingw 环境编译 liburl故障一例
环境是 windows 10,已经安装 mingw,并设置好mingw 和 msys的环境变量 C:\Users\cracker>set |grep MinGW Path=C:\Program ...
- Spark和hadoop的关系
1. Spark VSHadoop有哪些异同点? Hadoop:分布式批处理计算,强调批处理,常用于数据挖掘和数据分析. Spark:是一个基于内存计算的开源的集群计算系统,目的是让数据分析更加快速, ...
- 批量Ping IP
刚刚接触Python 想做点什么 听说Python 在网络方便很厉害 后来总结如下: 第一:发现公司都固定IP 每次新来同事都要猜一个没有人用的IP 很费劲 第二:我们公司有的IP可以上QQ 有的不 ...