Linux-2.6.32.2 kernel transplantation on mini2440 (Part 3) ---DM9000 network card driver transplantation

Publisher:SereneSerenityLatest update time:2016-12-05 Source: eefocusKeywords:Linux Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Migration environment 

1. Host environment: CentOS 5.5 under VMare, 1G memory.

2. Integrated development environment: Eclipse IDE

3. Compilation environment: arm-linux-gcc v4.4.3, arm-none-linux-gnueabi-gcc v4.5.1.

4. Development board: mini2440, 2M nor flash, 128M nand flash.

5.u-boot version: u-boot-2009.08

6. Linux version: linux-2.6.32.2

7. References:

【1】Complete Handbook of Embedded Linux Application Development, edited by Wei Dongshan.

【2】Mini2440 Linux Porting Development Practical Guide

【3】http://linux.chinaunix.net/techdoc/system/2009/08/24/1131864.shtml

3.1, transplant DM9000 network card driver

【1】Device resource initialization

Linux-2..6.32.2 already comes with a complete DM9000 network card driver (source code location: linux-2.6.32.2/drivers/net/dm9000.c). It is also a platform device. Therefore, in the target platform initialization code, you only need to fill in the corresponding structure table. The specific steps are as follows:
(1) Confirm that the header file dm9000.h required by the driver has been added:

Use gedit to open linux-2.6.32.2/arch/arm/mach-mini2440.c, locate around line 55, and add dm9000.h, as shown below:

#include

#include  
#include  
#include  
#include  
#include
#include

(2) Fill in the resource settings of the platform device

Locate near line 210 and enter the following code:

tatic struct s3c2410_platform_nand mini2440_nand_info = {
 .tacls = 20,
 .twrph0 = 60,
 .twrph1 = 20,
 .nr_sets = ARRAY_SIZE(mini2440_nand_sets),
 .sets = mini2440_nand_sets,
 .ignore_unset_ecc = 1,
};
/* DM9000AEP 10/100 ethernet controller */ //Define the physical base address of the DM9000 network card device for later use
#define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)

//Fill in the resource settings of the platform device so that it can be matched with the DM9000 network card driver interface

static struct resource mini2440_dm9k_resource[] = {
        [0] = {
                .start = MACH_MINI2440_DM9K_BASE,
                .end = MACH_MINI2440_DM9K_BASE + 3,
                .flags = IORESOURCE_MEM
        },
        [1] = {
                .start = MACH_MINI2440_DM9K_BASE + 4,
                .end = MACH_ MINI2440_DM9K_BASE + 7,
                .flags = IORESOURCE_MEM
        },
        [2] = {
                .start = IRQ_EINT7,
                .end = IRQ_EINT7,
                .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
        }
};
/*
 * * The DM9000 has no eeprom, and it's MAC address is set by
 * * the bootloader before starting the kernel.
 * */
static struct dm9000_plat_data mini2440_dm9k_pdata = {
        .flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
};

static struct platform_device mini2440_device_eth = {
        .name = "dm9000",
        .id = -1,
        .num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
        .resource = mini2440_dm9k_resource,
        .dev = {
                .platform_data = &mini2440_dm9k_pdata,
        },
};
static struct platform_device *mini2440_devices[] __initdata = {
 &s3c_device_usb,
 &s3c_device_lcd,
 &s3c_device_wdt,
 &s3c_device_i2c0,
 &s3c_device_iis,
 &s3c_device_nand, //; Add the nand flash device to the device list structure of the development board
 &mini2440_device_eth, //;Add the network card platform device to the device list structure of the development board
};

static void __init mini2440_map_io(void)

【2】Adjust the bit width register used by DM9000

Because the DM9000 network card driver of Linux-2.6.32.2 is not specially prepared for mini2440, some porting work needs to be done in its source code, as follows.

(1) Open linux-2.6.32.2/drivers/net/dm9000.c, locate around line 41, and add the configuration definition related to 2410, as shown in the red part below:

#include
#include
#include

#include "dm9000.h"
#if defined(CONFIG_ARCH_S3C2410)
#include
#endif

