linux-3.6.6移植usbhost(u盘)、sd卡及自动挂载

1,对于USB-HOST功能:

      其实2410的OHCI驱动已经相当完善,但是由于SMDK6410来说,还需要一个48M 的时钟信号产生,才能使能USB-HOST功能

     第一步,在mach-smdk6410.c里面添加头文件

#include <plat/regs-usb-hsotg-phy.h>

然后在任意一个地方添加

#ifdef CONFIG_USB_SUPPORT
void s3c_hsotg_phy_config(int enable) {
 u32 val;

 if (enable) {
  __raw_writel(0x0, S3C_PHYPWR); /* Power up */

  val = __raw_readl(S3C_PHYCLK);
  val &= ~S3C_PHYCLK_CLKSEL_MASK;
  __raw_writel(val, S3C_PHYCLK);

  __raw_writel(0x1, S3C_RSTCON);
  udelay(5);
  __raw_writel(0x0, S3C_RSTCON); /* Finish the reset */
  udelay(5);
 } else {
  __raw_writel(0x19, S3C_PHYPWR); /* Power down */
 }
}
EXPORT_SYMBOL(s3c_hsotg_phy_config);
#endif

这段代码是copy友坚2.6.36的,而这段代码实现的就是一个输出48M时钟信号的开关,当enable=1时,执行enable部分的代码,使能48M时钟信号输出,当enable=0时,执行else部分的代码,就禁止48M时钟信号,最后还需要在smdk6410_machine_init(void)单板初始化函数里面添加48M时钟使能信号:

s3c_hsotg_phy_config(1);

以及在硬件初始化函数 *smdk6410_devices[] __initdata里面添加&s3c_device_usb_hsotg,默认下*smdk6410_devices[] __initdata里面已经添加了&s3c_device_ohci,所以我们不需要再添加了。

而对于这个函数的实现是在/drivers/usb/目录下的相应的驱动函数里定义的,不需要去自己写。

最后就是在MAKE MENUCONFIG时,选中USB选项里面的相关项目就行了:

 DEVICE DRIVERS--------->

              <*>   Support for Host-side USB                              

      [*]     USB verbose debug messages                                 
      [*]     USB announce new devices                                   

      <*>   OHCI HCD support   

好了,到这里,就完成了smdk6410的LINUX-3.6.6的USB-OTG功能了,编译,运行,试试,呵呵,如果你们想看相关驱动代码的话,就直接到/linux-3.6.6/drivers/usb/core以及/linux-3.6.6/drivers/usb/host里面看!

//

  2,对于USB-STORAGE的功能

  其实这个是最简单的了,呵呵,只需要配置MENUCONFIG就行了,因为驱动代码已经相当完善了在/linux-3.6./drivers/usb/storage目录下,大家如果有兴趣的话,可以去看哈子。

但是,在这里,有一点,是需要注意的,就是如果你不配SCSI总线设备这个选项的话,这个USB-STORAGE是在配置里面看不到的哦,一开始我也觉得奇怪,然后仔细一想,也对, USB-STORAGE本来就是基于SCSI总线挂载的,你不支持SCSI总线设备,肯定就没得USB-STORAGE可选了啊,配置如下:

   SCSI device support  --->

         <*> SCSI device support

          [*] legacy /proc/scsi/ support                                    
          *** SCSI support type (disk, tape, CD-ROM) ***               
         <*> SCSI disk support 

         <*> SCSI generic support

配置完SCSI后,是不是再进USB选项里面,就看到USB MASS STORAGE的选项了啊,呵呵

    好了,然后再

    [*] USB support  --->

     <*>   USB Mass Storage support                                

    [*]     USB Mass Storage verbose debug

OK,好了,USB-STORAGE搞定了,其实配置MENUCONFIG,也是一门学问,呵呵,一定要弄清楚该选项是干嘛的,英语好的估计很好看懂的吧,毕竟里面的配置太多了,哎!

3,对于MMC/SD功能:

  和USB一样,驱动代码已经在内核里面,在linux-3.6.6/drivers/mmc下面相关目录里面,但是为了idea6410单板很好的工作,我们需要在mach-smdk6410.c里面添加头文件:

#include <plat/sdhci.h>

然后在任意位置添加一小段代码;

