您的位置:首页 > 其它

添加网卡驱动和USB支持 以及一些问题的集中处理

2016-07-31 17:09 651 查看
之前内核移植时没有添加网卡驱动和USB支持,添加如下:

1.以太网卡驱动安装:

1.1第一步、修改内核代码

[luxibao@centos ~]$ cd fl2440

[luxibao@centos fl2440]$ cd kernel

[luxibao@centos kernel]$ cd linux-3.0

[luxibao@centos linux-3.0]$ cd arch/arm/cd mach-s3c2440

[luxibao@centos mach-s3c2440]$ vim mach-smdk2440.c

#include <linux/dm9000.h> //添加DM9000网卡的头文件

并添加如下代码

/* add DM9000 ethernet drivers ,whitch is
modify by luxibao */

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

},

};

1.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,

};

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

#include <linux/io.h>

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



2.Linux内核添加USB支持

添加USB支持:

FL2440添加u盘的挂载比较简单,大部分的内容都是在内核里面做make menuconfig,配置内核

Device Drivers --->

Generic Driver Options --->

(/sbin/hotplug) path to uevent helper //配置u盘的热插拔

[*] Block devices --->

<*> Low Performance USB Block driver

SCSI device support --->

<*> SCSI device support

<*> SCSI generic support

[*]legacy /proc/scsi/ support

<*>SCSI disk support

<*> SCSI CDROM support

[*] Probe all LUNs on each SCSI device

[*] HID Devices --->

<*> USB Human Interface Device (full HID) support

[*] /dev/hiddev raw HID device support

[*] USB support --->

<*> Support for Host-side USB

[*] USB device filesystem (DEPRECATED)

[*] USB device class-devices (DEPRECATED)

<*> USB Monitor

<*> OHCI HCD support

<*> USB Mass Storage support

File systems ---> //配置u盘的文件系统

DOS/FAT/NT Filesystems --->

<*> MSDOS fs support

<*> VFAT (Windows-95) fs support

(936) Default codepage for FAT

(cp936) Default iocharset for FAT

-*- Native language support ---> //配置u盘的语言格式支持,不过感觉着个配置没什么用,中文也支持不了,也许是因为linux对中文的支持并不好吧

<*> Simplified Chinese charset (CP936, GB2312)

<*> ASCII (United States)

<*> NLS UTF-8

配置好之后,重新编译,烧写到板子上面运行,(现在板子上面有u盘)就可以看到以下信息了

usbcore: registered new interface driver usbfs

usbcore: registered new interface driver hub

usbcore: registered new device driver usb

usbcore: registered new interface driver ub

Uniform Multi-Platform E-IDE driver

usbcore: registered new interface driver uas

Initializing USB Mass Storage driver...

usbcore: registered new interface driver usb-storage

USB Mass Storage support registered.

mousedev: PS/2 mouse device common for all mice

i2c /dev entries driver

usbcore: registered new interface driver usbhid

usbhid: USB HID core driver

TCP cubic registered

NET: Registered protocol family 17

Freeing init memory: 13188K

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

hub 1-1:1.0: USB hub found

hub 1-1:1.0: 4 ports detected

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

uba: uba1

usb 1-1.2: USB disconnect, device number 3

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

uba: uba1

这时候就可以看到我们的u盘已经挂载好了。

后记:

有时候,我们可能发现我们配置好了内核,但是我们的u盘无论如何也发现不了,这时候就出现了一个问题,这个问题不是在于我的内核配置有错误,而是在于我们的u-boot设置usb的时钟不对引起的。这样,我就不得不重新回到u-boot,配置好usb的时钟。

修改u-boot中:board/fl2440/fl2440.c文件中关于usb的时钟的内容,将如下三个宏的值改为如下

#define U_M_MDIV 0x38

#define U_M_PDIV 0x2

#define U_M_SDIV 0x2

重新编译u-boot和内核,烧写,重启之后,我们的内核就能支持u盘了。

