ARM9开发板FL2440移植Linux-3.0内核————添加USB驱动

来源:互联网 发布:java中类的构造方法 编辑:程序博客网 时间:2024/06/02 17:00

前言:

         本开发板内核版本为Linux-3.0

此文章只是介绍USB移植的过程,对于Linux内核自带驱动的移植一般分为两个步骤:

1、修改代码,将USB初始化;

2、修改Linux内核配置,使其支持USB

第一步、对代码的操作

进入内核的mach-smdk2440.c  (路径为:linux-3.0/arch/arm/mach-s3c2440/mach-smdk2440.c  )

添加头文件

#include <mach/regs-clock.h>

#include <linux/delay.h>

添加USB初始化函数

  1. int usb_s3c2440_init(void)  
  2.       {  
  3.          unsigned long upllvalue= (0x38<<12)|(0x02<<4)|(0x02);   
  4.           while (upllvalue != __raw_readl(S3C2410_UPLLCON))   
  5.         {  
  6.                __raw_writel(upllvalue, S3C2410_UPLLCON);  
  7.           mdelay(1);  
  8.           }  
  9.           return 0;  
  10.     }  

然后在smdk2440_map_io函数中调用

  1. static void __init smdk2440_map_io(void)  
  2.         {  
  3.           s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));  
  4.           s3c24xx_init_clocks(12000000);  
  5.         //s3c24xx_init_clocks(16934400); fl2440的时钟晶振频率是12000000  
  6.           s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));  
  7.           usb_s3c2440_init();   
  8.         }  

接下来进入option.c文件进行修改(路径为linux-3.0/drivers/usb/serial/option.c)

改1:

 static int option_send_setup(struct usb_serial_port *port);
  static void option_instat_callback(struct urb *urb);
   /* Vendor and product IDs */
 
static int vendor = 0;
   static int product = 0;
  #define OPTION_VENDOR_RESERVED      0xFFFF /*    Add by huangan  */
  #define OPTION_RESERVED_DEVICE      0xFFFF /*    Add by huangan  */

  #define OPTION_VENDOR_ID            0x0AF0
  #define OPTION_PRODUCT_COLT         0x5000

改2:

static const struct usb_device_id option_ids[]中的const去掉,并添加代码

static struct usb_device_id option_ids[] = {
 455  
  { USB_DEVICE(OPTION_VENDOR_RESERVED, OPTION_RESERVED_DEVICE) },
 456     { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
 457     { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
 改3:

更改int __init option_init结构体

static int __init option_init(void)
1086 {
1087     int retval;
   
if ((vendor>0) && (product>0))
    {
       option_ids[0].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
         option_ids[0].idVendor = vendor;
         option_ids[0].idProduct = product;
       printk("Register option drvier for modem vendor=0x%04x                  product=0x%04x\n", vendor, product);
 }

1096     retval = usb_serial_register(&option_1port_device);
1097     if (retval)
1098         goto failed_1port_device_register;

改4、(可以先不该,假如烧到开发板上不能读取U盘的内容再回来改)

vim /etc/mdev.conf(这是自己制作的根文件系统)

   sd[a-z][0-9]      0:0 0777        @(mount /dev/$MDEV /mnt/usb)  //当检测到sda1类似的设备时将mdev检测到的设备挂载到mnt/usb上
   sd[a-z]             0:0 0777        $(umount /mnt/usb)

   ub[a-z][0-9]      0:0 0777        @(mount /dev/$MDEV /mnt/usb)//如果你u盘插上去能检测到设备但是不能看到里面的内容,就注释掉这2句话,是因为你没挂载成功。
   ub[a-z]             0:0 0777        $(umount /mnt/usb)


好了,以上就是对代码的修改,接下来是修改内核驱动的配置

第二步、修改内核驱动的配置

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

                  [*] Probe all LUNs on each SCSI device


   [*] USB support  --->
       {*}   Support for Host-side USB 
       [*]     USB device filesystem (DEPRECATED) 
       [*]     USB device class-devices (DEPRECATED)
       <*>     OHCI HCD support 
       <*>   USB Mass Storage support //这个如果不选进入开发板后看不到u盘里面的东西

//对于这个上面的具体选项可以参考这个博客:     http://blog.chinaunix.net/uid-9727915-id-259858.html

 [*] HID Devices  ---> 
     -*-  Generic HID support
     <*>     USB Human Interface Device (full HID) support

因为u盘用到了scsi命令,所以我们需要增加scsi支持.

(usb storage驱动利用scsi中间层将usb storage设备虚拟成scsi逻辑设备。这样可以方便的使用scsi驱动的设备IO接口,以及plugin/plugout等机制)

 SCSI device support  --->
   <*> SCSI device support
   [*] legacy /proc/scsi/ support
   <*> SCSI disk support 

现在的U盘等移动存储器使用的大都是 FAT/FAT32 格式的,因此我们还需要添加FAT32 文件系统以及分区格式的支持:
File systems  --->
  DOS/FAT/NT Filesystems  --->
<*> MSDOS fs support
<*> VFAT (Windows-95) fs support
(437) Default codepage for FAT
(iso8859-1) Default iocharset for FAT
<*> NTFS file system support
[*]   NTFS write support
Partition Types  --->
  [*]   PC BIOS (MSDOS partition tables) support
  [*]   Windows Logical Disk Manager (Dynamic Disk) support
-*- Native language support  --->
<*>   Codepage 437 (United States, Canada)
<*>   Simplified Chinese charset (CP936, GB2312)
<*>   ASCII (United States)
<*>   NLS ISO 8859-1 (Latin 1; Western European Languages)
<*>   NLS UTF-8

好了,以上就是要修改的地方












1 0
原创粉丝点击