s3c2440 dm9000网卡驱动移植

时间:2021-10-31 09:38:18


本文出自http://blog.csdn.net/edroid1530/article/details/63683344。


1.检查内核是否有网卡驱动

使用 ifconfig -a 命令可以看到内核当中没有网卡驱动,接下来我们就在内核中添加网卡的配置。s3c2440 dm9000网卡驱动移植


2.修改内核源码,添加网卡驱动编译


2-1.在mach-smdk2440.c文件中添加如下代码

[cpp] view plain copy print?s3c2440 dm9000网卡驱动移植s3c2440 dm9000网卡驱动移植
  1. [lwn@localhost linux-lwn-3.0.1]&nbsp;vim&nbsp;./arch/arm/mach-s3c2440/mach-smdk2440.c&nbsp;&nbsp;</span></span></li><li><span><span class="preprocessor">#include&nbsp;&lt;linux/dm9000.h&gt;&nbsp;&nbsp;//添加DM9000网卡的头文件&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="comment">/*&nbsp;add&nbsp;DM9000&nbsp;ethernet&nbsp;drivers&nbsp;,whitch&nbsp;is&nbsp;bodify&nbsp;by&nbsp;liuchengdeng&nbsp;*/</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li><span><span class="preprocessor">#define&nbsp;DM9000_BASE&nbsp;&nbsp;&nbsp;&nbsp;(S3C2410_CS4&nbsp;+&nbsp;0x300)&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">struct</span><span>&nbsp;resource&nbsp;s3c_dm9000_resource[]&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0]&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.start&nbsp;=&nbsp;DM9000_BASE,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.end&nbsp;&nbsp;&nbsp;=&nbsp;DM9000_BASE&nbsp;+&nbsp;3,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.flags&nbsp;=&nbsp;IORESOURCE_MEM&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;[1]&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.start&nbsp;=&nbsp;DM9000_BASE&nbsp;+&nbsp;4,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.end&nbsp;&nbsp;&nbsp;=&nbsp;DM9000_BASE&nbsp;+&nbsp;7,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.flags&nbsp;=&nbsp;IORESOURCE_MEM&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;[2]&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.start&nbsp;=&nbsp;IRQ_EINT7,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.end&nbsp;&nbsp;&nbsp;=&nbsp;IRQ_EINT7,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.flags&nbsp;=&nbsp;IORESOURCE_IRQ&nbsp;|&nbsp;IORESOURCE_IRQ_HIGHEDGE,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>};&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span><span class="comment">/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;</span></li><li class="alt"><span><span class="comment">&nbsp;*&nbsp;The&nbsp;DM9000&nbsp;has&nbsp;no&nbsp;eeprom,&nbsp;and&nbsp;it's&nbsp;MAC&nbsp;address&nbsp;is&nbsp;set&nbsp;by&nbsp;&nbsp;</span>&nbsp;</span></li><li><span><span class="comment">&nbsp;*&nbsp;the&nbsp;bootloader&nbsp;before&nbsp;starting&nbsp;the&nbsp;kernel.&nbsp;&nbsp;</span>&nbsp;</span></li><li class="alt"><span><span class="comment">&nbsp;*/</span><span>&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li><span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">struct</span><span>&nbsp;dm9000_plat_data&nbsp;s3c_dm9000_pdata&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;.flags&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;(DM9000_PLATF_16BITONLY&nbsp;|&nbsp;DM9000_PLATF_NO_EEPROM),&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>};&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">struct</span><span>&nbsp;platform_device&nbsp;s3c_device_dm9000&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;.name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;<span class="string">"dm9000"</span><span>,&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;.id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-1,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;.num_resources&nbsp;&nbsp;=&nbsp;ARRAY_SIZE(s3c_dm9000_resource),&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;.resource&nbsp;&nbsp;&nbsp;=&nbsp;s3c_dm9000_resource,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;.dev&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.platform_data&nbsp;&nbsp;=&nbsp;&amp;s3c_dm9000_pdata,&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>};&nbsp;&nbsp;&nbsp;&nbsp;</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]
  2. #include <linux/dm9000.h>  //添加DM9000网卡的头文件    
  3. /* add DM9000 ethernet drivers ,whitch is bodify by liuchengdeng */    
  4. #define DM9000_BASE    (S3C2410_CS4 + 0x300)    
  5. static struct resource s3c_dm9000_resource[] = {    
  6.      [0] = {    
  7.         .start = DM9000_BASE,    
  8.         .end   = DM9000_BASE + 3,    
  9.         .flags = IORESOURCE_MEM    
  10.     },    
  11.     [1] = {    
  12.         .start = DM9000_BASE + 4,    
  13.         .end   = DM9000_BASE + 7,    
  14.         .flags = IORESOURCE_MEM    
  15.     },    
  16.     [2] = {    
  17.         .start = IRQ_EINT7,    
  18.         .end   = IRQ_EINT7,    
  19.         .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,    
  20.     }    
  21. };    
  22. /*           
  23.  * The DM9000 has no eeprom, and it's MAC address is set by   
  24.  * the bootloader before starting the kernel.   
  25.  */    
  26. static struct dm9000_plat_data s3c_dm9000_pdata = {    
  27.     .flags      = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),    
  28. };    
  29. static struct platform_device s3c_device_dm9000 = {    
  30.     .name       = "dm9000",    
  31.     .id     = -1,    
  32.     .num_resources  = ARRAY_SIZE(s3c_dm9000_resource),    
  33.     .resource   = s3c_dm9000_resource,    
  34.     .dev        = {    
  35.         .platform_data  = &s3c_dm9000_pdata,    
  36.     },    
  37. };    
