in Embedded, IOT, Linux, 兴趣

Embedded Linux S3C2440 – USB Gadget Drivers

Summary

Tested on Embedded Linux S3C2440 target board to be configured as USB device, like USB mass storage and serial cable, the test result was successful. And tried to test S3C2440 board as USB Host, I didn’t get successful result.

Basics

S3C2440 supports 2-port USB host interface as follows,
– OHCI Rev 1.0 compatible.
– USB Rev 1.1 compatible
– Two down stream ports.
– Support for both LowSpeed and Full Speed USB devices.
S3C2440A device controller support:
– Full speed USB device controller compatible with USB specification v1.1
– DMA interface for bulk transfer.
– Five endpoints with FIFO:
EP0: 16 bytes(register)
EP1: 128 byte IN/OUT FIFO (dual port asynchronous RAM): interrupt or DMA.
EP2: 128 byte IN/OUT FIFO (dual port asynchronous RAM): interrupt or DMA.
EP3: 128 byte IN/OUT FIFO (dual port asynchronous RAM): interrupt or DMA.
EP4: 128 byte IN/OUT FIFO (dual port asynchronous RAM): interrupt or DMA.

S3C2440A board has two USB ports: the port with a type A connector works as a USB host; the other with a Type B connector works as a USB peripheral. Both USB host controller and UDC (USB device controller) are regarded as platform device and their drivers are registered as platform driver.
Source code of USB host controller driver is linux-3.8.7/drivers/usb/host/ohci-s3c2410.c.

The UDC driver reads/writes the registers of the UDC and reads/writes the FIFOs of the endpoints. Gadget drivers sit on top of the UDC dirver, and use the service it provides. A UDC driver must impelment a set of function to manipulate endpoints and gadget, as well as to register and unregister a gadget driver. They are defined in the file linux-3.8.7/include/linux/usb/gadget.h.

The UDC of S3C2440A is integrated on the S3C2440 chip and hence is regarded as a platform device. Its driver is a platform driver. Source code of the UDC drier for S3C2440 is linux-3.8.7/drivers/usb/gadget/s3c2410_udc.c. It is for all the S3C2410 based boards.

The UDC driver maintains a request queue for each of the 5 endpoints, a gadget driver puts request to the queues by calling queue(). When the request is completed and the request has a callback function, the UDC driver dequeues the requests and calls its complete function.

Using S3C2440 as a USB Host

In Linux 3.8.7 source code folder, make menuconfig.
In Linux/arm 3.8.7 Kernel Configuration –> Device Drivers --->, –> USB support

<*>   Support for Host-side USB
[*]     USB announce new devices
<*>   OHCI HCD support

Configure to install usb device driver in Kernel. In Device Drivers --->, then go to SCSI device support --->,

<*> SCSI device support
<*> SCSI disk support

Under [*] USB support --->, select,

[*] USB support  --->

Configure to support the file system, go to File systems --->, select,

DOS/FAT/NT Filesystems  --->
   <*> MSDOS fs support
   <*> VFAT (Windows-95) fs support
   (437) Default codepage for FAT
   (iso8859-1) Default iocharset for FAT
   <*> NTFS file system support
      [*]   NTFS debugging support
      [*]   NTFS write support

Change from

(utf8) Default iocharset for FAT

to

(iso8859-1) Default iocharset for FAT

Configure the language support, go to File systems --->, select,

-*- Native language support  --->
    (utf8) Default NLS Option
    <*>   Codepage 437 (United States, Canada)
    <*>   NLS ISO 8859-1  (Latin 1; Western European Languages)

To be able to support Chinese characters, go to Device Drivers --->, Input device support --->,

<*>   Event interface

Go to HID support ---> then, USB HID support --->,

<*> USB HID transport layer

After S3C2440 startup, inserted into one USB thumb driver, the S3C2440 cannot detect the USB thumb driver, the test result failed.

Using S3C2440 as a USB Disk

We use part of the NAND as a USB Disk. Edit the source code linux-3.8.7/arch/arm/mach-s3c24xx/mach-mini2440.c, allocate 50M to the root file system and the rest for the USB disk, it is around 195M.

[root@localhost mach-s3c24xx]# pwd
/home/iot/mini2440/linux-3.8.7/arch/arm/mach-s3c24xx
[root@localhost mach-s3c24xx]# vim mach-mini2440.c

0x03200000 is around 50M, it is for root file system.