/* MMC/SD config */
static struct s3c_sdhci_platdata smdk6410_hsmmc0_pdata = {
    .max_width      = 4,
    .cd_type        = S3C_SDHCI_CD_INTERNAL,
};

static struct s3c_sdhci_platdata smdk6410_hsmmc1_pdata = {
    .max_width      = 4,
    .cd_type        = S3C_SDHCI_CD_PERMANENT,
//    .cd_type        = S3C_SDHCI_CD_GPIO,
//    .ext_cd_gpio    = S3C64XX_GPN(6),
};

与USB一样,也需要在 smdk6410_machine_init(void)这个初始化函数里面初始化一遍hsmmc0_pdata,hsmmc1_pdata.

添加:

 s3c_sdhci0_set_platdata(&smdk6410_hsmmc0_pdata);
 s3c_sdhci1_set_platdata(&smdk6410_hsmmc1_pdata);

因为默认下,mach-smdk6410.c里面,已经有了

&s3c_device_hsmmc0,
 &s3c_device_hsmmc1,所以我们不需要再添加了。

最后就又轮到MENUCONFIG了,配置如下:

<*> MMC/SD/SDIO card support  --->

   [*]   MMC debugging 

   <*>   MMC block device driver                                    
    (8)     Number of minors per block device                       

    [*]     Use bounce buffer for simple hosts

<*>   Secure Digital Host Controller Interface support

<*>   SDHCI support on Samsung S3C SoC

 到此可以在、/dev/下看到sda或sda1了但是挂载不上,的加上下面部分:

-----------MSDOS fs和VFAT 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                                                                | | 
  | |                     [*]   NTFS debugging support                                                                | | 
  | |                     [*]   NTFS write support

(非必须)

 |                     -*- Enable the block layer  --->

                                               | |                           Partition Types  --->    

                                                       [*] Advanced partition selection 

                                                      [*]   PC BIOS (MSDOS partition tables) support (NEW)

///

-----------加入中文字体库---------------------
│ │ Native Language Support --->

  | |                     (cp437) Default NLS Option                                                                  | | 
  | |                     <*>   Codepage 437 (United States, Canada)         
│ │   <*> Simplified Chinese charset (CP936, GB2312)
│ │   <*> NLS UTF8

此时就能正常挂载了!~~~~~~~~~~~~~~~~~~~~~~~~~~

///

现在来看qt中怎么自动挂载u盘和sd卡!

------------配置USB鼠标键盘----------
Device Drivers >
       USB support  ---> 
            <*> Support for Host-side USB
            <*> OHCI HCD support
--- USB Input Devices
 <*>   Event interface

[*]   Mice  --->            <*>   PS/2 mouse 

------------配置U盘支持------------------------
因为要优盘用到了SCSI 命令,所以我们先增加SCSI 支持。
Device Drivers >
       SCSI device support  --->

             <*> SCSI device support  
            [*] legacy /proc/scsi support
   <*> SCSI disk support              缺少不会自动生成/dev/sda1设备
   [*]   SCSI generic support         

Device Drivers >
        USB support  --->
    [*] Support for Host-side USB        (内核的热拔插)

    [*]     USB verbose debug messages                                                          | | 

     [*]     USB announce new devices 

     <*>   USB Monitor

      <*>   OHCI HCD support                                   USB1.1驱动
    <*> USB Mass Storage support
                [*]     USB Mass Storage verbose debug
  Block devices --->
    <*> Low Performance USB Block driver                     (此项选择后作为块设备,挂载为/dev/uda[0-9],否则作为scsi,挂载为/dev/sd[a-z][0-9])

-----------MSDOS fs和VFAT 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                                                                | | 
  | |                     [*]   NTFS debugging support                                                                | | 
  | |                     [*]   NTFS write support

(非必须)

支持PC分区格式

 |                     -*- Enable the block layer  --->

                                               | |                           Partition Types  --->    

                                                       [*] Advanced partition selection 

                                                      [*]   PC BIOS (MSDOS partition tables) support (NEW)

///

-----------加入中文字体库---------------------
│ │ Native Language Support --->

  | |                     (cp437) Default NLS Option                                                                  | | 
  | |                     <*>   Codepage 437 (United States, Canada)         
│ │   <*> Simplified Chinese charset (CP936, GB2312)
│ │   <*> NLS UTF8

到此内核配置已经完成!

