驱动入门linux设备驱动之hello及网卡添加

我的开发环境

———————————————————————————————————————

机操作系统:Centos 6.7
交叉编译器环境:arm-linux-gcc-4.5.4 
交叉编译器:buildroot-2012.08
开发板平台: FL2440 
Linux内核版本: linux-3.0 
Bootloader:U-boot-2010.09
邮箱:[email protected]

———————————————————————————————————————

1.创建一个hello.c的文件
[hongfuhao@vboxcentos6 ~]$ ls
build.sh         dropbear-0.53.1.tar.bz2  fl2440                   rootfs.tar           vim_conf_V2.1.1.bin
dropbear-0.53.1  DUMMY.FIL                linux-3.0-s3c2440.patch  vim_conf_bak.tar.gz
[hongfuhao@vboxcentos6 ~]$ mkdir hello
[hongfuhao@vboxcentos6 ~]$ ls
build.sh         dropbear-0.53.1.tar.bz2  fl2440  linux-3.0-s3c2440.patch  vim_conf_bak.tar.gz
dropbear-0.53.1  DUMMY.FIL                hello   rootfs.tar               vim_conf_V2.1.1.bin
[hongfuhao@vboxcentos6 ~]$ cd hello/
[hongfuhao@vboxcentos6 hello]$ ls
[hongfuhao@vboxcentos6 hello]$ vim hello.c


 + hello.c                                                                                                                          
  1 /*********************************************************************************
  2  *      Copyright:  (C) 2016 hongfuhao
  3  *                  All rights reserved.
  4  *
  5  *       Filename:  hello.c
  6  *    Description:  This file 
  7  *                 
  8  *        Version:  1.0.0(2016年09月25日)
  9  *         Author:  hong fuhao <[email protected]>
 10  *      ChangeLog:  1, Release initial version on "2016年09月25日 02时21分37秒"
 11  *                 
 12  ********************************************************************************/
 13 #include
 14 #include
 15 MODULE_LICEENSE("Dual BSD/GPL");
 16 static int hello_init(void)
 17 {
 18     printk(KERN_ALERT"hello,hongfuhao\n");
 19     return 0;
 20 }  
 21 static void hello_exit(void)
 22 {
 23     printk(KERN_ALERT"Byebeye,hongfuhao\n");
 24 }                            
 25 module_init(hello_init);     
 26 module_exit(hello_exit);
 27            
该模块定义两个函数,一个在模块被装载打到内核时调用(hello_init),而另一个是在模块被移除时调用(hello_exit)。
另外,module_license是一个特殊宏,告诉内核,该模块采取自有许可证,若无此声明,内核装载该模块时会产生抱怨。
2.Hello 驱动的Makefile的编写(是用于linux系统):
[hongfuhao@vboxcentos6 hello]$ vim Makefile
 + Makefile                                                                                                                         
  1 obj-m=hello.o   //驱动模块从目标文件中构造
  2 modules:
  3     make -C /lib/modules/'uname -r'/build/ M='qwd' modules -C指定内核源代码的目录 uname -r 获得自己内核版本的信息           
    M指定编译生成的文件放在那个路径中
  4     make clean
  5 
  6 clean:
  7     rm -f *.o*.mod.c*.order*.symvers
2适用于开发板
[hongfuhao@vboxcentos6 hello]$ vim Makefile 


 + Makefile                                                                                                                         
  1 C=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
  2 KDIR?=/home/hongfuhao/fl2440/kernel/linux-3.0
  3 obj-m:=hello.o  
  4 
  5 default:  
  6     $(MAKE) -C $(KDIR) M=`pwd` modules  
  7     make clean  
  8 
  9 clean:  
 10     rm -f *.o *mod.c *.order *.symvers
