最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

在Linux USB Gadget下使用U盘

工作和技术 crifan 8108浏览 0评论

1.insmod USB Host Driver
insmod /lib/modules/2.6.28.4-as353x-patch-svn1406/kernel/drivers/usb/gadget/dwc_otg/dwc_otg.ko
dwc_otg: version 2.60a 05-JUN-2009
AHBValid bit set to 4 after 0 msec
AHBValid bit set to 4 after 1 msec
Connected
dwc_otg: Detected: Synopsys DWC OTG 2.60a Core
dwc_otg: Dedicated Tx FIFOs mode

2.insmod USB Gadget FS driver
# insmod /lib/modules/2.6.28.4-as353x-patch-svn1406/kernel/drivers/usb/gadget/gadgetfs.ko
gadgetfs: USB Gadget filesystem, version 24 Aug 2004

3.insmod a kind of USB Gadget driver, here use "File-backed Storage Gadget"
when insmod this driver, should pass a file/device and some patameter to the driver
here use the mmc block device :
follow is the SD card info:
when insert SD card:
# mmc0: new high speed SD card at address b368
mmcblk0: mmc0:b368 UD    952 MiB
mmcblk0: unknown partition table
then see block partitions info:
# cat /proc/partitions
major minor #blocks name
179        0     975360 mmcblk0
179        1       4096 mmcblk0p1
179        2     126976 mmcblk0p2
179        3     843792 mmcblk0p3
179        4        496 mmcblk0p4

then do:
# insmod /lib/modules/2.6.28.4-as353x-patch-svn1406/kernel/drivers/usb/gadget/g_file_storage.ko file=/dev/mmcblk0p3 stall=0 removable=1
g_file_storage gadget: File-backed Storage Gadget, version: 7 August 2007
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, file: /dev/mmcblk0p3

Also, if you use other file or nand flash, you can use something like /dev/mmcblock3 instead of /dev/mmcblk0p3.

如果不指定file参数,是无法正常insmod的,因为,USB的文件存储,必须要有对应的设备(文件)去操作,不可能凭空去支持USB的操作的。

4.after above operations, we can connect USB

will show info like this:
# dwc_otg: SRP: Device mode
dwc_otg: USB RESET
dwc_otg:

         CANNOT handle > 1 setup packet in DMA mode

dwc_otg: USB RESET
dwc_otg:
# dwc_otg: SRP: Device mode
dwc_otg: USB RESET
dwc_otg:
         CANNOT handle > 1 setup packet in DMA mode
dwc_otg: USB RESET
dwc_otg:
         CANNOT handle > 1 setup packet in DMA mode
dwc_otg: req 80.06 protocol STALL; err -22
dwc_otg: USB RESET
dwc_otg:
…..

and in PC, will show the USB Mass Storage disk..

【参考资料】

1.usb gadget mass storage 驱动开发

http://topic.csdn.net/u/20080925/20/585af370-9e59-4ef2-b162-3641574c5477.html

2.Linux-USB Gadget : Part 2: USB Gadget API for Linux (From Linux kernel 2.6.25.10)

http://blog.csdn.net/hongjiujing/archive/2009/09/01/4508105.aspx

转载请注明:在路上 » 在Linux USB Gadget下使用U盘

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 收藏一下
    GastonFeng15年前 (2009-10-31)回复
82 queries in 0.161 seconds, using 22.11MB memory