這裡是要把http://www.cnblogs.com/hackfun/p/6260396.html中的enc28j60網卡驅動模塊,添加到2.6.22.6內核中,這個模塊代碼不需要任何修改。只需要在內核目錄下的相關配置腳本文件,如Makefile,Kconfig,.config等,修改某些配置就行。
enc28j60網卡驅動模塊使用到的幾個文件:
enc28j60.c
enc28j60_hw.h
spi_bitbang.c
spi_s3c24xx.c
spi_platform_dev.c
實際上spi_bitbang.c,spi_s3c24xx.c為內核原生文件,也不需要任何改動。在http://www.cnblogs.com/hackfun/p/6260396.html這個例子中,我的內核沒有把這兩個文件編譯進去。因此需要手動把這兩個文件加載進去。
在這裡,我們在內核添加
enc28j60.c
enc28j60_hw.h
spi_platform_dev.c
這3個文件即可。
enc28j60.c,enc28j60_hw.h這兩個文件,是與平台無關的網絡驅動,因此把他們放到linux-2.6.22.6/drivers/net目錄下。
spi_platform_dev.c是與平台硬件有直接關系,因此把它放到linux-2.6.22.6/arch/arm/plat-s3c24xx目錄下。
1. 把spi模塊添加進內核
a. 進入到linux-2.6.22.6源碼目錄下
make makeconfig
這樣,就會在中端顯示圖形界面的內核配置菜單,找到SPI相關的配置:
Device Drivers --->
SPI support --->
[*] SPI support
[*] SPI Master Support
<*> Bitbanging SPI master
<*> Samsung S3C24XX series SPI
<M> Samsung S3C24XX series SPI by GPIO
在[]或<>的條目按空格鍵,*號表示把相關的模塊文件添加進內核,M表示把相關的文件編譯成模塊,不添加到內核,空格表示不配置:如
[*] SPI support 設置把linux-2.6.22.6\drivers\spi目錄添加到上層drivers目錄
[*] SPI Master Support 設置把spi.c添加進內核
<*> Bitbanging SPI master 設置把spi_bitbang.c添加進內核
<*> Samsung S3C24XX series SPI 設置把spi_s3c24xx.c添加內核,硬件SPI
<M> Samsung S3C24XX series SPI by GPIO 設置把spi_s3c24xx_gpio.c生成模塊,模擬SPI
b. 退出配置菜單,保存,會在linux-2.6.22.6源碼目錄下生成.config文件。
vi .config
找到SPI的相關配置:
# # SPI support # CONFIG_SPI=y # CONFIG_SPI_DEBUG is not set CONFIG_SPI_MASTER=y # # SPI Master Controller Drivers # CONFIG_SPI_BITBANG=y # CONFIG_SPI_BUTTERFLY is not set CONFIG_SPI_S3C24XX=y CONFIG_SPI_S3C24XX_GPIO=m # # SPI Protocol Masters # # CONFIG_SPI_AT25 is not set # CONFIG_SPI_SPIDEV is not set
對應關系:
[*] SPI support 對應生成配置CONFIG_SPI=y
[*] SPI Master Support 對應生成配置 CONFIG_SPI_MASTER=y
<*> Bitbanging SPI master 對應生成配置 CONFIG_SPI_BITBANG=y
... ....
[]或<>裡面是空格的,對應生成CONFIG_XXX is not set
也就是說如果不使用make menuconfig圖形界面, 可以直接修改.config文件。
c. 在各層Kconfig和Makefile的配置關系
linux-2.6.22.6\drivers\Kconfig
... ... source "drivers/spi/Kconfig" ... ...
linux-2.6.22.6\drivers\Makefile
... ... obj-$(CONFIG_SPI) += spi/ ... ...
linux-2.6.22.6\drivers\spi\Kconfig,這個文件裡的配置是用於make menuconfig裡的菜單項顯示,如make menuconfig之後。"config SPI"會在linux-2.6.22.6\.config生成CONFIG_SPI的宏,
make menuconfig中的[*] SPI support 對應生成配置CONFIG_SPI=y
... ... config SPI bool "SPI support" help The "Serial Peripheral Interface" is a low level synchronous protocol. Chips that support SPI can have data transfer rates up to several tens of Mbit/sec. Chips are addressed with a controller and a chipselect. Most SPI slaves don't support dynamic device discovery; some are even write-only or read-only. SPI is widely used by microcontrollers to talk with sensors, eeprom and flash memory, codecs and various other controller chips, analog to digital (and d-to-a) converters, and more. MMC and SD cards can be accessed using SPI protocol; and for DataFlash cards used in MMC sockets, SPI must always be used. SPI is one of a family of similar protocols using a four wire interface (select, clock, data in, data out) including Microwire (half duplex), SSP, SSI, and PSP. This driver framework should work with most such devices and controllers. ... ... config SPI_MASTER boolean "SPI Master Support" help If your system has an master-capable SPI controller (which provides the clock and chipselect), you can enable that controller and the protocol drivers for the SPI slave chips that are connected. ... ... config SPI_BITBANG tristate "Bitbanging SPI master" depends on SPI_MASTER && EXPERIMENTAL help With a few GPIO pins, your system can bitbang the SPI protocol. Select this to get SPI support through I/O pins (GPIO, parallel port, etc). Or, some systems' SPI master controller drivers use this code to manage the per-word or per-transfer accesses to the hardware shift registers. This is library code, and is automatically selected by drivers that need it. You only need to select this explicitly to support driver modules that aren't part of this kernel tree. ... ... config SPI_S3C24XX tristate "Samsung S3C24XX series SPI" depends on SPI_MASTER && ARCH_S3C2410 && EXPERIMENTAL help SPI driver for Samsung S3C24XX series ARM SoCs ... ...
linux-2.6.22.6\drivers\spi\Makefile
... ... obj-$(CONFIG_SPI_MASTER) += spi.o ... ... obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o ... ... obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o ... ...
d. 修改完以上配置之後,在linux-2.6.22.6目錄下輸入:
make uImage
進行編譯,耐心等候。。。。。。。。。。。。。。
編譯完之後,通過觀察編譯輸出信息,驗證一下到底有沒有編譯進內核,第一次編譯輸出的信息太多不好找。可以打開
spi_bitbang.c
spi_s3c24xx.c
這兩個文件,分別在裡面空白的地方輸入一個空格,保存,再編譯,會看到以下信息:
... ... CC drivers/spi/spi_bitbang.o CC drivers/spi/spi_s3c24xx.o ... ...
到這裡,SPI的驅動就已經添加到內核了
2. enc28j60的驅動的添加方法也是類似的,這裡只給出基於JZ2440自帶內核的修改地方不再分析Kconfig和Makefile的配關系。
linux-2.6.22.6\drivers\net\Kconfig
... ... config ENC28J60 tristate "ENC28J60 support" depends on NET_ETHERNET ---help--- Support for ENC28J60 chipset. To compile this driver as a module, choose M here and read <file:Documentation/networking/net-modules.txt>. The module will be called enc28j60. ... ...
linux-2.6.22.6\drivers\net\Makefile
... ... obj-$(CONFIG_ENC28J60) += enc28j60.o ... ...
make menuconfig
Device Drivers ---> Network device support ---> Ethernet (10 or 100Mbit) ---> <*> ENC28J60 support
linux-2.6.22.6\arch\arm\plat-s3c24xx\Makefile
... ... obj-$(CONFIG_CPU_S3C244X) += s3c244x.o spi_platform_dev.o ... ...
3. 重新編譯
make uImage
4. 燒寫
燒寫uImage到開發板中
5. 啟動
a. 啟動起來後,看內核打印的信息:
查看驅動加載情況
b. 讓系統掛載系統文件之後,配置eth1(enc28j60)
vi /etc/init.d/rcS
添加:
ifconfig eth1 192.168.1.12 netmask 255.255.255.0 up
重新啟動,看網絡配置情況
關閉eth0,自動切換到eth1掛載nfs
到這裡,enc28j60已經可以正常工作了
http://www.bkjia.com/Linuxjc/1194197.html TechArticle