Tuesday, December 23, 2008

quick removable drive with omap3

One neat little trick of having an OTG port is the capability to have the board act as any type of device you'd want it to be.. in my case, I wanted to emulate a disk drive for the heck of it..
I found this link particularly useful. g_file_storage.ko which is generated once you enable file storage gadget as a module in the kernel build.
Step 1: create the "disk" - essentially a file
dd bs=1M count=64 if=/dev/zero of=fs
fdisk fs (follow the steps in the link)
fdisk -lu fs
sudo losetup -o 4096 /dev/loop0 fs
sudo mkdosfs /dev/loop0
mkdir r
sudo mount -t vfat /dev/loop0 r
vim r/hellow.txt (put what ever files we want here)
sudo umount r
sudo losetup -d /dev/loop0

ensure that fs file exists in the filesystem of the target
Step 2: load it up..
insmod g_file_storage.ko file=./fs stall=n

where fs is the file which we created in the first place.. and that'z it.. once you connect the musb to a windows PC, it appears as a disk ;)...

No comments: