20130513

请教:tiny210 linux,尝试s3c-udc与gadgetfs一起使用,失败

请教各位专家。
- 问题:tiny210 linux,尝试s3c-udc与gadgetfs一起使用,失败。
- 错误现象:
1.把usb.c(gadgetfs官方测试程序,我修改过)编译为可执行程序 usb。执行usb时,到向文
件描述符write后死机.
我对usb.c的修改,是为了使之识别 s3c-ucd。按s3c-hsudc.c注释,
   The S3C24XX USB 2.0 high-speed USB controller supports upto 9 endpoints.
   Each endpoint can be configured as either in or out endpoint. Endpoints
   can be configured for Bulk or Interrupt transfer mode.
我试着进行了几种配置,均导致死机。


2. 执行前usb运行前,执行了下述操作,控制台均无报错。
mkdir /dev/gadget
insmod gadgetfs.ko
mount -t gadgetfs none /dev/gadget
此时,
[root@FriendlyARM plg]# ls /dev/gadget
ls /dev/gadget
s3c-udc

3. dmesg的出错信息:
[  299.539226] gadgetfs: USB Gadget filesystem, version 24 Aug 2004
[  353.895836] s3c-udc: bind to driver nop --> error -120
其中第二行是mount操作后出现的。
我猜测,usb.c死机的原因在这里,即gadgetfs加载失败。
请教原因何在?

- 操作系统:
[root@FriendlyARM plg]# uname -a
uname -a
Linux FriendlyARM 3.0.8-FriendlyARM #9 PREEMPT Tue May 7 22:56:46 CST 2013 armv7l GNU/Linux

- 内核配置:
  │ │      --- USB Gadget Support                                                       │ │  
  │ │      [*]   Debugging messages (DEVELOPMENT)                                       │ │  
  │ │      [*]   Debugging information files (DEVELOPMENT)                              │ │  
  │ │      (500) Maximum VBUS Power usage (2-500 mA)                                    │ │  
  │ │            USB Peripheral Controller (S3C HS USB OTG Device)  --->                │ │  
  │ │            *** NOTE: S3C OTG device role enables the controller driver below ***  │ │  
  │ │      <*>   S3C high speed(2.0, dual-speed) USB OTG device (NEW)                   │ │  
  │ │              S3C OTGD transfer mode (enabled DMA MODE)  --->                      │ │  
  │ │      <M>   USB Gadget Drivers                                                     │ │  
  │ │      <M>     Gadget Zero (DEVELOPMENT)                                            │ │  
  │ │      < >     Audio Gadget (EXPERIMENTAL)                                          │ │  
  │ │      < >     Ethernet Gadget (with CDC Ethernet support)                          │ │  
  │ │      < >     Network Control Model (NCM) support                                  │ │  
  │ │      <M>     Gadget Filesystem (EXPERIMENTAL)                                     │ │  
  │ │      < >     Function Filesystem (EXPERIMENTAL)                                   │ │  
  │ │      < >     File-backed Storage Gadget                                           │ │  
  │ │      <M>     Mass Storage Gadget                                                  │ │  
  │ │      <M>     Serial Gadget (with CDC ACM and CDC OBEX support)                    │ │  
  │ │      < >     MIDI Gadget (EXPERIMENTAL)                                           │ │  
  │ │      < >     Printer Gadget                                                       │ │  
  │ │      < >     CDC Composite Device (Ethernet and ACM)                              │ │  
  │ │      < >     Nokia composite gadget                                               │ │  
  │ │      < >     Multifunction Composite Gadget (EXPERIMENTAL)                        │ │  
  │ │      < >     HID Gadget                                                           │ │  
  │ │      < >     EHCI Debug Device Gadget                                             │ │  
  │ │      < >     USB Webcam Gadget                                                    │ │ 

- 其他信息:
1. g_serial.ko与s3c-udc配合,可以与PC的HOST端通信;
我的理解,这表明 tiny210的ucd 确实是 s3c-udc.

