U-Boot 命令解析(一)

简介: U-Boot 命令解析(一)

一般情况下,U-Boot 启动后、Linux 内核启动倒计时结束前,通过按下任何按键即可中断 Linux 内核的启动,并进入 U-Boot 的命令模式。我们可以通过输入一些命令对 U-Boot 执行一些操作。


在 U-Boot 命令模式下,我们可以通过输入 help 或者 ? 查看 U-Boot 支持的所有命令以及这些命令的主要功能:

=> 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]
bmp     - manipulate BMP image data
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
clrlogo - fill the boot logo area with black
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
fdt     - flattened device tree utility commands
flinfo  - print FLASH memory information
forlinx - forlinx params menu
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

查询命令

  • 输入 bdinfo 查看开发板信息:


  • 输入 printenv 查看 U-Boot 环境变量,如当前串口的波特率为 115200,Linux 内核启动倒计时为 3 秒:

  • 输入 version 查看 U-Boot 版本


环境变量操作命令

环境变量的操作涉及到两个命令:setenv 和 saveenv,命令 setenv 用于设置或者修改环境变量的值,命令 saveenv 用于保存修改后的环境变量。一般环境变量是存放在外部 Flash 中的,U-Boot 启动时会将环境变量从 Flash 读取到 DRAM 中。使用命令 setenv 修改的是 DRAM 中的环境变量值,修改后要使用 saveenv 命令将修改后的环境变量保存到 Flash 中,否则 U-Boot 下一次重启会继续使用以前的环境变量值。

=> setenv
setenv - set environment variables

Usage:
setenv [-f] name value ...
    - [forcibly] set environment variable 'name' to 'value ...'
setenv [-f] name
    - [forcibly] delete environment variable 'name'
=> saveenv
Saving Environment to MMC...
Writing to MMC(1)... done

修改环境变量

  • 以修改 Linux 内核启动倒计时为例:

  • 修改倒计时为 5 秒:
setenv bootdelay 5
saveenv
  • 输入 printenv 查看环境变量:


  • 重启开发板,5 秒倒计时:

新建环境变量

  • 新建一个 author 环境变量
setenv author alpha
saveenv


  • 查看新建的环境变量:

删除环境变量,

  • 只要将环境变量设为空即可:
setenv author
saveenv
  • 查看 author 环境变量已删除:

接 U-Boot 常用命令(一),我们继续介绍 U-Boot 的常用命令。

内存操作命令

内存查看命令 md

  • md 使用方法:
=> ? md
md - memory display

Usage:
md [.b, .w, .l] address [# of objects]
  • 命令中的 [.b .w .l] 对应 byte、word 和 long,[# of objects] 表示要查看的数据类型的长度,用十六进制表示。比如查看内存地址 0x80000000 起始的连续 16 个 byte 的内容:
md.b 80000000 10

  • 每次敲下回车可以继续查看下一个 16 个 byte:

  • 查看内存地址 0x80000000 起始的连续 16 个 word 的内容:

内存修改命令 nm

  • nm 使用方法:
=> ? nm
nm - memory modify (constant address)

Usage:
nm [.b, .w, .l] address


  • 如修改 0x80000000 地址的 long 型数据:
nm.l 80000000
  • 000001ae 表示地址 0x80000000 当前的数据,?提示输入要修改的数据 0x12345678,输入完成后按下回车,再输入 q 退出:

内存修改命令 mm

  • mm 支持连续修改内存,内存地址自增:
=> ? mm
mm - memory modify (auto-incrementing address)

Usage:
mm [.b, .w, .l] address
  • 如修改从 0x80000000 地址开始的连续 3 个 long 数据,将内容都修改为 0x12345678:
mm.l 80000000


  • 输入 3 次 12345678,最后一次输入 q:

  • 查看内存:

内存填充命令 mw

  • mw 可以以一个指定的数据填充一段内存:
=> ? mw
mw - memory write (fill)

Usage:
mw [.b, .w, .l] address value [count]
  • 如将从 0x80000000 地址开始的 16 个 long 填充为 0xa0a0a0a0:
md.l 80000000 a0a0a0a0 10


  • 查看内存:

内存拷贝命令 cp

  • cp 用于将一段内存的数据拷贝到另一段内存中:
=> ? cp   
cp - memory copy

Usage:
cp [.b, .w, .l] source target count
  • 如将 0x80000000 地址处的数据拷贝到 0x80000100 处,长度为 16 个 long:
cp.l 80000000 80000100 10
  • 查看内存:

内存对比命令 cmp

  • cmp 用于比较两段内存的数据是否一致:
=> ? cmp
cmp - memory compare

Usage:
cmp [.b, .w, .l] addr1 addr2 count
  • 如比较 0x80000000 和 0x80000100 这两个地址数据是否相等,比较长度为 16 个 long 的数据:
cmp.l 80000000 80000100 10
  • 再比较 0x80000200 和 0x80000300 这两个地址数据是否相等,比较长度为 16 个 long 的数据:

  • 未完待续……

更多内容

  • CSDN博客:@Hello阿尔法
  • 哔哩哔哩:@Hello阿尔法
  • 知乎:@Hello阿尔法
相关文章
|
2月前
|
缓存 网络协议 Linux
【Shell 命令集合 网络通讯 】Linux 配置DNS dnsconf 命令 使用教程
【Shell 命令集合 网络通讯 】Linux 配置DNS dnsconf 命令 使用教程
39 0
|
2月前
|
Shell Linux 开发工具
【Shell 命令集合 文件管理】Linux 高级的文件管理器 mc 命令解析
【Shell 命令集合 文件管理】Linux 高级的文件管理器 mc 命令解析
42 0
|
2月前
|
存储 Shell Linux
【Shell 命令集合 文件管理】Linux 更新locate命令所使用的数据库 updatedb命令解析
【Shell 命令集合 文件管理】Linux 更新locate命令所使用的数据库 updatedb命令解析
155 0
|
2月前
|
开发工具 git
|
3月前
|
安全 Unix Shell
【Linux】Linux系统编程——Linux命令解析器
【Linux】Linux系统编程——Linux命令解析器
52 1
|
3月前
|
安全 网络协议 Linux
Linux网络常用命令解析
Linux网络常用命令解析
33 0
|
4月前
|
安全 Go 开发工具
go clean命令 完全解析
go clean命令 完全解析
145 0
|
5月前
|
Linux
Linux 命令 ps aux 命令解析
Linux 命令 ps aux 命令解析
95 0
|
5月前
|
存储 开发工具 数据库
Git命令大全|必会常用Git命令解析
Git是目前最流行的版本控制工具,熟练掌握Git命令对于开发者来说非常重要。本文收集了常用的Git命令,包括初始化仓库、克隆远程仓库、提交修改等操作,详解每个命令的作用和用法,让您轻松学会使用Git进行版本控制。
267 0
|
5天前
|
XML 人工智能 Java
Spring Bean名称生成规则(含源码解析、自定义Spring Bean名称方式)
Spring Bean名称生成规则(含源码解析、自定义Spring Bean名称方式)

推荐镜像

更多