(2) Add the following red part to the initialization function of the DM9000 device. This is the timing of configuring the chip select bus used by the DM9000. Since mini2440 currently has only one device that is expanded through the bus, it is easier to understand by directly modifying the relevant register configuration in this device driver. Of course, this part can also be placed in mach-mini2440.c.

Open linux-2.6.32.2/drivers/net/dm9000.c, locate around line 1555, and add the following code:

static int __init
dm9000_init(void)
{
#if defined(CONFIG_ARCH_S3C2410)
 unsigned int oldval_bwscon = *(volatile unsigned int *)S3C2410_BWSCON;
 unsigned int oldval_bankcon4 = *(volatile unsigned int *)S3C2410_BANKCON4;
 *((volatile unsigned int *)S3C2410_BWSCON) =
   (oldval_bwscon & ~(3<<16)) | S3C2410_BWSCON_DW4_16 | S3C2410_BWSCON_WS4 | S3C2410_BWSCON_ST4;
 *((volatile unsigned int *)S3C2410_BANKCON4) = 0x1f7c;
#endif 
 printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION);

 return platform_driver_register(&dm9000_driver);
}

【3】It should be noted that the DM9000 network card used in this development board does not have an external EEPROM to store the MAC address. Therefore, the MAC address in the system is a "soft" address, which means that it can be modified by software and can be changed to other values ​​at will.

Open linux-2.6.32.2/drivers/net/dm9000.c, locate around line 1461, and add the following line of code:

static int __devinit
dm9000_probe(struct platform_device *pdev)
{

... ...

/* try reading the node address from the attached EEPROM */

//;Try to read MAC address from EEPROM
 for (i = 0; i < 6; i += 2)
  dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);

 if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) {
  mac_src = "platform data";
  memcpy(ndev->dev_addr, pdata->dev_addr, 6);
 }

 if (!is_valid_ether_addr(ndev->dev_addr)) {
  /* try reading from mac */
  
  mac_src = "chip";
  for (i = 0; i < 6; i++)
   ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
 }

 //;Use "soft" MAC address: 08:90:90:90:90:90
 memcpy(ndev->dev_addr, "\x08\x90\x90\x90\x90\x90", 6);

 if (!is_valid_ether_addr(ndev->dev_addr))
  dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please "
    "set using ifconfig\n", ndev->name);

 platform_set_drvdata(pdev, ndev);
 ret = register_netdev(ndev);

 if (ret == 0)
  printk(KERN_INFO "%s: dm9000%c at %p,%p IRQ %d MAC: %pM (%s)\n",
         ndev->name, dm9000_type_to_char(db->type) ,
         db->io_addr, db->io_data, ndev->irq,
         ndev->dev_addr, mac_src);
 return 0;

out:
 dev_err(db->dev, "not found (%d).\n", ret);

 dm9000_release_board(pdev, db);
 free_netdev(ndev);

 return ret;
}

In fact, the DM9000 has been ported at this point.

3.2, compile test

【1】Before compiling, you need to confirm that the network card driver has been configured in the kernel.

Execute in the kernel directory:

[root@localhost linux-2.6.32.2]# make menuconfig

In the opened configuration menu Device Drivers ---> Network device support ---> Ethernet (10 or 100Mbit) --->, you can see the following figure

Linux-2.6.32.2 kernel porting on mini2440 (Part 3) ---DM9000 network card driver porting - singleboy - singleboy's blog

DM9000 has been selected because the default kernel configuration of Linux-2.6.32.2 has added support for DM9000.


【2】Compilation

[root@localhost linux-2.6.32.2]# make clean
[root@localhost linux-2.6.32.2]# make uImage

After compilation is complete, zImage and uImage are generated

【3】Test the network card driver

