您的位置:首页 > 其它

File-backed Storage Gadget

2013-11-21 14:24 281 查看


File-backed Storage Gadget

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 MMCcard
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]
<M> Support for USB Gadgets
<M>   File-backed Storage Gadget
[*]     File-backed Storage Gadget testing version



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


Use real ATAPI IDE disk of EZKIT-BF548

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 "Backing
Storage for the File-backed Storage Gadget" as reference.


Use NAND flash on BF548-EZKIT as USB mass storage

Sometimes, people have Nand flash on their device, and they want this Nand flash accessible as USB storage.
In many case, they access this storage using a MSWindows PC, which is not friendly to jffs2 or yaffs2. Here is a workaround:


Enable yaffs2 on Nand

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


Create a file-backed VFAT FS backed on Yaffs2/Nand

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: