Showing posts with label usb. Show all posts
Showing posts with label usb. Show all posts

Apr 28, 2008

S3C2440, USB in Linux

他媽的USB似乎根本就沒啟動

帥哥的測試:
GPH10 控制小 port:0 是打開 1 是關掉
GPH8 控制大 port: 1 是打開 0 是關掉

送電之後就可以用了...他媽的白費兩個禮拜

05/23 :
之前請正哥寄信去要電路圖都不屌我們

COLOR 打電話去就要到了

更正
GPH8 : USB_HOST_EN

GPH10 : nUSB_PULL_UP_EN

USB_HOST_EN 控制 USB_H_5V --> USB HOST PORT 的供電 (大PORT)

nUSB_PULL_UP_EN 控制 USB_C_D+ --> MINI USB 的供電 (小PORT)

ASUS WL-167G (USB WLAN Adapter) For ARM Linux

UPDATE : 學弟搞定了
usb host timeout的原因是....usb controller過熱被保護電路關電.......

林老師卡好勒


=============================================================
great~ it offers linux driver~

copy the directory Linux/rt73 in the Driver CDROM    ( remember to chmod +w )

follow the README in Linux/rt73/module/
if you got error "undefined get_wireless_stats"

just fix rtmp_main.c, replace  netdev->get_wireless_stats to netdev->get_stats

=======================================

編譯module


網路上有非官方driver : rt2x00 project

每天最新版本

或是直接用CVS更新
cvs -d:pserver:anonymous@rt2400.cvs.sourceforge.net:/cvsroot/rt2400 login

cvs -z3 -d:pserver:anonymous@rt2400.cvs.sourceforge.net:/cvsroot/rt2400 co -P source/rt73

修改Makefile

最前面增加五行

ARCH=arm

CROSS_COMPILE=/usr/local/arm/3.4.1/bin/arm-linux-

KERNDIR=/home2/fyodor/kernel/linux-2.6.25__from__2.6.24.3

(KERNDIR要指到目標板所使用的KERNEL SOURCE,而且KERNEL必須先設定好交叉編譯)

ROOTFS = /home2/fyodor/filesystem/rootfs

MODDIR = /lib/modules/2.6.24.3/extra

把module install 的目標位置依照目標kernel版本設定

否則就會安裝到目前uname -r 所找到的kernel module位置...

ps. make install時,modules.dep的設定不會跟著MODDIR而改變

所以還是得設定成extra

修改一行
FIRM_DIR :=    $(ROOTFS)/lib/firmware

編譯

(host)# make armdebug

警告訊息

!!! WARNING: Module file much too big (>1MB)
!!! Check your kernel settings or use 'strip'
*** Module rt73.ko built successfully

表示編出來的module太大了,這個好解決

必須削減(strip)多餘訊息 (strip之後,板子上無法modprobe!format不合)
(host)# arm-linux-strip ./rt73.ko

把module安裝到target rootfs


這一步,我不很確定怎麼做,試看看吧~

(host)# sudo make install
*** Install module in /lib/modules/2.6.24.3/extra ...
make[1]: Entering directory `/home2/fyodor/kernel/linux-2.6.25__from__2.6.24.3'
INSTALL /home2/fyodor/filesystem/tools/wirelessTool/WL-167G/rt73-cvs/rt73-cvs-2008042100/Module/rt73.ko
DEPMOD  2.6.24.3
make[1]: Leaving directory `/home2/fyodor/kernel/linux-2.6.25__from__2.6.24.3'
/sbin/depmod -a
*** Update /etc/modprobe.d/ralink alias for wlan*
*** Install firmware in /home2/fyodor/filesystem/rootfs/lib/firmware ...
*** Check old config ...

警告訊息

WARNING: Couldn't find symtab and strtab in module /lib/modules/2.6.20-15-generic/extra/rt73.ko
*** Update /etc/modprobe.d/ralink alias for wlan*
*** Install firmware in /home2/fyodor/filesystem/rootfs/lib/firmware ...
*** Check old config ...

