现在的位置: 首页 > 综合 > 正文

向内核中添加驱动

2013年08月24日 ⁄ 综合 ⁄ 共 1210字 ⁄ 字号 评论关闭

 

本文为《编译S3C2410kernel》的续

 

       这里以最简单的驱动为例:网卡驱动。

步骤一:

       准备网卡驱动程序,enc28j60.cenc28j60.h

步骤二:

       在内核的驱动目录下建立ncard的文件夹

       # cd /home/su/kernel/drivers

       # mkdir ncart

把网卡驱动程序拷到该文件夹下

# cd ncard

# cp /home/su/enc28j60.c /home/su/enc28j60.h ./

步骤三:

       在网卡驱动的目录下写一个配置文件Config.in

# vi Config.in

其内容如下:

#netcard drviver configuration

mainmenu_option next_comment

comment 'Net Card Driver'

 

bool 'NET CARD support' CONFIG_NCARD

 

endmenu

步骤四:

       在网卡驱动的目录下写Makefile

       # vi Makefile

其内容如下:

#driver Makefile

O_TARGET := ncard.o

export-objs :=

obj-$(CONFIG_NCARD) += enc28j60.o

include $(TOPDIR)/Rules.make

步骤五:

       修改总驱动目录下的Makefile

       # pwd

       /home/su/kernel/drivers/ncard

# cd ..

       # vi Makefile

       在其42行加入以下这句:

subdir-$(CONFIG_NCARD)        += ncard

步骤六:

       修改kernel中某个目录下的Config.in 文件,这里选择改kernel/arch/arm 下的Config.in

       # cd /home/su/kernel/arch/arm

       # vi Config.in

在其最后一行加入下面的一句话:

source drivers/ncard/Config.in

步骤七:

       修改kernel顶层目录的Makefile

       # cd /home/su/kernel

       # vi Makefile

       161行加入如下的一句话:

       DRIVERS-$(CONFIG_NCARD) += drivers/ncard/ncard.o

步骤八:

       配置内核的选项

# make menuconfig

这时,可看到菜单列表中多了一项

Net Card Drive --à

进去按“Y”选上,形如

*NET CARD support

步骤九:

       保存,退出

步骤十:

       编译内核

       # make zImage

步骤十一:

       新生成的内核zImage,可在kernel/arch/arm/boot 下找到,把其烧到arm板上。

 

抱歉!评论已关闭.