(1) Use the root file system that has been transplanted by the friendly official. You can copy it directly from the CD image/linux directory provided by it.
[root@localhost ~]# cd linux-test
[root@localhost linux-test]# ls
busybox-1.13.3 mkyaffs2image.tgz
busybox-1.13.3-mini2440.tgz myrootfs
busybox-1.18.4 rootfs_qtopia_qt4
busybox-1.18.4.tar.bz2 rootfs_qtopia_qt4-20110304.tar.gz
linux-2.6.32.2 usr
linux-2.6.39 yaffs2
[root@localhost linux-test

(2) Copy it to the host machine's /nfsboot directory and name it rootfs

[root@localhost linux-test]# cp -rf rootfs_qtopia_qt4 /nfsboot/rootfs
[root@localhost linux-test]#

And make sure the rootfs directory is readable and writable

[root@localhost linux-test]# cd /nfsboot
[root@localhost nfsboot]# ls -l
total 65280
drwxr-xr-x 18 root root 4096 06-01 19:06 rootfs
-rwxrw-rw- 1 root root 58487616 2009 -07-18 root_qtopia-128M.img
-rw-r--r-- 1 root root 2110720 06-01 13:31 uImage
-rwxr-xr-x 1 root root 2022412 05-12 11:37 uImage_T35
-rwxr-xr -x 1 root root 2110656 06-01 13:31 zImage
-rwxrw-rw- 1 root root 2022348 2009-07-08 zImage_T35
[root@localhost nfsboot]#

(3) Modify the /etc/exports configuration file to set the default shared directory of rootfs

[root@localhost ~]# vim /etc/exports

The opened configuration file modifies the shared directory as follows:

/nfsboot/rootfs 10.1.0.*(rw,sync,no_root_squash)
/nfsboot/kernel 10.1.0.*(rw,sync,no_root_squash)
/nfsboot/nfs 10.1.0.*(rw,sync,no_root_squash)

# /nfsboot/rootfs is a shared directory, storing the root file system (using an absolute path)
# /nfsboot/kernel is a shared directory, storing the root file system (using an absolute path)
# /nfsboot/nfs is a shared directory, storing applications (using an absolute path)
# 10.1.0.* indicates the network segment 10.1.0.0/24 where the client is located
# 10.1.0.0/24 indicates the network segment 10.1.0.1~10.1.0.254, and the subnet mask is 255.255.255.0.
# How does the subnet mask come from? In fact, the key lies in "24". We know that an IP address is
composed of four decimal numbers #, which is equivalent to 32 bits of binary. In CIDR notation, the last number separates the 32 bits
#(take 24 as an example): the first 24 bits are represented by "1", and the last 8 bits are represented by 0, resulting in a binary number:
# 11111111 11111111 11111111 00000000
# Convert it to decimal, which is: 255.255.255.0.
# rw: Read and write
# sync: Synchronous write to disk.
# no_root_squash: Allow non-root users to operate the folder

Then save and exit, and restart the nfs service:

[root@localhost ~]# service nfs restart
Shutting down NFS mountd: [OK] Shutting down NFS
daemon: [
OK] Shutting down NFS quotas: [OK]
Shutting down NFS service: [OK]
Starting NFS service: [OK]
Turning off NFS quotas: [OK]
Starting NFS daemon: [OK]
Starting NFS mountd: [OK]
[root@localhost ~]#

(4) Modify the u-boot kernel boot parameters

Start in u-boot and enter the command line state

A, make sure bootargs ="noinitrd console=ttySAC0,115200 init=/linuxrc mem=64M \
 root=/dev/nfs rw nfsroot=10.1.0.128:/nfsboot \
 ip=10.1.0.129:10.1.128:10.1.0.1: 255.255.255.0::eth0:off"

B, make sure bootcmd="nfs 0x30008000 10.1.0.128:/nfsboot/uImage;bootm"

First check the u-boot environment variables


 [u-boot@MINI2440]# printenv
bootargs=noinitrd console=ttySAC0,115200 init=/linuxrc root=/dev/mtdblock3 rw r
ootfstype=yaffs ip=10.1.0.129:10.1.0.128:10.1.0.1:255.255.255.0: :eth0:off
bootcmd=nand read 0x30008000 0x80000 0x300000;bootm 0x30008000
bootdelay=3
baudrate=115200
ethaddr=08:00:3e:26:0a:5b
ipaddr=10.1.0.129
serverip=10.1.0.128
gatewayip=10 .1.0.1
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial
ethact=dm9000

Environment size: 405/131068 bytes
[u-boot@MINI2440]#

The u-boot kernel boot parameters bootargs and bootcmd here are obviously inconsistent with our requirements. We need to reset this parameter:

[u-boot@MINI2440]# setenv bootargs 'noinitrd console=ttySAC0,115200 init=/linux'
rc mem=64M root=/dev/nfs rw nfsroot=10.1.0.128:/nfsboot/rootfs ip=10.1.0.129:10 '
.1.0.128:10.1.0.1:255.255.255.0::eht0:off'
[u-boot@MINI2440]# setenv bootcmd 'nfs 0x31000000 10.1.0.128:/uImage;bootm 0x31000000'

Then save this variable to nand flash

[u-boot@MINI2440]# saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x4000000000002 -- 0% complete.
Writing to Nand... done

For the meaning of kernel boot parameters, please refer to u-boot-2009.08 transplantation on mini2440 (VI) --- adding kernel boot function .

(5) Confirm the kernel command line parameters

If the compiled kernel generates a zImage image file, then CONFIG_CMDLINE needs to

CONFIG_CMDLINE="root=/dev/nfs rw nfsroot=10.1.0.128:/nfsboot/rootfs ip=10.1.0.129 console=ttySAC0 mem=64M"

If the compiled kernel generates a uImage image file, then CONFIG_CMDLINE can be empty, because the parameters in the uImage file header will be passed to this place.

(6) Copy the compiled zImage and uImage files to the host machine's /nfsboot/ directory

[root@localhost nfsboot]# ls
rootfs root_qtopia-128M.img uImage uImage_T35 zImage zImage_T35
[root@localhost nfsboot]# 
(7) Power on the development board and start u-boot

I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 128 MiB
Video: 240x320x16 20kHz 62Hz
In: serial
Out: serial
Err: serial
Net: dm9000
U-Boot 2009.08
modified by singleboy( singleboy@163.com )
Love Linux forever! !!
Hit any key to stop autoboot: 0
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:5b
operating at 100M full duplex mode
Using dm9000 device
File transfer via NFS from server 10.1.0.128; our IP address is 10.1.0.129
Filename '/nfsboot/uImage'.
Load address: 0x31000000
Loading: ################################### ############################
         ###################### #########################################
         ####### ################################################ ########
         ################################################ ###############
         ################################## #############################
         #################### ###########################################
         ##### ##################
done
Bytes transferred = 2110772 (203534 hex)
## Booting kernel from Legacy Image at 31000000 ...
   Image Name: Linux-2.6.32.2
   Created: 2011-06-01 11:10:24 UTC
   Image Type: ARM Linux Kernel Image (uncompressed)
   Data Size: 2110708 Bytes = 2 MB
   Load Address : 30008000
   Entry Point: 30008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux................................................ .............................................................................
​............................. done,
booting the kernel.
Linux version 2.6.32.2 ( root@localhost. localdomain ) (gcc version 4.4.3 (ctng-1.6
.1) ) #11 Wed Jun 1 19:10:07 CST 2011
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177
CPU: VIVT data cache, VIVT instruction cache
Machine: my mini2440 devolopment board  singleboy@163.com

... ...

S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-
bit)
Scanning device for bad blocks
Creating 5 MTD partitions on "NAND 128MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "boot"
0x000000040000-0x00000 0060000 : "param"
0x000000060000-0x000000560000 : "kernel"
0x000000560000-0x000008000000 : "rootfs" 0x000000000000-0x000008000000
: "nand"
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c486e300,c4872304 IRQ 51 MAC: 08:90:90:90 :90:90 (chip)

