首页 > 系统相关 >linux驱动入门-hello设备驱动程序编写及内核的更新(网卡的添加)

linux驱动入门-hello设备驱动程序编写及内核的更新(网卡的添加)

时间:2022-10-18 17:02:55浏览次数:49  
标签:驱动程序 leiyuxing bytes number order 网卡 linux device hello


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

主机操作系统:Centos 6.7
交叉编译器环境:arm-linux-gcc-4.5.4 
开发板平台: FL2440 
Linux内核版本: linux-3.0 
开发模块: HELLO入门驱动
邮箱:[email protected]

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

1.1创建一个hello.c文件

[leiyuxing@centos6 ~]$ mkdir hello

[leiyuxing@centos6 ~]$ ls

dropbear-0.53.1 fl2440 vmware-tools-distrib 模板 图片 下载 桌面

dropbear-0.53.1.tar.bz2 hello 公共的 视频 文档 音乐

[leiyuxing@centos6 ~]$ cd hello/

[leiyuxing@centos6 hello]$ ls

[leiyuxing@centos6 hello]$ vim hello.c
/******************************************************************************
* Copyright: (C) 2016 leiyuxing<[email protected]>
* All rights reserved.
*
* Filename: hello.c
* Description: This file
*
* Version: 1.0.0(2016年07月23日)
* Author: leiyuxing <[email protected]>
* ChangeLog: 1, Release initial version on "2016年7月23日19时48分00秒"
*
*
*******************************************************************************/
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
printk(KERN_ALERT "Hello, leiyuxing\n");
return 0;
}



static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, leiyuxing\n");
}


module_init(hello_init);
module_exit(hello_exit);

这个模块定义了两个函数,其中一个在模块被装载打到内核是调用(hello——init),而另一个则是在模块被移除时调用(hello_exit)。

特殊宏(MODULE_LICENSE)用来告诉内核,该模块采取自由许可证,如果没有这样的声明,内核在装载该模块时会产生抱怨。

 1.2Hello 驱动的Makefile编写:

适用于Linux操作系统:

 1.2 在hello.c同一级目录下创建Makefile

[leiyuxing@centos6 hello]$ vim Makefile
obj-m=hello.o      //驱动模块从目标文件中构造
modules:
make -C /lib/modules/`uname -r`/build/ M=`pwd` modules -C指定内核源代码的目录 uname -r获得自己内核的版本信息M指定编译生成的文件放在哪个路径中
make clean

clean:
rm -f *.o *.mod.c *.order *.symvers
[leiyuxing@centos6 hello]$ ls

hello.c makefile

[leiyuxing@centos6 hello]$ make
make -C /lib/modules/`uname -r`/build/ M=`pwd` modules

make[1]: Entering directory `/usr/src/kernels/2.6.32-573.el6.i686'

CC [M] /home/leiyuxing/hello/hello.o

Building modules, stage 2.

MODPOST 1 modules

CC /home/leiyuxing/hello/hello.mod.o

LD [M] /home/leiyuxing/hello/hello.ko.unsigned

NO SIGN [M] /home/leiyuxing/hello/hello.ko

make[1]: Leaving directory `/usr/src/kernels/2.6.32-573.el6.i686'

make clean

make[1]: Entering directory `/home/leiyuxing/hello'

rm -f *.o *.mod.c *.order *.symvers

make[1]: Leaving directory `/home/leiyuxing/hello'



[leiyuxing@centos6 hello]$ ls

hello.c hello.ko hello.ko.unsigned Makefile

[leiyuxing@centos6 hello]$ sudo insmod ./hello.ko

[leiyuxing@centos6 hello]$ dmesg

可以看到:

 

linux驱动入门-hello设备驱动程序编写及内核的更新(网卡的添加)_-hello设备驱动程序编写及内核的更新

[leiyuxing@centos6 hello]$ sudo rmmod ./hello.ko

[leiyuxing@centos6 hello]$ dmesg

可以看到:

 

linux驱动入门-hello设备驱动程序编写及内核的更新(网卡的添加)_linux_02

[leiyuxing@centos6 hello]$ lsmod

[leiyuxing@centos6 hello]$ dmesg

linux驱动入门-hello设备驱动程序编写及内核的更新(网卡的添加)_centos_03

 

2.1适用于fl2440开发板:

[leiyuxing@centos6 hello.1]$ vim Makefile
C=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
KDIR?=/home/leiyuxing/fl2440/kernel/linux-3.0
obj-m:=hello.o

default:
$(MAKE) -C $(KDIR) M=`pwd` modules
make clean

