A disk or file on the board is mapped to a mobile disk on the PC by OTG under Linux

Source: Internet
Author: User

We often put mobile phones or other electronic devices into the PC to carry out some files, when the phone is plugged into a PC, you will see a mobile disk on the PC, but how to implement in Linux, now the method is described below, as to the detailed principle here is not introduced, Because I just know it and don't know why. Well, not much nonsense, now introduced as follows:
1, first, want to see the disk on the Linux board card on the PC, first of all your Linux board needs to support OTG and the manufacturer has provided the appropriate driver, I use the i.mx6 platform, the OTG driver has been configured.
2, second, compile the kernel corresponding module, the required modules are:
Location:
│-> Device Drivers
│-> USB Support (Usb_support [=y])
│-> USB Gadget Support (Usb_gadget [=y])
USB Gadget Drivers (<choice> [=m])
->file-backed Storage Gadget (usb_file_storage [=m])
3. The core module that will be used is named G_file_storage.ko, using the following method
~# Modprobe G_file_storage File=/root/block
4, note it is best to use modprobe to load the driver module, because the driver module will have some associated modules, manual one load too cumbersome. The module parameter is "file=" immediately after you want to see the file name on the PC, the main file on the PC side when seen, the file as a separate mobile disk. For example, your Linux board has an SD card, the device file file on Linux is/DEV/MMCBLK1, and you want to see the SD card on the PC as follows:
~# Modprobe G_file_storage FILE=/DEV/MMCBLK1
Note, do not write/dev/mmcblk1/dev/mmcblk1p1, otherwise on the PC will be mmcblk1p1 this SD card partition as a new mobile disk, re-partition format, so that the Linux side and the PC side see the file inconsistencies.
5, of course, you can also directly attach a file to the PC side of a disk,
Create a blank file with the DD command first:
~# DD If=/dev/zero of=/root/block bs=1m count=100
Push the file to a removable disk on the PC side:
~ #modprobe G_file_storageFile=/root/block
So the PC can see a 100M size of the removable disk, after the format can be directly accessed, and directly mount the SD card compared to the method, it is impossible to mount the Linux side of the block file after the implementation and PC-side access, because on the Linux side, The block file mount is mounted directly as a disk partition, on the PC side, the block file is mounted as a removable disk to repartition the resulting new partition, and there is an offset gap on both sides of the MBR. Of course, how to not mount the file system on both sides, just as a device file to read and write directly, it is possible to achieve mutual communication.

A disk or file on the board is mapped to a mobile disk on the PC by OTG under Linux

Related Article

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.