... ...

eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
IP-Config: Complete:
     device=eth0, addr=10.1.0.129, mask=255.255.255.0, gw=10.1.0.1,
     host=10.1.0.129, domain=, nis-domain=(none),
     bootserver=10.1.0.128, rootserver=10.1.0.128, rootpath=
Looking up port of RPC 100003/2 on 10.1.0.128
Looking up port of RPC 100005/1 on 10.1.0.128
VFS: Mounted root (nfs filesystem) on device 0:14.
Freeing init memory: 132K
----------munt all----------------
******* ****************************************
************booting to mini2440 *******************
Kernel version:linux-2.6.32.2
the fans:singelboy
Date:2011.5.30
* **********************************************

Please press Enter to activate this console.

According to the kernel startup information, we can see that the DM9000 network card driver has been successfully transplanted.

Next, we will create the root file system for the kernel.


Keywords:Linux Reference address:Linux-2.6.32.2 kernel transplantation on mini2440 (Part 3) ---DM9000 network card driver transplantation

Previous article:Linux-2.6.32.2 kernel porting on mini2440 (XVIII) --- Changing UART2 to a normal serial port
Next article:Linux-2.6.32.2 kernel transplantation on mini2440 (Part 2) ---Yaffs2 file system transplantation

Recommended ReadingLatest update time:2024-11-15 15:44