因為這一個編譯所使用的kernel版本2.6.24.3,和host機器上目前使用的版本2.6.15不同導致這個錯誤不知道怎麼處理... 應該是沒關係因為真正運作時,這個module在板子上所配合的kernel 版本就對上了參考: http://www.linuxsir.org/bbs/thread307321.html
結束

一樣照著路徑複製到rootfs裡面
module : /lib/modules/2.6.24.3/extra/rt73.ko

firmware : /lib/firmware/rt73.bin

status code :

s3c2410-ohci s3c2410-ohci: urb c2704ec0 path 1 ep0in 5ec20000 cc 5
–> status -62

all status code : include/asm-generic/errno.h
#define ETIME 62      /* Timer expired */

Document of error codes : Documentation/usb/error-codes.txt

-ETIME (**)
No response packet received within the prescribed bus turn-around time.  This error may instead be reported as -EPROTO or -EILSEQ.

懶惰的script



ROOTFS=/home2/fyodor/filesystem/rootfs
echo " install module to $ROOTFS/lib/modules/2.6.24.3/extra/"
cp /lib/modules/2.6.24.3/extra/rt73.ko $ROOTFS/lib/modules/2.6.24.3/extra/rt73.ko
echo " install firmware to $ROOTFS/lib/firmware/"
cp /lib/firmware/rt73.bin $ROOTFS/lib/firmware/
ls -alh $ROOTFS/lib/modules/2.6.24.3/extra/rt73.ko
ls -alh $ROOTFS/lib/firmware/rt73.bin

modprobe


[busybox] # modprobe rt73 debug=15 firmware=/lib/firmware/rt73.bin

[busybox] # ifconfig wlan0 up

[busybox] # dmesg
rt73: USBVendorRequest TIMEOUT
rt73: Retry count exhausted or device removed!!!
rt73: BBP version = 0
s3c2410-ohci s3c2410-ohci: urb c1980840 path 1 ep0in 5ec20000 cc 5 --> status -62

rt73: USBVendorRequest TIMEOUT
s3c2410-ohci s3c2410-ohci: urb c1980840 path 1 ep0out 5ec20000 cc 5 --> status -62

rt73: USBVendorRequest TIMEOUT
s3c2410-ohci s3c2410-ohci: urb c1980840 path 1 ep0in 5ec20000 cc 5 --> status -62

rt73: USBVendorRequest TIMEOUT
s3c2410-ohci s3c2410-ohci: urb c1980840 path 1 ep0in 5ec20000 cc 5 --> status -62

rt73: USBVendorRequest TIMEOUT
s3c2410-ohci s3c2410-ohci: urb c1980840 path 1 ep0in 5ec20000 cc 5 --> status -62

rt73: USBVendorRequest TIMEOUT
rt73: Retry count exhausted or device removed!!!
rt73: BBP version = 0

為什麼會timeout勒.....  搞了一個禮拜還是搞不清楚
rt73: USBVendorRequest TIMEOUT是我自己加的訊息

總之status -62 = -ETIME,就是TIMEOUT

上面說過了,status code的詳細定義在$(KERNDIR)/include/asm-generic/errno.h

error的解釋在$(KERNDIR)/Documentation/usb/error-codes.txt

去rt2x00.serialmonkey.com post問題,一邊trace driver 一邊等

覺得問題比較有可能出在s3c2410-ohci

畢竟這部份的2440移植,我做的很粗糙

Error Code Tracing


rt73: USBVendorRequest TIMEOUT


$(RT73)/Module/rtusb_io.c ===> RTUSB_VendorRequest function內的ret 值

ret=usb_control_msg(pAd->pUsb_Dev, usb_sndctrlpipe( pAd->pUsb_Dev, 0 ), \

Request, RequestType, Value,Index, TransferBuffer, TransferBufferLength, \

CONTROL_TIMEOUT_JIFFIES);

