Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1038768
  • 博文数量: 244
  • 博客积分: 6820
  • 博客等级: 准将
  • 技术积分: 3020
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-09 21:33
文章分类

全部博文(244)

文章存档

2013年(1)

2012年(16)

2011年(132)

2010年(3)

2009年(12)

2008年(80)

我的朋友

分类: LINUX

2011-04-15 17:47:32

File-backed Storage implements the USB Mass Storage class (as CB, CBI, or BBB), appearing to the host as a SCSI disk drive. This uses a file or block device as a backing store for the drive, like the “loop” driver. (Read about how to set up the backing store.) The 2.6 version also lets you change the backing file associated with a given LUN. For example, you might specify the block device for an MMC card when that card is inserted (maybe using a hotplug script, or a GUI). Note that for MS-Windows interoperability, your backing store needs to be formatted with a DOS partition label. Data partitions can then be formatted with VFAT (for the widest interoperability) or some other filesystem (such as ext3 or reiserfs, for use with Linux).

Souce code is drivers/usb/gadget/file_storage.c

Kernel config of File-backed Storage

[Linux Kernel Configuration] -→ [Device Drivers] -→ [USB support] -→ [USB Gadget Support]

 Support for USB Gadgets 
   File-backed Storage Gadget
[*]     File-backed Storage Gadget testing version

Use EZKIT-BF548 as USB Mass Storage device for Windows/Linux Host

EZKIT-BF548 provides IDE hard disk connected by ATAPI of BF54x. If the kernel add BF54x ATAPI support, some you can get following booting message. We can use this real hard disk as backing storage of file-backed storage gadget driver.

register bfin atapi driver
scsi0 : pata-bf54x
ata1: PATA max UDMA/100 cmd 0x00000000 ctl 0xffc03800 bmdma 0x00000000 irq 68
ata1.00: ATA-6: TOSHIBA MK4032GAX, AD101A, max UDMA/100
ata1.00: 78140160 sectors, multi 16: LBA48 
ata1.00: configured for UDMA/100
blk_queue_max_hw_segments: set to minimum 1
scsi 0:0:0:0: Direct-Access     ATA      TOSHIBA MK4032GA AD10 PQ: 0 ANSI: 5
sd 0:0:0:0: [sda] 78140160 512-byte hardware sectors (40008 MB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
sd 0:0:0:0: [sda] 78140160 512-byte hardware sectors (40008 MB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
 sda: sda1
sd 0:0:0:0: [sda] Attached SCSI disk

On EZKIT-BF548, install the g_file_storage driver:

root:~> modprobe g_file_storage file=/dev/sda1 stall=0
g_file_storage gadget: File-backed Storage Gadget, version: 28 November 2005
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, file: /dev/sda1
g_file_storage gadget: full speed config #1
root:~> 

Then on the host PC, both Windows and Linux can found the 40GB driver mounted. You can do fdisk/formate/copy/delete operation as normal disk.

If the IDE hard disk has been partitioned and formated as MSDOS (for Windows) or other file system can be recognized by host PC, it will be automatically mounted on you PC. You can directly operate this disk driver. If not, on Windows host please go to [Control Panel] --> [Administrative Tools] --> [Computer Management] --> [Disk Management] and you can find the 40GB hard disk is ready for partition and format. After that, you can use the hard disk driver normally.

Use RAM based file as backing storage

Sometime there is no such hard disk installed in your system, then we can use RAM based block file as backing storage as below:

root:~> dd if=/dev/zero of=fsg.block bs=1M count=16
16+0 records in
16+0 records out
root:~> modprobe g_file_storage file=/fsg.block stall=0
g_file_storage gadget: File-backed Storage Gadget, version: 28 November 2005
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, file: /fsg.block
g_file_storage gadget: full speed config #1
root:~>

You can partition and format this block disk driver on host Windows/Linux PC. The block file also can be partitioned and formated on Blackfin embedded devices, please read as reference.

Sometimes, people have Nand flash on their device, and they want this Nand flash accessible as

Please refer to . Here we have yaffs2 on /dev/mtdblock1.

root:/> mount -t yaffs2 -o sync /dev/mtdblock1 /mnt/
yaffs: dev is 32505857 name is "mtdblock1"
yaffs: Attempting MTD mount on 31.1, "mtdblock1"
yaffs: restored from checkpoint

root:/> cd /mnt
root:/mnt> dd if=/dev/zero of=/mnt/vfat.bin bs=1M count=100
100+0 records in
100+0 records out

root:/mnt> mkdosfs vfat.bin 
mkdosfs 2.10 (22 Sep 2003)

root:/mnt> mkdir vfat_dir

root:/mnt> mount -t vfat -o sync /mnt/vfat.bin /mnt/vfat_dir/

root:/mnt> cd vfat_dir/

root:/mnt/vfat_dir> time dd if=/dev/zero of=/mnt/vfat_dir/test.bin bs=1M count=50
50+0 records in
50+0 records out
real    0m 35.49s
user    0m 0.00s
sys     0m 4.28s

root:/mnt/vfat_dir> modprobe g_file_storage file=/mnt/vfat.bin removable=1 
g_file_storage gadget: File-backed Storage Gadget, version: 28 November 2005
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, file: /mnt/vfat.bin

Connect BF548-EZKIT with Windows PC via

阅读(2100) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~