Using J-Link to debug S3C2440 bare metal code on Linux
tool: Segger's JLink emulator Segger's JLink for Linux arm-xx-linux-xx-gdb in the cross-compilation toolchain Initialization Script Tool Installation Segger's JLink for Linux Go to Segger official website --- Download --- J-Link/J-Trace --- J-Link Softwa
[Microcontroller]
Design of autonomous obstacle-avoiding robot fish using ARM chip and LINUX embedded system
With the development and progress of science and technology, intelligent machines with special functions have emerged, such as the pet robot dog produced by Sony that can "feel", "learn" and "feed" with self-awareness, and the SAFFIR firefighting robot that is upgraded and modified based on the CHARLI-L1 robot develop
[Microcontroller]
Design of autonomous obstacle-avoiding robot fish using ARM chip and LINUX embedded system
Linux 2.6.32.2 mini2440 platform transplantation-kernel transplantation, yaffs2 file system transplantation
1.1 Obtain the Linux kernel source code There are many ways to obtain the Linux kernel source code. If your Linux platform can access the Internet, you can directly enter the following command on the command line to obtain Linux-2.6.32.2: #wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.2.tar.gz Of
[Microcontroller]
Camera used in embedded Linux system
1) Currently, more and more embedded systems use camera applications, mainly in the following ways Remote monitoring: such as closed-circuit television systems, operators use cameras to remotely monitor a specific area, which can be as small as a community or as large as a municipal public place. Surveillance vide
[Microcontroller]
Camera used in embedded Linux system
ARM-Linux driver transplantation--Linux burning tool DNW and USB driver installation
Host platform: Gentoo Linux 11.2 with linux kernel 3.0.6 Hardware platform: FL2440 (S3C2440) with linux kernel 2.6.35 Original work, please indicate the source when reprinting http://blog.csdn.net/yming0221/article/details/7211396 1. First download DNW for linux  http://download.csdn.net/source/1011140 2. Unzi
[Microcontroller]
ARM-Linux driver transplantation--Linux burning tool DNW and USB driver installation
The first bare-metal program for mini2440 - Light up the LED
After leaving my Mini2440 unused for two and a half years, I decided to take it out again and try to learn embedded Linux again. I used the Mini2440 development board from Friendly Arm, Wei Dongshan's "Embedded Linux Application Development Complete Manual" and its video tutorial. Therefore, all the software involve
[Microcontroller]
The first bare-metal program for mini2440 - Light up the LED
Linux on iPhone will be available to support dual boot with iOS
      According to FOSSBRTES, users will soon be able to run Linux on their iPhones like on Android devices through dual booting. Currently, jailbreakers and developers Raffaele and mcg29 have published detailed instructions on their Github page, detailing how to dual boot 64-bit iOS devices.       These instruction
[Mobile phone portable]
3.4. Embedded Linux kernel production
We have already made uboot, and the next step is to make the kernel. First enter the kernel source code and execute make distclean to clear the files generated by the previous compilation. Note that there is an additional condition ARCH=arm when configuring the kernel. After pr
[Microcontroller]
3.4. Embedded Linux kernel production
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号