clean:
rm -f *.o *mod.c *.order *.symvers

 

[leiyuxing@centos6 hello.1]$ make

make -C /home/leiyuxing/fl2440/kernel/linux-3.0 M=`pwd` modules

make[1]: Entering directory `/home/leiyuxing/fl2440/kernel/linux-3.0'

CC [M] /home/leiyuxing/hello.1/hello.o

Building modules, stage 2.

MODPOST 1 modules

CC /home/leiyuxing/hello.1/hello.mod.o

LD [M] /home/leiyuxing/hello.1/hello.ko

make[1]: Leaving directory `/home/leiyuxing/fl2440/kernel/linux-3.0'

make clean

make[1]: Entering directory `/home/leiyuxing/hello.1'

rm -f *.o *mod.c *.order *.symvers

make[1]: Leaving directory `/home/leiyuxing/hello.1'

[leiyuxing@centos6 hello.1]$ ls

hello.c hello.ko Makefile

2.2在开发板上操作:

首先在开发板上操作之前我们必须理解以下几个命令的含义:

U-Boot 2010.09 (Mar 28 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, leiyuxing

>: 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 <bio-0> 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, leiyuxing

>: lsmod

hello 632 0 - Live 0xbf000000

>: rmmod hello

Goodbye, leiyuxing

>: 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 <bio-0> 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, leiyuxing

Goodbye, leiyuxing

 遇到的错误:

错误一:

obj-m=hello.c

modules:

make -C /lib/modules/`uname -r`/build/ M=`pwd` modules

make clean



clean:

rm -f *.ko.* *.o *.mod.c *.order *.symvers

 

linux驱动入门-hello设备驱动程序编写及内核的更新(网卡的添加)_centos_04

解决方法:

把.*.ko.*删掉

错误二:

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

解决方法:

第一步、修改内核代码

vim arch/arm/mach-s3c2440/mach-smdk2440.c
#include <linux/dm9000.h>  //添加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 <linux/io.h>

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

标签:驱动程序,leiyuxing,bytes,number,order,网卡,linux,device,hello
From: https://blog.51cto.com/u_15834920/5767615

相关文章

  • linux驱动开发FL2440开发板-LED驱动及其测试程序
    ———————————————————————————————————————主机操作系统:Centos6.7交叉编译器环境:arm-linux-gcc-4.5.4 开发板平台:FL2440 Linu......
  • Linux常用工具和命令总结
    一.Linux常用命令1.Linux常用命令列表命令作用常用参数参数作用ls列出指定目录的列表,包括文件和子目录。默认是当前目录-l以列表方式查看-a显示隐含文件和目录-h以便于阅读的......
  • Linux文件操作命令之二
    本周任务:1.用户zhangsan是项目经理,他有时想看devlopment组(研发部门)的文件,有时又想看market组(市场部)的文件;在Linux系统下该怎么处理能满足这个需求?      ......
  • Linux常用的tar指令
    tar-zxvf*****.tar.gz-C/opt/**(解压到指定目录) 整理对应的命令tar–xvffile.tar//解压tar包tar-xzvffile.tar.gz//解压tar.gztar-xjvffile.tar.bz2//......
  • Linux系统管理_用户管理
    cat/etc/passwd #账户文件cat/etc/shadow #密码文件cat/etc/login.defs #密码策略机UID定义文件#普通用户UID范围1000~60000;系统用户UID取值范围201~9......
  • Linux下安装git工具及访问github问题的解决
    什么是git参考下这里:​​https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-Git-%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F​​站长写的很详细。如何安装安装[root@OpenKM~]......
  • linux windows双系统 磁盘扩充 系统备份
    前言由于工作需要,从windows迁移到linux,但是怕linux下有工作不能胜任,所以先装了双系统过度。用了一段时间,对windows的依赖越来越低,所以准备卸载windows上的一些软件,清理一......
  • Linux split package into more parts
    Sometimestheirsinglepackagespaceislimited,justlikenobiggerthan10Mforeachdocument,intheseconditions,weneedsplitthebigoneintomorepiece......
  • Linux安装mysql之路
    1、登录机器(1)链接机器ssh+ip,回车ssh192.168.1.1(2)输入密码,回车2、上传文件由于作者这边是内网,安全原因不能暴露具体内容,大致是利用工具将文件传到的指定目录中(非内网情况可......
  • Linux (Debain11) 安装 docker-desktop 时出现依赖问题
    安装Docker-Desktop出现依赖问题添加docker-ce-cli的安装源$echo\"deb[arch=$(dpkg--print-architecture)signed-by=/usr/share/keyrings/docker-archive-keyr......