[hongfuhao@vboxcentos6 hello]$ make
make -C /home/hongfuhao/fl2440/kernel/linux-3.0 M=`pwd` modules  
make[1]: Entering directory `/home/hongfuhao/fl2440/kernel/linux-3.0'
  CC [M]  /home/hongfuhao/hello/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/hongfuhao/hello/hello.mod.o
  LD [M]  /home/hongfuhao/hello/hello.ko
make[1]: Leaving directory `/home/hongfuhao/fl2440/kernel/linux-3.0'
make clean  
make[1]: Entering directory `/home/hongfuhao/hello'
rm -f *.o *mod.c *.order *.symvers
make[1]: Leaving directory `/home/hongfuhao/hello'
[hongfuhao@vboxcentos6 hello]$ ls
hello.c  hello.ko  hello.ko.unsigned  Makefile
[hongfuhao@vboxcentos6 hello]$ 

3在开发板上操作
需要了解的一些简单命令

U-Boot 2010.09 (Sep 26 2016 - 12:51:00)
DRAM:  64 MiB
NAND:  256 MiB
*** Warning - bad CRC or NAND, using default environment
没有保存u-boot的环境变量,敲save命令解决。
1, mount命令用来查看挂载的文件系统;
2, dmesg命令用来查看Linux内核打印的启动或调试信息,内核或驱动printk打印的信息;
3, cat /proc/mtd 查看分区情况,也可以用dmesg命令查看;
4,umount /dev/mtdblock4  块设备只是用来挂载或卸载的,使用时要建立文件系统;
5,flash_eraseall /dev/mtd4命令用来在Linux运行时擦除某一个分区,擦除之前一定先卸载;
6,挂载一个普通分区: mount -t jffs2或者yaffs2 /dev/mtdblock4 /data/
7, 升级内核:
    flash_eraseall /dev/mtd1  擦除整个分区
ifconfig eth0 192.168.2.168 up
tftp -gr linuxrom-s3c2440.bin 192.168.2.219
nandwrite -p /dev/mtd1 linuxrom-s3c2440.bin
更换根文件系统类型,务必:
  1, 如果是在Linux系统运行时,先卸载文件系统: umount /dev/mtdblock4
  2, 擦除整个分区
  3, 再挂载      mount -t jffs2 /dev/mtdblock4 /data/
  4,/data 这个路径没有被挂载到某个分区上,所以他属于根文件系统。写入到/data里的文件实际上写到了根文件系统里了。如果根文件系统是Initramfs,那么就写入到内存中去了。因为initramfs是基于内存的一种文件系统,掉电文件丢失。

  5,一旦/data被挂载之后,/data下的就是相应分区里的文件。写入到/data路径下的文件就写入到了相应的分区下。

下面开始在开发板上操作:

>: ifconfig

eth0      Link encap:Ethernet  HWaddr 08:00:3E:26:0A:51  

          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:71 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:8010 (7.8 KiB)  TX bytes:0 (0.0 B)

          Interrupt:51 Base address:0x2300

 下载前要先把配置好网卡的内核与之前的进行替换

>: tftp -gr hello.ko 192.168.1.2

hello.ko             100% |*******************************|  2138   0:00:00 ETA

>: ls

apps                  init                  sbin

bin                   lib                   sys

data                  linuxrc               tmp

dev                   linuxrom-s3c2440.bin  usr

etc                   mnt                   var

hello.ko              proc

info                  root

>: insmod hello.ko

Hello, hongfuhao

>: ls /lib/modules/3.0.0/modules.dep.bb

>: ls /lib/

ld-uClibc-0.9.33.2.so       libnsl-0.9.33.2.so

ld-uClibc.so.0              libnsl.so.0

libc.so.0                   libpthread-0.9.33.2.so

libcrypt-0.9.33.2.so        libpthread.so.0

libcrypt.so.0               libresolv-0.9.33.2.so

libdl-0.9.33.2.so           libresolv.so.0

libdl.so.0                  librt-0.9.33.2.so

libgcc_s.so                 librt.so.0

libgcc_s.so.1               libstdc++.so

libm-0.9.33.2.so            libstdc++.so.6

libm.so.0                   libstdc++.so.6.0.14

libmudflap.so               libstdc++.so.6.0.14-gdb.py

libmudflap.so.0             libuClibc-0.9.33.2.so

libmudflap.so.0.0.0         libutil-0.9.33.2.so

libmudflapth.so             libutil.so.0

