• linux usb驱动——Gadget编译生产


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

    make kernel_menuconfig

    Device Drivers ---> USB support ---> USB Gadget Support ---> <M> 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 <<EOT | sfdisk --in-order -L -uM /mass_storage 
    ,,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
    
  • 相关阅读:
    asp.net中常用提示对话框
    winForm 常用总结
    C#的IS和AS运算符区别
    转 七种武器——.NET工程师求职面试必杀技
    C#中bool与Boolean有什么区别?string和String区别?
    转 面向程序员的数据库访问性能优化法则
    转:回音消除技术
    转C#中using和new的用法
    转 C# 性能优化之斤斤计较篇
    转:三种运行Powershell代码的方法
  • 原文地址:https://www.cnblogs.com/mahj/p/8494509.html
Copyright © 2020-2023  润新知