s3c2440 dm9000网卡驱动移植



#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中添加如下成员变量。


[cpp] view plain copy print?s3c2440 dm9000网卡驱动移植s3c2440 dm9000网卡驱动移植
  1. static struct platform_device *smdk2440_devices[] __initdata = {  
  2.     &s3c_device_ohci,  
  3.     &s3c_device_lcd,  
  4.     &s3c_device_wdt,  
  5.     &s3c_device_i2c0,  
  6.     &s3c_device_iis,  
  7.     &s3c_device_dm9000,//添加dm9000成员变量  
  8. };  
s3c2440 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中添加如下头文件

[cpp] view plain copy print?s3c2440 dm9000网卡驱动移植s3c2440 dm9000网卡驱动移植
  1. vim include/linux/dm9000.h  
  2. #ifndef __DM9000_PLATFORM_DATA  
  3. #define __DM9000_PLATFORM_DATA __FILE__  
  4. #include <linux/io.h>  //添加 linux/io.h 头文件  
  5. /* IO control flags */  
s3c2440 dm9000网卡驱动移植
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,即网卡没有使能。

          s3c2440 dm9000网卡驱动移植


3-1.暂时使能

    下面 使用ifconfig命令将网卡使能。使能之后我们可以看到已经可以和主机进行通信了。


               s3c2440 dm9000网卡驱动移植



3-2.永久使能

注意这个时候我们只是暂时性的使能了网卡,开发板下次启动的时候需要重新使能。如果我们想要网卡使能长期有效,修改开发板上的配置文件


s3c2440 dm9000网卡驱动移植

[cpp] view plain copy print?s3c2440 dm9000网卡驱动移植s3c2440 dm9000网卡驱动移植
  1. >: vim etc/init.d/S01_network  
  2. #!/bin/bash  
  3. ifconfig eth0 192.168.1.199 netmask 255.255.255.0  
s3c2440 dm9000网卡驱动移植
>: vim etc/init.d/S01_network




#!/bin/bashifconfig eth0 192.168.1.199 netmask 255.255.255.0


到此,fl2440开发板的整个网卡驱动配置就已经完成了。