移植rt73 usb无线网卡到linux2.6.28的过程中所遇到问题集锦

时间:2021-06-09 16:36:17

做毕业设计了,需要将rt73移植到tiny6410核心板上面,官方给的linux2.6.28的内核。期间遇到了一些问题,在此记录。

移植步骤:

1.到这个网址下载源码包:http://www.mediatek.com/en/downloads/

   我下载的是如下图所示的版本:

   移植rt73 usb无线网卡到linux2.6.28的过程中所遇到问题集锦

   注意:下载的时候需要输入姓名、邮箱、验证码,这些都输自己的就行了,不许要注册,但验证码等一定要输入正确。如果验证码总是错误,请刷新重来。


2.解压后进入源码目录下的Module文件夹,这个文件夹中有Makefile, Makefile.4, Makefile.6 。

   删除掉Makefile, 然后将Makefile.6复制为Makefile

   注意:Makefile.4为linux2.4.x专用, Makefile.6为linux2.6.x专用。


3.编辑复制过后的Makefile,将其中的PLATFORM=PC注释掉,让PLATFORM=CMPC有效,如下所示:

#PLATFORM=PC
PLATFORM=CMPC

   将LINUX_SRC改为自己的linux2.6.28的内核源码的路径。

LINUX_SRC =/opt/FriendlyARM/tiny6410_linux_src/linux-2.6.28.6

  注意两点:(1)linux2.6.28必须要至少交叉编译成功过一次,linux2.6.28的内核中关于USB无线网卡的配置此处不再赘述,按网上的说法走即可。

                      (2)千万千万注意LINUX_SRC中的路径中不要多了什么符号,特别是最后千万不要多了一个空格,本人上过当。若多了空格则编译时会发生如下错误:

root@kyc-System-Product-Name:/FriendlyArm6410/wifi/rt73_2011/2011_0210_RT73_Linux_STA_Drv1.1.0.5/Module# make
make -C /opt/FriendlyARM/tiny6410_linux_src/linux-2.6.28.6  SUBDIRS=/FriendlyArm6410/wifi/rt73_2011/2011_0210_RT73_Linux_STA_Drv1.1.0.5/Module modules
make[1]: 正在进入目录 `/opt/FriendlyARM/tiny6410_linux_src/linux-2.6.28.6'
  CC [M]  /FriendlyArm6410/wifi/rt73_2011/2011_0210_RT73_Linux_STA_Drv1.1.0.5/Module/rtmp_main.o
arm-linux-gcc: /include: No such file or directory
/FriendlyArm6410/wifi/rt73_2011/2011_0210_RT73_Linux_STA_Drv1.1.0.5/Module/rtmp_main.c: In function 'usb_rtusb_close':
/FriendlyArm6410/wifi/rt73_2011/2011_0210_RT73_Linux_STA_Drv1.1.0.5/Module/rtmp_main.c:655:1: warning: the frame size of 2136 bytes is larger than 1024 bytes
make[2]: *** [/FriendlyArm6410/wifi/rt73_2011/2011_0210_RT73_Linux_STA_Drv1.1.0.5/Module/rtmp_main.o] 错误 1
make[1]: *** [_module_/FriendlyArm6410/wifi/rt73_2011/2011_0210_RT73_Linux_STA_Drv1.1.0.5/Module] 错误 2
make[1]:正在离开目录 `/opt/FriendlyARM/tiny6410_linux_src/linux-2.6.28.6'
make: *** [all] 错误 2

4.修改好后交叉编译,编译成功后便会在本目录下生成rt73.ko这个驱动文件

   将这个文件拷贝到开发板上,加载这个驱动文件 :insmod rt73.ko

   出现如下提示,表示驱动安装成功:

   usbcore: registered new interface driver rt73   


5.然而此时如果插上usb无线网卡,会报如下的OOPS错误信息:

  

[root@UP-TECH application]# usb 1-1.3: new full speed USB device using s3c2410-3
usb 1-1.3: configuration #1 chosen from 1 choice                                
idVendor = 0x148f, idProduct = 0x2573                                           
register_netdev failed err=0                                                    
kernel BUG at net/core/dev.c:4380!                                              
Unable to handle kernel NULL pointer dereference at virtual address 00000000    
pgd = c0004000                                                                  
[00000000] *pgd=00000000                                                        
Internal error: Oops: 817 [#1]                                                  
Modules linked in: rt73                                                         
CPU: 0    Not tainted  (2.6.28.6-FriendlyARM #6)                                
PC is at __bug+0x24/0x30                                                        
LR is at release_console_sem+0x1a0/0x1c4                                        
pc : [<c00d7a8c>]    lr : [<c00f2a9c>]    psr: 20000113                         
sp : cf0cbc30  ip : cf0cbb40  fp : cf0cbc3c                                     
r10: 00000000  r9 : cf3d7800  r8 : cf0cbc6c                                     
r7 : 00000000  r6 : cf3d7800  r5 : d0b02000  r4 : cf3d7800                      
r3 : 00000000  r2 : 00000001  r1 : 60000193  r0 : 00000026                      
Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel             
Control: 00c5387d  Table: 5f134008  DAC: 00000017                               
Process khubd (pid: 293, stack limit = 0xcf0ca260)                              
Stack: (0xcf0cbc30 to 0xcf0cc000)                                               
bc20:                                     cf0cbc54 cf0cbc40 c0389774 c00d7a74   
bc40: c060f6e0 d0b02000 cf0cbc9c cf0cbc58 bf000714 c0389738 bf03a8b0 73756172   
bc60: bf003062 cf49d000 cf0cbc8c 0002573a c041428c cf26b620 cf26b600 cf26b6ec   
bc80: bf03a8b0 bf03a870 bf03a5f0 cf49d000 cf0cbccc cf0cbca0 c030e900 bf0002e8   
bca0: c030e7c4 00000001 cf26b620 c023e8e4 bf03a8b0 00000001 cf49d060 c05f3898   
bcc0: cf0cbcec cf0cbcd0 c023e7b0 c030e7d0 cf26b620 cf0cbd00 c023e8e4 00000000   
bce0: cf0cbcfc cf0cbcf0 c023e8f4 c023e6f0 cf0cbd24 cf0cbd00 c023d80c c023e8f0   
bd00: cf0b0128 cf45c4c4 cf26b70c cf26b620 00000000 cf49d060 cf0cbd3c cf0cbd28   
bd20: c023e6a0 c023d7c0 c05f38c8 cf26b620 cf0cbd54 cf0cbd40 c023e08c c023e654   
bd40: cf26b620 cf26b6c8 cf0cbd9c cf0cbd58 c023c6fc c023e068 00000001 00000000   
bd60: cf49d060 cf49d12c cf0cbd8c cf0cbd78 c041428c cf26b600 00000000 cf26b6ec   
bd80: 00000001 00000001 cf49d060 cf49d12c cf0cbe0c cf0cbda0 c030dcf0 c023c330   
bda0: 00000001 00000000 00000000 00000000 00001388 cf0cbdc0 cf26b620 cf26b400   
bdc0: cf3899d8 cf49d12c cf49d060 cf26b410 cf3899dc cf26b450 00000010 cf26b450   
bde0: cf49d12c cf49d000 00000001 c023e8e4 c05f3f24 cf0073c0 00000003 c05f3688   
be00: cf0cbe34 cf0cbe10 c0314568 c030d864 cf0cbe2c cf0cbe2c cf0cbe4c cf49d060   
be20: c05f3f24 c023e8e4 cf0cbe4c cf0cbe38 c030df48 c0314518 00000001 cf49d060   
be40: cf0cbe6c cf0cbe50 c023e7b0 c030def8 cf49d060 cf0cbe80 c023e8e4 00000000   
be60: cf0cbe7c cf0cbe70 c023e8f4 c023e6f0 cf0cbea4 cf0cbe80 c023d80c c023e8f0   
be80: cf0b0128 cf0698c4 cf49d14c cf49d060 00000000 cf395460 cf0cbebc cf0cbea8   
bea0: c023e6a0 c023d7c0 c05f38c8 cf49d060 cf0cbed4 cf0cbec0 c023e08c c023e654   
bec0: cf49d060 cf49d108 cf0cbf1c cf0cbed8 c023c6fc c023e068 cf0cbf04 00000000   
bee0: 3a393831 c0130032 00000010 00000000 cf49d000 cf49d000 cf49d060 00000000   
bf00: 00000000 cf395400 00000003 cf394814 cf0cbf44 cf0cbf20 c0308350 c023c330   
bf20: 00000007 cf392800 cf392800 cf49d000 00000000 00000003 cf0cbfdc cf0cbf48   
bf40: c0308da0 c0308308 00000064 00000064 00000101 cf0cbf60 c00ec038 cf39554c   
bf60: cf392808 cf394800 cf395408 cf392802 00000002 cf3926ec cf3956c8 cf392620   
bf80: cf395400 cf392620 cf3926ec 00000000 00000000 cf04da00 c010624c cf0cbf9c   
bfa0: cf0cbf9c 00000101 01010001 cf0cbfb8 c00eec84 c0308444 00000000 00000000   
bfc0: 00000000 00000000 00000000 00000000 cf0cbff4 cf0cbfe0 c0105e7c c0308450   
bfe0: 00000000 00000000 00000000 cf0cbff8 c00f49e4 c0105e3c 00000000 00000000   
Backtrace:                                                                      
[<c00d7a68>] (__bug+0x0/0x30) from [<c0389774>] (free_netdev+0x48/0x64)         
[<c038972c>] (free_netdev+0x0/0x64) from [<bf000714>] (usb_rtusb_probe+0x438/0x)
 r4:d0b02000 r3:c060f6e0                                                        
[<bf0002dc>] (usb_rtusb_probe+0x0/0x4c4 [rt73]) from [<c030e900>] (usb_probe_in)
[<c030e7c4>] (usb_probe_interface+0x0/0x180) from [<c023e7b0>] (driver_probe_de)
[<c023e6e4>] (driver_probe_device+0x0/0x174) from [<c023e8f4>] (__device_attach)
 r7:00000000 r6:c023e8e4 r5:cf0cbd00 r4:cf26b620                                
[<c023e8e4>] (__device_attach+0x0/0x14) from [<c023d80c>] (bus_for_each_drv+0x5)
[<c023d7b4>] (bus_for_each_drv+0x0/0x94) from [<c023e6a0>] (device_attach+0x58/)
 r7:cf49d060 r6:00000000 r5:cf26b620 r4:cf26b70c                                
[<c023e648>] (device_attach+0x0/0x78) from [<c023e08c>] (bus_attach_device+0x30)
 r5:cf26b620 r4:c05f38c8                                                        
[<c023e05c>] (bus_attach_device+0x0/0x60) from [<c023c6fc>] (device_add+0x3d8/0)
 r5:cf26b6c8 r4:cf26b620                                                        
[<c023c324>] (device_add+0x0/0x54c) from [<c030dcf0>] (usb_set_configuration+0x)
[<c030d858>] (usb_set_configuration+0x0/0x524) from [<c0314568>] (generic_probe)
[<c031450c>] (generic_probe+0x0/0xa0) from [<c030df48>] (usb_probe_device+0x5c/)
 r6:c023e8e4 r5:c05f3f24 r4:cf49d060                                            
[<c030deec>] (usb_probe_device+0x0/0x74) from [<c023e7b0>] (driver_probe_device)
 r5:cf49d060 r4:00000001                                                        
[<c023e6e4>] (driver_probe_device+0x0/0x174) from [<c023e8f4>] (__device_attach)
 r7:00000000 r6:c023e8e4 r5:cf0cbe80 r4:cf49d060                                
[<c023e8e4>] (__device_attach+0x0/0x14) from [<c023d80c>] (bus_for_each_drv+0x5)
[<c023d7b4>] (bus_for_each_drv+0x0/0x94) from [<c023e6a0>] (device_attach+0x58/)
 r7:cf395460 r6:00000000 r5:cf49d060 r4:cf49d14c                                
[<c023e648>] (device_attach+0x0/0x78) from [<c023e08c>] (bus_attach_device+0x30)
 r5:cf49d060 r4:c05f38c8                                                        
[<c023e05c>] (bus_attach_device+0x0/0x60) from [<c023c6fc>] (device_add+0x3d8/0)
 r5:cf49d108 r4:cf49d060                                                        
[<c023c324>] (device_add+0x0/0x54c) from [<c0308350>] (usb_new_device+0x54/0x14)
[<c03082fc>] (usb_new_device+0x0/0x148) from [<c0308da0>] (hub_thread+0x95c/0xe)
 r7:00000003 r6:00000000 r5:cf49d000 r4:cf392800                                
[<c0308444>] (hub_thread+0x0/0xe4c) from [<c0105e7c>] (kthread+0x4c/0x78)       
[<c0105e30>] (kthread+0x0/0x78) from [<c00f49e4>] (do_exit+0x0/0x6fc)           
 r5:00000000 r4:00000000                                                        
Code: e59f0010 e1a01003 eb0cf1f7 e3a03000 (e5833000)                            
---[ end trace c64e03da50cd4d0d ]---   


6.此时不要慌张,我只到网上关于这个问题的搜索结果少得可怜(否则我也不会写这篇文章了),按如下步骤做:

   回到源代码目录,编辑rtmp_init.c 这个源文件,按如下的代码修改kmalloc的第二个参数:

         ////pFirmwareImage = kmalloc(MAX_FIRMWARE_IMAGE_SIZE, MEM_ALLOC_FLAG);  // just here 
   1883 
   1884         pFirmwareImage = kmalloc(MAX_FIRMWARE_IMAGE_SIZE, GFP_KERNEL);
   1885 
   1886         if (pFirmwareImage == NULL)
   1887         {
   1888                 DBGPRINT(RT_DEBUG_ERROR, "NICLoadFirmware-Memory allocate fail\n");
   1889                 Status = NDIS_STATUS_FAILURE;
   1890                 goto out;
   1891         }       
   1892         

     然后保存,重新编译加载驱动,插上usb无线网卡。


7.现在没有错了,恭喜恭喜。附上开发板终端输出的信息:

[root@UP-TECH application]# ls                                                  
rt73.ko                                                                         
[root@UP-TECH application]# insmod rt73.ko                                      
usbcore: registered new interface driver rt73                                   
[root@UP-TECH application]# usb 1-1.3: new full speed USB device using s3c2410-3
usb 1-1.3: configuration #1 chosen from 1 choice                                
idVendor = 0x148f, idProduct = 0x2573                                           
usb 1-1.3: New USB device found, idVendor=148f, idProduct=2573                  
usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0             
usb 1-1.3: Product: 802.11 bg WLAN                                              
usb 1-1.3: Manufacturer: Ralink                                                 
                                                                                
[root@UP-TECH application]#                                                     
[root@UP-TECH application]# ifconfig                                            
lo        Link encap:Local Loopback                                             
          inet addr:127.0.0.1  Mask:255.0.0.0                                   
          UP LOOPBACK RUNNING  MTU:16436  Metric:1                              
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0                    
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0                  
          collisions:0 txqueuelen:0                                             
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)                                
                                                                                
[root@UP-TECH application]# ifconfig rausb0 up                                  
=> usb_rtusb_open                                                               
[root@UP-TECH application]# ifconfig                                            
lo        Link encap:Local Loopback                                             
          inet addr:127.0.0.1  Mask:255.0.0.0                                   
          UP LOOPBACK RUNNING  MTU:16436  Metric:1                              
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0                    
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0                  
          collisions:0 txqueuelen:0                                             
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)                                
                                                                                
rausb0    Link encap:Ethernet  HWaddr 48:02:2A:13:A0:5B                         
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1                    
          RX packets:30 errors:0 dropped:0 overruns:0 frame:0                   
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0                 
          collisions:0 txqueuelen:1000                                          
          RX bytes:5300 (5.1 KiB)  TX bytes:858 (858.0 B)                       
                                                                                
[root@UP-TECH application]# 

啊哈哈,这个问题终于解决了!

(--------完-----------)


参考资料:http://blog.sina.com.cn/s/blog_60cde0340100m8cg.html