2. gadgetfs.ko载入内核(with dummy_hcd + usb.c),dmesg无错误信息。
我的理解,这表明gadgetfs.ko与dummy_hcd可以配合工作。

# lsusb -v
lsusb -v

Bus 3 Device 7 ID 0525a4a4 Netchip Technology, Inc. Linux-USB user-mode bulk source/sink
Device Descriptor
   bLength                18
   bDescriptorType         1
   bcdUSB               2.00
   bDeviceClass          255 Vendor Specific Class
   bDeviceSubClass         0 
   bDeviceProtocol         0 
   bMaxPacketSize0        64
   idVendor           0x0525 Netchip Technology, Inc.
   idProduct          0xa4a4 Linux-USB user-mode bulk source/sink
   bcdDevice            1.00
   iManufacturer           1 Licensed to Code, LLC
   iProduct                2 My Source/Sink Product
   iSerial                 3 1.3
   bNumConfigurations      1
   Configuration Descriptor
     bLength                 9
     bDescriptorType         2
     wTotalLength           39
     bNumInterfaces          1
     bConfigurationValue     3
     iConfiguration          4 The Configuration
     bmAttributes         0xc0
       Self Powered
     MaxPower                2mA
     Interface Descriptor
       bLength                 9
       bDescriptorType         4
       bInterfaceNumber        0
       bAlternateSetting       0
       bNumEndpoints           3
       bInterfaceClass       255 Vendor Specific Class
       bInterfaceSubClass      0 
       bInterfaceProtocol      0 
       iInterface              5 Source/Sink
       Endpoint Descriptor
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x87  EP 7 IN
         bmAttributes            2
           Transfer Type            Bulk
           Synch Type               None
           Usage Type               Data
         wMaxPacketSize     0x0200  1x 512 bytes
         bInterval               0
       Endpoint Descriptor
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x03  EP 3 OUT
         bmAttributes            2
           Transfer Type            Bulk
           Synch Type               None
           Usage Type               Data
         wMaxPacketSize     0x0200  1x 512 bytes
         bInterval               1
       Endpoint Descriptor
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x8b  EP 11 IN
         bmAttributes            3
           Transfer Type            Interrupt
           Synch Type               None
           Usage Type               Data
         wMaxPacketSize     0x0008  1x 8 bytes
         bInterval               6
Device Qualifier (for other device speed)
   bLength                10
   bDescriptorType         6
   bcdUSB               2.00
   bDeviceClass          255 Vendor Specific Class
   bDeviceSubClass         0 
   bDeviceProtocol         0 
   bMaxPacketSize0        64
   bNumConfigurations      1
Device Status     0x0000
   (Bus Powered)

Bus 3 Device 1 ID 1d6b0002 Linux Foundation 2.0 root hub
Device Descriptor
   bLength                18
   bDescriptorType         1
   bcdUSB               2.00
   bDeviceClass            9 Hub
   bDeviceSubClass         0 Unused
   bDeviceProtocol         1 Single TT
   bMaxPacketSize0        64
   idVendor           0x1d6b Linux Foundation
   idProduct          0x0002 2.0 root hub
   bcdDevice            3.00
   iManufacturer           3 Linux 3.0.8-FriendlyARM dummy_hcd
   iProduct                2 Dummy host controller
   iSerial                 1 dummy_hcd
   bNumConfigurations      1
   Configuration Descriptor
     bLength                 9
     bDescriptorType         2
     wTotalLength           25
     bNumInterfaces          1
     bConfigurationValue     1
     iConfiguration          0 
     bmAttributes         0xe0
       Self Powered
       Remote Wakeup
     MaxPower                0mA
     Interface Descriptor
       bLength                 9
       bDescriptorType         4
       bInterfaceNumber        0
       bAlternateSetting       0
       bNumEndpoints           1
       bInterfaceClass         9 Hub
       bInterfaceSubClass      0 Unused
       bInterfaceProtocol      0 Full speed (or root) hub
       iInterface              0 
       Endpoint Descriptor
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x81  EP 1 IN
         bmAttributes            3
           Transfer Type            Interrupt
           Synch Type               None
           Usage Type               Data
         wMaxPacketSize     0x0004  1x 4 bytes
         bInterval              12