libmudflapth.so.0           modules

libmudflapth.so.0.0.0

>: dmesg

Linux version 3.0.0 ([email protected]) (gcc version 4.5.4 (Buildroot 2012.08) ) #10 Sun Jul 24 18:39:28 CST 2016

CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177

CPU: VIVT data cache, VIVT instruction cache

Machine: SMDK2440

Memory policy: ECC disabled, Data cache writeback

CPU S3C2440A (id 0x32440001)

S3C24XX Clocks, Copyright 2004 Simtec Electronics

S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz

CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on

On node 0 totalpages: 16384

free_area_init_node: node 0, pgdat c0477674, node_mem_map c04b0000

  Normal zone: 128 pages used for memmap

  Normal zone: 0 pages reserved

  Normal zone: 16256 pages, LIFO batch:3

pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768

pcpu-alloc: [0] 0

Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256

Kernel command line: console=ttyS0,115200 mem=64M ubi.mtd=2 root=ubi0:rootfs rootwait rootfstype=ubifs rw

PID hash table entries: 256 (order: -2, 1024 bytes)

Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)

Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)

Memory: 64MB = 64MB total

Memory: 60112k/60112k available, 5424k reserved, 0K highmem

Virtual kernel memory layout:

    vector  : 0xffff0000 - 0xffff1000   (   4 kB)

    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)

    DMA     : 0xffc00000 - 0xffe00000   (   2 MB)

    vmalloc : 0xc4800000 - 0xf6000000   ( 792 MB)

    lowmem  : 0xc0000000 - 0xc4000000   (  64 MB)

    modules : 0xbf000000 - 0xc0000000   (  16 MB)

      .init : 0xc0008000 - 0xc0029000   ( 132 kB)

      .text : 0xc0029000 - 0xc0453000   (4264 kB)

      .data : 0xc0454000 - 0xc0477ea0   ( 144 kB)

       .bss : 0xc0477ec4 - 0xc04afc30   ( 224 kB)

SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1

NR_IRQS:85

irq: clearing pending ext status 00080800

irq: clearing pending ext status 00080000

irq: clearing subpending status 00000003

irq: clearing subpending status 00000002

timer tcon=00500000, tcnt a4ca, tcfg 00000200,00000000, usec 00001e57

Console: colour dummy device 80x30

console [ttyS0] enabled

Calibrating delay loop... 201.52 BogoMIPS (lpj=503808)

pid_max: default: 32768 minimum: 301

Mount-cache hash table entries: 512

CPU: Testing write buffer coherency: ok

gpiochip_add: gpios 288..303 (GPIOK) failed to register

gpiochip_add: gpios 320..334 (GPIOL) failed to register

gpiochip_add: gpios 352..353 (GPIOM) failed to register

NET: Registered protocol family 16

S3C Power Management, Copyright 2004 Simtec Electronics

S3C2440: Initialising architecture

S3C2440: IRQ Support

S3C244X: Clock Support, DVS off

bio: create slab at 0

SCSI subsystem initialized

usbcore: registered new interface driver usbfs

usbcore: registered new interface driver hub

usbcore: registered new device driver usb

s3c-i2c s3c2440-i2c: slave address 0x10

s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz

s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter

Advanced Linux Sound Architecture Driver Version 1.0.24.

cfg80211: Calling CRDA to update world regulatory domain

NET: Registered protocol family 2

IP route cache hash table entries: 1024 (order: 0, 4096 bytes)

TCP established hash table entries: 2048 (order: 2, 16384 bytes)

TCP bind hash table entries: 2048 (order: 1, 8192 bytes)

TCP: Hash tables configured (established 2048 bind 2048)

TCP reno registered

UDP hash table entries: 256 (order: 0, 4096 bytes)

UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)

NET: Registered protocol family 1

RPC: Registered named UNIX socket transport module.

RPC: Registered udp transport module.

RPC: Registered tcp transport module.

RPC: Registered tcp NFSv4.1 backchannel transport module.

NetWinder Floating Point Emulator V0.97 (extended precision)

NTFS driver 2.1.30 [Flags: R/W].

