最简单的linux hello的驱动源程序

//下面是驱动源代码  

#include <linux/init.h>  
#include <linux/module.h>   

static int hello_init(void)  
{  
    printk(KERN_ALERT "Hello, Tekkaman Ninja !\n");  
    return 0;  
}  

static void hello_exit(void)  
{  
    printk(KERN_ALERT "Goodbye, Tekkaman Ninja !\n Love Linux !Love ARM ! Love KeKe !\n");  
}  

module_init(hello_init);  
module_exit(hello_exit);  



MODULE_LICENSE("Dual BSD/GPL");

下面是Makefile

#!/bin/bash
#通知编译器我们要编译模块的哪些源码
#这里是编译itop4412_hello.c这个文件编译成中间文件itop4412_hello.o
obj-m += mini_linux_module.o 

#源码目录变量,这里用户需要根据实际情况选择路径
#作者是将Linux的源码拷贝到目录/home/topeet/android4.0下并解压的
KDIR := /home/iTop4412_Kernel_3.0

#当前目录变量
PWD ?= $(shell pwd)

#make命名默认寻找第一个目标
#make -C就是指调用执行的路径
#$(KDIR)Linux源码目录,作者这里指的是/home/iTop4412_Kernel_3.0
#$(PWD)当前目录变量
#modules要执行的操作
all:
    make -C $(KDIR) M=$(PWD) modules

#make clean执行的操作是删除后缀为o的文件
clean:
    rm -rf *.o

执行make出现错误

make -C /home/kernel/iTop4412_Kernel_3.0 M=/mnt/code/01qudong/mini_linux_module modules
make[1]: Entering directory '/home/kernel/iTop4412_Kernel_3.0'

  ERROR: Kernel configuration is invalid.
         include/generated/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.


  WARNING: Symbol version dump /home/kernel/iTop4412_Kernel_3.0/Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /mnt/code/01qudong/mini_linux_module/mini_linux_module.o
cc1: fatal error: include/generated/autoconf.h: No such file or directory
compilation terminated.
scripts/Makefile.build:311: recipe for target '/mnt/code/01qudong/mini_linux_module/mini_linux_module.o' failed
make[2]: *** [/mnt/code/01qudong/mini_linux_module/mini_linux_module.o] Error 1
Makefile:1368: recipe for target '_module_/mnt/code/01qudong/mini_linux_module' failed
make[1]: *** [_module_/mnt/code/01qudong/mini_linux_module] Error 2
make[1]: Leaving directory '/home/kernel/iTop4412_Kernel_3.0'
Makefile:18: recipe for target 'all' failed
make: *** [all] Error 2

或者是

make[1]: Entering directory `/home/xduser/study/driver/src/linux-2.6.22'    

      ERROR: Kernel configuration is invalid.    
      include/linux/autoconf.h or include/config/auto.conf are missing.    
       Run 'make oldconfig && make prepare' on kernel src to fix it.    
  WARNING: Symbol version dump /home/xduser/study/driver/src/linux-2.6.22'/Module.symvers is missing; modules will have no dependencies and modversions.

原因是内核没有编译,先处理内核 编译
简单说一说内核编译
1、先make distclean,然后确认主Makefile的设置
(1)主要是检查交叉编译工具链有没有设置对。CROSS_COMPILE ?= /usr/local/arm/arm-2009q3/bin/arm-none-linux-gnueabi-
(2)确认ARCH = arm。主要目的是为了编译时能找到arch/arm目录。
2、make x210ii_qt_defconfig
最后出现configuration written to .config,就证明我们的操作是正确的。
如果没有得到.config文件,不能进入下一步。实测发现没有.config也可以make menuconfig,但是这样做出来的内核编译和烧写运行应该是有问题的。
3、make menuconfig
(1)可能出现的错误1:ncurses库没装
错误信息:
* Unable to find the ncurses libraries or the
* required header files.
* ‘make menuconfig’ requires the ncurses libraries.


* Install ncurses (ncurses-devel) and try again.
解决方案:apt-get install libncurses5-dev
(2)可能出现的错误2:屏幕太小
错误信息:
Your display is too small to run Menuconfig!
It must be at least 19 lines by 80 columns.
解决方案:全屏,或者是把字体调小。

总结:
(1)这里会弹出配置界面。
(2)make menuconfig是第二步配置。
(3)因为此内核是九鼎已经移植过的,因此这里的配置可以不做,直接退出即可。
4、make
编译完成后得到的内核镜像不在源码树的根目录下,而是在arch/arm/boot这个目录下。
得到的镜像名是zImage。