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 ...
随机推荐
- C#点点滴滴:枚举enum
一.enum简介 enum为枚举类型,即一种由一组称为枚举数列表的命名常量组成的独特类型 在声明一个枚举时,要指定该枚举可以包含的一组可接受的实例值,还可以给值指定易于记忆的名称 注:如果在代码中试图 ...
- Thinkpad X240使用U盘安装Win7系统
更改BIOS设置 不同电脑的进入BIOS的方式可能不太一样,Thinkpad X240的进入方式是在电脑启动的时候按下回车键,然后按F1进入BIOS. 1. 修改secure boot为Disable ...
- 在WPF中使用字体图标
一.源码描述 这是一款基于WPF窗体应用程序的字体图标示例源码, 该源码简单易懂使用于初学者和实战项目应用, 感兴趣的朋友们可以下载看看哦. 二.功能介绍 1.用ICO字体代替 ...
- console 让 js 调试更简单
浏览器的控制台(console)是最重要的面板,主要作用是显示网页加载过程中产生各类信息. 显示信息 console.log('hello world'); console.debug('debug' ...
- 关于在mac 配置eclipse c开发
新建一个c 项目,如下 勾选hello world ANSL project ,勾选右边的MacOSX GCC 安装插件CDT - http://download.eclipse.org/tools/ ...
- Ehcache 使用
自从Ehcache 到了1.2+的版本,就支持分布式缓存了 Spring + Hibernate的结构 ,ehcache的对这几个框架的支持较好,就采用这个缓存方案 下面是配置文件: <ehca ...
- Windows 64位 安装Oracle instantclient 官方绿色版和PL/SQL Developer 总结
原文: http://blog.csdn.net/kimsoft/article/details/8751267 操作系统:Windows 7 64位旗舰 要求,安装PL/SQL Developer用 ...
- 【Cocos2d-Js基础教学(4)cocostudio在cocos2dx-Js中的使用】
首先我们打开官方网站www.cocos2d-x.org,下载我们安装最新的cocostudio(cocos). 简介: Cocos Studio升级为cocos.更优秀的产品.更优质的服务.游戏开发一 ...
- ios辅助功能之voiceover实战
一个元素朗读的内容可分为以下4个部分(4部分按先后顺序朗读) 1. Label:元素的标题 2. Value:元素的值(可选) 3. Traits:元素的特征,即类型,包含: 按钮/链接/搜索框/ ...
- SAP ECC CO 配置
SAP ECC 6.0 Configuration Document Controlling (CO) Table of Content TOC \o \h \z 1. Enterprise Stru ...