Linux USB driver--gadget compiled production

Source: Internet
Author: User

Reference Http://linux-sunxi.org/USB_Gadget/Mass_storage

Make Kernel_menuconfig

Device Drivers---> USB support---> USB Gadget support---> <M> Mass Storage Gadget

Generate G_mass_storage.ko under Src/linux-3.14/drivers/usb/gadget

Load:

Creating a sparse file

Use "dd" command ' s "Count" and "seek" options to create a 1GB file that won't use storage until it's 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 1 6:40/mass_storage# du-hs/mass_storage 0       /mass_storage
partitioning and formatting sparse file

To is 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 <<eot | Sfdisk--in-order-l-um/mass_storage,, Ceot
Find Partition Offset
# fdisk-lu/mass_storage disk/mass_storage:1073 MB, 1073741824 bytes139 heads, 8 sectors/track, 1885 cylinders, Total 2 097152 sectorsunits = sectors of 1 * = bytessector size (logical/physical): bytes/512 bytesi/o Size (minimum /optimal): bytes/512 bytesdisk identifier:0x00000000device Boot      Start         End      Blocks   Id  system/ Mass_storage1               1     2097151     1048575+   C  W95 FAT32 (LBA)

First partition starts at first sector:offset = 1 * = + 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/mntfilesystem      Size  used Avail use% mounted on/dev/loop0     1022M  4.0 K 1022M   1%/mnt# Mount | grep mnt/dev/loop0 on/mnt type VFAT (Rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocha Rset=ascii,shortname=mixed,errors=remount-ro)
Release Device
# umount  /mnt/# losetup-d/dev/loop0 # losetup-a

As we can see below, 1GB sparse file was 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 16:54/mass_storage

Linux USB driver--gadget compiled production

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.