ROMFS MTD (C) 2007 Red Hat, Inc.

msgmni has been set to 117

io scheduler noop registered

io scheduler deadline registered

io scheduler cfq registered (default)

Console: switching to colour frame buffer device 60x53

fb0: s3c2410fb frame buffer device

s3c2440-uart.0: ttyS0 at MMIO 0x50000000 (irq = 70) is a S3C2440

s3c2440-uart.1: ttyS1 at MMIO 0x50004000 (irq = 73) is a S3C2440

s3c2440-uart.2: ttyS2 at MMIO 0x50008000 (irq = 76) is a S3C2440

brd: module loaded

loop: module loaded

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: 0xda (Samsung NAND 256MiB 3,3V 8-bit)

Scanning device for bad blocks

Bad eraseblock 46 at 0x0000005c0000

Bad eraseblock 397 at 0x0000031a0000

Creating 6 MTD partitions on "NAND":

0x000000000000-0x000000100000 : "mtdblock0 u-boot 1MB"

0x000000100000-0x000001000000 : "mtdblock1 kernel 15MB"

0x000001000000-0x000005000000 : "mtdblock2 rootfs 64MB"

0x000005000000-0x00000a000000 : "mtdblock3 apps 80MB"

0x00000a000000-0x00000d000000 : "mtdblock4 data 48MB"

0x00000d000000-0x000010000000 : "mtdblock5 backup 48MB"

UBI: attaching mtd2 to ubi0

UBI: physical eraseblock size:   131072 bytes (128 KiB)

UBI: logical eraseblock size:    129024 bytes

UBI: smallest flash I/O unit:    2048

UBI: sub-page size:              512

UBI: VID header offset:          512 (aligned 512)

UBI: data offset:                2048

UBI: max. sequence number:       0

UBI: volume 0 ("rootfs") re-sized from 490 to 502 LEBs

UBI: attached mtd2 to ubi0

UBI: MTD device name:            "mtdblock2 rootfs 64MB"

UBI: MTD device size:            64 MiB

UBI: number of good PEBs:        511

UBI: number of bad PEBs:         1

UBI: number of corrupted PEBs:   0

UBI: max. allowed volumes:       128

UBI: wear-leveling threshold:    4096

UBI: number of internal volumes: 1

UBI: number of user volumes:     1

UBI: available PEBs:             0

UBI: total number of reserved PEBs: 511

UBI: number of PEBs reserved for bad PEB handling: 5

UBI: max/mean erase counter: 1/0

UBI: image sequence number:  378407341

UBI: background thread "ubi_bgt0d" started, PID 700

dm9000 Ethernet Driver, V1.31

eth0: dm9000a at c4862300,c4864304 IRQ 51 MAC: 08:00:3e:26:0a:51 (chip)

ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver

s3c2410-ohci s3c2410-ohci: S3C24XX OHCI

s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1

s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000

hub 1-0:1.0: USB hub found

hub 1-0:1.0: 2 ports detected

usbcore: registered new interface driver libusual

s3c2410_udc: debugfs dir creation failed -19

mousedev: PS/2 mouse device common for all mice

S3C24XX RTC, (c) 2004,2006 Simtec Electronics

i2c /dev entries driver

sdhci: Secure Digital Host Controller Interface driver

sdhci: Copyright(c) Pierre Ossman

Registered led device: led4

Registered led device: led5

Registered led device: led6

Registered led device: led7

usbcore: registered new interface driver usbhid

usbhid: USB HID core driver

ALSA device list:

  No soundcards found.

TCP cubic registered

NET: Registered protocol family 17

lib80211: common routines for IEEE802.11 drivers

lib80211_crypt: registered algorithm 'NULL'

Registering the dns_resolver key type

drivers/rtc/hctosys.c: unable to open rtc device (rtc0)

UBIFS: mounted UBI device 0, volume 0, name "rootfs"

UBIFS: file system size:   61931520 bytes (60480 KiB, 59 MiB, 480 LEBs)

UBIFS: journal size:       8257536 bytes (8064 KiB, 7 MiB, 64 LEBs)

