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)的更多相关文章

  1. ok6410 android driver(5)

    Test the android driver by JNI (Java Native Interface), In the third article, we know how to compile ...

  2. ok6410 android driver(11)

    This essay, I go to a deeply studying to android HAL device driver program. According to the android ...

  3. 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 ...

  4. ok6410 android driver(8)

    In the past, we know how to create and run a simple character device driver on pc, goldfish and ok64 ...

  5. ok6410 android driver(12)

    In this essay, I will talk about how to write the service libraries. TIPS : I won't discuss the name ...

  6. ok6410 android driver(10)

    From this essay, we go to a new discussion "Android Hardware Abstraction Layer". In this e ...

  7. ok6410 android driver(7)

    This article talk about how to test device driver on JNI. There are two ways to test the device driv ...

  8. ok6410 android driver(6)

    This is a short essay about the mistakes in compiling ok6410 android-2.3 source codes. If there is n ...

  9. ok6410 android driver(1)

    target system : Android (OK6410) host system : Debian Wheezy AMD64 1.Set up android system in ok6410 ...

随机推荐

  1. [aaronyang]WPF4.5 - AyTabControlBase样式分享,绝对好看

    样式代码如下: 对于博客园将文章移除首页的做法:我就迁移了.文章已经迁移:http://www.ayjs.net/post/75.html 由于例子比较简单,你只要指定Style即可,难点,透明区域的 ...

  2. 【C++沉思录】句柄1

    1.在[C++沉思录]代理类中,使用了代理类,存在问题: a.代理复制,每次创建一个副本,这个开销有可能很大 b.有些对象不能轻易创建副本,比如文件2.怎么解决这个问题? 使用引用计数句柄,对动态资源 ...

  3. Android开发贴士集合

    Activity.startActivities()——对于从app流的中部启动会非常好. TextUtils.isEmpty()——一个普遍适用的简单工具类. Html.fromHtml()——格式 ...

  4. 演化理解 Android 异步加载图片

    原文:http://www.cnblogs.com/ghj1976/archive/2011/05/06/2038738.html#3018499 在学习"Android异步加载图像小结&q ...

  5. Arduino 封装库

    这里是一个在Arduino平台下将常用的代码以库的形式封装的示例. 第一步:在Arduino的安装目录下的对应目录建立文件夹 C:\Program Files (x86)\Arduino\librar ...

  6. android自定义view仿照MIUI中音量控制效果

    先看效果图: 这就是miui中的音量效果图,实现思路是自定义视图,绘制圆环,然后设置进度显示. 核心代码在onDraw中实现如下: @Override protected void onDraw(Ca ...

  7. NFS挂载Android文件系统

    NFS挂载Android文件系统 [日期:2012-02-14] 来源:Linux社区  作者:cjok376240497 [字体:大 中 小]     1.安装NFS服务 $sudo apt-get ...

  8. linux下 C++ 读取mat文件 MATLAB extern cyphon scipy 未完待续

    1.使用Matlab的C扩展,需要用户安装matlab. g++ -L/media/exsoftware/MATLAB/R2013b/bin/glnxa64 -Wl,-rpath,/media/exs ...

  9. Ajax实现提交表单时验证码自动验证(原创自Zjmainstay)

    本文通过源码展示如何实现表单提交前,验证码先检测正确性,不正确则不提交表单,更新验证码. 1.前端代码 index.html <!DOCTYPE html> <html> &l ...

  10. Android Studio配置和使用OpenCV3.x,不需要OpencvManager

    转载声明,本文转自CSDN:http://blog.csdn.net/qq_22033759/article/details/51156121 ps:本来在贴吧上有人问,想自己写的,但时间有限,当初自 ...