随笔-118  评论-133  文章-4  trackbacks-0

USB 驱动移植心得
一、代码修改
主要是按照这个贴来做:
http://www.hfrk.net/S3C2410/kaifa/063152202483252_37.htm
我也看过其它不同版本的内核关于usb驱动的移植,移植方法几乎一样,只是修改的文件不同而已。上面的贴子有不少头文件没有例出来,以下是我按照以上贴子添加的代码(好像在很多论坛上包括头文件部分都显示不出来,在这里把include前面的#给删了,希望有帮助):

/*add by lfc*/
include <asm/arch/regs-clock.h>
include <asm/arch/usb-control.h>
include <linux/device.h>
include <linux/delay.h>
/*end add*/

/**********************add by lfc*************************************/
static struct s3c2410_hcd_info usb_sbc2410_info = {
       .port[0]        = {
               .flags  = S3C_HCDFLG_USED
       }
};

int usb_sbc2410_init(void)
{
unsigned long upllvalue = (0x78<<12)|(0x02<<4)|(0x03);
printk("USB Control, (c) 2006 sbc2410\n");
s3c_device_usb.dev.platform_data = &usb_sbc2410_info;
while(upllvalue!=__raw_readl(S3C2410_UPLLCON))
{
__raw_writel(upllvalue,S3C2410_UPLLCON);
mdelay(1);
}
return 0;
}

/***************************end add**********************/

static void __init smdk2410_map_io(void)
{
s3c24xx_init_io(smdk2410_iodesc, ARRAY_SIZE(smdk2410_iodesc));
s3c24xx_init_clocks(0);
s3c24xx_init_uarts(smdk2410_uartcfgs, ARRAY_SIZE(smdk2410_uartcfgs));
s3c24xx_set_board(&smdk2410_board);
/*************************add by lfc****************************/
       usb_sbc2410_init();
/*************************end add*******************************/
}

上面的修改其实也参考了这个牛贴一下,里面有大虾们对USB驱动移植的讨论,还不错:
http://www.linuxforum.net/forum/showflat.php?Cat=&Board=embedded&Number=556915&page=0&view=collapsed&sb=5&o=0&fpart=

其实到了这里,要修改的代码已经修改完了,比添加Nand flash的支持修改的地方还要少^_^,不过我一直以为还没修改好,最后发现原来是没配置好~_~

二、内核配置
下面说一下郁闷了我好一阵子的内核配置(支持USB)问题,这个就比Nand flash的配置要复杂多了。
1、让内核支持热插拔
               General setup  --->  
 
│ │[*] Support for hot-pluggable devices

2、USB驱动设置,可能有些不选也行,不过没时间去试,至于为什么要选这些选项的话可以看一下这个贴(Linux下的硬件驱动——USB设备):
http://www-128.ibm.com/developerworks/cn/linux/l-usb/index1.html

  │ │                Device Drivers  --->
│ │              Generic Driver Options  --->          
<*> Hotplug firmware loading support    
 
│ │              Block devices  --->  
 
│ │              <*> Low Performance USB Block driver  
 
│ │              SCSI device support  --->  
 
│ │  <*>   SCSI generic support  
│ │  [*]   Probe all LUNs on each SCSI device    
 
│ │              USB support  --->        
 
│ │<*> Support for Host-side USB    
│ │[*]   USB device filesystem
 
│ │<*>   OHCI HCD support  
│ │<*>   USB Mass Storage support
 
│ │[*]   USB Monitor

3、加入了MSDOS fsVFAT fs的支持。

  │ │                File systems  --->      
 
│ │        DOS/FAT/NT Filesystems  --->  
 
│ ┌─────────────────────────────────────────────────────────────────────┐ │
 
│ │                 <*> MSDOS fs support                                │ │
 
│ │                 <*> VFAT (Windows-95) fs support                    │ │
 
│ │                 (936) Default codepage for FAT                      │ │
 
│ │                 (cp936) Default iocharset for FAT                   │ │
 
│ │                 < > NTFS file system support

做完这些后,插入u盘后,内核应该可以识别到u盘,出现:
usb 1-1: new full speed USB device using s3c2410-ohci and address 3
ub(1.3): GetMaxLUN returned 0, using 1 LUNs

但是,还有下面一句出错提示:
/dev/ub/a: unknown partition table

再次查看了贴子上大虾们的讨论,提到:“使能CONFIG_MSDOS_PARTITION选项”,再仔细查找,发现配置选项如下:
│ │                File systems  --->
│ │                Partition Types  --->  
 
│ │     [*]   PC BIOS (MSDOS partition tables) support
加上这个后应该就可以挂载usb上的MSDOS分区了

以下是我的内核插入u盘后的提示信息:
usb 1-1: new full speed USB device using s3c2410-ohci and 2
ub(1.2): GetMaxLUN returned 0, using 1 LUNs
/dev/ub/a: p1
表示usb设备已经挂载到/dev/ub/a/part1目录下

4. 加入中文字体库(可惜在我的板上还是没能正常显示中文~_~,知道的朋友麻烦告诉我一声,大家一起探讨)
 
│ │        Native Language Support  --->    
 
│ │<*>   Simplified Chinese charset (CP936, GB2312)  
 
│ │<*>   NLS UTF8

以下是挂载usb设备后的显示:
[root@luofuchong /]# mount -t vfat -o iocharset=cp936 /dev/ub/a/part1 /mnt
[root@luofuchong /]# ls /mnt
cramfs-1.1.tar.gz        netkit-base-0.17.tar.gz  thttpd-2.25b.tar.gz
lfc                      settings.dat             . . I. ..  . .txt

三、一点心得。

1、如果想知道内核有没有识别出u盘的话可以执行命令:cat /proc/partitions ,看看插入USB前后分区信息有什么不同就知道了。


2、另外,如果想让内核把它当成SCSI设备来处理的话,只要把上面:
 │ │                Device Drivers  --->    
 
│ │              Block devices  --->  
 
│ │              <*> Low Performance USB Block driver
的 Low Performance USB Block driver这个选项去掉,然后把:
 │ │                Device Drivers  --->
 │ │              SCSI device support  --->  
 │ │              <*>SCSI disk support
的SCSI disk support这个选项选上,重新编译内核就行。
注:
    个人觉得使用usb设备的话Low Performance USB Block driver比SCSI disk要好,自己看着办吧^_^

3、最后,一般都会新建一个/dev/sda1的链接指向usb设备的挂载点的,可以在启动文件中使用命令ln -s xxx xxx来建立这个链接。
 

四、
   呵呵,说了一大堆的废话,希望不要见怪。毕竟我对usb设备了解不多,如果有什么说错的地方请各位大虾见谅。其实关于usb驱动的移植在网上有不少的贴,我在这里只对针对我的经历作一点总结而已,希望能对大家有一点的帮助^_^

 

posted on 2007-01-24 13:21 lfc 阅读(7799) 评论(9)  编辑 收藏 引用

评论:
# re: linux-2.6.14下USB驱动移植心得 2007-01-24 15:55 | ruru
<*> Low Performance USB Block driver 沒錯,把這個去掉,就可以出現scsi了~早上貼錯了^^""  回复  更多评论
  
# re: linux-2.6.14下USB驱动移植心得 2007-01-24 16:05 | ruru
好像把CONFIG_BLK_DEV_UB關掉,<*> Low Performance USB Block driver 打開,一樣可以使用SCSI~但是另外一個朋友使用,就沒辦法,要直接關掉<*> Low Performance USB Block driver 才能出現scsi~這部分我再想想看^^  回复  更多评论
  
# re: linux-2.6.14下USB驱动移植心得 2007-06-17 17:39 | sailing
呵呵,分析整理的挺好的
集合了大家的长处,来龙去脉很清楚  回复  更多评论
  
# re: linux-2.6.14下USB驱动移植心得 2008-01-11 10:00 | tequlialv@gmail.com
大侠, 小弟有个问题,我现在不明白smdk2410_map_io这个函数的作用,是应该初始化吧?我目前在做usb gadget驱动移植,参考pxa的驱动,在generic.c文件中有个platform_add_device来将设备加入到设备总线上,我找了一阵也没有发现2410上调用了这个函数(只是在启动基本的uart时用到了),那么这些数组中的设备是怎样挂载到总线上的呢?  回复  更多评论
  
# re: linux-2.6.14下USB驱动移植心得 2008-01-11 10:57 | suke9
请问大侠,我在看ohci-s3c2410.c时候,看到代码s3c2410_usb_set_power(dev->dev.platform_data, 1, 1)
时钟搞不懂这行代码是做什么的,能否给指点一下  回复  更多评论
  
# re: linux-2.6.14下USB驱动移植心得 2008-07-19 13:03 | trtzrdb
文中有:个人觉得使用usb设备的话Low Performance USB Block driver比SCSI disk要好,自己看着办吧^_^ ,但在http://gentoo-wiki.com/HOWTO_USB_Mass_Storage_Device 对Low Performance USB Block driver做了这样的描述:If your USB disk is shown as /dev/ub/a then you're using the low Performance USB Block Driver (Device Drivers -> Block Devices -> Low Performance USB Block Driver). You will find that your transfer speed is crippled by this driver, because it is designed to meet the lowest common denominator of features for seriously lightweight (or cheap) devices. Disable it and use the usb-storage module (devices > usb) instead if you can.
不知道到底选什么,还望DX指点.  回复  更多评论
  
# re: linux-2.6.14下USB驱动移植心得 2008-08-17 16:37 | luren
选择(gb2312) Default iocharset for FAT
#mount -t vfat /dev/ub/a/part1 /mnt
就可以显示中文  回复  更多评论
  
# re: linux-2.6.14下USB驱动移植心得 2009-03-04 16:03 | lly
博主,谢谢你的分享!我是刚刚接触到Linux,你这里讲的是USB HOST 移植,我想请教一下基于s3c2412 linux2.6的USB device移植要怎么做?谢谢!  回复  更多评论
  
只有注册用户登录后才能发表评论。