Hub Descriptor
   bLength               9
   bDescriptorType      41
   nNbrPorts             1
   wHubCharacteristic 0x0001
     Per-port power switching
     Ganged overcurrent protection
     TT think time 8 FS bits
   bPwrOn2PwrGood        0 * 2 milli seconds
   bHubContrCurrent      0 milli Ampere
   DeviceRemovable    0xff
   PortPwrCtrlMask    0xff
  Hub Port Status
    Port 1 0000.0503 highspeed power enable connect
Device Status     0x0003
   Self Powered
   Remote Wakeup Enabled

Bus 2 Device 1 ID 1d6b0001 Linux Foundation 1.1 root hub
Device Descriptor
   bLength                18
   bDescriptorType         1
   bcdUSB               1.10
   bDeviceClass            9 Hub
   bDeviceSubClass         0 Unused
   bDeviceProtocol         0 Full speed (or root) hub
   bMaxPacketSize0        64
   idVendor           0x1d6b Linux Foundation
   idProduct          0x0001 1.1 root hub
   bcdDevice            3.00
   iManufacturer           3 Linux 3.0.8-FriendlyARM ohci_hcd
   iProduct                2 EXYNOS OHCI Host Controller
   iSerial                 1 s5p-ohci
   bNumConfigurations      1
   Configuration Descriptor
     bLength                 9
     bDescriptorType         2
     wTotalLength           25
     bNumInterfaces          1
     bConfigurationValue     1
     iConfiguration          0 
     bmAttributes         0xe0
       Self Powered
       Remote Wakeup
     MaxPower                0mA
     Interface Descriptor
       bLength                 9
       bDescriptorType         4
       bInterfaceNumber        0
       bAlternateSetting       0
       bNumEndpoints           1
       bInterfaceClass         9 Hub
       bInterfaceSubClass      0 Unused
       bInterfaceProtocol      0 Full speed (or root) hub
       iInterface              0 
       Endpoint Descriptor
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x81  EP 1 IN
         bmAttributes            3
           Transfer Type            Interrupt
           Synch Type               None
           Usage Type               Data
         wMaxPacketSize     0x0002  1x 2 bytes
         bInterval             255
Hub Descriptor
   bLength               9
   bDescriptorType      41
   nNbrPorts             1
   wHubCharacteristic 0x0002
     No power switching (usb 1.0)
     Ganged overcurrent protection
   bPwrOn2PwrGood        2 * 2 milli seconds
   bHubContrCurrent      0 milli Ampere
   DeviceRemovable    0x00
   PortPwrCtrlMask    0xff
  Hub Port Status
    Port 1 0000.0100 power
Device Status     0x0003
   Self Powered
   Remote Wakeup Enabled

Bus 1 Device 1 ID 1d6b0002 Linux Foundation 2.0 root hub
Device Descriptor
   bLength                18
   bDescriptorType         1
   bcdUSB               2.00
   bDeviceClass            9 Hub
   bDeviceSubClass         0 Unused
   bDeviceProtocol         0 Full speed (or root) hub
   bMaxPacketSize0        64
   idVendor           0x1d6b Linux Foundation
   idProduct          0x0002 2.0 root hub
   bcdDevice            3.00
   iManufacturer           3 Linux 3.0.8-FriendlyARM ehci_hcd
   iProduct                2 S5P EHCI Host Controller
   iSerial                 1 s5p-ehci
   bNumConfigurations      1
   Configuration Descriptor
     bLength                 9
     bDescriptorType         2
     wTotalLength           25
     bNumInterfaces          1
     bConfigurationValue     1
     iConfiguration          0 
     bmAttributes         0xe0
       Self Powered
       Remote Wakeup
     MaxPower                0mA
     Interface Descriptor
       bLength                 9
       bDescriptorType         4
       bInterfaceNumber        0
       bAlternateSetting       0
       bNumEndpoints           1
       bInterfaceClass         9 Hub
       bInterfaceSubClass      0 Unused
       bInterfaceProtocol      0 Full speed (or root) hub
       iInterface              0 
       Endpoint Descriptor
         bLength                 7
         bDescriptorType         5
         bEndpointAddress     0x81  EP 1 IN
         bmAttributes            3
           Transfer Type            Interrupt
           Synch Type               None
           Usage Type               Data
         wMaxPacketSize     0x0004  1x 4 bytes
         bInterval              12
Hub Descriptor
   bLength               9
   bDescriptorType      41
   nNbrPorts             1
   wHubCharacteristic 0x0009
     Per-port power switching
     Per-port overcurrent protection
   bPwrOn2PwrGood       10 * 2 milli seconds
   bHubContrCurrent      0 milli Ampere
   DeviceRemovable    0x00
   PortPwrCtrlMask    0xff
  Hub Port Status
    Port 1 0000.0100 power
Device Status     0x0003
   Self Powered
   Remote Wakeup Enabled
[root@FriendlyARM plg]# 

3. g_zero.ko载入内核,dmesg无错误信息,如下:
[  495.979552] zero gadget: adding config #3 'source/sink'/bf1fad28
[  495.979569] zero gadget: adding 'source/sink'/d9c30080 to config 'source/sink'/bf1fad28
[  495.979586] zero gadget: dual speed source/sink: IN/ep2-bulk, OUT/ep1-bulk
[  495.979596] zero gadget: cfg 3/bf1fad28 speeds: high full
[  495.979605] zero gadget:   interface 0 = source/sink/d9c30080
[  495.979615] zero gadget: adding config #2 'loopback'/bf1fada8
[  495.979625] zero gadget: adding 'loopback'/d9c30880 to config 'loopback'/bf1fada8
[  495.979637] zero gadget: dual speed loopback: IN/ep2-bulk, OUT/ep1-bulk
[  495.979646] zero gadget: cfg 2/bf1fada8 speeds: high full
[  495.979655] zero gadget:   interface 0 = loopback/d9c30880
[  495.979664] zero gadget: Gadget Zero, version: Cinco de Mayo 2008
[  495.979724] zero gadget: zero ready
[  495.998990] Registered gadget driver 'zero'
4. usb.c我修改的那一段,某个版本如下:

/* s3c-udc, high speed. by Young */

} else if 
                (stat (DEVNAME = "s3c-udc", &statb) == 0) {
HIGHSPEED = 1;
device_desc.bcdDevice = __constant_cpu_to_le16 (0x0100);
                fs_source_desc.bEndpointAddress
                    = hs_source_desc.bEndpointAddress
                    = USB_DIR_IN | 2;
EP_IN_NAME = "ep2-bulk";
                fs_sink_desc.bEndpointAddress
                    = hs_sink_desc.bEndpointAddress
                    =USB_DIR_OUT | 1;
EP_OUT_NAME = "ep1-bulk";


source_sink_intf.bNumEndpoints = 3;
                fs_status_desc.bEndpointAddress
                    = hs_status_desc.bEndpointAddress
                    = USB_DIR_IN | 3;
EP_STATUS_NAME = "ep3-int";
}

20130501

少年派 vs. 哈尔罗杰

少年派 vs. 哈尔罗杰

今天,看完了哈尔罗杰历险记,十四册。这是很多八零九零后小朋友小时候的读物,不少人盛赞过,陪伴过他们的童年。

