目录
一、help命令
1、第一种用法:
(1) 输入命令:help 或者 ?
(2) 作用:显示所有可用的命令列表;
(3) 结果:
=> help
? - alias for 'help'
base - print or set address offset
bdinfo - print Board Info structure
bmode - sd1|sd2|qspi1|normal|usb|sata|ecspi1:0|ecspi1:1|ecspi1:2|ecspi1:3|esdhc1|esdhc2|esdhc3|esdhc4 [noreset]
boot - boot default, i.e., run 'bootcmd'
bootd - boot default, i.e., run 'bootcmd'
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
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 /)
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
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
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
mdio - MDIO utility commands
mii - MII utility commands
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)
ping - send ICMP ECHO_REQUEST to network host
pmic - PMIC
printenv- print environment variables
protect - enable or disable FLASH write protection
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
usb - USB sub-system
usbboot - boot from USB device
version - print monitor, compiler and linker version
=>
2、第二种用法:
(1) 输入命令:help(或?) 命令名
(2) 作用:可以查看命令的详细用法
(3) 结果:以“bootz”这个命令为例
=> help bootz
bootz - boot Linux zImage image from memoryUsage:
bootz [addr [initrd[:size]] [fdt]]
- boot Linux zImage stored in memory
The argument 'initrd' is optional and specifies the address
of the initrd in memory. The optional argument ':size' allows
specifying the size of RAW initrd.
When booting a Linux kernel which requires a flat device-tree
a third argument is required which is the address of the
device-tree blob. To boot that kernel without an initrd image,
use a '-' for the second argument. If you do not pass a third
a bd_info struct will be passed instead=>
二、信息查询命令
常用的和信息查询有关的命令有 3 个: bdinfo、 printenv 和 version:
1、bdinfo命令
(1) 输入命令:bdinfo
(2) 作用:用于查看板子信息;
(3) 结果:
=> bdinfo
arch_number = 0x00000000
boot_params = 0x80000100
DRAM bank = 0x00000000
-> start = 0x80000000
-> size = 0x10000000
eth0name = FEC1
ethaddr = b8:ae:1d:01:00:00
current eth = FEC1
ip_addr = 192.168.31.50
baudrate = 115200 bps
TLB addr = 0x8FFF0000
relocaddr = 0x8FF56000
reloc off = 0x08756000
irq_sp = 0x8EF53EA0
sp start = 0x8EF53E90
=>
2、printenv 命令
(1) 输入命令:printenv
(2) 作用:输出环境变量信息;
(3) 结果:
=> printenv
baudrate=115200
board_name=EVK
board_rev=14X14
boot_fdt=try
bootargs=console=ttymxc0,115200 rw nfsroot=192.168.31.116:/home/can/linux/nfs/rootfs ip=192.168.31.50:192.168.31.116:192.168.31.1:255.255.255.0::eth0:off
bootcmd=nfs 80800000 192.168.31.116:/home/can/linux/nfs/zImage;nfs 83000000 192.168.31.116:/home/can/linux/nfs/imx6ull-alientek-emmc.dtb;bootz 80800000 - 83000000
bootcmd_mfg=run mfgtool_args;bootz ${loadaddr} ${initrd_addr} ${fdt_addr};
bootdelay=5
bootfile=/home/can/linux/nfs/zImage
bootscript=echo Running bootscript from mmc ...; source
console=ttymxc0
ethact=FEC1
ethaddr=b8:ae:1d:01:00:00
ethprime=FEC
fdt_addr=0x83000000
fdt_file=imx6ull-14x14-emmc-4.3-800x480-c.dtb
fdt_high=0xffffffff
fileaddr=80800000
filesize=594ba0
findfdt=if test $fdt_file = undefined; then if test $board_name = EVK && test $board_rev = 9X9; then setenv fdt_file imx6ull-9x9-evk.dtb; fi; if test $board_name = EVK && test $board_rev = 14X14; then setenv fdt_file imx6ull-14x14-evk.dtb; fi; if test $fdt_file = undefined; then echo WARNING: Could not determine dtb to use; fi; fi;
gatewayip=192.168.31.1
image=zImage
initrd_addr=0x83800000
initrd_high=0xffffffff
ip_dyn=yes
ipaddr=192.168.31.50
loadaddr=0x80800000
loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${script};
loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}
loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}
logo_file=alientek.bmp
mfgtool_args=setenv bootargs console=${console},${baudrate} rdinit=/linuxrc g_mass_storage.stall=0 g_mass_storage.removable=1 g_mass_storage.file=/fat g_mass_storage.ro=1 g_mass_storage.idVendor=0x066F g_mass_storage.idProduct=0x37FF g_mass_storage.iSerialNumber="" clk_ignore_unused
mmcargs=setenv bootargs console=${console},${baudrate} root=${mmcroot}
mmcautodetect=yes
mmcboot=echo Booting from mmc ...; run mmcargs; if test ${boot_fdt} = yes || test ${boot_fdt} = try; then if run loadfdt; then bootz ${loadaddr} - ${fdt_addr}; else if test ${boot_fdt} = try; then bootz; else echo WARN: Cannot load the DT; fi; fi; else bootz; fi;
mmcdev=1
mmcpart=1
mmcroot=/dev/mmcblk1p2 rootwait rw
netargs=setenv bootargs console=${console},${baudrate} root=/dev/nfs ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp
netboot=echo Booting from net ...; run netargs; if test ${ip_dyn} = yes; then setenv get_cmd dhcp; else setenv get_cmd tftp; fi; ${get_cmd} ${image}; if test ${boot_fdt} = yes || test ${boot_fdt} = try; then if ${get_cmd} ${fdt_addr} ${fdt_file}; then bootz ${loadaddr} - ${fdt_addr}; else if test ${boot_fdt} = try; then bootz; else echo WARN: Cannot load the DT; fi; fi; else bootz; fi;
netmask=255.255.255.0
panel=ATK-LCD-4.3-800x480
script=boot.scr
serverip=192.168.31.116
splashimage=0x88000000
splashpos=m,m
stderr=serial
stdin=serial
stdout=serialEnvironment size: 2895/8188 bytes
=>
3、version 命令
(1) 输入命令:version
(2) 作用:查看 uboot 的版本号;
(3) 结果:
=> version
U-Boot 2016.03-gee88051 (Nov 05 2021 - 17:58:55 +0800)
arm-poky-linux-gnueabi-gcc (GCC) 5.3.0 //编译器
GNU ld (GNU Binutils) 2.26.0.20160226
=>
三、环境变量操作命令
环境变量的操作涉及到两个命令: setenv 和 saveenv
1、setenv 命令用于设置或者修改环境变量的值, saveenv 命令用于保存修改后的环境变量:
(1) 比如我们要将环境变量 bootdelay 改为 5,就可以使用如下所示命令:
=> setenv bootdelay 5
=> saveenv
Saving Environment to MMC...
Writing to MMC(1)... done
=>
修改 bootdelay 以后,重启开发板, uboot 就是变为 5 秒倒计时
(2) 有时候我们修改的环境变量值可能会有空格, 比如 bootcmd、 bootargs 等, 这个时候环境变
量值就得用单引号括起来:
=> setenv bootargs 'console=ttymxc0,115200 root=/dev/mmcblk1p2 rootwait rw'
=> saveenv
Saving Environment to MMC...
Writing to MMC(1)... done
=>
其中“console=ttymxc0,115200”、“root=/dev/mmcblk1p2”、“rootwait”和“rw”相当于四组“值”,
这四组“值”之间用空格隔开,所以需要使用单引号‘’将其括起来,表示这四组“值”都属
于环境变量 bootargs。
2、新建环境变量
(1) 命令 setenv 也可以用于新建命令,用法和修改环境变量一样,比如我们新建一个环境变量
author, author 的值为 test_cmd,那么就可以使用如下命令:
=> setenv author test_cmd //设置环境变量 author ,值为 test_cmd
=> saveenv
Saving Environment to MMC...
Writing to MMC(1)... done
=> printenv //使用 printenv 查看是否存在环境变量
author=test_cmd //存在
baudrate=115200
board_name=EVK
board_rev=14X14
boot_fdt=try
(2) 删除环境变量,直接设置不赋值就行:
=> setenv author //变量不赋值
=> saveenv
Saving Environment to MMC...
Writing to MMC(1)... done
=> printenv //查看变量已经不存在
baudrate=115200
board_name=EVK
board_rev=14X14
boot_fdt=try
四、网络操作命令
3.1、配置好开发板网络环境:将开发板和主机 PC 都连接到同一个路由器上, 然后设置相关环境变量:
环境变量 | 描述 |
ipaddr | 开发板 ip 地址,可以不设置,使用 dhcp 命令来从路由器获取 IP 地址。 |
ethaddr | 开发板的 MAC 地址,一定要设置。 |
gatewayip | 网关地址。 |
netmask | 子网掩码。 |
serverip | 服务器 IP 地址,也就是 Ubuntu 主机 IP 地址,用于调试代码。 |
=> setenv ipaddr 192.168.31.50
=> setenv ethaddr b8:ae:1d:01:00:00
=> setenv gatewayip 192.168.31.1
=> setenv netmask 255.255.255.0
=> setenv serverip 192.168.31.116
=> saveenv
Saving Environment to MMC...
Writing to MMC(1)... done
=>
3.2、uboot 支持大量的网络相关命令,比如 ping、dhcp、nfs 和 tftp;
1、ping 命令
开发板的网络能否使用,是否可以和服务器(Ubuntu 主机)进行通信,通过 ping 命令就可以验证,直接 ping 服务器的 IP 地址即可,比如我的服务器 IP 地址为 192.168.31.116,命令如下:
=> ping 192.168.31.116 //主机 ubuntu ip 地址
FEC1 Waiting for PHY auto negotiation to complete.... done
Using FEC1 device
host 192.168.31.116 is alive //主机存在,ping 成功
=>
注意!只能在 uboot 中 ping 其他的机器,其他机器不能 ping uboot,因为 uboot 没有对 ping
命令做处理,如果用其他的机器 ping uboot 的话会失败!
2、dhcp 命令
用于从路由器获取 IP 地址:
=> dhcp
BOOTP broadcast 1
BOOTP broadcast 2
*** Unhandled DHCP Option in OFFER/ACK: 43
*** Unhandled DHCP Option in OFFER/ACK: 43
DHCP client bound to address 192.168.31.115 (336 ms) //获取到的 ip 地址
Using FEC1 device
TFTP from server 192.168.31.1; our IP address is 192.168.31.115
Filename '/home/can/linux/nfs/zImage'.
Load address: 0x80800000
Loading: T T T T
3、nfs 命令
一般使用 uboot 中的 nfs 命令将 Ubuntu 中的文件下载到开发板的 DRAM 中,在使用之前需要开启 Ubuntu 主机的 NFS 服务,并且要新建一个 NFS 使用的目录,以后所有要通过NFS 访问的文件都需要放到这个 NFS 目录中。
=> help nfs
nfs - boot image via network using NFS protocolUsage:
nfs [loadAddress] [[hostIPaddr:]bootfilename]
=>
loadAddress 是要保存的 DRAM 地址, [[hostIPaddr:]bootfilename]是要下载的文件地址。
用例:
bootcmd=nfs 80800000 192.168.31.116:/home/can/linux/nfs/zImage;nfs 83000000 192.168.31.116:/home/can/linux/nfs/imx6ull-alientek-emmc.dtb;bootz 80800000 - 8300000
4、tftp 命令
tftp 命令的作用和 nfs 命令一样,都是用于通过网络下载东西到 DRAM 中,只是 tftp 命令使用的 TFTP 协议, Ubuntu 主机作为 TFTP 服务器,需要在 Ubuntu 上搭建 TFTP 服务器。
五、EMMC操作命令
mmc 是一系列的命令,其后可以跟不同的参数,输入“? mmc”即可查看 mmc 有关的命令:
=> ? mmc
mmc - MMC sub systemUsage:
mmc info - display info of the current MMC device
mmc read addr blk# cnt
mmc write addr blk# cnt
mmc erase blk# cnt
mmc rescan
mmc part - lists available partition on current mmc device
mmc dev [dev] [part] - show or set current mmc device [partition]
mmc list - lists available devices
mmc hwpartition [args...] - does hardware partitioning
arguments (sizes in 512-byte blocks):
[user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes
[gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition
[check|set|complete] - mode, complete set partitioning completed
WARNING: Partitioning is a write-once setting once it is set to complete.
Power cycling is required to initialize partitions after set to complete.
mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode
- Set the BOOT_BUS_WIDTH field of the specified device
mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>
- Change sizes of boot and RPMB partitions of specified device
mmc partconf dev boot_ack boot_partition partition_access
- Change the bits of the PARTITION_CONFIG field of the specified device
mmc rst-function dev value
- Change the RST_n_FUNCTION field of the specified device
WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.
mmc setdsr <value> - set DSR register value=>
命令 | 描述 |
mmc info | 输出 MMC 设备信息。 |
mmc read | 读取 MMC 中的数据。 |
mmc write | 向 MMC 设备写入数据。 |
mmc erase | 擦除 MMC 设备。 |
mmc rescan | 扫描 MMC 设备。 |
mmc part | 列出 MMC 设备的分区。 |
mmc dev | 切换 MMC 设备。 |
mmc list | 列出当前有效的所有 MMC 设备。 |
mmc hwpartition | 设置 MMC 设备的分区。 |
mmc bootbus...... | 设置指定 MMC 设备的 BOOT_BUS_WIDTH 域的值。 |
mmc bootpart...... | 设置指定 MMC 设备的 boot 和 RPMB 分区的大小。 |
mmc partconf...... | 设置指定 MMC 设备的 boot 和 RPMB 分区的大小。 |
mmc rst | 复位 MMC 设备。 |
mmc setdsr | 设置 DSR 寄存器的值。 |
六、其它常用命令
uboot 中还有其他一些常用的命令,比如 reset、run 和 mtest 等。
1、reset 命令
重启 uboot:
=> reset
resetting ...
.........
2、run 命令
用于运行环境变量中定义的命令,但是 run 命令最大的作用在于运行我们自定义的环境变量,使用setenv命令可以创建自定义的环境变量,例如:可以自己定义一个 can_bootcmd 变量,用来存放类似 bootcmd的启动参数,然后用 run 命令来启动:
run can_bootcmd