Wednesday, August 23, 2017

emulator a virtual usb storage device

1- check your kernel whether CONFIG_USB_DUMMY_HCD is enabled
from file /boot/config-4.8.17, to see line like below
CONFIG_USB_DUMMY_HCD=m

2- if not you have to recompile the kernel to use this feature
- install linux-source
$ sudo apt-get install linux-source
$ tar xvf /usr/src/linux-source-xxx/linux-source-xxx.tar.gz
$ cd linux-source-xxx
$ cp /boot/comfig-xxx .
$ make menuconfig

- go to below path to enable (/ to search)  │     -> Device Drivers                                                   │ 
  │       -> USB support (USB_SUPPORT [=y])                                 │ 
  │         -> USB Gadget Support (USB_GADGET [=m])                         │ 
  │            -> USB Peripheral Controller  


                     -->USB_DUMMY_HCD [=m]   


 then save

- compile and install

$ make
or make with 8 concurrency (8 cpu+thread)
$ make -j8
$ make -j8 modules
$ make -j8 modules_install
$ make install

** if we want to setup on other machine, we can make deb package
$ make -j8
$ make -j8 modules
$ make -j8 deb-pkg

4- then install
$ sudo dpkg -i ../*.deb


5- usages
$ sudo modprobe dummy_hcd 
$ ls_usb (will see a new device being attached)

- for quick adding use ram disk
$ modprobe g_mass_storage file=/dev/ram0

then a new drive will appear

or create with a image file, below 1gb
$ dd if=/dev/zero of=usb.img count=1024 bs=1M 

then
$ modprobe g_mass_storage file=usb.img
-

No comments:

Post a Comment