message : s3c2410-ohci s3c2410-ohci: urb c1980840 path 1 ep0out 5ec20000 cc 5 --> status -62


來源:drivers/usb/host/ohci-q.c : dl_done_list() --> dl_reverse_done_list() --> ed_halted()

誰呼叫RTUSB_VendorRequest


RTUSBReadMACRegister

RTUSBWriteMACRegister


Apr 11, 2008

Linux Driver - Platform Device

platform-driver


Driver裡面先定義出platform-driver的名稱

這個名稱是s3c2410-ohci

static struct platform_driver ohci_hcd_s3c2410_driver = {
.probe          = ohci_hcd_s3c2410_drv_probe,
.remove         = ohci_hcd_s3c2410_drv_remove,
.shutdown       = usb_hcd_platform_shutdown,
/*.suspend      = ohci_hcd_s3c2410_drv_suspend, */
/*.resume       = ohci_hcd_s3c2410_drv_resume, */
.driver         = {
.owner  = THIS_MODULE,
.name   = "s3c2410-ohci",
},
};

----

platform_driver的資料結構:

[include/linux/platform_device.h]

struct platform_driver {
int (*probe)(struct platform_device *);
int (*remove)(struct platform_device *);
void (*shutdown)(struct platform_device *);
int (*suspend)(struct platform_device *, pm_message_t state);
int (*suspend_late)(struct platform_device *, pm_message_t state);
int (*resume_early)(struct platform_device *);
int (*resume)(struct platform_device *);
struct device_driver driver;
};

resource