UBIFS: media format:       w4/r0 (latest is w4/r0)

UBIFS: default compressor: lzo

UBIFS: reserved for root:  0 bytes (0 KiB)

VFS: Mounted root (ubifs filesystem) on device 0:12.

Freeing init memory: 132K

usb 1-1: new full speed USB device number 2 using s3c2410-ohci

usb 1-1: device descriptor read/64, error -62

usb 1-1: device descriptor read/64, error -62

usb 1-1: new full speed USB device number 3 using s3c2410-ohci

usb 1-1: device descriptor read/64, error -62

usb 1-1: device descriptor read/64, error -62

usb 1-1: new full speed USB device number 4 using s3c2410-ohci

usb 1-1: device not accepting address 4, error -62

usb 1-1: new full speed USB device number 5 using s3c2410-ohci

usb 1-1: device not accepting address 5, error -62

hub 1-0:1.0: unable to enumerate USB device on port 1

dm9000 dm9000: eth0: link down

dm9000 dm9000: eth0: link up, 100Mbps, full-duplex, lpa 0x5DE1

Hello, hongfuhao 

>: lsmod

hello 632 0 - Live 0xbf000000

>: rmmod hello

Goodbye, hongfuhao

>: dmesg 

Linux version 3.0.0 ([email protected]) (gcc version 4.5.4 (Buildroot 2012.08) ) #10 Sun Jul 24 18:39:28 CST 2016

CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177

CPU: VIVT data cache, VIVT instruction cache

Machine: SMDK2440

Memory policy: ECC disabled, Data cache writeback

CPU S3C2440A (id 0x32440001)

S3C24XX Clocks, Copyright 2004 Simtec Electronics

S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz

CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on

On node 0 totalpages: 16384

free_area_init_node: node 0, pgdat c0477674, node_mem_map c04b0000

  Normal zone: 128 pages used for memmap

  Normal zone: 0 pages reserved

  Normal zone: 16256 pages, LIFO batch:3

pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768

pcpu-alloc: [0] 0

Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256

Kernel command line: console=ttyS0,115200 mem=64M ubi.mtd=2 root=ubi0:rootfs rootwait rootfstype=ubifs rw

PID hash table entries: 256 (order: -2, 1024 bytes)

Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)

Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)

Memory: 64MB = 64MB total

Memory: 60112k/60112k available, 5424k reserved, 0K highmem

Virtual kernel memory layout:

    vector  : 0xffff0000 - 0xffff1000   (   4 kB)

    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)

    DMA     : 0xffc00000 - 0xffe00000   (   2 MB)

    vmalloc : 0xc4800000 - 0xf6000000   ( 792 MB)

    lowmem  : 0xc0000000 - 0xc4000000   (  64 MB)

    modules : 0xbf000000 - 0xc0000000   (  16 MB)

      .init : 0xc0008000 - 0xc0029000   ( 132 kB)

      .text : 0xc0029000 - 0xc0453000   (4264 kB)

      .data : 0xc0454000 - 0xc0477ea0   ( 144 kB)

       .bss : 0xc0477ec4 - 0xc04afc30   ( 224 kB)

SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1

NR_IRQS:85

irq: clearing pending ext status 00080800

irq: clearing pending ext status 00080000

irq: clearing subpending status 00000003

irq: clearing subpending status 00000002

timer tcon=00500000, tcnt a4ca, tcfg 00000200,00000000, usec 00001e57

Console: colour dummy device 80x30

console [ttyS0] enabled

Calibrating delay loop... 201.52 BogoMIPS (lpj=503808)

pid_max: default: 32768 minimum: 301

Mount-cache hash table entries: 512

CPU: Testing write buffer coherency: ok

gpiochip_add: gpios 288..303 (GPIOK) failed to register

gpiochip_add: gpios 320..334 (GPIOL) failed to register

gpiochip_add: gpios 352..353 (GPIOM) failed to register

NET: Registered protocol family 16

S3C Power Management, Copyright 2004 Simtec Electronics

S3C2440: Initialising architecture

S3C2440: IRQ Support

S3C244X: Clock Support, DVS off

