(8) USB 操作指令
指令 |
功能 |
usb reset | 初始化USB控制器 |
usb stop [f] | 关闭USB控制器 |
usb tree | 已连接的USB设备树 |
usb info [dev] | 显示USB设备[dev]的信息 |
usb storage | 显示已连接的USB存储设备 |
usb dev [dev] | 显示和设置当前USB存储设备 |
usb part [dev] | 显示USB存储设备[dev]的分区信息 |
usb read addr blk# cnt | 读取USB存储设备数据 |
在所有的命令使用前,必须先插入USB设备,然后使用:usb
reset,以初始化USB控制器,获取设备信息。
我将一个4G的kingstonU盘(可引导盘)插入 mini2440,然后读取他的头512 字节(MBR):
[u-boot@MINI2440]# usb reset (Re)start USB... USB: scanning bus for devices... 2 USB Device(s) found scanning bus for storage devices... 1 Storage Device(s) found [u-boot@MINI2440]# usb tree Device Tree: 1 Hub (12 Mb/s, 0mA) | OHCI Root Hub | +-2 Mass Storage (12 Mb/s, 100mA) Kingston DT 101 II 0019E02CB6EB5B8B1B120051 [u-boot@MINI2440]# usb 2: Mass Storage, USB Revision 2.0 [u-boot@MINI2440]# usb Partition Map for USB device 0 -- Partition Type: DOS Partition Start Sector Num Sectors Type |
(9) SD卡(MMC)指令
SD卡的使用命令比较简单,只有初始化和设备信息的显示,读写是通过文件系统命令实现的。
mmc init [dev] - 初始化MMC子系统
mmc device [dev] - 查看和设置当前设备
使用和USB类似,在所有的命令使用前,必须先插入SD卡,然后使用:mmc init,以初始化MMC 控制器,获取设备信息。
我在mini2440中插入1GB SD卡:
[u-boot@MINI2440]# mmc init mmc: Probing for SDHC ... mmc: SD 2.0 or later card found trying to detect SD Card... Manufacturer: 0x00, OEM "roduct name: " ", revision 0.0 Serial number: 7864775 Manufacturing date: 11/2006 CRC: 0x4f, b0 = 1 READ_BL_LEN=6, C_SIZE_MULT=7, C_SIZE=4095 size = 0 SD Card detected RCA: 0x2 type: SD mmc1 is available [u-boot@MINI2440]# mmc device mmc1 is current device |
(10) FAT文件系统指令
fatinfo:显示文件系统的相关信息
格式:fatinfo <interface> <dev[:part]>
Interface:代表接口,如usb、mmc;
dev:代表设备编号,如0、1……;
part:代表存储设备中的分区,如1、2……。
fatload:从FAT32文件系统中读取二进制文件到SDRAM。
格式:fatload <interface> <dev[:part]> <addr> <filename> [bytes]
Interface、dev和part同上;
addr:代表写入SDRAM的地址;
filename:代表存储设备中的文件名;
bytes:代表从存储设备中读取的文件大小,可不填;如果填的数据比文件小,就只读取bytes字节,如果填的数据比文件大,也只读取文件的大小。
fatls:列出FAT32文件系统中目录里的文件。
格式:fatls <interface> <dev[:part]> [directory]
Interface、dev和part同上;
directoryr:代表所要查看的目录,可不填,默认为/。
这些指令基本上要和U盘或者SD卡同时使用,主要用于读取这些移动存储器上的FAT32分区。
使用范例:
[u-boot@MINI2440]# usb part 0 print_part of 0 Partition Map for USB device 0 -- Partition Type: DOS Partition Start Sector Num Sectors Type 4 file(s), 5 dir(s) [u-boot@MINI2440]# fatls 6 file(s), 4 dir(s) 256220 bytes read 512 bytes read |
(11) 系统引导指令
boot 和bootd 都是运行ENV”bootcmd”中指定的指令。
bootm 指令是专门用于启动在SDRAM中的用U-boot的mkimage工具处理过的内核映像。
格式:bootm [addr [arg ...]]
addr 是内核映像所在的SDRAM中的地址
当启动的是Linux内核时,'arg' 可以使 initrd 的地址。
[u-boot@MINI2440]# setenv bootcmd tftp\;bootm [u-boot@MINI2440]# saveenv Saving Environment to NAND... Erasing Nand... Erasing at 0x6000000000002 -- 0% complete. Writing to Nand... done [u-boot@MINI2440]# boot dm9000 i/o: 0x20000300, id: 0x90000a46 DM9000: running in 16 bit mode MAC: 08:08:11:18:12:27 operating at 100M full duplex mode Using dm9000 device TFTP from server 192.168.1.100; our IP address is 192.168.1.101 Filename 'zImage.img'. Load address: 0x30008000 Loading: T ################################################################# ################################################################# ########################## done Bytes transferred = 2277540 (22c0a4 hex) ## Booting kernel from Legacy Image at 30008000 ... Image Name: tekkaman Created: 2010-03-29 12:59:51 UTC Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 2277476 Bytes = 2.2 MB Load Address: 30008000 Entry Point: 30008040 Verifying Checksum ... OK XIP Kernel Image ... OK OK Starting kernel ... Uncompressing Linux... done, booting the kernel. U-Boot 2009.11 ( 4月 04 2010 - 12:09:25) modified by tekkamanninja (tekkamanninja@163.com) I2C: ready Starting kernel ... |
12)EEPROM 读写指令eeprom - I2C 接口的EEPROM 读写指令
格式:
eeprom read addr off cnt
eeprom write addr off cnt
第一个参数addr 是要写入或读出的数据在SDRAM中的存放地址;
第二个参数off 是在EEPROM中的偏移;
第三个参数cnt 是读写的数据字节数。
使用范例:
[u-boot@MINI2440]# md.b 0x30008000 2 30008000: aa aa .. [u-boot@MINI2440]# eeprom read 0x30008000 10 2 EEPROM @0x50 read: addr 30008000 off 0010 count 2 ... done [u-boot@MINI2440]# md.b 0x30008000 2 30008000: ff ff .. [u-boot@MINI2440]# mm.b 0x30008000 30008000: ff ? aa 30008001: ff ? 55 30008002: aa ? q [u-boot@MINI2440]# md.b 0x30008000 2 30008000: aa 55 .U [u-boot@MINI2440]# eeprom write 0x30008000 10 2 EEPROM @0x50 write: addr 30008000 off 0010 count 2 ... done [u-boot@MINI2440]# eeprom read 0x30008010 10 2 EEPROM @0x50 read: addr 30008010 off 0010 count 2 ... done [u-boot@MINI2440]# md.b 0x30008010 2 30008010: aa 55 .U |
(13)设置和读取RTC指令
date - 设置和读取RTC
格式:
date [MMDDhhmm[[CC]YY][.ss]]
MM:月份
DD:日期
hh:小时
mm 分钟
CC:年份的前两个数字
YY:年份的后两个数字
ss:秒数
使用范例:
[u-boot@MINI2440]# date Date: 1980-00-06 (Thursday) Time: 20:30:25 [u-boot@MINI2440]# date 041100582010.20 Date: 2010-04-11 (Sunday) Time: 0:58:20 |
(14)脚本运行指令
run var [...]
var :ENV中的脚本名
使用范例:
[u-boot@MINI2440]# setenv a_run_test echo $bootfile \; version [u-boot@MINI2440]# run a_run_test zImage.img U-Boot 2009.11 ( 4月 04 |
(15)系统重启指令
reset
- 重启CPU
[u-boot@MINI2440]# reset resetting ... U-Boot 2009.11 ( 4月 04 modified by tekkamanninja (tekkamanninja@163.com) I2C: ready |
四、U-boot的使用(四)
下载与烧写
使用U-boot将映像文件烧写到板上的Flash,一般步骤是:
(1)通过网络、串口、U盘、SD卡等方式将文件传输到SDRAM;
(2)使用Nand Flash或Nor Flash相关的读写命令将SDRAM中的数据烧入Flash。
下面是烧写范例:
如果使用 SD卡和U盘形式更新U-boot,那么首先SD卡和U盘中必须有FAT32文件系统,并在里面存放了u-boot.bin 文件。
1) 通过SD卡烧入Nand Flash:
[u-boot@MINI2440]# mmc init mmc: Probing for SDHC ... mmc: SD 2.0 or later card found trying to detect SD Card... Manufacturer: 0x00, OEM "roduct name: " ", revision 0.0 Serial number: 7864775 Manufacturing date: 11/2006 CRC: 0x4f, b0 = 1 READ_BL_LEN=6, C_SIZE_MULT=7, C_SIZE=4095 size = 0 SD Card detected RCA: 0x2 type: SD mmc1 is available [u-boot@MINI2440]# fatload mmc 1 0x30008000 u-boot.bin reading u-boot.bin 256220 bytes read NAND erase: device 0 offset 0x0, size 0x40000 NAND write: device 0 offset 0x0, size 0x40000 |
2) 通过U盘烧入Nor Flash:
[u-boot@MINI2440]# usb start (Re)start USB... USB: scanning bus for devices... 2 USB Device(s) found scanning bus for storage devices... 1 Storage Device(s) found Type: Removable Hard Disk Capacity: 3875.0 MB = 3.7 GB (7936000 x 512) Partition Map for USB device 0 Partition
63 7935937 [u-boot@MINI2440]# fatload usb 0:4 0x30008000 u-boot.bin 256220 bytes read |
3) 通过TFTP服务烧入Nand Flash:
[u-boot@MINI2440]# tftpboot 30008000 192.168.1.100:u-boot.bin dm9000 i/o: 0x20000300, id: 0x90000a46 DM9000: running in 16 bit mode MAC: 08:08:11:18:12:27 operating at 100M full duplex mode Using dm9000 device TFTP from server 192.168.1.100; our IP address is 192.168.1.101 Filename 'u-boot.bin'. Load address: 0x30008000 Loading: T ################## done Bytes transferred = 256220 (3e8dc hex) [u-boot@MINI2440]# nand erase 0 0x40000 NAND erase: device 0 offset 0x0, size 0x40000 Erasing at 0x2000000000004 -- 0% complete. OK [u-boot@MINI2440]# nand write 0x30008000 0 0x40000 NAND write: device 0 offset 0x0, size 0x40000 |
4) 通过NFS 服务烧入Nand Flash:
[u-boot@MINI2440]# nfs 30008000 192.168.1.100:/home/tekkaman/development/share/u-boot.bin dm9000 i/o: 0x20000300, id: 0x90000a46 DM9000: running in 16 bit mode MAC: 08:08:11:18:12:27 operating at 100M full duplex mode Using dm9000 device File transfer via NFS from server 192.168.1.100; our IP address is 192.168.1.101 Filename '/home/tekkaman/development/share/u-boot.bin'. Load address: 0x30008000 Loading: ################################################### done Bytes transferred = 256220 (3e8dc hex) [u-boot@MINI2440]# nand erase 0 0x40000 NAND erase: device 0 offset 0x0, size 0x40000 Erasing at 0x2000000000004 -- 0% complete. OK [u-boot@MINI2440]# nand write 0x30008000 0 0x40000 NAND write: device 0 offset 0x0, size 0x40000 |
内核引导
内核的引导步骤如下:
(1)用U-boot的mkimage工具处理内核映像zImage。
(2)通过网络、串口、U盘、SD卡等方式将处理过的内核映像传输到SDRAM的一定位置(一般使用0x30008000)
(3)然后使用”bootm"等内核引导命令来启动内核。
为什么要用U-boot的mkimage工具处理内核映像zImage? 因为在用bootm命令引导内核的时候,bootm需要读取一个64字节的文件头,来获取这个内核映象所针对的CPU体系结构、OS、加载到内存中的位置、在内存中入口点的位置以及映象名等等信息。这样bootm才能为OS设置好启动环境,并跳入内核映象的入口点。而mkimage就是添加这个文件头的专用工具。具体的实现请看U-boot中bootm的源码和mkimage的源码。 |
mkimage工具的使用:
参数说明: 以下是制作内核映像的命令示例: |
以下是使用范例:
1) 通过SD卡引导内核:
首先SD卡中必须有FAT32文件系统,并在里面存放了处理过的内核映像文件。
[u-boot@MINI2440]# mmc init mmc: Probing for SDHC ... 2277540 bytes read Image Name: Created: Image Type: Data Size: Load Address: 30008000 Entry Point: Verifying Checksum ... OK XIP Kernel Image ... OK Starting kernel ... Uncompressing Linux... done, booting the kernel. |
2) 通过TFTP服务引导内核:
[u-boot@MINI2440]# tftpboot 0x30008000 192.168.1.100:zImage.img dm9000 i/o: 0x20000300, id: 0x90000a46 DM9000: running in 16 bit mode MAC: 08:08:11:18:12:27 operating at 100M full duplex mode Using dm9000 device TFTP from server 192.168.1.100; our IP address is 192.168.1.101 Filename 'zImage.img'. Load address: 0x30008000 Loading: T ################################################################# ################################################################# ########################## Image Name: Created: Image Type: Data Size: Load Address: 30008000 Entry Point: Verifying Checksum ... OK XIP Kernel Image ... OK Starting kernel ... Uncompressing Linux... done, booting the kernel. |
3) 通过NFS服务引导内核:
[u-boot@MINI2440]# nfs 30008000 192.168.1.100:/home/tekkaman/development/share/zImage.img dm9000 i/o: 0x20000300, id: 0x90000a46 DM9000: running in 16 bit mode MAC: 08:08:11:18:12:27 operating at 100M full duplex mode Using dm9000 device File transfer via NFS from server 192.168.1.100; our IP address is 192.168.1.101 Filename '/home/tekkaman/development/share/zImage.img'. Load address: 0x30008000 Loading: ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ####################################################### Image Name: Created: Image Type: Data Size: Load Address: 30008000 Entry Point: Verifying Checksum ... OK XIP Kernel Image ... OK Starting kernel ... Uncompressing Linux... done, booting the kernel. |
4) 通过Nand Flash引导内核:
首先要将处理过的内核映像文件烧入Nand Flash的一定位置(由内核分区表决定)。以后每次启动时用Nand Flash的读取命令先将这个内核映像文件读到内存的一定位置(由制作内核映像时的-a参数决定),再使用bootm命令引导内核。
内核映像文件的烧入:
[u-boot@MINI2440]# nfs 30008000 192.168.1.100:/home/tekkaman/development/share/zImage.img dm9000 i/o: 0x20000300, id: 0x90000a46 DM9000: running in 16 bit mode MAC: 08:08:11:18:12:27 operating at 100M full duplex mode Using dm9000 device File transfer via NFS from server 192.168.1.100; our IP address is 192.168.1.101 Filename '/home/tekkaman/development/share/zImage.img'. Load address: 0x30008000 Loading: ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ####################################################### NAND erase: device 0 offset 0x80000, size 0x300000 NAND write: device 0 offset 0x80000, size 0x300000 Writing at 0x36000000020000 -- 100% is complete. 3145728 bytes written: OK |
内核引导:
[u-boot@MINI2440]#
nand read 30008000 0x80000 300000
NAND read: device 0 offset 0x80000, size 0x300000
3145728 bytes read: OK
[u-boot@MINI2440]# bootm 30008000
## Booting kernel from Legacy Image at 30008000 ...
Image Name:
tekkaman
Created:
2010-03-29
12:59:51 UTC
Image Type:
ARM Linux Kernel Image (uncompressed)
Data Size:
2277476 Bytes =
2.2 MB
Load Address: 30008000
Entry Point:
30008040
Verifying Checksum ... OK
XIP Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
Linux version 2.6.33.1 (tekkaman@MAGI-Linux) (gcc version 4.3.2 (crosstool-NG-1.6.1-tekkaman) ) #5 Mon Mar 29 20:58:50 CST 2010
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440