static struct mtd_partition mini2440_default_nand_part[] __initdata = {
        [0] = {
                .name   = "u-boot",
                .size   = SZ_256K,
                .offset = 0,
        },
        [1] = {
                .name   = "u-boot-env",
                .size   = SZ_128K,
                .offset = SZ_256K,
        },
        [2] = {
                .name   = "kernel",
                /* 5 megabytes, for a kernel with no modules
                 * or a uImage with a ramdisk attached */
                .size   = 0x00600000,
                .offset = SZ_256K + SZ_128K,
        },
        [3] = {
                .name   = "root",
                .offset = SZ_256K + SZ_128K + 0x00600000,
                /*.size = MTDPART_SIZ_FULL,*/
                .size   = 0x03200000,
        },
        [4] = {
                .name   = "udisk",
                .offset = SZ_256K + SZ_128K + 0x00600000 + 0x03200000,
                .size   = MTDPART_SIZ_FULL,
        },
};

Configure busybox,

[root@localhost busybox-1.19.4]# pwd
/home/iot/mini2440/busybox-1.19.4
[root@localhost busybox-1.19.4]# make menuconfig

Under Linux System Utilities --->, change the configuration, [*] mkfs_vfat, then save the configuration.

Compile and install busybox,

[root@localhost busybox-1.19.4]# make clean
  CLEAN   applets
  CLEAN   .tmp_versions _install
  CLEAN   busybox busybox_unstripped.map busybox_unstripped.out busybox_unstripped busybox.links .kernelrelease
[root@localhost busybox-1.19.4]# make
[root@localhost busybox-1.19.4]# make install

Generate the root file system,

[root@localhost rootfilesystem]# pwd
/home/iot/mini2440/rootfilesystem
[root@localhost rootfilesystem]#
[root@localhost rootfilesystem]# vim create_rootfs_bash.sh

Edit file,

Add following line

mkdir lib/modules/3.8.7-FriendlyARM

Before the line,

echo "---------Copy from busybox, rootfs-base, libs -----------"

Add the following line,

cp -rP /lib/modules/3.8.7-FriendlyARM/* lib/modules/3.8.7-FriendlyARM/

Before following line,

chown -R root.root ../rootfs

Change directory to linux-3.8.7,

[root@localhost rootfilesystem]# cd /home/iot/mini2440/linux-3.8.7/
[root@localhost linux-3.8.7]# pwd
/home/iot/mini2440/linux-3.8.7
[root@localhost linux-3.8.7]#

Configure the Linux kernel to support USB Gadget,

[root@localhost linux-3.8.7]# make menuconfig

Under Linux/arm 3.8.7 Kernel Configuration, go to Device Drivers --->, then go to [*] USB support --->, and < *> USB Gadget Support --->.
Configure as the following as show below,

--- USB Gadget Support                                                                                                      
[ ]   Debugging messages (DEVELOPMENT)
[ ]   Debugging information files (DEVELOPMENT)
[ ]   Debugging information files in debugfs (DEVELOPMENT)
(2)   Maximum VBUS Power usage (2-500 mA) 
(2)   Number of storage pipeline buffers
      USB Peripheral Controller  ---> 
<M>   USB Gadget Drivers     
< >     Gadget Zero (DEVELOPMENT) 
<M>     Ethernet Gadget (with CDC Ethernet support) 
[*]       RNDIS support (NEW) 
[ ]       Ethernet Emulation Model (EEM) support (NEW) 
< >     Network Control Model (NCM) support
< >     Gadget Filesystem 
< >     Function Filesystem  
<M>     Mass Storage Gadget   
<M>     Serial Gadget (with CDC ACM and CDC OBEX support) 
< >     Printer Gadget           
< >     CDC Composite Device (Ethernet and ACM)   
< >     CDC Composite Device (ACM and mass storage)    
< >     Multifunction Composite Gadget 
< >     HID Gadget        
< >     EHCI Debug Device Gadget   
< >     USB Webcam Gadget

Enter USB Peripheral Controller –>, USB Peripheral Controller --->, it is the same menu further go down, and select < *> S3C2410 USB Device Controller.

< > Faraday FUSB300 USB Peripheral Controller
< > Renesas R8A66597 USB Peripheral Controller
<*> S3C2410 USB Device Controller
[ ]   S3C2410 udc debug messages (NEW)
<  > S3C2416, S3C2443 and S3C2450 USB Device Controller
< > Marvell USB2.0 Device Controller 
< > Renesas M66592 USB Peripheral Controller
< > PLX NET2272 
< > Dummy HCD (DEVELOPMENT)

Exit to Device Drivers, Enter into < *> Memory Technology Device (MTD) support --->,
Select as below items,

--- Memory Technology Device (MTD) support 
< >   MTD tests support (DANGEROUS) 
< >   RedBoot partition table parsing  
[ ]   Command line partition table parsing   
< >   ARM Firmware Suite partition parsing        
< >   TI AR7 partitioning support            
      *** User Modules And Translation Layers ***     
<*>   Direct char device access to MTD devices 
-*-   Common interface to block layer for MTD 'translation layers'  
<*>   Caching block device access to MTD devices  
<*>   FTL (Flash Translation Layer) support      
<*>   NFTL (NAND Flash Translation Layer) support  
[*]     Write support for NFTL   
< >   INFTL (Inverse NAND Flash Translation Layer) support 
< >   Resident Flash Disk (Flash Translation Layer) support  
< >   NAND SSFDC (SmartMedia) read only translation layer 
< >   SmartMedia/xD new translation layer       
< >   Log panic/oops to an MTD buffer         
    RAM/ROM/Flash chip drivers  --->                   
    Mapping drivers for chip access  --->             
    Self-contained MTD device drivers  --->    
[ ]   NAND ECC Smart Media byte order  
<*>   NAND Device Support  --->     
< >   OneNAND Device Support  --->          
    LPDDR flash memory drivers  --->     
< >   Enable UBI - Unsorted block images  --->

Exit to Linux/arm 3.8.7 Kernel Configuration.
Select File systems ---> DOS/FAT/NT Filesystems ---> < *> VFAT (Windows-95) fs support.
Change the Default codepage for FAT to 437,
From

(936) Default codepage for FAT

to

(437) Default codepage for FAT

Select File systems --> -*- Native language support ---> (utf8) Default NLS Option, select below options,

<*>   Codepage 437 (United States, Canada)
<*>   NLS UTF-8

We will use initramfs and not the rootfs in the NAND flash as we tested the YAFFS2 file system before, we need to change it back.
Enter General setup ---> and scroll down to "[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support".
Set the Initramfs open source file(s) to "initramfs.cpio", exit from "General setup".
Exit and save the configuration.

Compile the kernel and modules.

[root@localhost linux-3.8.7]# make clean
[root@localhost linux-3.8.7]# make
[root@localhost linux-3.8.7]# make modules_install
  INSTALL drivers/char/foo.ko
  INSTALL drivers/usb/gadget/g_ether.ko
  INSTALL drivers/usb/gadget/g_mass_storage.ko
  INSTALL drivers/usb/gadget/g_serial.ko
  INSTALL drivers/usb/gadget/libcomposite.ko
  INSTALL fs/nfs/nfs_layout_nfsv41_files.ko
  DEPMOD  3.8.7-FriendlyARM
[root@localhost linux-3.8.7]# 

Create root file system,

[root@localhost rootfilesystem]# pwd
/home/iot/mini2440/rootfilesystem
[root@localhost rootfilesystem]# ./create_rootfs_bash.sh 
------Create rootfs --------
/home/iot/mini2440/rootfilesystem/rootfs /home/iot/mini2440/rootfilesystem
--------Create root,dev....----------
---------Copy from busybox, rootfs-base, libs -----------
---------make node dev/console dev/null-----------------
mknod: ‘/dev/ptmx’: File exists
17654 blocks
/home/iot/mini2440/rootfilesystem

Recompile the kernel for the newly created root file system, it is to incorporate the newly created the root file system.

[root@localhost rootfilesystem]# cd /home/iot/mini2440/linux-3.8.7/
[root@localhost linux-3.8.7]# pwd
/home/iot/mini2440/linux-3.8.7
[root@localhost linux-3.8.7]# make

Download the new kernel into the S3C2440 board, and boot it up,

Now the kernel is too big, need to increase the kernel partition size, 6M size is not enough, need to increase to 7M, the error when downloading the zImage was as below,


##### FriendlyARM BIOS 2.0 for 2440 ##### [x] format NAND FLASH for Linux [v] Download vivi [k] Download linux kernel [y] Download root_yaffs image [a] Absolute User Application [n] Download Nboot for WinCE [l] Download WinCE boot-logo [w] Download WinCE NK.bin [d] Download & Run [z] Download zImage into RAM [g] Boot linux from RAM [f] Format the nand flash [b] Boot the system [s] Set the boot parameters [u] Backup NAND Flash to HOST through USB(upload) [r] Restore NAND Flash from HOST through USB [q] Goto shell of vivi [i] Version: 1026-2K Enter your selection: k USB host is connected. Waiting a download. Length of file is too big : 6500184 > 6291456 Failed downloading file

Change the partition, increase the kernel partition to 0x00700000

[root@localhost mach-s3c24xx]# pwd
/home/iot/mini2440/linux-3.8.7/arch/arm/mach-s3c24xx
[root@localhost mach-s3c24xx]# vim mach-mini2440.c 

Modify the source code, linux-3.8.7/arch/arm/mach-s3c24xx/mach-mini2440.c

/* NAND Flash on MINI2440 board */

static struct mtd_partition mini2440_default_nand_part[] __initdata = {
        [0] = {
                .name   = "u-boot",
                .size   = SZ_256K,
                .offset = 0,
        },  
        [1] = { 
                .name   = "u-boot-env",
                .size   = SZ_128K,
                .offset = SZ_256K,
        },  
        [2] = { 
                .name   = "kernel",
                /* 5 megabytes, for a kernel with no modules
                 * or a uImage with a ramdisk attached */
                .size   = 0x00700000,
                .offset = SZ_256K + SZ_128K,
        },  
        [3] = { 
                .name   = "root",
                .offset = SZ_256K + SZ_128K + 0x00700000,
                /*.size = MTDPART_SIZ_FULL,*/
                .size   = 0x03200000,
        },  
        [4] = { 
                .name   = "udisk",
                .offset = SZ_256K + SZ_128K + 0x00700000 + 0x03200000,
                .size   = MTDPART_SIZ_FULL,
        },  
};

Recompile the kernel,

[root@localhost mach-s3c24xx]# cd /home/iot/mini2440/linux-3.8.7/
[root@localhost linux-3.8.7]# pwd
/home/iot/mini2440/linux-3.8.7
[root@localhost linux-3.8.7]# 

Since the newly generated zImage is more than 6M, we need to change the setting, using command part add kernel 0x00060000 0x00700000 0, the first number in command is the starting address of kernel stored in the NAND flash. The second number in the command is the number of bytes the bootloader will copy from kernel partition to RAM, it must be greater than the size of the zImage.

The new table is as below,

Name Offset Size
vivi “u-boot” 0x000000000000 0x000000040000
param “u-boot-env” 0x000000040000 0x000000020000
“kernel” 0x000000060000 0x000000700000
“root” 0x000000760000 0x00003fa80000

Refer to this article: Embedded Linux S3C2440 Profiling , use vivi command line to modify the part table, and refer to this article Embedded Linux S3C2440 – Partitions an FileSytem (YAFFS2) to change linux_cmd_line parameter.

##### FriendlyARM BIOS 2.0 for 2440 #####
[x] format NAND FLASH for Linux
[v] Download vivi 
[k] Download linux kernel 
[y] Download root_yaffs image 
[a] Absolute User Application
[n] Download Nboot for WinCE 
[l] Download WinCE boot-logo
[w] Download WinCE NK.bin 
[d] Download & Run 
[z] Download zImage into RAM 
[g] Boot linux from RAM 
[f] Format the nand flash 
[b] Boot the system 
[s] Set the boot parameters 
[u] Backup NAND Flash to HOST through USB(upload) 
[r] Restore NAND Flash from HOST through USB 
[q] Goto shell of vivi 
[i] Version: 1026-2K
Enter your selection: q
Supervivi> part show
Number of partitions: 4
name            :       offset          size            flag
------------------------------------------------------------
vivi            :       0x00000000      0x00040000      0
param           :       0x00040000      0x00020000      0
kernel          :       0x00060000      0x00600000      0
root            :       0x00660000      0x3fa80000      0
Supervivi> part del root  
deleted 'root' partition
Supervivi> part del kernel
deleted 'kernel' partition
Supervivi> part show
Number of partitions: 2
name            :       offset          size            flag
------------------------------------------------------------
vivi            :       0x00000000      0x00040000      0
param           :       0x00040000      0x00020000      0
Supervivi> part add kernel 0x00060000 0x00700000 0
kernel: offset = 0x00060000, size = 0x00700000, flag = 0
Supervivi> part add root 0x00760000 0x3fa80000 0  
root: offset = 0x00760000, size = 0x3fa80000, flag = 0
Supervivi> part show
Number of partitions: 4
name            :       offset          size            flag
------------------------------------------------------------
vivi            :       0x00000000      0x00040000      0
param           :       0x00040000      0x00020000      0
kernel          :       0x00060000      0x00700000      0
root            :       0x00760000      0x3fa80000      0
Supervivi> help part
Usage:
part help
part add <name> <offset> <size> <flag>  -- Add a mtd partition entry
part del <name>                         -- Delete a mtd partition entry
part reset                              -- Reset mtd parition table
part save                               -- Save mtd partition table
part show                               -- Display mtd partition table
Supervivi> part save
Found block size = 0x00020000
Erasing...    ... done
Writing...    ... done
Written 49152 bytes
Supervivi> 

Change the linux command line to noinitrd init=/init console=ttySAC0,115200.

Supervivi> param show
Number of parameters: 9
name                    :          hex             integer
-------------------------------------------------------------
mach_type               :       000007cf                 1999
media_type              :       00000003                    3
boot_mem_base           :       30000000            805306368
baudrate                :       0001c200               115200
xmodem                  :       00000001                    1
xmodem_one_nak          :       00000000                    0
xmodem_initial_timeout  :       000493e0               300000
xmodem_timeout          :       000f4240              1000000
boot_delay              :       01000000             16777216
Linux command line: root=/dev/mtdblock3 console=ttySAC0,115200
Supervivi> help param
Usage:
param help                      -- Help aout 'param' command
param reset                     -- Reset parameter table to default table
param save                      -- Save parameter table to flash memeory
param set <name> <value>        -- Reset value of parameter
param set linux_cmd_line "..."  -- set boot parameter
param show                      -- Display parameter table
Supervivi> param set linux_cmd_line "noinitrd init=/init console=ttySAC0,115200"
Change linux command line to "noinitrd init=/init console=ttySAC0,115200"
Supervivi> param save
Found block size = 0x00020000
Erasing...    ... done
Writing...    ... done
Written 49152 bytes
Saved vivi private data
Supervivi> param show
Number of parameters: 9
name                    :          hex             integer
-------------------------------------------------------------
mach_type               :       000007cf                 1999
media_type              :       00000003                    3
boot_mem_base           :       30000000            805306368
baudrate                :       0001c200               115200
xmodem                  :       00000001                    1
xmodem_one_nak          :       00000000                    0
xmodem_initial_timeout  :       000493e0               300000
xmodem_timeout          :       000f4240              1000000
boot_delay              :       01000000             16777216
Linux command line: noinitrd init=/init console=ttySAC0,115200
Supervivi> 

Now donwload the kernel zImage again, the downloading of the new zImage was successful.

At Host side,

[root@localhost mini2440]# ./download_image.sh 
csum = 0x5f4a
send_file: addr = 0x33f80000, len = 0x00632f58
Error downloading program
[root@localhost mini2440]# 

At board side,

##### FriendlyARM BIOS 2.0 for 2440 #####
[x] format NAND FLASH for Linux
[v] Download vivi 
[k] Download linux kernel 
[y] Download root_yaffs image 
[a] Absolute User Application
[n] Download Nboot for WinCE 
[l] Download WinCE boot-logo
[w] Download WinCE NK.bin 
[d] Download & Run 
[z] Download zImage into RAM 
[g] Boot linux from RAM 
[f] Format the nand flash 
[b] Boot the system 
[s] Set the boot parameters 
[u] Backup NAND Flash to HOST through USB(upload) 
[r] Restore NAND Flash from HOST through USB 
[q] Goto shell of vivi 
[i] Version: 1026-2K
Enter your selection: k
USB host is connected. Waiting a download.

Now, Downloading [ADDRESS:30000000h,TOTAL:6500194]
RECEIVED FILE SIZE: 6500194 (19KB/S, 331S)
Downloaded file at 0x30000000, size = 6500184 bytes
Found block size = 0x00640000
Erasing...    ... done
Writing...    ... done
Written 6500184 bytes

Boot up the S3C2440 board.
Create fat32 filesystem on /dev/mtdblock4.

[root@mini2440 /]# mkfs.vfat /dev/mtdblock4

Connect the USB type B port of the board to the USB tyep A port of the PC.
On the S3C2440 board, load the driver module and use /dev/mtdblock4 as the storage file.

[root@mini2440 /]# modprobe /lib/modules/3.8.7-FriendlyARM/kernel/drivers/usb/gadget/g_mass_storage.ko file=/dev/mtdblock4 stall=0 removable=1
g_mass_storage gadget: Mass Storage Function, version: 2009/09/11
g_mass_storage gadget: Number of LUNs=1
 lun0: LUN: removable file: /dev/mtdblock4
g_mass_storage gadget: Mass Storage Gadget, version: 2009/09/11
g_mass_storage gadget: userspace failed to provide iSerialNumber
g_mass_storage gadget: g_mass_storage ready
g_mass_storage gadget: full-speed config #1: Linux File-Backed Storage
g_mass_storage gadget: full-speed config #1: Linux File-Backed Storage

At host side, the PC will detect the USB device as a File-Backed Storage Gadget.

Below was the message showed on the Fedora by typing command dmesg. Mount the storage and copy the file download_image.sh into the storage.

[root@localhost mini2440]# dmesg
......
[29682.804613] usb 1-3: new full-speed USB device number 12 using ohci_hcd
[29683.266058] usb 1-3: New USB device found, idVendor=0525, idProduct=a4a5
[29683.266062] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[29683.266064] usb 1-3: Product: Mass Storage Gadget
[29683.266067] usb 1-3: Manufacturer: Linux 3.8.7-FriendlyARM with s3c2410_udc
[29683.393339] Initializing USB Mass Storage driver...
[29683.395592] usb-storage 1-3:1.0: Quirks match for vid 0525 pid a4a5: 10000
[29683.395614] scsi3 : usb-storage 1-3:1.0
[29683.397864] usbcore: registered new interface driver usb-storage
[29683.397867] USB Mass Storage support registered.
[29684.438713] scsi 3:0:0:0: Direct-Access     Linux    File-CD Gadget   0308 PQ: 0 ANSI: 2
[29684.442797] sd 3:0:0:0: Attached scsi generic sg2 type 0
[29684.479111] sd 3:0:0:0: [sdb] 406784 512-byte logical blocks: (208 MB/198 MiB)
[29684.487498] sd 3:0:0:0: [sdb] Write Protect is off
[29684.487502] sd 3:0:0:0: [sdb] Mode Sense: 0f 00 00 00
[29684.500274] sd 3:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[29684.577987]  sdb:
[29684.649574] sd 3:0:0:0: [sdb] Attached SCSI removable disk
......
[root@localhost mini2440]# ls /dev/sdb
/dev/sdb
[root@localhost mini2440]# mount /dev/sdb /mnt/
[root@localhost mini2440]# ls
buildroot-2013.02  busybox-1.19.4  config-files  download_image.sh  download_image_yaffs.sh  initramfs.cpio  linux-3.8.7  myapp  ready-built  rootfilesystem  rootfs  s3c2410_boot_usb
[root@localhost mini2440]# cp download_image.sh /mnt
[root@localhost mini2440]# ls /mnt/
download_image.sh  System Volume Information
[root@localhost mini2440]# umount /mnt
[root@localhost mini2440]# 

[root@localhost mini2440]# df -h
Filesystem               Size  Used Avail Use% Mounted on
rootfs                    26G   22G  3.2G  88% /
devtmpfs                 366M     0  366M   0% /dev
tmpfs                    375M   68K  375M   1% /dev/shm
tmpfs                    375M  4.0M  371M   2% /run
tmpfs                    375M     0  375M   0% /sys/fs/cgroup
/dev/mapper/fedora-root   26G   22G  3.2G  88% /
tmpfs                    375M   24K  375M   1% /tmp
/dev/sda1                485M   49M  411M  11% /boot
Linux                    120G  111G  8.8G  93% /media/sf_Linux
/dev/sdb                 196M  2.5K  196M   1% /mnt
[root@localhost mini2440]# 

At S3C2440 board side, remove the module g_mass_storage, and mount the /dev/mtdblock4, it was checked the file download_image.sh after checking on the S3C2440 board.

[root@mini2440 /]# rmmod g_mass_storage
[root@mini2440 /]# mount -t vfat /dev/mtdblock4 /mnt/udisk
[root@mini2440 /]# ls /mnt/udisk
System Volume Information  download_image.sh
[root@mini2440 /]# cat /mnt/udisk/download_image.sh 
#!/bin/sh
./s3c2410_boot_usb linux-3.8.7/arch/arm/boot/zImage

We can also check the USB gadget disk on the Windows system, just connect the host PC windows system, the result is as below.
Detected the S3C2440 – USB Gadget as 195M memory size.
usb gadget 1
Detected the S3C2440 – USB Gadget as and the file download_image.sh is inside.
usb gadget 2

Using the Gadget Serial Driver

The gadget serial driver talks over USB to either a CDC ACM driver or a generic USB serial driver running on a host PC. On the S3C2440 device side Linux system, the gadget serial driver looks like a serial device. On the host-side system, the gadget serial device looks like a CDC ACM compliant class device or a simple vendor specific device with bulk in and bulk out endpoints, and it is treated similarly to other serial devices.

We have generated the gadget serial driver module linux-3.8.7/drivers/usb/gadget/g_serial.ko.

On the S3C2440 side, load the driver module, by default it will be loaded as ACM device as below shows.

[root@mini2440 /root]# modprobe /lib/modules/3.8.7-FriendlyARM/kernel/drivers/usb/gadget/g_serial.ko 
g_serial gadget: Gadget Serial v2.4
g_serial gadget: g_serial ready
g_serial gadget: full-speed config #2: CDC ACM config
gerial gadget: full-speed config #2: CDC ACM config

We find a new device node /dev/ttyGS0 is created.

[root@mini2440 /root]# ls /dev/ttyG*
/dev/ttyGS0
[root@mini2440 /root]# 

And the host PC detects the new device and a new device node /dev/ttyACM0 is created, the dmsg command shows as below,

[root@localhost linux-3.8.7]# dmesg
......
[30844.512119] sd 4:0:0:0: [sdb] Synchronizing SCSI cache
[30844.512143] sd 4:0:0:0: [sdb]  
[30844.512145] Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
[32160.418124] usb 1-3: new full-speed USB device number 14 using ohci_hcd
[32160.888156] usb 1-3: New USB device found, idVendor=0525, idProduct=a4a7
[32160.888161] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[32160.888163] usb 1-3: Product: Gadget Serial v2.4
[32160.888165] usb 1-3: Manufacturer: Linux 3.8.7-FriendlyARM with s3c2410_udc
[32160.944340] cdc_acm 1-3:2.0: This device cannot do calls on its own. It is not a modem.
[32160.944378] cdc_acm 1-3:2.0: ttyACM0: USB ACM device
[32160.960056] usbcore: registered new interface driver cdc_acm
[32160.960059] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

Use lsusb command to show the detail of the device, and send string 2222222222 to the serial device /dev/ttyACM0.

[root@localhost linux-3.8.7]# ls /dev/ttyA*                                                                                                                                                                                                            
/dev/ttyACM0                                                                                                                                                                                                                                 
[root@localhost ~]#
[root@localhost linux-3.8.7]# lsusb
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 008: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 014: ID 0525:a4a7 Netchip Technology, Inc. Linux-USB Serial Gadget (CDC ACM mode)
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

[root@localhost linux-3.8.7]# echo 2222222222 > /dev/ttyACM0


At S3C2440 board side, run cat to read from the serial devcie /dev/ttyGS0, after the host PC sent string 2222222222, the target S3C2440 received the same string 2222222222 right away.

[root@mini2440 /root]# cat /dev/ttyGS0
2222222222

Reference

Embedded Linux S3C2440 environment setup
Embedded Linux S3C2440 Environment Startup
Embedded Linux S3C2440 Build and Boot an Image
Embedded Linux S3C2440 Application Development and Debugging
Embedded Linux S3C2440 Networking
Embedded Linux S3C2440 – Kernel Module
Embedded Linux S3C2440 – Kernel Debugging
Embedded Linux S3C2440 – Multi-thread Scheduling
Embedded Linux S3C2440 Profiling
Embedded Linux S3C2440 – QEMU and Graphic
Embedded Linux S3C2440 – Partitions an FileSytem (YAFFS2)
Host controller interface (USB, Firewire) Wiki
mini2440 usb设备支持
mini2440的U盘挂载
Kconfig – Tips and Best Practices
S3C24XX USB Host support

Write a Comment

Comment