In Linux, OTG maps a disk or file on the board to a Mobile Disk on a PC.

Source: Internet
Author: User

In Linux, OTG maps a disk or file on the board to a Mobile Disk on a PC.
We often insert mobile phones or other electronic devices into PCs for mutual transmission of some files. When we insert a mobile phone into a PC, we will see a Mobile Disk on the PC, but how to implement it in Linux is described as follows. As for the detailed principle, I will not introduce it here, because I just don't know why. Well, there is not much nonsense. The following is an introduction:
1. First, you want to see the disk on the Linux board on a PC. First, your Linux board must support OTG and the vendor has provided the corresponding driver. Here I use I. the mx6 platform and OTG drivers have been configured.
2. Compile the corresponding kernel modules. 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 to be used is g_file_storage.ko. The usage is as follows:
~ # Modprobe g_file_storage file =/root/block
4. It is best to use modprobe to load the driver module, because the driver module has some associated modules, it is too troublesome to manually load them one by one. The module parameter is "file =" followed by the file name you want to see on the PC. When the file is viewed on the PC end, the file will be treated as an independent Mobile Disk. For example, if your Linux Board has an SD card and the device file on Linux is/dev/mmcblk1, you want to see the SD card operation on your PC as follows:
~ # Modprobe g_file_storage file =/dev/mmcblk1
Note: Do not write/dev/mmcblk1 as/dev/mmcblk1p1. Otherwise, the SD card partition of mmcblk1p1 will be used as a new mobile disk on the PC, and the partition will be reformatted, in this way, the files on the Linux side and on the PC side are inconsistent.
5. Of course, you can directly mount a file to a disk on the PC end,
Use the dd command to create a blank file:
~ # Dd if =/dev/zero of =/root/block bs = 1 M count = 100
Push the file to a removable disk on the PC:
~ # Modprobe g_file_storage file =/root/block
In this way, you can see a m removable disk on the PC end. After formatting, you can directly access the disk. Compared with the direct mounting of the SD card, that is, you cannot mount the block file on the Linux end to achieve the same access as that on the PC end. Because on the Linux side, the block file is directly mounted as a disk partition on the PC side, this block file is a new partition attached after being partitioned by a removable disk. There is an MBR offset gap between the two sides. Of course, you can achieve mutual communication if you do not mount a file system on both sides, but directly read or write a file as a device file.

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.