Linux Development Board (Linux USB Gadget) simulate U disk __php

Source: Internet
Author: User

A few days ago, hid device, through the USB HID device and Windows communication. Now let's get this mass storge.

First description of the environment: Linux version: 3.15 Using the Development Board: SAMA5D3 compilation Environment: Ubuntu 12.04

1, first configure the kernel, see the following figure

Enter

Device Drivers--->

Select Enter

[*] USB Support--->

Then select the last entry

<*> USB Gadget Support--->

Select compile into module, save exit.

USB Peripheral Controller--->
││<m> USB Gadget Drivers
││< > USB functions configurable through CONFIGFS
││< > Gadget Zero (DEVELOPMENT)
││< > Ethernet Gadget (with CDC Ethernet support)
││< > Network control Model (NCM) support
││< > Gadget filesystem
││< > Function filesystem
││<m> Mass Storage Gadget



The following KO files are generated in the driver/usb/gadget/directory:


-rw-rw-r--1 a_tu a_tu 11253 February 18:03 Drivers/usb/gadget/g_mass_storage.ko
-rw-rw-r--1 a_tu a_tu 49265 February 18:03 Drivers/usb/gadget/libcomposite.ko
-rw-rw-r--1 a_tu a_tu 57658 February 18:03 Drivers/usb/gadget/usb_f_mass_storage.ko

If you are using the 2.6.3 kernel, the kernel configuration is the same as the previous one except the last. The last option:

<M> file-backed Storage Gadget

The resulting KO file is:

Drivers/usb/gadget/g_file_storage.ko


Copy the driver files and kernels to the Development Board.

2, the development of the board operation

First set up a mirror analog USB disk

#dd If=/dev/zero of=vfat.img bs=1m count=20//Make a FAT format mirror file, on the host, the Development Board can be

Then mkdir vfat_mount_point//Create the mount point

Mkfs.vfat vfat.img//formatted Mirror (if your development board does not have the MKFS command, you can insert the SD card into the virtual machine and perform it under Ubuntu in the virtual machine) of course, if this step is not done, it doesn't matter, when Windows discovers new removable devices, will prompt you to format the device, at which point you will be prompted to choose the format of the format, choose the default, formatting on the OK.

Finally, execute the script storage.sh. It is convenient to write these commands in a script, without the input of a piece, you can/etc/init.d/rcs/this script to the startup file, so that it runs on its own every time it is powered on. The script content is as follows. Reminders, the following commands are to be written sequentially

Losetup/dev/loop0 vfat.img//Connect mirrors to Loop0
Insmod Gadgetfs.ko
Insmod Libcomposite.ko
Insmod Usb_f_mass_storage.ko
Mount/dev/loop0 Vfat_mount_point//Mount mount point
Insmod G_mass_storage.ko file=/dev/loop0 stall=0 removable=1


After the script is executed, the kernel prompts the information g_mass_storage Gadget:g_mass_storage ready, which means that you have successfully plugged in the USB device. Windows prompts you to discover new removable devices.

After everything is done, verify that it is correct. Found to write files under Windows or create a new folder. Information that can be synchronized to Windows in the folder in the mount point of the Development Board. A new file or folder in the Development Board requires the device to be disconnected before it can be synchronized to a removable device in Windows.

There may be a problem there is no find, I hope the master pointing correction ...

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.