Monday, May 2, 2011

mini2440 as USB mass storage gadget device

To make mini2440 as USB mass storage device,I needed to check both the schematics and source code. I am not sure the reason GPG12 GPIO port pin is used by touch screen, however this is not captured in schematics. also referred http://www.linux-usb.org/gadget/file_storage.html link to establish this task.

Step 1:
so the first step is to disable the touch screen driver in the kernel source tree.

step 2:
--- USB support
[*] USB device filesystem
<*> USB Gadget Support --->
File-backed Storage Gadget

step 3:
cross compile the kernel,boot the new kernel and filesystem. go to compiled linux source tree and download g_file_storage.ko to mini2440.

step 4:
Creating a backing storage file
since the mini2440 has 64 MB flash, I allocated 10MB space for backup storage file.
bash# dd bs=1M count=10 if=/dev/zero of=/root/backing_file

step 5:

Partitioning the backing storage

     bash# fdisk /root/backing_file
Device contains neither a valid DOS partition table, nor Sun or SGI disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

You must set heads sectors and cylinders.
You can do this from the extra functions menu.

Command (m for help):

Give the "x" (eXpert or eXtra) command:

Command (m for help): x
now select Heads, Sectors, and Cylinders
g_file_storage uses a sector size of 512 bytes, so 8 sectors/track will give us 4096 bytes
per track
Expert command (m for help): s
Number of sectors (1-63): 8
Warning: setting sector offset for DOS compatiblity

With 4 KB per track, 16 heads will give us a total of 64 KB per cylinder
Expert command (m for help): h
Number of heads (1-256): 16

Since we've got 64 KB per cylinder and 10 MB total, we need to use 320
cylinders.
Expert command (m for help): c
Number of cylinders (1-131071): 320

Now return to the normal menu (the "r" command):
Expert command (m for help): r

creating a primary partition

     Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1024, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1024, default 1024):
Using default value 1024

Since you want to use the gadget with a Windows host, you should change the
partition type (the "t" command) to FAT32 (code "b")
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (Win95 FAT32)

Finally write out ("w") the partition table to the backing storage:
Command (m for help): w
The partition table has been altered!

Adding a filesystem
   You use the losetup program to set up the loop
device driver with the proper offset:

# losetup -o 4096 /dev/loop0 /root/backing_file

and then you can mount it:

# mount -t vfat /dev/loop0 /mnt/loop

/dev/loop0
is mapped to the partition within the backing
storage. You can create a filesystem on it:
# mkdosfs /dev/loop0


now do "insmod
g_file_storage file=/root/backing_file" on mini2440,then connect mini2440 to host PC.
the FAT32 partition with will be visible as storage device on Host system

3 comments:

  1. which version of linux are you using? i tried linux 2.6.29 and usb gadget/udc doesnt seem to work on mini2440

    ReplyDelete
  2. Hi Ravi,

    I am using linux-2.6.32, u need to apply the patch with this kernel and try.

    https://docs.google.com/leaf?id=0B1nQtD1MkxoDYWMyMmJhYTEtYjhjMS00NzZhLTg0OWQtOTE3OGVhZDdhOWIy&hl=en_US

    ReplyDelete
  3. Please help!!!
    I try to do that but i have

    root@am335x-evm:/# mount -t vfat /dev/loop0 /mnt/loop
    mount: mounting /dev/loop0 on /mnt/loop failed: Invalid argument

    What shell i do?

    ReplyDelete