U-Boot命令篇 | 通用串行总线命令usb
Posted Neutionwei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了U-Boot命令篇 | 通用串行总线命令usb相关的知识,希望对你有一定的参考价值。
UBOOT中一般USB的配置:
#define CONFIG_USB_OHCI
#define CONFIG_USB_STORAGE
#define CONFIG_CMD_USB
#define CONFIG_CMD_FAT
#define CONFIG_DOS_PARTITION
#define CONFIG_SUPPORT_VFAT
UBOOT进入命令行 输入 help 可以看到有很多内置的命令,也可以自己添加命令
这篇介绍usb命令:
=> usb
usb - USB sub-system
Usage:
usb start - start (scan) USB controller
usb reset - reset (rescan) USB controller
usb stop [f] - stop USB [f]=force stop
usb tree - show USB device tree
usb info [dev] - show available USB devices
usb test [dev] [port] [mode] - set USB 2.0 test mode
(specify port 0 to indicate the device's upstream port)
Available modes: J, K, S[E0_NAK], P[acket], F[orce_Enable]
usb storage - show details of USB storage devices
usb dev [dev] - show or set current USB storage device
usb part [dev] - print partition table of one or all USB storage devices
usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'
to memory address `addr'
usb write addr blk# cnt - write `cnt' blocks starting at block `blk#'
from memory address `addr'
1.使用usb之前要执行 usb reset 或者 usb start,一般推荐usb reset
=> usb reset
resetting USB...
entry ali_ehci_usb_remove
usb_init-(drivers/usb/host/usb-uclass.c)
USB0: entry ali_ehci_usb_ofdata_to_platdata, name:ehci@0x1803A100
usb_reg:0xb803a000, hccr:0xb803a100, usb_phy:0xb803d800
usb_power:0
fdtdec_get_int_array_count: phy-setting
entry ali_ehci_usb_probe
hccr b803a100 hcor b803a120, usb_regs:b803a000, phy_regs:b803d800
Wr USB setting (0x04 ,0x00000000) (rd back 0x00000000)
Wr USB setting (0x10 ,0x03000000) (rd back 0x83000000)
Wr USB setting (0x24 ,0x00080000) (rd back 0x00080000)
Wr USB setting (0x2c ,0x00000000) (rd back 0x00000000)
USB EHCI 1.00
adth] 1 USB Device(s) found [status:1]
scanning bus 0 for devices... 4 USB Device(s) found
scan end
2. 执行1步骤后,usb info 可以查看usb的一些信息
// 这里是我的usb信息
=> usb info
...
...
4: Mass Storage, USB Revision 2.0
- Kingston DataTraveler 2.0 C86000BDBE37EE307A2100C4
- Class: (from Interface) Mass Storage
- PacketSize: 64 Configurations: 1
- Vendor: 0x0930 Product 0x6545 Version 1.0
Configuration: 1
- Interfaces: 1 Bus Powered 200mA
Interface: 0
- Alternate Setting 0, Endpoints: 2
- Class Mass Storage, Transp. SCSI, Bulk only
- Endpoint 1 In Bulk MaxPacket 512
- Endpoint 2 Out Bulk MaxPacket 512
3. usb tree 树形目录查看所有的usb的信息
=> usb tree
USB device tree:
1 Hub (480 Mb/s, 0mA)
| u-boot EHCI Host Controller
|
+-2 Vendor specific (480 Mb/s, 500mA)
| Realtek 802.11n AC5D5C51BE6F
|
+-3 Hub (480 Mb/s, 100mA)
| USB2.0 Hub
|
+-4 Mass Storage (480 Mb/s, 200mA)
Kingston DataTraveler 2.0 C86000BDBE37EE307A2100C4
4. usb storage , usb dev 查看当前使用usb的信息
=> usb storage
Device 0: Vendor: Kingston Rev: PMAP Prod: DataTraveler 2.0
Type: Removable Hard Disk
Capacity: 29774.8 MB = 29.0 GB (60978816 x 512)
=> usb dev
USB device 0: Vendor: Kingston Rev: PMAP Prod: DataTraveler 2.0
Type: Removable Hard Disk
Capacity: 29774.8 MB = 29.0 GB (60978816 x 512)
5. 正常U盘的系统信息在第一个分区中,但也不排除有时候在其他的分区,所以就导致了有时候插入U盘但是怎么也识别不到
尤其是代码中类似写死了 "fatload usb 0 %x %s", 这时候我们可以通过 usb part 来查看有几个分区。
//两个不同U盘的信息
=> usb part
Partition Map for USB device 0 -- Partition Type: DOS
Part Start Sector Num Sectors UUID Type
1 2 60978814 3f3a81c0-01 0b Boot
=> usb part
Partition Map for USB device 0 -- Partition Type: DOS
Part Start Sector Num Sectors UUID Type
1 32 60062468 00000000-01 0c
检测是第几个具体没想到什么好方法,一般都是手动去查看
=> usb part 0
Partition Map for USB device 0 -- Partition Type: DOS
Part Start Sector Num Sectors UUID Type
1 32 60062468 00000000-01 0c
=> usb part 1
no USB devices available
=> usb part 2
no USB devices available
//上面基本可以确定在第一个分区中。
6. 停止U盘
=> usb stop
stopping USB..
entry ali_ehci_usb_remove
其他几个命令也没怎么用过,像usb write,usb read, 如果U盘格式是fat格式,一般就用 fatwrite,fatread 这些对应的文件系统的命令读写比较好。类似下面这样:
"fatwrite usb 0 0x%x(addr) test.bin 0x%x(size)"
"fatload usb 0 0x%x(addr) test.bin"
补充:
上面提到过,如果U盘有几个分区,虽说默认系统信息在第一个分区,但不排除列外,有时候代码写死也不想去改。
那么这个时候我的做法就是修改uboot查找分区代码,当然这种做法是在于uboot本身使用usb命令不那么严格要求,把代码写死从第几个分区改为一样自动寻找。
// disk/Part.c 中 get_device_and_partition 函数
// 添加的代码,写死自动去找。
part = PART_AUTO;
/*
* If user didn't specify a partition number, or did specify something
* other than "auto", use that partition number directly.
*/
if (part != PART_AUTO) {
ret = get_partition_info(*dev_desc, part, info);
if (ret) {
printf("** Invalid partition %d **\\n", part);
goto cleanup;
}
} else {
以上是关于U-Boot命令篇 | 通用串行总线命令usb的主要内容,如果未能解决你的问题,请参考以下文章
RK356x U-Boot研究所(命令篇)3.5 usb命令的用法