《Android深度探索》(卷1)HAL与驱动开发 第四章心得体会

本书的第四章讲的是源代码的下载和编译。分为Android源代码和Linux内核源代码。Android移植主要就是Linux内核的移植。而Linux内核移植主要是Linux驱动的移植。所以为了开发和测试Linux驱动,需要在Ubuntu Linux 下搭建两套开发环境:Android应用程序开发环境和Linux内核开发环境。其中Linux内核开发环境是重点。

一.环境搭建步骤

     下载Linux源码 

 1.~#apt-cache search linux-source

出现:linux-source - Linux kernel source with Ubuntu patches
           linux-source-3.0.0 - Linux kernel source for version 3.0.0 with Ubuntu patches

  2.~#apt-get   install linux-source-3.0.0

                  下载完成后,在/usr/src/下会出现一个linux-source-3.0.0.tar.bz2。解压:      tar  jxvf   linux-source-3.0.0.tar.bz2

  3.然后在Linux内核源码目录/usr/src/linux-source-2.6.32目录下面用老的方法配置好Linux内核:

                 ~#make oldconfig

  4.编译内核:~#make     //大概需要一个小时

  5.编译模块:~#make modules

  6.安装模块:~#make modules_install

  以上步骤完成后,会在/lib/modules 目录下生成一个文件夹3.0.0-12-generic

二.hello.c

 

三.Makefile

四.~#make   //生成文件如下

hello.c   hello.ko     hello.mod.o  Makefile   modules.order
hello.c~  hello.mod.c  hello.o      Makefile~  Module.symvers

1.装载目标模块:~#insmod  ./hello.ko

     ~#lsmod  //查看目前安装的驱动模块,有hello 

2.模块装载触发hello.cinit()方法,输出hello world,如果没有的话,是因为其将输出放到/var/log/syslog中去了。打开便可以看见你的结果!

卸载目标模块命令是:~#rmmod ./hello.ko

通过对第四章的学习,我知道了学好Linux驱动的移植是十分重要的。

http://www.cnblogs.com/z378560707/

原文地址:https://www.cnblogs.com/z378560707/p/5446182.html