添加USB结构体变量,加厂商ID和设备ID

[Ciel@localhost linux-3.0]$ vim drivers/usb/serial/option.c

2964 @@ -51,6 +51,13 @@

2965 static void option_instat_callback(struct urb *urb);

2966

2967 /* Vendor and product IDs */

2968 +static int vendor = 0; /* Add by guowenxue */

2969 +static int product = 0; /* Add by guowenxue */

2970 +

2971 +/* Vendor and product IDs */

2972 +#define OPTION_VENDOR_RESERVED 0xFFFF /* Add by guowenxue */

2973 +#define OPTION_RESERVED_DEVICE 0xFFFF /* Add by guowenxue */

2974 +

2975 #define OPTION_VENDOR_ID 0x0AF0

2976 #define OPTION_PRODUCT_COLT 0x5000

2977 #define OPTION_PRODUCT_RICOLA 0x6000

2978 @@ -446,7 +453,8 @@

2979 .reason = OPTION_BLACKLIST_SENDSETUP

2980 };

2981

2982 -static const struct usb_device_id option_ids[] = {

2983 +static struct usb_device_id option_ids[] = {

2984 + { USB_DEVICE(OPTION_VENDOR_RESERVED, OPTION_RESERVED_DEVICE) }, /* Add by guowenxue */

2985 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },

2986 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },

2987 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_LIGHT) },

2988 @@ -1079,6 +1087,15 @@

2989 static int __init option_init(void)

2990 {

2991 int retval;

2992 +

2993 + if ((vendor>0) && (product>0))

2994 + {

2995 + option_ids[0].match_flags = USB_DEVICE_ID_MATCH_DEVICE;

2996 + option_ids[0].idVendor = vendor;

2997 + option_ids[0].idProduct = product;

2998 + printk("Register option drvier for modem vendor=0x%04x product=0x%04x\n", vendor, product);

2999 + }

3000 +

[Ciel@localhost linux-3.0]$ vim arch/arm/mach-s3c2440/mach-smdk2440.c

4 @@ -23,6 +23,13 @@

5 #include <linux/platform_device.h>

6 #include <linux/io.h>

7

8 +/* add by guowenxue for norflash */

9 +#include <linux/gpio_keys.h>

10 +#include <linux/input.h>

11 +#include <linux/mtd/physmap.h>

12 +#include <linux/mtd/mtd.h>

13 +#include <linux/mtd/partitions.h>

14 +

15 #include <asm/mach/arch.h>

16 #include <asm/mach/map.h>

17 #include <asm/mach/irq.h>

18 @@ -44,6 +51,11 @@

19 #include <plat/clock.h>

20 #include <plat/devs.h>

21 #include <plat/cpu.h>

22 +#include <plat/ts.h> /*Add by guowenxue to support Touch screen, 2011.09.06*/

23 +#include <mach/regs-clock.h> /*Add by guowenxue 2012.07.15, for usb_s3c2440_init() */

24 +#include <linux/i2c.h> /*Add by guowenxue 2012.10.22, for AT24C512 driver */

25 +#include <linux/i2c/at24.h> /* Add by guowenxue 2012.10.22, for AT24C512 driver */

26 +#include <linux/delay.h>

27

28 #include <plat/common-smdk.h>

29

30 @@ -102,6 +114,13 @@

31 }

224 +/* Add by guowenxue 2012.07.15, fix device descriptor read/64, error -62 bug, value refer to datasheet P255 */

225 +int usb_s3c2440_init(void)

226 +{

227 + /* Input Frequency is 12.0000MHz, and MDEV=0x38 PDIV=2 SDIV=2, so output frequency 48.00MHz */

228 + unsigned long upllvalue = (0x38<<12)|(0x02<<4)|(0x02);

229 + while (upllvalue != __raw_readl(S3C2410_UPLLCON))

230 + {

231 + __raw_writel(upllvalue, S3C2410_UPLLCON);

232 + mdelay(1);

233 + }

234 +

235 + return 0;

236 +}

