下面是我在mini2440上使用USB Gadget功能的过程。我将USB Gadget的各个功能编译成内核模块,目前只尝试了g_serial和g_ether功能,有兴趣的兄弟可以试试其余的,别忘了告诉大家结果:)
就像powerpan在帖子
http://www.aiothome.com/bbs/read.php?tid-1683.html里提到的,2.6.29内核对于内核模块的处理存在bug,要使用内核模块,必须先给内核打上
这个补丁,重新编译内核zImage下载到板子中运行。
这是我编译的所有的Gadget模块
[root@FriendlyARM /]# ls -l /lib/modules/2.6.29-FriendlyARM/kernel/drivers/usb/gadget/
-rw-r--r-- 1 root root 40404 May 4 2009 g_cdc.ko
-rw-r--r-- 1 root root 40331 May 4 2009 g_ether.ko
-rw-r--r-- 1 root root 34559 May 4 2009 g_file_storage.ko
-rw-r--r-- 1 root root 34116 May 4 2009 g_serial.ko
-rw-r--r-- 1 root root 23541 May 4 2009 s3c2410_udc.ko
A. 加载S3C2440A的USB Device (s3c2410_udc.ko)模块:
[root@FriendlyARM /]# modprobe s3c2410_udc
s3c2410_udc: debugfs dir creation failed -19
s3c2440-usbgadget s3c2440-usbgadget: S3C2440: increasing FIFO to 128 bytes
[root@FriendlyARM /]#
[root@FriendlyARM /]#
[root@FriendlyARM /]# lsmod
s3c2410_udc 20360 0 - Live 0xbf000000
B. 加载g_serial (g_serial.ko, 在mini2440上模拟出一个USB串口):
[root@FriendlyARM /]# modprobe g_serial
g_serial gadget: Gadget Serial v2.4
g_serial gadget: g_serial ready
[root@FriendlyARM /]#
[root@FriendlyARM /]# lsmod
g_serial 22056 0 - Live 0xbf00a000
s3c2410_udc 20360 1 g_serial, Live 0xbf000000
[root@FriendlyARM /]#
[root@FriendlyARM /]#
[root@FriendlyARM /]# g_serial gadget: full speed config #2: CDC ACM config
这是在我的PC Ubuntu 9.04上lsusb的输出
Bus 002 Device 006: ID 0525:a4a7 Netchip Technology, Inc. Linux-USB Serial Gadget (CDC ACM mode)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 2 Communications
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0525 Netchip Technology, Inc.
idProduct 0xa4a7 Linux-USB Serial Gadget (CDC ACM mode)
bcdDevice 24.12
iManufacturer 1
iProduct 2
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 67
bNumInterfaces 2
bConfigurationValue 2
iConfiguration 3
bmAttributes 0xc0
Self Powered
MaxPower 2mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 2 Communications
bInterfaceSubClass 2 Abstract (modem)
bInterfaceProtocol 1 AT-commands (v.25ter)
iInterface 4
CDC Header:
bcdCDC 1.10
CDC Call Management:
bmCapabilities 0x00
bDataInterface 1
CDC ACM:
bmCapabilities 0x02
line coding and serial state
CDC Union:
bMasterInterface 0
bSlaveInterface 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x000a 1x 10 bytes
bInterval 32
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 10 CDC Data
bInterfaceSubClass 0 Unused
bInterfaceProtocol 0
iInterface 5
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
can't get device qualifier: Operation not permitted
can't get debug descriptor: Operation not permitted
cannot read device status, Operation not permitted (1)
PC端对应生成的设备是/dev/ttyACM0
C. 加载e_ether模块(g_ether.ko, 由于Gadget功能一次只能加载一个,所以先卸载g_serial)
[root@FriendlyARM /]# rmmod g_serial
[root@FriendlyARM /]# modprobe g_ether
s3c2410_udc: debugfs dir creation failed -19
s3c2440-usbgadget s3c2440-usbgadget: S3C2440: increasing FIFO to 128 bytes
g_ether gadget: using random self ethernet address
g_ether gadget: using random host ethernet address
usb0: MAC 16:1a:1d:a8:3f:97
usb0: HOST MAC e6:62:d2:0d:be:18
g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
g_ether gadget: g_ether ready
[root@FriendlyARM /]#
[root@FriendlyARM /]#
[root@FriendlyARM /]#
[root@FriendlyARM /]#
[root@FriendlyARM /]#
[root@FriendlyARM /]# g_ether gadget: full speed config #1: CDC Ethernet (ECM)
[root@FriendlyARM /]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 08:90:90:90:90:90
inet addr:192.168.1.230 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:201 errors:0 dropped:0 overruns:0 frame:0
TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25151 (24.5 KiB) TX bytes:2140 (2.0 KiB)
Interrupt:51
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:370 (370.0 B) TX bytes:370 (370.0 B)
usb0 Link encap:Ethernet HWaddr 16:1A:1D:A8:3F:97
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
[root@FriendlyARM /]# ifconfig usb0 192.168.0.202
[root@FriendlyARM /]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 08:90:90:90:90:90
inet addr:192.168.1.230 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:202 errors:0 dropped:0 overruns:0 frame:0
TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25215 (24.6 KiB) TX bytes:2182 (2.1 KiB)
Interrupt:51
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:370 (370.0 B) TX bytes:370 (370.0 B)
usb0 Link encap:Ethernet HWaddr 16:1A:1D:A8:3F:97
inet addr:192.168.0.202 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
对应的PC端也将生成usb0以太网卡,将其IP地址配置为192.168.0.200(我之前已经通过脚本配置,大家可以用ifconfig命令手动配置), 通过ftp功能验证可以连接开发板
alex@alex-desktop:~$ ifconfig -a
eth6 Link encap:Ethernet HWaddr 00:0c:29:6c:73:0e
inet addr:192.168.247.129 Bcast:192.168.247.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe6c:730e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:54558 errors:0 dropped:0 overruns:0 frame:0
TX packets:105673 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3362020 (3.3 MB) TX bytes:12912584 (12.9 MB)
Interrupt:19 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:74 errors:0 dropped:0 overruns:0 frame:0
TX packets:74 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5616 (5.6 KB) TX bytes:5616 (5.6 KB)
pan0 Link encap:Ethernet HWaddr 0a:d4:ab:6d:db:f3
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
usb0 Link encap:Ethernet HWaddr e6:62:d2:0d:be:18
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
alex@alex-desktop:~$ sudo ifup usb0
[sudo] password for alex:
WARNING: All config files need .conf: /etc/modprobe.d/lrm-video, it will be ignored in a future release.
WARNING: All config files need .conf: /etc/modprobe.d/ipw3945, it will be ignored in a future release.
WARNING: All config files need .conf: /etc/modprobe.d/nvidia-kernel-nkc, it will be ignored in a future release.
WARNING: All config files need .conf: /etc/modprobe.d/vmware-tools, it will be ignored in a future release.
WARNING: All config files need .conf: /etc/modprobe.d/kqemu, it will be ignored in a future release.
* if-up.d/mountnfs[usb0]: waiting for interface eth0 before doing NFS mounts
* if-up.d/mountnfs[usb0]: waiting for interface ath0 before doing NFS mounts
* if-up.d/mountnfs[usb0]: waiting for interface wlan0 before doing NFS mounts
* Stopping NTP server ntpd
alex@alex-desktop:~$ ...done.
alex@alex-desktop:~$
alex@alex-desktop:~$ ifconfig -a
eth6 Link encap:Ethernet HWaddr 00:0c:29:6c:73:0e
inet addr:192.168.247.129 Bcast:192.168.247.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe6c:730e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:54636 errors:0 dropped:0 overruns:0 frame:0
TX packets:105745 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3369316 (3.3 MB) TX bytes:12922223 (12.9 MB)
Interrupt:19 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:74 errors:0 dropped:0 overruns:0 frame:0
TX packets:74 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5616 (5.6 KB) TX bytes:5616 (5.6 KB)
pan0 Link encap:Ethernet HWaddr 0a:d4:ab:6d:db:f3
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
usb0 Link encap:Ethernet HWaddr e6:62:d2:0d:be:18
inet addr:192.168.0.200 Bcast:192.168.0.207 Mask:255.255.255.240
inet6 addr: fe80::e462:d2ff:fe0d:be18/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:21 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:3245 (3.2 KB)
alex@alex-desktop:~$ ping 192.168.0.202
PING 192.168.0.202 (192.168.0.202) 56(84) bytes of data.
64 bytes from 192.168.0.202: icmp_seq=1 ttl=64 time=43.4 ms
64 bytes from 192.168.0.202: icmp_seq=2 ttl=64 time=6.68 ms
64 bytes from 192.168.0.202: icmp_seq=3 ttl=64 time=6.62 ms
^C
--- 192.168.0.202 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2006ms
rtt min/avg/max/mdev = 6.626/18.932/43.492/17.366 ms
alex@alex-desktop:~$
alex@alex-desktop:~$
alex@alex-desktop:~$ ftp 192.168.0.202
Connected to 192.168.0.202.
220 FriendlyARM FTP server (Version 6.4/OpenBSD/Linux-ftpd-0.17) ready.
Name (192.168.0.202:alex):
331 Password required for alex.
Password:
530 Login incorrect.
Login failed.
ftp>
这里是我编译的所有模块,使用时可解压到开发板文件系统的/lib目录下,Gadget模块位于/lib/modules/2.6.29-FriendlyARM/kernel/drivers/usb/gadget目录下。