4.3. uboot命令¶
当不清楚uboot支持什么命令时,
可输入 help 或 ? 可查看uboot支持的命令列表,如下所示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92? - alias for 'help'
base - print or set address offset
bdinfo - print Board Info structure
blkcache - block cache diagnostics and control
bmode - sd1|sd2|qspi1|normal|usb|sata|ecspi1:0|ecspi1:1|ecspi1:2|ecspi1:3|esdhc1|esdhc2|esdhc3|esdhc4
bmode - getprisec
boot - boot default, i.e., run 'bootcmd'
bootd - boot default, i.e., run 'bootcmd'
bootefi - Boots an EFI payload from memory
bootelf - Boot from an ELF image in memory
bootm - boot application image from memory
bootp - boot image via network using BOOTP/TFTP protocol
bootvx - Boot vxWorks from an ELF image
bootz - boot Linux zImage image from memory
clocks - display clocks
cmp - memory compare
coninfo - print console devices and information
cp - memory copy
crc32 - checksum calculation
dcache - enable or disable data cache
dhcp - boot image via network using DHCP/TFTP protocol
dm - Driver model low level access
dtfile - dtoverlay utility commands
echo - echo args to console
editenv - edit environment variable
env - environment handling commands
erase - erase FLASH memory
exit - exit script
ext2load - load binary file from a Ext2 filesystem
ext2ls - list files in a directory (default /)
ext4load - load binary file from a Ext4 filesystem
ext4ls - list files in a directory (default /)
ext4size - determine a file's size
ext4write - create a file in the root directory
false - do nothing, unsuccessfully
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls - list files in a directory (default /)
fatmkdir - create a directory
fatrm - delete a file
fatsize - determine a file's size
fatwrite - write file into a dos filesystem
fdt - flattened device tree utility commands
flinfo - print FLASH memory information
fstype - Look up a filesystem type
fstypes - List supported filesystem types
fuse - Fuse sub-system
go - start application at address 'addr'
gpio - query and control gpio pins
help - print command description/usage
i2c - I2C sub-system
icache - enable or disable instruction cache
iminfo - print header information for application image
imxtract - extract a part of a multi-image
itest - return true/false on integer compare
ln - Create a symbolic link
load - load binary file from a filesystem
loadb - load binary file over serial line (kermit mode)
loads - load S-Record file over serial line
loadx - load binary file over serial line (xmodem mode)
loady - load binary file over serial line (ymodem mode)
loop - infinite loop on address range
ls - list files in a directory (default /)
md - memory display
mm - memory modify (auto-incrementing address)
mmc - MMC sub system
mmcinfo - display MMC info
mtest - simple RAM read/write test
mw - memory write (fill)
nfs - boot image via network using NFS protocol
nm - memory modify (constant address)
panic - Panic with optional message
ping - send ICMP ECHO_REQUEST to network host
pinmux - show pin-controller muxing
printenv - print environment variables
protect - enable or disable FLASH write protection
random - fill memory with random pattern
reset - Perform RESET of the CPU
run - run commands in an environment variable
save - save file to a filesystem
saveenv - save environment variables to persistent storage
setenv - set environment variables
setexpr - set environment variable as the result of eval expression
sf - SPI flash sub-system
showvar - print local hushshell variables
size - determine a file's size
sleep - delay execution for some time
source - run script from memory
test - minimal test like /bin/sh
tftpboot - boot image via network using TFTP protocol
true - do nothing, successfully
version - print monitor, compiler and linker version
可看到uboot支持很多的命令,功能十分强大,与linux类似,在执行某条uboot命令时,
可使用 tab 自动补全命令,在没有命令名冲突的情况下可以使用命令的前几个字母作为命令的输入,
例如想要执行 reset 命令,输入 res 或 re 即可。
当需要具体使用哪个命令时,可使用
“help 命令” 或 “? 命令” 的方式查看具体命令的使用说明。以 “help printenv” 为例,
1
2
3
4
5
6
7
8=> help printenv
printenv - print environment variables
Usage:
printenv [-a]
- print [all] values of all environment variables
printenv name ...
- print value of environment variable 'name'
可以看到printenv命令的说明以及使用方法。
关于uboot命令的使用可参考uboot官方链接:
http://www.denx.de/wiki/DULG/Manual
5.9. uboot Command Line Interface 部分。
4.3.1. uboot常见命令¶
uboot命令众多,下面介绍常用的uboot命令,详细的uboot命令使用方式请使用
help [命令] 查看。
常见命令¶
命令
说明
举例
help
列出当前uboot所有支持的命令
help [命令]
查看指定命令的帮助
help printenv
reset
重启uboot
printenv
打印所有环境参数的值
printenv [环境参数名]
查看指定的环境参数值
printenv bootdelay
setenv
设置/修改/删除环境参数的值
setenv bootdelay 3
saveenv
保存环境参数
ping
检测网络是否连通
ping 192.168.0.1
md
查看内存地址上的值
md.b 0x80000000 10
以字节查看0x80000000后0x10个数据
mw
用于修改内存地址上的值
mw.b 0x80000000 ff 10
以字节修改0x80000000后0x10个数据为ff
echo
打印信息,与linux下的echo类似
run
在执行某条环境参数命令
run bootcmd,执行bootcmd
bootz
在内存中引导内核启动
ls
查看文件系统中目录下的文件
load
从文件系统中加载二进制文件到内存
以上为用户较为常用使用的部分命令,具体的使用方式可使用 help [命令] 查看。
4.3.2. mmc命令¶
mmc命令能够对如sd卡以及emmc类的存储介质进行操作,以下进行简单说明,
对于mmc命令不熟悉可使用 help mmc 查看相关命令的帮助,常用功能如下所示
mmc命令功能¶
命令
说明
mmc list
查看板子上mmc设备
mmc dev
查看/切换当前默认mmc设备
mmc info
查看当前mmc设备信息
mmc part
查看当前mmc设备分区
mmc read
读取当前mmc设备数据
mmc write
写入当前mmc设备数据
mmc erase
擦除当前mmc设备数据
4.3.2.1. 查看mmc设备¶
使用 mmc list 查看板子上相关设备,本人使用的是emmc版本的开发板,并插入了sd卡,
可看到打印信息如下。
1
2
3=> mmc list
FSL_SDHC: 0 (SD)
FSL_SDHC: 1
使用 mmc dev 查看当前使用的mmc设备,打印信息如下,可看到当前设备为mmc0即sd卡。
1
2
3=> mmc dev
switch to partitions #0, OK
mmc0 is current device
提示
可使用 mmc dev 1 命令切换当前设备为emmc设备
使用 mmc info 查看当前使用的sd卡设备的信息。
1
2
3
4
5
6
7
8
9
10
11
12
13=> mmc info
Device: FSL_SDHC
Manufacturer ID: 3
OEM: 5344
Name: SC16G
Bus Speed: 50000000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 14.8 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
4.3.2.2. 查看分区信息¶
使用 mmc part 列出当前mmc设备分区
1
2
3
4
5
6
7 => mmc part
Partition Map for MMC device 0 -- Partition Type: DOS
Part Start Sector Num Sectors UUID Type
1 8192 81920 2ba51413-01 0e Boot
2 90112 31026176 2ba51413-02 83
4.3.2.3. mmc操作¶
可使用以下指令对mmc存储介质以block为操作单位进行读、写、擦除操作,根据上面sd的信息可知,
一个block为512字节。
1
2
3 mmc read addr blk# cnt #读
mmc write addr blk# cnt #写
mmc erase blk# cnt #擦除
简单实例:将mmc设备的的前10个block读取到0x80000000地址处:
mmc read 0x80000000 0 10
4.3.3. 文件系统操作命令¶
uboot能够对ext2/3/4以及fat文件系统设备进行访问,
可使用fstype命令判断存储介质分区使用的是什么类型的文件系统。
以mmc介质为例,判断sd的两个分区的文件系统类型
1
2
3
4=> fstype mmc 0:1
fat
=> fstype mmc 0:2
ext4
野火linux开发板具有U盘功能,能够通过PC以访问U盘的形式访问/boot目录下的文件,
/boot目录对应的即是 mmc 0:1 分区。
而ext4分区对应的则是Debian根文件系统。
知道了文件系统的类型即可使用相对应的命令对分区内容进行操作了。
4.3.3.1. FAT格式文件系统¶
uboot提供了能够对于FAT格式文件系统操作的各个指令,
如下所示,详细可通过 help [命令] 查看
FAT格式文件系统命令¶
命令
说明
fatinfo
打印关于文件系统的信息
fatls
查看存储设备的fat分区里的内容
fatload
从fat分区里读出文件到指定的内存地址
fatwrite
把内存上的数据存储到fat分区的一个文件里
fatmkdir
创建文件夹
fatrm
删除文件
4.3.3.1.1. 查看文件系统信息¶
使用fatinfo查看文件系统信息,打印信息如下
1
2
3
4
5
6=> fatinfo mmc 0:1
Interface: MMC
Device 0: Vendor: Man 000003 Snr 6d8b9601 Rev: 1.0 Prod: SC16G▒
Type: Removable Hard Disk
Capacity: 15193.5 MB = 14.8 GB (31116288 x 512)
Filesystem: FAT16 "BOOT "
4.3.3.1.2. 查看分区下的文件目录¶
使用fatls查看分区下的文件目录,打印信息如下
1
2
3
4
5
6
7
8
9
10
11
12 => fatls mmc 0:1
38 ID.txt
kernel/
2418 uEnv.txt
577 SOC.sh
boot/
34 autorun.inf
System Volume Information/
dtbs/
1472 BOOTEX.LOG
5 file(s), 4 dir(s)
若想要查看其它目录下的文件列表,只要加上文件路径即可,如下
1
2
3
4
5
6
7
8
9 => fatls mmc 0:1 kernel/
./
../
9187912 vmlinuz-4.19.35-imx6
143341 config-4.19.35-imx6
3104898 System.map-4.19.35-imx6
5160838 initrd.img-4.19.35-imx6
4 file(s), 2 dir(s)
4.3.3.1.3. 读取文件内容¶
使用fatload将FAT文件系统的文件加载到内存中,如下所示
1
2 => fatload mmc 0:1 0x80000000 uEnv.txt
2418 bytes read in 13 ms (181.6 KiB/s)
可使用md命令查看0x80000000内存中的部分数据内容
1
2
3
4
5
6
7
8
9=> md.b 0x80000000 0x80
80000000: 23 44 6f 63 73 3a 20 68 74 74 70 73 3a 2f 2f 65 #Docs: https://e
80000010: 6d 62 65 64 2d 6c 69 6e 75 78 2d 74 75 74 6f 72 mbed-linux-tutor
80000020: 69 61 6c 2e 72 65 61 64 74 68 65 64 6f 63 73 2e ial.readthedocs.
80000030: 69 6f 2f 7a 68 5f 43 4e 2f 6c 61 74 65 73 74 2f io/zh_CN/latest/
80000040: 52 45 41 44 4d 45 2e 68 74 6d 6c 0a 0a 75 6e 61 README.html..una
80000050: 6d 65 5f 72 3d 34 2e 31 39 2e 33 35 2d 69 6d 78 me_r=4.19.35-imx
80000060: 36 0a 23 75 75 69 64 3d 0a 6d 6d 63 5f 64 74 62 6.#uuid=.mmc_dtb
80000070: 3d 69 6d 78 36 75 6c 6c 2d 6d 6d 63 2d 6e 70 69 =imx6ull-mmc-npi
读取到的内容就是我们日常在/boot/uEnv.txt文件中的看到的内容了。
4.3.3.1.4. FAT文件系统其他操作¶
uboot还提供了FAT文件系统的其他操作命令,可用于创建目录、写入、删除等操作,
通常情况下在uboot中需要使用这类命令的场景很少,简单介绍如下:
fatmkdir:创建目录
fatrm:删除文件
fatwrite:把内存上的数据存储到FAT分区的一个文件里
4.3.3.2. ext4格式文件系统¶
ext4文件系统的命令使用方式和FAT使用方式相似,仅命令名不同,
uboot提供的ext文件系统命令如下
ext4格式文件系统命令¶
命令
说明
ext4ls
查看存储设备的ext4分区里的内容
ext4load
从ext4分区里读出文件到指定的内存地址
ext4write
把内存上的数据存储到ext4分区的一个文件里
4.3.3.2.1. ext4文件系统操作¶
下面以将/etc/apt/sources.list的内容读取到内存实例,简单说明uboot对ext4文件系统操作。
1.查看/etc/apt目录中的文件内容,
1
2
3
4
5
6
7
8
9
10
11 => ext4ls mmc 0:2 /etc/apt/
865 sources.list
2175 trusted.gpg
382 trusted.gpg~
2.将/etc/apt/sources.list 文件读取到内存地址0x8000 0000处
1
2=> ext4load mmc 0:2 0x80000000 /etc/apt/sources.list
865 bytes read in 30 ms (27.3 KiB/s)
3.查看内存0x8000 0000的部分数据内存
1
2
3
4
5
6
7
8
9=> md.b 0x80000000 0x80
80000000: 64 65 62 20 68 74 74 70 3a 2f 2f 6d 69 72 72 6f deb http://mirro
80000010: 72 73 2e 74 75 6e 61 2e 74 73 69 6e 67 68 75 61 rs.tuna.tsinghua
80000020: 2e 65 64 75 2e 63 6e 2f 64 65 62 69 61 6e 20 62 .edu.cn/debian b
80000030: 75 73 74 65 72 20 6d 61 69 6e 20 63 6f 6e 74 72 uster main contr
80000040: 69 62 20 6e 6f 6e 2d 66 72 65 65 0a 23 64 65 62 ib non-free.#deb
80000050: 2d 73 72 63 20 68 74 74 70 3a 2f 2f 6d 69 72 72 -src http://mirr
80000060: 6f 72 73 2e 74 75 6e 61 2e 74 73 69 6e 67 68 75 ors.tuna.tsinghu
80000070: 61 2e 65 64 75 2e 63 6e 2f 64 65 62 69 61 6e 20 a.edu.cn/debian