En28j60 network card driver module is added into linux kernel, Kconfig, Makefile configuration process

Keywords: Linux Makefile network

This is to add enc28j60 network card driver module in http://www.cnblogs.com/hackfun/p/6260396.html to the 2.6.22.6 kernel without any modification of the module code. You just need to modify some configurations in the relevant configuration script files in the kernel directory, such as Makefile, Kconfig,.config, etc.

Several files used in enc28j60 network card driver module:

enc28j60.c

enc28j60_hw.h

spi_bitbang.c

spi_s3c24xx.c

spi_platform_dev.c

In fact, spi_bitbang.c and spi_s3c24xx.c are kernel native files without any changes. In the example of http://www.cnblogs.com/hackfun/p/6260396.html, my kernel did not compile these two files. So you need to load these two files manually.

Here, we add in the kernel

enc28j60.c

enc28j60_hw.h

spi_platform_dev.c

These three files will do.

En28j60.c and enc28j60_hw.h are platform-independent network drivers, so they are placed in the linux-2.6.22.6/drivers/net directory.

spi_platform_dev.c is directly related to the platform hardware, so put it in the linux-2.6.22.6/arch/arm/plat-s3c24xx directory.

 

1. Add spi module to the kernel

a. Enter the linux-2.6.22.6 source directory

make makeconfig

In this way, the kernel configuration menu of the graphical interface will be displayed at the mid-end, and the SPI-related configuration will be found:

Device Drivers  --->

    SPI support  --->

        [*] SPI support

        [*] SPI Master Support

        <*>   Bitbanging SPI master

        <*>   Samsung S3C24XX series SPI

        <M>   Samsung S3C24XX series SPI by GPIO

In [] or <> entries, press the space key, * sign to add the relevant module files to the kernel, M means to compile the relevant files into modules, not to add to the kernel, and space means not to configure:

[*] SPI support settings add linux-2.6.22.6\ drivers SPI directory to the upper drivers directory

[*] SPI Master Support settings add spi.c to the kernel

<*> Bitbanging SPI master settings add spi_bitbang.c to the kernel

Samsung S3C24XX series SPI settings add spi_s3c24xx.c to the kernel, hardware SPI

Samsung S3C24XX series SPI by GPIO setting generates spi_s3c24xx_gpio.c module to simulate SPI

b. Exit the configuration menu and save it. The. config file will be generated in the linux-2.6.22.6 source directory.

vi .config

Find the SPI configuration:

#
# 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


Corresponding relationship:

[*] SPI support corresponding generation configuration CONFIG_SPI=y

[*] SPI Master Support corresponding generation configuration CONFIG_SPI_MASTER=y

<*> Bitbanging SPI master corresponding generation configuration CONFIG_SPI_BITBANG=y

... ....

[] or <> where there is a space, corresponding to the generation of CONFIG_XXX is not set

That is to say, if you don't use the make menuconfig graphical interface, you can modify the. config file directly.

 

c. Configuration relationship between Kconfig and Makefile at each level

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. The configuration in this file is used to display menu items in make menuconfig, such as after make menuconfig. "config SPI" generates macros of CONFIG_SPI in linux-2.6.22.6\ config.

The [*] SPI support in make menuconfig corresponds to the generation configuration 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. After modifying the above configuration, enter in the linux-2.6.22.6 directory:

make uImage

Compile and wait patiently.

After compiling, by observing the compiled output information, to verify whether it has been compiled into the kernel, the first compiled output information is too much to find. Can open

spi_bitbang.c

spi_s3c24xx.c

These two files, respectively, enter a space in the blank space, save, compile, you will see the following information:

... ...
  CC      drivers/spi/spi_bitbang.o
  CC      drivers/spi/spi_s3c24xx.o
... ...

At this point, the SPI driver has been added to the kernel.

2. En28j60 drivers are added in a similar way. Here only the modifications based on JZ2440 with its own kernel are given. The relationship between Kconfig and Makefile is no longer analyzed.

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. Re-compilation

make uImage

4. burn and write

Burn uImage into Development Board

 

5. boot

After booting up, look at the information printed by the kernel:

 

View driver loading

 

b. After the system mounts the system files, configure eth1 (enc28j60)

vi /etc/init.d/rcS

Add to:

ifconfig eth1 192.168.1.12 netmask 255.255.255.0 up

 

Restart to see the network configuration

 

Turn off eth0 and automatically switch to eth1 to mount nfs

En28j60 is now working properly.

Posted by Michael_C on Thu, 20 Dec 2018 06:24:05 -0800