Difference between revisions of "USB Gadget"

From ArmadeusWiki
Jump to: navigation, search
(Installation)
(Usage)
Line 31: Line 31:
  
 
First, load the core controller driver on your board:
 
First, load the core controller driver on your board:
  # insmod /lib/modules/imx_udc.ko
+
  # modprobe imx_udc
 +
  usb: imx_udc version: 0.5
  
 
===To emulate a mass storage device:===
 
===To emulate a mass storage device:===
 
* create or get a "backing storage file", for example: [[http://artemys25.free.fr/armadeus/binaires/backing_file.gz]]
 
* create or get a "backing storage file", for example: [[http://artemys25.free.fr/armadeus/binaires/backing_file.gz]]
 
* copy this file (uncompressed) in the '''/tmp''' directory of your rootfs (see NetworkConfig if necessary)
 
* copy this file (uncompressed) in the '''/tmp''' directory of your rootfs (see NetworkConfig if necessary)
 +
# cp /mnt/nfs/backing_file.gz /tmp/
 +
# gunzip /tmp/backing_file.gz
 +
 
* load g_file_storage module:
 
* load g_file_storage module:
  # insmod /lib/modules/g_file_storage.ko file=/tmp/backing_file
+
  # modprobe g_file_storage file=/tmp/backing_file
 +
g_file_storage gadget: File-backed Storage Gadget, version: 28 November 2005
 +
g_file_storage gadget: Number of LUNs=1
 +
g_file_storage gadget-lun0: ro=0, file: /tmp/backing_file
 
* connect target's USB cable to your PC and,  
 
* connect target's USB cable to your PC and,  
On Linux:
+
On your Linux Host:
* as root, launch dmesg and find the /dev/sdaX device assigned to your board
+
* as root, launch ''dmesg'' and find the ''/dev/sdaX'' device assigned to your board:
 +
... usb 1-1.4: new full speed USB device using uhci_hcd and address 7
 +
... usb 1-1.4: configuration #1 chosen from 1 choice
 +
... scsi1 : SCSI emulation for USB Mass Storage devices
 +
...    Vendor: Linux    Model: File-Stor Gadget  Rev: 0314
 +
...    Type:  Direct-Access                      ANSI SCSI revision: 02
 +
...  SCSI device sda: 8192 512-byte hdwr sectors (4 MB)
 +
...  sda: Write Protect is off
 +
...  SCSI device sda: 8192 512-byte hdwr sectors (4 MB)
 +
...  sda: Write Protect is off
 +
...  sda: sda1
 +
...  sd 1:0:0:0: Attached scsi disk sda
 +
...  sd 1:0:0:0: Attached scsi generic sg0 type 0
 +
 
 
* then mount the device and enjoy file sharing:
 
* then mount the device and enjoy file sharing:
 
  [root@toto]# mount /dev/sda1 /mnt/tmp
 
  [root@toto]# mount /dev/sda1 /mnt/tmp
Line 48: Line 68:
 
===To emulate a serial port:===
 
===To emulate a serial port:===
 
  # mknod /dev/ttygserial c 127 0  (only needed the first time you want to use it, if not already existing)
 
  # mknod /dev/ttygserial c 127 0  (only needed the first time you want to use it, if not already existing)
  # insmod /lib/modules/g_serial.ko
+
  # modprobe g_serial
 +
gs_bind: Gadget Serial v2.2 bound
 +
gs_module_init: Gadget Serial v2.2 loaded
  
 
==TBDL==
 
==TBDL==

Revision as of 23:08, 26 November 2007

Instructions to use the USB port of your Armadeus board to communicate with your PC

Introduction

You can connect your Armadeus board to a PC using its USB port and it can be enumerated as many USB devices (depending on the type of communication way you want to use):

  • serial device
  • net device
  • mass storage device

Installation

  • configure your Linux kernel:
[armadeus]$ make linux-menuconfig

in Device Drivers->USB support->USB Gadget Support, choose Support for USB Gadgets and activate all USB Gadget Drivers:

Linux config usb gadget.png

  • save your configuration and then rebuild your kernel image:
[armadeus]$ make

now you should have following drivers in your kernel source tree:

drivers/usb/gadget/gadgetfs.ko        For test
drivers/usb/gadget/g_ether.ko         Ethernet emulation on USB
drivers/usb/gadget/g_file_storage.ko  Mass storage
drivers/usb/gadget/g_serial.ko        Serial emulation on USB
drivers/usb/gadget/g_zero.ko          For test
drivers/usb/gadget/imx_udc.ko         i.MXL USB device Core Controller 
  • reflash your RootFS or manually copy imx_udc.ko, g_file_storage.ko & g_serial.ko to your target in /lib/modules/...

Usage

First, load the core controller driver on your board:

# modprobe imx_udc
 usb: imx_udc version: 0.5

To emulate a mass storage device:

  • create or get a "backing storage file", for example: [[1]]
  • copy this file (uncompressed) in the /tmp directory of your rootfs (see NetworkConfig if necessary)
# cp /mnt/nfs/backing_file.gz /tmp/
# gunzip /tmp/backing_file.gz
  • load g_file_storage module:
# modprobe g_file_storage file=/tmp/backing_file
g_file_storage gadget: File-backed Storage Gadget, version: 28 November 2005
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, file: /tmp/backing_file
  • connect target's USB cable to your PC and,

On your Linux Host:

  • as root, launch dmesg and find the /dev/sdaX device assigned to your board:
... usb 1-1.4: new full speed USB device using uhci_hcd and address 7
... usb 1-1.4: configuration #1 chosen from 1 choice
... scsi1 : SCSI emulation for USB Mass Storage devices
...    Vendor: Linux     Model: File-Stor Gadget  Rev: 0314
...    Type:   Direct-Access                      ANSI SCSI revision: 02
...  SCSI device sda: 8192 512-byte hdwr sectors (4 MB)
...  sda: Write Protect is off
...  SCSI device sda: 8192 512-byte hdwr sectors (4 MB)
...  sda: Write Protect is off
...   sda: sda1
...  sd 1:0:0:0: Attached scsi disk sda
...  sd 1:0:0:0: Attached scsi generic sg0 type 0
  • then mount the device and enjoy file sharing:
[root@toto]# mount /dev/sda1 /mnt/tmp
[root@toto]# cd /mnt/tmp
[root@toto]# showimage /mnt/tmp/test.jpg

To emulate a serial port:

# mknod /dev/ttygserial c 127 0   (only needed the first time you want to use it, if not already existing)
# modprobe g_serial
gs_bind: Gadget Serial v2.2 bound
gs_module_init: Gadget Serial v2.2 loaded

TBDL

Links