237 +

238 static void __init smdk2440_map_io(void)

239 {

240 s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));

241 - s3c24xx_init_clocks(16934400);

242 + s3c24xx_init_clocks(12000000); /*Modify by guowenxue, 2011.08.30*/

243 s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));

244 + usb_s3c2440_init(); /* Add by guowenxue, 2012.07.15 */

245 }

246

重新编译下内核,加载到开发板,插入U盘

由于之前的种种原因导致出现的一些问题集中解决了一些,如下:

1.由于之前安装虚拟机时候没有注意系统时间的设置导致后面make出现问题----date设置之后没有进行hwclock设置,硬件时钟同软件时钟不同步:



解决:

方法一: Date 命令

在 Linux 中, 你可以通过 date 命令来更改系统的日期和时间:

# date --set='NEW_DATE'

其中 NEW_DATE 是诸如 "Sun, 28 Sep 2014 16:21:42" 或者 "2014-09-29 16:21:42" 的可读格式的日期字符串.

日期格式也可以手动指定以获得更精确的结果:

# date +FORMAT --set='NEW_DATE'

例如:

# date +’%Y%m%d %H%m’ --set='20140928 1518'



你也可以用相对的方式地增加或减少一定的天数,周数,月数和秒数,分钟数,小时数。 你也可以把日期和时间的参数放到一个命令中。

# date --set='+5 minutes'# date --set='-2 weeks'# date --set='+3 months'# date --set='-3 months +2 weeks -5 minutes'



最后, 把硬件时钟设置为当前系统时钟:

# hwclock --systohc

运行 hwclock --systohc 的目的是将硬件时钟同软件时钟同步, 这可以更正硬件时钟的系统漂移(即时钟按照一定的速度走快或走慢).

另一方面, 如果硬件时钟是正确的, 但系统时钟有误, 可以用下面的命令更正:

# hwclock --hctosys

在两种情况下, hwclock 命令都是将两个时钟同步. 否则, 重启后时间会是错误的, 因为当电源关闭时硬件时钟会记忆时间. 然而, 这对于虚拟机器并不适用, 因为虚拟机器并不能访问硬件时钟.

方法二: NTP

另一种使系统日期和时间保持精确的方法是使用 NTP (网络时间协议). 在 Linux 上, ntpdate 命令通过 NTP 将系统时钟和公共 NTP 服务器同步.

你可以使用如下命令来安装 ntpdate:

在 Debian 及基于 Debian 的发行版上:

# aptitude install ntpdate

在基于 Ret Hat 的发行版上:

# yum install ntpdate

使用 NTP 同步系统时钟:

# ntpdate -u <NTP 服务器名或IP># hwclock --systohc



除了一次性使用 ntpdate 来同步时钟, 你也可以使用 NTP 守护进程(ntpd), 它会始终在后台运行, 不断地通过 NTP 来调整系统时钟。

2.修改好系统时间后没有重新make导致






解决:删除原来的hello.ko,重新make生成hello.ko,然后重新tftp载入






3.重新编译的内核烧录到开发板上后无法烧录ubifs文件系统:






解决:查看根文件系统树的init和linuxrc 是否存在 busybox的版本是否是ARM版本








没有问题。 试用了其他同学的文件系统还是不行,最后确定是内核的问题,转了同学的.congfig文件重新make后可以了。

4.

我们配置好了内核,但是我们的u盘无论如何也发现不了,这时候就出现了一个问题,这个问题不是在于我的内核配置有错误,而是在于我们的u-boot设置usb的时钟不对引起的。这样,我就不得不重新回到u-boot,配置好usb的时钟。






解决:修改u-boot中:board/fl2440/fl2440.c文件中关于usb的时钟的内容,将如下三个宏的值改为如下

#define U_M_MDIV 0x38

#define U_M_PDIV 0x2

#define U_M_SDIV 0x2

重新编译u-boot和内核,烧写,重启之后,我们的内核就能支持u盘了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