本文出自http://blog.csdn.net/edroid1530/article/details/63683344。
1.检查内核是否有网卡驱动
使用 ifconfig -a 命令可以看到内核当中没有网卡驱动,接下来我们就在内核中添加网卡的配置。
2.修改内核源码,添加网卡驱动编译
2-1.在mach-smdk2440.c文件中添加如下代码
- [lwn@localhost linux-lwn-3.0.1] vim ./arch/arm/mach-s3c2440/mach-smdk2440.c </span></span></li><li><span><span class="preprocessor">#include <linux/dm9000.h> //添加DM9000网卡的头文件 </span><span> </span></span></li><li class="alt"><span><span class="comment">/* add DM9000 ethernet drivers ,whitch is bodify by liuchengdeng */</span><span> </span></span></li><li><span><span class="preprocessor">#define DM9000_BASE (S3C2410_CS4 + 0x300) </span><span> </span></span></li><li class="alt"><span><span class="keyword">static</span><span> </span><span class="keyword">struct</span><span> resource s3c_dm9000_resource[] = { </span></span></li><li><span> [0] = { </span></li><li class="alt"><span> .start = DM9000_BASE, </span></li><li><span> .end = DM9000_BASE + 3, </span></li><li class="alt"><span> .flags = IORESOURCE_MEM </span></li><li><span> }, </span></li><li class="alt"><span> [1] = { </span></li><li><span> .start = DM9000_BASE + 4, </span></li><li class="alt"><span> .end = DM9000_BASE + 7, </span></li><li><span> .flags = IORESOURCE_MEM </span></li><li class="alt"><span> }, </span></li><li><span> [2] = { </span></li><li class="alt"><span> .start = IRQ_EINT7, </span></li><li><span> .end = IRQ_EINT7, </span></li><li class="alt"><span> .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE, </span></li><li><span> } </span></li><li class="alt"><span>}; </span></li><li><span><span class="comment">/* </span> </span></li><li class="alt"><span><span class="comment"> * The DM9000 has no eeprom, and it's MAC address is set by </span> </span></li><li><span><span class="comment"> * the bootloader before starting the kernel. </span> </span></li><li class="alt"><span><span class="comment"> */</span><span> </span></span></li><li><span><span class="keyword">static</span><span> </span><span class="keyword">struct</span><span> dm9000_plat_data s3c_dm9000_pdata = { </span></span></li><li class="alt"><span> .flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM), </span></li><li><span>}; </span></li><li class="alt"><span><span class="keyword">static</span><span> </span><span class="keyword">struct</span><span> platform_device s3c_device_dm9000 = { </span></span></li><li><span> .name = <span class="string">"dm9000"</span><span>, </span></span></li><li class="alt"><span> .id = -1, </span></li><li><span> .num_resources = ARRAY_SIZE(s3c_dm9000_resource), </span></li><li class="alt"><span> .resource = s3c_dm9000_resource, </span></li><li><span> .dev = { </span></li><li class="alt"><span> .platform_data = &s3c_dm9000_pdata, </span></li><li><span> }, </span></li><li class="alt"><span>}; </span></li></ol><div class="save_code tracking-ad" data-mod="popu_249"><a href="javascript:;" target="_blank"><img src="http://static.blog.csdn.net/images/save_snippets.png"></a></div></div><pre class="cpp" style="display: none;" name="code" snippet_file_name="blog_20170319_1_9710561" code_snippet_id="2274372">[lwn@localhost linux-lwn-3.0.1]
- #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,
- },
- };
#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-2.添加成员变量
在mach-smdk2440.c文件中的结构体platform_device *smdk2440_devices[] __initdata中添加如下成员变量。
- 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,//添加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,//添加dm9000成员变量
};
2-3.添加头文件
在 dm9000.h中添加如下头文件
- vim include/linux/dm9000.h
- #ifndef __DM9000_PLATFORM_DATA
- #define __DM9000_PLATFORM_DATA __FILE__
- #include <linux/io.h> //添加 linux/io.h 头文件
- /* IO control flags */
vim include/linux/dm9000.h#ifndef __DM9000_PLATFORM_DATA#define __DM9000_PLATFORM_DATA __FILE__#include <linux/io.h> //添加 linux/io.h 头文件/* IO control flags */
3.网卡使能
使用make命令重新编译内核并烧录到开发板上,再使用ifconfig -a命令已经可以网卡驱动已经添加上了,但是此刻依然不能与主机通信,因为还没有配置ip,即网卡没有使能。
3-1.暂时使能
下面 使用ifconfig命令将网卡使能。使能之后我们可以看到已经可以和主机进行通信了。
3-2.永久使能
注意这个时候我们只是暂时性的使能了网卡,开发板下次启动的时候需要重新使能。如果我们想要网卡使能长期有效,修改开发板上的配置文件
- >: vim etc/init.d/S01_network
- #!/bin/bash
- ifconfig eth0 192.168.1.199 netmask 255.255.255.0
>: vim etc/init.d/S01_network#!/bin/bashifconfig eth0 192.168.1.199 netmask 255.255.255.0
到此,fl2440开发板的整个网卡驱动配置就已经完成了。