哈尔和罗杰是两兄弟,大的十九岁,小的十三四岁。都身强力壮,在历险记里的主要职业是替他们的爸抓各种动物--活捉,然后卖给动物园。这些动物包括,虎、狮子、象、各种灵长类、爬行类、鲨鱼、鲸。凡是能想起来的凶猛的,全抓了。我一度非常奇怪,这些看哈尔罗杰长大的八零九零后们,怎么就会出了那么多环境保护的,比如不用方便筷子,不吃狗肉,不穿动物皮毛的,没有买卖就没有杀害的。看了大半历险记的时候,我开始逐渐明白了。

原因之一是,八零九零后们看哈尔罗杰的可能不算太多。

原因之二是,时代不同了。前两天我听高晓松的青春无悔,月亮,白衣飘飘的年代,什么的,听得我心旷神怡的。然后我就跑到DOUBAN上去搜,看看别人都啥看法。赫然看到一贴评论,原文忘记了,大体意思是 "那个直男横行的时代"。高的歌里也充满了各种文艺的意像,当然也噫噫呀呀了。不过,按二猫妈的说法,歌曲里主要是积极向上和励志的。白衣,充满了向往和留恋,月亮,大气滂薄,风雨欲来。这两首歌,据说都是纪念诗人海子的。诗人海子并非战士,所以他 (不知道为什么)自杀了。不过,那个年代的人选择的是决绝的抗争,死也好,怎么也好。现在的人们,不少会选择哭喊,没人听的话,就哭喊为什么没有人听。

哭喊这种事,少年派也干过。少年派,就是李安导演的那个印度少年。不管是老虎还是lie狗要咬他,还是天上下雨海里浪大,他都叫喊,为什么啊,为什么,或者在猩猩一巴掌把lie狗打趴下的时候大喊,好哎,加油啊。

我看片子的时候,一直在给他出主意,"应该往狗嘴里捅,别来回扫,那样没劲","傻啊,那是老虎,跳啊"。就跟少年派一直在跟上帝商量讨论一样,他也不理我。不过,我在这喊是秉承"大喊大叫是看电影的一部分"这样一个低俗原则,少年派一个劲地想跟上帝对话,是遵循哪条精神病法则呢?果然,上帝一次也没有理过他。大暴雨以后出了太阳,少年派顶礼膜拜那次,并非上帝答理他了,他自作多情而已。他应该学学中国古文,"天地不仁 以万物为刍狗"。

如果光看李安,会以为西方普遍是这种调调,打算靠臣服跟上帝结盟缔约的呢。看了哈尔罗杰以后,我们会了解到,李安只是西方一个流派而已。还存在像哈尔罗杰这样,活捉动物,打算开发亚马逊森林的人们。想想 lengends of the fall,就会知道,还有那种跟上帝绝不合解,最后上帝妥协,或者干脆战死的。此外,李安在西方人眼中,十有八九是个东方人。而此"东方",值得注意,在西方语境中,一般并不指中国及东亚,而是指印度,有时候还包括土耳基伊朗一带。特意提到这点,是希望小资们对西方人讨论李安时提到的"东方"二字不要太自恋,Raj说,这是一部分非常印度的片子。

每当我上面提到"李安"二字,总想说"安"。网上有故事说,说李安当年靠老婆为生,快放弃的时候,他老婆说"安,不要忘记你的理想。"我对他们夫妻俩的对话非常震惊。这段加了引话,在很多中语言里称为直接引语的话里,他老婆称他为"安"而不是"李安"。这是非常有毛病的称呼方法。欧美人才这样称呼别人的名字,不带姓吧,比如简,比如静云 (不是静香,静云全称柳生静云),比如安。中国人似乎只对名字三个字的,才能去掉名字称呼,比如贵福。

直接引语现在越来越多地被记者篡改其中的名词,民工大哥经常使用大学教授才知道的术语,没想到李安或者报道李安的家伙也这么不老实。这让我对他们及他们所报道的电影中引用的上帝说的话也产生了怀疑。上帝可能一声没吱,他们吱吱了半天。

哈尔罗杰在遭遇各种动物袭击时,都没有想到那是大自然或者动物们报复,在吃各种动物的肉时都没有过心存内疚。如果他们像少年派那么吱吱歪歪,估计死多少回了。少年派在海上漂流中的种种,让我想起另一个家伙,作为参照。有个叫 wild 的片子。那里面有个小子,想去阿拉斯加或者类似的地方,远离都市--是不是有小资的汗毛立起来了?他放弃学业攒了些钱买装备,然后去图书馆看了本书,自认为学会了腌肉,然后就去了荒野。爽了半个夏天以后,这家伙遇到个问题就是吃的不够了。好不容易打到一头牛,腌肉的时候因为动作不够快,苍蝇在上面产了卵,失败了,后来他就饿死了。

我看到腌肉的时候忍不住大喊,傻啊,不能把整头牛全腌了的话,腌一半也行啊,腌三五斤也行啊。看了书以后事先没有演练一下要花多少时间么,一头牛需要多少盐,算过没有,试过没有,有脑子没有。

这位兄弟一边赶苍蝇,一边哭 (我记得),一边跟上帝讨论命运为什么如何残忍(我记得)。

对少年派和上面这位兄弟,我想请他们对着哈尔罗杰照照镜子。想对他们说一句,你们对生活哪那么多态度,哪那么多感受哩?谁TM希望关心你们的感受啊。

前一阵子流行弃学辞职走遍哪哪的风,同学们纷纷打算见识一下真实的世界。一位青年旅舍的老板对此吐糟了一段。他说,不少小年轻的,胳膊腿都全乎的,对他说,老板,你看这是我打算走遍中国/世界的计划,已经走过哪哪和哪哪了。老板说,好。然后小年轻的说,住宿费能便宜点么。老板吐的就是这个槽,他说:你乐意走遍哪走遍哪,为什么我应该给你减住宿费呢,你的理想跟我有个P关系。你如果没钱,我可能给你提供打工的机会,挣了钱付住宿费。

直男时代以后,大家都比较乐意叫喊,期待这个世界 (除了他本人以外的其他部分)倾听和乐于倾听他的声音。这个世界如果很忙没工夫听的话,他们就希望上帝能够倾听一下。其实,上帝和这个世界一样都没空。换句话说,这个世界也有很多想发言的,你拿出一秒钟听一下了没?啥都没听,你就敢断言这个世界需要以你的方式拯救,你就去拦运狗的大货车,去当志愿者,去指责别人没有"爱心"啦。

罗素指责他那个时代的教育时提到,有些人认为教育应该有专门给贵族的,教育如何享受生活,另一些教育是专门给非贵族的,教育如何饲候贵族们。少年派与哈尔罗杰的分野,不在对生活有多小资上,而在于,有些人认为自己是不必创造价值,只要感受这个世界就可以了。他们应该去搬砖头扛麻袋,去和真正的自然和谐相处那么一段时间,然后再来讨论这个世界应该如何。

我想起了小资们怀念一个时代抨击另一个时代的一些文章,其中提到,那些了不起的知识分子以及他们的孩子被下放到农村,过的日子有多么惨淡,天理如何不公平。我每读到这些的时候就特别想问他们,那些出生在他们下凡的地方的农村孩子,天理有多么公平。如果说知识分子由于社会分工能够远离生产,那他们的孩子哪个细胞长得与众不同了?

小资们是不是真地信奉"人生而平等"?所以,每个人都应该像哈尔罗杰一样与自然斗争,争得人类包括其他人类生存的权利。所以,有时候我恶意地想,少年派们就应该扔到海里去,而且不必每次都那么幸运,还给他们机会YY与神相处过。

--------------------

博客会手工同步到以下地址: