BORA SOM/BELK-L/Pheripherals/USB OTG

From DAVE Developer's Wiki
Jump to: navigation, search



USB OTG[edit | edit source]

Host mode[edit | edit source]

For the USB Host mode an USB stick or another device must be pluged in at the system boot. See the issue related to USB not hotplug capable after the system boot.

This example shows how a memory stick is detected by the Linux kernel.

root@bora:~# [   37.340873] usb 1-1: new high-speed USB device number 2 using zynq-ehci
[   37.508377] usb 1-1: device v05e3 p0736 is not supported
[   37.514823] usb-storage 1-1:1.0: USB Mass Storage device detected
[   37.521869] scsi host0: usb-storage 1-1:1.0
[   38.522235] scsi 0:0:0:0: Direct-Access     Generic  STORAGE DEVICE   0272 PQ: 0 ANSI: 0
[   38.531274] sd 0:0:0:0: Attached scsi generic sg0 type 0
[   38.663662] sd 0:0:0:0: [sda] 30679040 512-byte logical blocks: (15.7 GB/14.6 GiB)
[   38.673145] sd 0:0:0:0: [sda] Write Protect is off
[   38.677862] sd 0:0:0:0: [sda] Mode Sense: 0b 00 00 08
[   38.684026] sd 0:0:0:0: [sda] No Caching mode page found
[   38.689257] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   38.703539]  sda: sda1 sda2
[   38.715870] sd 0:0:0:0: [sda] Attached SCSI removable disk

To connect it to micro AB connector (J19), a cable like the one shown in the following picture has been used [1].

USB cable used to connect memory stick


Once mounted (at mnt/sda1 in the example), the memory stick can be accessed by regular commands:

root@bora:~# mount /dev/sda1 /mnt/sda1/
root@bora:~# mount
192.168.0.13:/opt/nfsroot/users/mgeromin/bora/belk on / type nfs (rw,relatime,vers=2,rsize=4096,wsize=4096,namlen=255,hard,nolock,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.0.13,mountvers=1,mountproto=tcp,local_lock=all,addr=192.168.0.13)
devtmpfs on /dev type devtmpfs (rw,relatime,size=507916k,nr_inodes=126979,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /var/volatile type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
/dev/sda1 on /mnt/sda1 type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
root@bora:~# time cp LibreOffice_4.1.1_Win_x86.msi /mnt/sda1/

real    0m25.114s
user    0m0.010s
sys     0m4.070s
root@bora:~# umount /mnt/sda1/
root@bora:~# mount /dev/sda1 /mnt/sda1/
root@bora:~# md5sum LibreOffice_4.1.1_Win_x86.msi /mnt/sda1/LibreOffice_4.1.1_Win_x86.msi
4fa047c0590097ce201f49655365d772  LibreOffice_4.1.1_Win_x86.msi
4fa047c0590097ce201f49655365d772  /mnt/sda1/LibreOffice_4.1.1_Win_x86.msi
root@bora:~#

[1] This type of cables forces the ID signal of the USB port to be connected to ground, selecting the host mode on SBC Lynx side.

Device mode[edit | edit source]

The following examples shows how to configure Bora/BoraEVB or BoraX/BoraXEVB to act as a mass storage device.

First, a local file named mass is created to emulate a mass storage disk that is populated with a file named file.txt:

root@bora:~# dd if=/dev/zero of=mass count=16 bs=1M
16+0 records in
16+0 records out
root@bora:~# mkfs.ext3 mass
mke2fs 1.42.9 (28-Dec-2013)
mass is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
4096 inodes, 16384 blocks
819 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=16777216
2 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
        8193

Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
root@bora:~# mkdir loop
root@bora:~# mount -o loop mass loop
[   92.316783] kjournald starting.  Commit interval 5 seconds
[   92.316901] EXT3-fs (loop0): using internal journal
[   92.316908] EXT3-fs (loop0): mounted filesystem with writeback data mode
root@bora:~# echo dummy > loop/file.txt
root@bora:~# umount loop

Then the proper drivers are loaded on target side:

root@bora:~# modprobe g_mass_storage file=/home/root/mass
[  209.058156] Number of LUNs=8
[  209.061005] Mass Storage Function, version: 2009/09/11
[  209.066085] LUN: removable file: (no medium)
[  209.070349] Number of LUNs=1
[  209.073781] LUN: file: /home/root/mass
[  209.077444] Number of LUNs=1
[  209.080452] g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11
[  209.087381] g_mass_storage gadget: userspace failed to provide iSerialNumber
[  209.094393] g_mass_storage gadget: g_mass_storage ready
[  209.099572] zynq-udc: bind to driver g_mass_storage

Last, BoraEVB (or BoraXEVB) is connected to a Linux PC with a USB cable like this one:

USB cable used to connect BoraXEVB to PC


On PC side, BoraEVB (or BoraXEVB) is detected as a common USB mass storage device.