1)确保内核支持热插拔

CONFIG_HOTPLUG=y  //确保这项为y
CONFIG_PRINTK=y
CONFIG_NET=y     //确保这项也为y

确保以上两项都选上,不然/proc/sys/kernel/目录不会出现hotplug文件!
2)确保busybox支持mdev
mdev是busybox中udev设备文件系统的精简版
# make menuconfig
确保以下几项被选中:
Linux System Utilities  --->
mdev                                           
      
   Support /etc/mdev.conf                                
      
     Support subdirs/symlinks                            
      
       Support regular expressions substitutions when renaming dev
      
     Support command execution at device addition/removal       
      
   Support loading of firmwares
3)根文件系统
etc/fatab文件的内容为:
proc  /proc           proc    defaults        0       0
sysfs            /sys            sysfs    defaults        0        0
tmpfs            /var            tmpfs    defaults        0        0
tmpfs            /tmp            tmpfs    defaults        0        0
tmpfs            /dev            tmpfs    defaults        0        0
etc/init.d/rcS添加如下的内容:mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
4)解析
执行 mdev -s:
以 "-s" 为参数调用位于 /sbin 目录下的 mdev(其实mdev是个软链接,其作用是传递参数给 /bin 目录下的 busybox 程序并调用它),
mdev 扫描 /sys/class 和 /sys/block 目录中所有的类设备目录,如果在类设备目录中含有名为 "dev" 的文件,且文件中包含的是设备号,则 mdev 就利用这些信息为这个设备在 /dev 目录下创建设备节点文件。
一般只在启动时才执行一次 "mdev -s" 。
热插拔事件:
由于启动时执行了命令:echo /sbin/mdev > /proc/sys/kernel/hotplug ,
那么当有热插拔事件产生时,内核就会调用位于 /sbin 目录下的mdev。
这时 mdev 通过环境变量中的 ACTION 和 DEVPATH,来确定此次热插拔事件的动作以及影响了 /sys 中的那一个类设备目录。
接着会看看这个类设备目录中是否有名为 "dev" 的文件,如果有就利用这些信息为这个设备在 /dev 目录下创建或删除设备节点文件并执行相应的动作 ACTION 。
5)添加对热插拔事件的响应,实现U盘和SD卡的自动挂载与缷载
# vi /etc/mdev.conf        
内容为:                                
sd[a-z][0-9]      0:0 666        * /etc/udisk_insert
#sd[a-z]           0:0 666        $ /etc/udisk_remove
mmcblk[0-9]p[0-9] 0:0 666        * /etc/sd_insert
#mmcblk[0-9]       0:0 666        $ /etc/sd_remove

                       
内容为:
#! /bin/sh
mkdir -p /udisk
#mount -t vfat /dev/mmcblk0p1            /sdcard/
mount -t vfat /dev/sd[a-z][0-9]             /udisk

内容为:
#!/bin/sh
umount           /udisk
为以上两个脚本加上可执行权限:
# chmod +x /etc/hotplug/usb/udisk_insert
# chmod +x /etc/hotplug/usb/udisk_remove

sd_insert内容:

#! /bin/sh
mount -t vfat /dev/mmcblk[0-9]p[0-9]                       /sdcard/

chmod +x sd_insert

延伸:

MDEV 入门
-------------
For those of us who know how to use mdev, a primer might seem lame. For
这份文档对于那些知道如何使用mdev 的人看来可能有些肤浅。
everyone else, mdev is a weird black box that they hear is awesome, but can't
但对于其他人,mdev 可能是一个神秘的黑匣子,以至让人敬畏。
seem to get their head around how it works. Thus, a primer.

而这份文档又不足以让他们知道mdev 是如何工作的。 因此,这是一份入门文档。
-----------
Basic Use

基本使用方法
-----------
Mdev has two primary uses: initial population and dynamic updates. Both
mdev 有两个主要的应用:初始化对象和动态更新。
require sysfs support in the kernel and have it mounted at /sys. For dynamic
两个应用都需要内核 sysfs 的支持,且必须挂载到 /sys 。为了实现动态更新,
updates, you also need to have hotplugging enabled in your kernel.
你还必须在内核配置时增加热插拔支持(hotplugging)。
Here's a typical code snippet from the init script:

以下是系统初始化脚本中一个典型的使用mdev 的代码片段:
    [1] mount -t sysfs sysfs /sys
    [2] echo /bin/mdev > /proc/sys/kernel/hotplug
    [3] mdev -s

Of course, a more "full" setup would entail executing this before the previous
当然,一个对mdev 更完整的安装还必须在以上代码片段前执行下面的命令:
code snippet:
    [4] mount -t tmpfs mdev /dev
    [5] mkdir /dev/pts
    [6] mount -t devpts devpts /dev/pts

The simple explanation here is that [1] you need to have /sys mounted before
简单说明一下上面的代码:[1]你必须在执行mdev 前挂载 /sys 。
executing mdev. Then you [2] instruct the kernel to execute /bin/mdev whenever
随后你 [2] 命令内核在增删设备时执行 /bin/mdev ,
a device is added or removed so that the device node can be created or
使设备节点文件会被创建和删除。
destroyed. Then you [3] seed /dev with all the device nodes that were created
最后你 [3] 设置mdev,让它在系统启动时创建所有的设备节点。
while the system was booting.
For the "full" setup, you want to [4] make sure /dev is a tmpfs filesystem
而对mdev 更完整的安装,你必须[4]确保 /dev 是 tmpfs 文件系统
(assuming you're running out of flash). Then you want to [5] create the
(假设文件系统在 flash 外运行)。 而且你必须 [5] 创建


-------------
MDEV Config (/etc/mdev.conf)
MDEV 配置 (/etc/mdev.conf)
-------------
Mdev has an optional config file for controlling ownership/permissions of
device nodes if your system needs something more than the default root/root
660 permissions.

如果你的系统需要一些比默认的 root/root 660 更多的权限,
你可以使用 mdev 的可选配置文件,以控制设备节点的 所有者 和 权限。
The file has the format:
这个文件的格式如下:
    <device regex> <uid>:<gid> <octal permissions>
For example:
例如:
    hd[a-z][0-9]* 0:3 660
The config file parsing stops at the first matching line. If no line is
这个配置文件在第一个匹配行处停止解析。 如果没有匹配行,
matched, then the default of 0:0 660 is used. To set your own default, simply

那么就使用默认的 0:0 660 。 你也可以通过在最后创建如下的全匹配
create your own total match like so:
行,来设置你自己的默认设置:
    .* 1:1 777
If you also enable support for executing your own commands, then the file has
如果你想 mdev 在找到匹配行时可以执行自定义的命令,那么文件格式如下:
the format:
    <device regex> <uid>:<gid> <octal permissions> [<@|$|*> <command>]
The special characters have the meaning:
特殊字符的意义如下:
   @ Run after creating the device.

    @ 在创建设备节点后运行命令。
    $ Run before removing the device.
    $ 在删除设备节点前运行命令。
    * Run both after creating and before removing the device.

    * 在创建设备节点后和删除设备节点前都运行命令。
The command is executed via the system() function (which means you're giving a
这些命令是通过系统函数(system())执行的(也就是说你在对shell 下命令)
command to the shell), so make sure you have a shell installed at /bin/sh.
,所以请确保你已在 /bin/sh 安装了shell。
For your convenience, the shell env var $MDEV is set to the device name. So if
为了方便,shell 的环境变量 $MDEV 会被设置成设备名。 例如
the device 'hdc' was matched, MDEV would be set to "hdc".
mdev 解析到设备 'hdc' 匹配,MDEV 将会被设置为 "hdc"。


----------
FIRMWARE
固件
----------
Some kernel device drivers need to request firmware at runtime in order to
有些设备驱动程序在运行时,为了正确的初始化设备,需要上传固件。
properly initialize a device. Place all such firmware files into the
请将所有的固件文件放入
/lib/firmware/ directory. At runtime, the kernel will invoke mdev with the
/lib/firmware/ 目录。 在运行时,内核将会按固件文件名调用 mdev ,
filename of the firmware which mdev will load out of /lib/firmware/ and into
之后 mdev 会通过 sysfs 接口将固件从 /lib/firmware/
the kernel via the sysfs interface. The exact filename is hardcoded in the
装载到内核。 确定的文件名被固化在内核中,
kernel, so look there if you need to want to know what to name the file in
如有必要,你必须知道如何在用户空间命名这个文件。
userspace.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

apple_51426592

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值