bio: create slab at 0

SCSI subsystem initialized

usbcore: registered new interface driver usbfs

usbcore: registered new interface driver hub

usbcore: registered new device driver usb

s3c-i2c s3c2440-i2c: slave address 0x10

s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz

s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter

Advanced Linux Sound Architecture Driver Version 1.0.24.

cfg80211: Calling CRDA to update world regulatory domain

NET: Registered protocol family 2

IP route cache hash table entries: 1024 (order: 0, 4096 bytes)

TCP established hash table entries: 2048 (order: 2, 16384 bytes)

TCP bind hash table entries: 2048 (order: 1, 8192 bytes)

TCP: Hash tables configured (established 2048 bind 2048)

TCP reno registered

UDP hash table entries: 256 (order: 0, 4096 bytes)

UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)

NET: Registered protocol family 1

RPC: Registered named UNIX socket transport module.

RPC: Registered udp transport module.

RPC: Registered tcp transport module.

RPC: Registered tcp NFSv4.1 backchannel transport module.

NetWinder Floating Point Emulator V0.97 (extended precision)

NTFS driver 2.1.30 [Flags: R/W].

ROMFS MTD (C) 2007 Red Hat, Inc.

msgmni has been set to 117

io scheduler noop registered

io scheduler deadline registered

io scheduler cfq registered (default)

Console: switching to colour frame buffer device 60x53

fb0: s3c2410fb frame buffer device

s3c2440-uart.0: ttyS0 at MMIO 0x50000000 (irq = 70) is a S3C2440

s3c2440-uart.1: ttyS1 at MMIO 0x50004000 (irq = 73) is a S3C2440

s3c2440-uart.2: ttyS2 at MMIO 0x50008000 (irq = 76) is a S3C2440

brd: module loaded

loop: module loaded

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: 0xda (Samsung NAND 256MiB 3,3V 8-bit)

Scanning device for bad blocks

Bad eraseblock 46 at 0x0000005c0000

Bad eraseblock 397 at 0x0000031a0000

Creating 6 MTD partitions on "NAND":

0x000000000000-0x000000100000 : "mtdblock0 u-boot 1MB"

0x000000100000-0x000001000000 : "mtdblock1 kernel 15MB"

0x000001000000-0x000005000000 : "mtdblock2 rootfs 64MB"

0x000005000000-0x00000a000000 : "mtdblock3 apps 80MB"

0x00000a000000-0x00000d000000 : "mtdblock4 data 48MB"

0x00000d000000-0x000010000000 : "mtdblock5 backup 48MB"

UBI: attaching mtd2 to ubi0

UBI: physical eraseblock size:   131072 bytes (128 KiB)

UBI: logical eraseblock size:    129024 bytes

UBI: smallest flash I/O unit:    2048

UBI: sub-page size:              512

UBI: VID header offset:          512 (aligned 512)

UBI: data offset:                2048

UBI: max. sequence number:       0

UBI: volume 0 ("rootfs") re-sized from 490 to 502 LEBs

UBI: attached mtd2 to ubi0

UBI: MTD device name:            "mtdblock2 rootfs 64MB"

UBI: MTD device size:            64 MiB

UBI: number of good PEBs:        511

UBI: number of bad PEBs:         1

UBI: number of corrupted PEBs:   0

UBI: max. allowed volumes:       128

UBI: wear-leveling threshold:    4096

UBI: number of internal volumes: 1

UBI: number of user volumes:     1

UBI: available PEBs:             0

UBI: total number of reserved PEBs: 511

UBI: number of PEBs reserved for bad PEB handling: 5

UBI: max/mean erase counter: 1/0

UBI: image sequence number:  378407341

UBI: background thread "ubi_bgt0d" started, PID 700

dm9000 Ethernet Driver, V1.31

eth0: dm9000a at c4862300,c4864304 IRQ 51 MAC: 08:00:3e:26:0a:51 (chip)

ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver

s3c2410-ohci s3c2410-ohci: S3C24XX OHCI

s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1

s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000

hub 1-0:1.0: USB hub found

hub 1-0:1.0: 2 ports detected

usbcore: registered new interface driver libusual

s3c2410_udc: debugfs dir creation failed -19

mousedev: PS/2 mouse device common for all mice

S3C24XX RTC, (c) 2004,2006 Simtec Electronics

i2c /dev entries driver

sdhci: Secure Digital Host Controller Interface driver

sdhci: Copyright(c) Pierre Ossman

Registered led device: led4

Registered led device: led5

Registered led device: led6

Registered led device: led7

usbcore: registered new interface driver usbhid

usbhid: USB HID core driver

ALSA device list:

  No soundcards found.

TCP cubic registered

NET: Registered protocol family 17

lib80211: common routines for IEEE802.11 drivers

lib80211_crypt: registered algorithm 'NULL'

Registering the dns_resolver key type

drivers/rtc/hctosys.c: unable to open rtc device (rtc0)

UBIFS: mounted UBI device 0, volume 0, name "rootfs"

UBIFS: file system size:   61931520 bytes (60480 KiB, 59 MiB, 480 LEBs)

UBIFS: journal size:       8257536 bytes (8064 KiB, 7 MiB, 64 LEBs)

UBIFS: media format:       w4/r0 (latest is w4/r0)

UBIFS: default compressor: lzo

UBIFS: reserved for root:  0 bytes (0 KiB)

VFS: Mounted root (ubifs filesystem) on device 0:12.

Freeing init memory: 132K

usb 1-1: new full speed USB device number 2 using s3c2410-ohci

usb 1-1: device descriptor read/64, error -62

usb 1-1: device descriptor read/64, error -62

usb 1-1: new full speed USB device number 3 using s3c2410-ohci

usb 1-1: device descriptor read/64, error -62

usb 1-1: device descriptor read/64, error -62

usb 1-1: new full speed USB device number 4 using s3c2410-ohci

usb 1-1: device not accepting address 4, error -62

usb 1-1: new full speed USB device number 5 using s3c2410-ohci

usb 1-1: device not accepting address 5, error -62

hub 1-0:1.0: unable to enumerate USB device on port 1

dm9000 dm9000: eth0: link down

dm9000 dm9000: eth0: link up, 100Mbps, full-duplex, lpa 0x5DE1

Hello, hongfuhao

Goodbye, hongfuhao

过程中遇到的问题:

以太网卡驱动没安装,ifconfig -a都看不到网卡

解决方法:

第一步、修改内核代码

vim arch/arm/mach-s3c2440/mach-smdk2440.c

#include  //添加DM9000网卡的头文件  
并添加如下代码  
/* add DM9000 ethernet drivers ,whitch is bodify by liuchengdeng */  
#define DM9000_BASE    (S3C2410_CS4 + 0x300)  
static struct resource s3c_dm9000_resource[] = {  
     [0] = {  
        .start = DM9000_BASE,  
        .end   = DM9000_BASE + 3,  
        .flags = IORESOURCE_MEM  
    },  
    [1] = {  
        .start = DM9000_BASE + 4,  
        .end   = DM9000_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 s3c_dm9000_pdata = {  
    .flags      = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),  
};  
static struct platform_device s3c_device_dm9000 = {  
    .name       = "dm9000",  
    .id     = -1,  
    .num_resources  = ARRAY_SIZE(s3c_dm9000_resource),  
    .resource   = s3c_dm9000_resource,  
    .dev        = {  
        .platform_data  = &s3c_dm9000_pdata,  
    },  
}; 

2.修改platform_device *smdk2440_devices[] __initdata结构体为如下,在其中添加启动DM9000

static struct platform_device *smdk2440_devices[] __initdata = {
    &s3c_device_ohci,
    &s3c_device_lcd,
    &s3c_device_wdt,
    &s3c_device_i2c0,
    &s3c_device_iis,
    &s3c_device_dm9000,
};

3.vim include/linux/dm9000.h  添加如下头文件

#include

重新make之后,我们的内核文件就支持dm9000网卡了,在开发板上跑起来后,就能够ping 192.168.1.2(电脑有线IP






你可能感兴趣的:(驱动模块)