linux系统编译usb驱动,linux usb驱动——Gadget编译生产

参考 http://linux-sunxi.org/USB_Gadget/Mass_storage

make kernel_menuconfig

Device Drivers ---> USB support ---> USB Gadget Support ---> Mass Storage Gadget

在src/linux-3.14/drivers/usb/gadget下生成g_mass_storage.ko

加载:

Creating a sparse file

Use "dd" command‘s "count" and "seek" options to create a 1GB file that will not use storage until it is used:

# dd if=/dev/zero of=/mass_storage bs=1M seek=1024 count=0

# ls -l /mass_storage

-rw-r--r-- 1 root root 1073741824 Feb 15 16:40 /mass_storage

# du -hs /mass_storage

0 /mass_storage

Partitioning and formatting sparse file

To be recognized by most Operating Systems, create a single FAT type partition and format it as DOS filesystem using Linux loop device driver.

Create a single partition

# cat <

,,c

EOT

Find partition offset

# fdisk -lu /mass_storage

Disk /mass_storage: 1073 MB, 1073741824 bytes

139 heads, 8 sectors/track, 1885 cylinders, total 2097152 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Device Boot Start End Blocks Id System

/mass_storage1 1 2097151 1048575+ c W95 FAT32 (LBA)

First partition starts at first sector: offset = 1 * 512 = 512 bytes

Set up loop device

# losetup -o512 /dev/loop0 /mass_storage

# losetup -a

/dev/loop0: [b302]:14867 (/mass_storage), offset 512

Format device

# apt-get install dosfstools

# mkdosfs /dev/loop0

Test device

# mount -t vfat /dev/loop0 /mnt/

# df -h /mnt

Filesystem Size Used Avail Use% Mounted on

/dev/loop0 1022M 4.0K 1022M 1% /mnt

# mount | grep mnt

/dev/loop0 on /mnt type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro)

Release device

# umount /mnt/

# losetup -d /dev/loop0

# losetup -a

As we can see below, 1GB sparse file is only using 2.1MB storage (size of filesystem metadata):

# du -sh /mass_storage

2.1M /mass_storage

# ls -lh /mass_storage

-rw-r--r-- 1 root root 1.0G Feb 15 16:54 /mass_storage

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值