[arch/arm/plat-s3c24xx/devs.c"]
/* USB Host Controller */

static struct resource s3c_usb_resource[] = {
[0] = {
.start = S3C24XX_PA_USBHOST,
.end   = S3C24XX_PA_USBHOST + S3C24XX_SZ_USBHOST - 1,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = IRQ_USBH,
.end   = IRQ_USBH,
.flags = IORESOURCE_IRQ,
}
};

platform-device (單一)


platporm裡要註冊device

使用的name對應到欲使用的driver

還有resource則是對應到上面

[arch/arm/plat-s3c24xx/devs.c"]
struct platform_device s3c_device_usb = {
.name             = "s3c2410-ohci",
.id               = -1,
.num_resources    = ARRAY_SIZE(s3c_usb_resource),
.resource         = s3c_usb_resource,
.dev              = {
.dma_mask = &s3c_device_usb_dmamask,
.coherent_dma_mask = 0xffffffffUL
}
};

EXPORT_SYMBOL(s3c_device_usb)

----

platform_device的資料結構:

[include/linux/platform_device.h]

struct platform_device {
const char      * name;
int             id;
struct device dev;
u32             num_resources;
struct resource * resource;
};

----

device的資料結構:

[include/linux/device.h]

struct device {
struct klist            klist_children;
struct klist_node       knode_parent;           /* node in sibling list */
struct klist_node       knode_driver;
struct klist_node       knode_bus;
struct device           *parent;

struct kobject kobj;
char    bus_id[BUS_ID_SIZE];    /* position on parent bus */
struct device_type      *type;
unsigned                is_registered:1;
unsigned                uevent_suppress:1;

struct semaphore        sem;    /* semaphore to synchronize calls to
* its driver.
*/

struct bus_type * bus;          /* type of bus device is on */
struct device_driver *driver;   /* which driver has allocated this
device */
void            *driver_data;   /* data private to the driver */
void            *platform_data; /* Platform specific data, device
core doesn't touch it */
struct dev_pm_info      power;

#ifdef CONFIG_NUMA
int             numa_node;      /* NUMA node this device is close to */
#endif
u64             *dma_mask;      /* dma mask (if dma'able device) */
u64             coherent_dma_mask;/* Like dma_mask, but for
alloc_coherent mappings as
not all hardware supports
64 bit addresses for consistent
allocations such descriptors. */

struct list_head        dma_pools;      /* dma pools (if dma'ble) */

struct dma_coherent_mem *dma_mem; /* internal for coherent mem
override */
/* arch specific additions */
struct dev_archdata     archdata;

spinlock_t              devres_lock;
struct list_head        devres_head;

/* class_device migration path */
struct list_head        node;
struct class            *class;
dev_t                   devt;           /* dev_t, creates the sysfs "dev" */
struct attribute_group  **groups;       /* optional groups */

void    (*release)(struct device * dev);
};

platform-device (全部)


最後把整個platform特有的device放在devices[]裡面

[arch/arm/mach-s3c2440/mach-smdk2440.c]

static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c,
&s3c_device_iis,
};

machine init


在machine init的時候,把devices加進platform

[arch/arm/mach-s3c2440/mach-smdk2440.c]

static void __init smdk2440_machine_init(void)
{
s3c24xx_fb_set_platdata(&smdk2440_fb_info);

platform_add_devices(smdk2440_devices, ARRAY_SIZE(smdk2440_devices));

printk("smdk2440 machine init\n");
smdk_machine_init();
}

參考資料


帥哥安的 linux kernel 2.6.24.3 platform device driver

2.6.24 Kernel Document :
driver-model/Platform.txt

driver-model/Driver.txt

Mar 29, 2008

交叉編譯usbutils

先編譯 libusb


這是放在arm-linux上,給usbutils使用的library
(libusb-0.1.12\) $ ./configure --host=arm-linux --build=i686-linux --enable-shared \


--prefix=/usr/local/arm/3.4.1/arm-linux


(libusb-0.1.12\) $ make


(libusb-0.1.12\) # make install


主角usbutils


(usbutils-0.73\) $ CC=arm-linux-gcc ./configure --host=arm-linux --build=i686-linux\


--prefix=/home2/fyodor/FileSystem/rootfs/usr

(usbutils-0.73\)  $ make


錯誤:undefined reference to `rpl_malloc'


修改config.h,把 #define malloc rpl_malloc 註解



(usbutils-0.73\)  # make install


 


動態編譯,所以查看需要的library


$ arm-linux-readelf -d ../sbin/lsusb



Dynamic segment at offset 0xf214 contains 21 entries:
  Tag        Type                         Name/Value
0x00000001 (NEEDED)                     Shared library: [libusb-0.1.so.4]
0x00000001 (NEEDED)                     Shared library: [libc.so.6]
0x0000000c (INIT)                       0x8c94
0x0000000d (FINI)                       0x11230
0x00000004 (HASH)                       0x8128
0x00000005 (STRTAB)                     0x8778
0x00000006 (SYMTAB)                     0x8348
0x0000000a (STRSZ)                      683 (bytes)
0x0000000b (SYMENT)                     16 (bytes)
0x00000015 (DEBUG)                      0x0
0x00000003 (PLTGOT)                     0x1f2f8
0x00000002 (PLTRELSZ)                   376 (bytes)
0x00000014 (PLTREL)                     REL
0x00000017 (JMPREL)                     0x8b1c
0x00000011 (REL)                        0x8aec
0x00000012 (RELSZ)                      48 (bytes)
0x00000013 (RELENT)                     8 (bytes)
0x6ffffffe (VERNEED)                    0x8aac
0x6fffffff (VERNEEDNUM)                 1
0x6ffffff0 (VERSYM)                     0x8a24
0x00000000 (NULL)                       0x0



libc之前就已經包進去了


libusb編譯的時候,prefix在 /usr/local/arm/3.4.1/arm-linux


所以libusb-0.1.so.4會在/usr/local/arm/3.4.1/arm-linux/lib


注意一下,其實libusb-0.1.so.4是一個指向libusb-0.1.so.4.4.4 的soft link


把它複製到rootfs/usr/lib,依樣畫葫蘆做個soft link


接著就是重包rootfs.jffs2


 


 


 


執行的時候還是有問題.............悶