目标:在uboot中加入usb功能,实现从usb存储设备上启动kernel。
ralink的SDK提供的uboot是支持usb相关命令的,只需要在config.mk打开相应的开关即可。一开始以为只需要这样做:
RALINK_USB = ON RALINK_EHCI = ON RALINK_OHCI = ON
编译烧写后,发现usb相关命令已经出现在uboot中了,但是每次usb reset,都扫描不到storage存储设备。
MT7620 # usb reset (Re)start USB... USB: scanning bus for devices... ## RH_GET_DESCRIPTOR ## RH_SET_ADDRESS ## RH_GET_DESCRIPTOR ## RH_GET_DESCRIPTOR ## RH_GET_DESCRIPTOR ## RH_SET_CONFIGURATION ## RH_GET_DESCRIPTOR ## RH_GET_DESCRIPTOR ## RH_GET_DESCRIPTOR | RH_CLASS ## RH_GET_DESCRIPTOR | RH_CLASS ## RH_GET_STATUS | RH_CLASS 1 USB Device(s) found scanning bus for storage devices... 0 Storage Device(s) found
usb info中,product和vendor id均为0,太怪异了!
MT7620 # usb info 1: Hub, USB Revision 1.10 - OHCI Root Hub - Class: Hub - PacketSize: 8 Configurations: 1 - Vendor: 0x0000 Product 0x0000 Version 0.0 Configuration: 1 - Interfaces: 1 Self Powered 0mA Interface: 0 - Alternate Settings 0, Endpoints: 1 - Class Hub - Endpoint 1 In Interrupt MaxPacket 2 Interval 255ms
并且发现uboot识别的usb host只有12M/s的速度
MT7620 # usb tree Device Tree: 1 Hub (12 Mb/s, 0mA) OHCI Root Hub
按理说,MT7620的usb应该是2.0的高速设备,不可能是12M/s的。仔细分析了一下代码,发现只要开启了RALINK_OHCI,RALINK_EHCI就会失效。so,只打开EHCI,关闭OHCI。
RALINK_USB = ON RALINK_EHCI = ON RALINK_OHCI = OFF
编译烧录,发现问题更离奇:
U-Boot 1.1.3 (Jun 9 2014 - 17:38:01) MT7620 # usb reset (Re)start USB... USB: in usb_lowlevel_init Error, couldn't init Lowlevel part
看来调用usb_lowlevel_init失败!找到usb_lowlevel_init的代码,并加入一些printf信息,便于分析问题:
发现,usb_lowlevel_init返回-1,于是继续跟踪代码,发现usb_lowlevel_init调用了如下代码:
位于ehci-ra.c中
int ehci_hcd_init(void) { #if defined(RT3352_ASIC_BOARD) || defined(RT3883_ASIC_BOARD) || defined(RT5350_ASIC_BOARD) leave_power_saving(); mdelay(100); rt_set_host(); mdelay(100); hccr = (struct ehci_hccr *)(0xb01c0000); hcor = (struct ehci_hcor *)((uint32_t) hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase))); printf("Mediatek/Ralink USB EHCI host init hccr %x and hcor %x hc_length %d\n", (uint32_t)hccr, (uint32_t)hcor, (uint32_t)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); return 0; #else return -1; #endif }
拿着死马当活马医的精神,屏蔽掉对主控的判断,编译烧录,哈哈,扫描到东东了!
MT7620 # usb reset (Re)start USB... USB: in usb_lowlevel_init Mediatek/Ralink USB EHCI host init hccr b01c0000 and hcor b01c0010 hc_length 16 Register 1111 NbrPorts 1 USB EHCI 1.00 scanning bus for devices... 2 USB Device(s) found scanning bus for storage devices... 1 Storage Device(s) found MT7620 # usb info 1: Hub, USB Revision 0.2 - u-boot EHCI Host Controller - Class: Hub - PacketSize: 64 Configurations: 1 - Vendor: 0x0000 Product 0x0000 Version 0.1 Configuration: 1 - Interfaces: 1 Self Powered 0mA Interface: 0 - Alternate Settings 0, Endpoints: 1 - Class Hub - Endpoint 1 In Interrupt MaxPacket 8 Interval 0ms 2: Mass Storage, USB Revision 2.0 - HP USB 2.0 Flash 00CCCBB99999 - Class: (from Interface) Mass Storage - PacketSize: 64 Configurations: 1 - Vendor: 0x0204 Product 0x6025 Version 1.0 Configuration: 1 - Interfaces: 1 Bus Powered 100mA Interface: 0 - Alternate Settings 0, Endpoints: 2 - Class Mass Storage, Transp. SCSI, Bulk only - Endpoint 1 Out Bulk MaxPacket 512 - Endpoint 1 In Bulk MaxPacket 512
速度也正确了!
MT7620 # usb tree Device Tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Mass Storage (480 Mb/s, 100mA) HP USB 2.0 Flash 00CCCBB99999
看来,是原始代码的问题,解决的办法是在ehci-ra.c的ehci_hcd_init中加入MT7620_ASIC_BOARD定义。
本文作者:https://blog.csdn.net/manfeel/
本文章由作者:佐须之男 整理编辑,原文地址: mt7620 u-boot 实现usb启动系统
本站的文章和资源来自互联网或者站长的原创,按照 CC BY -NC -SA 3.0 CN协议发布和共享,转载或引用本站文章应遵循相同协议。如果有侵犯版权的资 源请尽快联系站长,我们会在24h内删除有争议的资源。欢迎大家多多交流,期待共同学习进步。