enc28j60网卡驱动模块添加进linux内核,Kconfig,Makefile配置过程

这里是要把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

           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

   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
      .  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. 启动起来后,看内核打印的信息:

 

查看驱动加载情况

enc28j60网卡驱动模块添加进linux内核,Kconfig,Makefile配置过程_第1张图片

 

b. 让系统挂载系统文件之后,配置eth1(enc28j60)

vi /etc/init.d/rcS

添加:

ifconfig eth1 192.168.1.12 netmask 255.255.255.0 up

 

重新启动,看网络配置情况

enc28j60网卡驱动模块添加进linux内核,Kconfig,Makefile配置过程_第2张图片

 

关闭eth0,自动切换到eth1挂载nfs

enc28j60网卡驱动模块添加进linux内核,Kconfig,Makefile配置过程_第3张图片

 到这里,enc28j60已经可以正常工作了

 

 

   

 

你可能感兴趣的:(enc28j60网卡驱动模块添加进linux内核,Kconfig,Makefile配置过程)