U-Boot常用命令介绍

U-Boot 上电启动后,按任意键可以退出自动启动状态,进入命令行。U-Boot 可支持几十个常用命令,通过这些命令,可以对开发板进行调试,引导 Linux 内核,还可以擦写 Flash 完成系统部署等功 能。掌握这些命令的使用,才能够顺利地进行嵌入式系统的开发。

输入 help 命令,可以得到当前 U-Boot 的所有命令列表。每一条命令后面是简单的命令说明。由于开发过程的需要,有必要先把 U-Boot 命令的用法弄清楚。接下来,根据每一条命令的 帮助信息,解释一下这些命令的功能和参数。

bootm

# help bootm
bootm - boot application image from memory
Usage:
bootm [addr [arg ...]]
	- boot application image stored in memory passing arguments 'arg ...'; when booting a Linux kernel,'arg' can be the address of an initrd image
  • bootm 命令可以引导启动存储在内存中的程序映像,这些内存包括 RAM 和可以永久保存的 Flash。
  • addr 是程序映像的地址,这个程序映像必须转换成 U-Boot 的格式。
  • 对于引导 Linux 内核有用,通常作为 U-Boot 格式的 RAMDISK 映像存 储地址;也可以是传递给 Linux 内核的参数,但默认情况下传递 bootargs 环境变量给内核。

bootp

# help bootp
bootp - boot image via network using BOOTP/TFTP protocol
Usage:
bootp [loadAddress] [[hostIPaddr:]bootfilename]
  • bootp 命令要求 DHCP 服务器分配 IP 地址,然后通过 TFTP 协议下载指定的文件到内存。
  • load Address 指下载文件存放的内存地址。
  • bootfilename 要下载的文件名称,这个文件应该在开发主机上准备好。

cmp

# help cmp
cmp - memory compare
Usage:
cmp[.b, .w, .l] addr1 addr2 count
  • cmp 命令可以比较两块内存中的内容。.b 以字节为单位;.w 以字为单位;.l 以长字为单 位。

  • addr1 是第一块内存的起始地址。

  • addr2 是第二块内存的起始地址。

  • count 是要比较的数目,单位是字节、字或者长字。

cp

# help cp
cp - memory copy
Usage:
cp[.b, .w, .l] source target count
  • cp 命令可以在内存中复制数据块,包括对 Flash 的读写操作。
  • source 是要复制的数据块起始地址。
  • target 是数据块要复制到的地址。这个地址如果在 Flash 中,那么会直接调用写 Flash 的函数操作。所以 U-Boot 写 Flash 就使用这个命令,当然需要先把对应 Flash 区域擦干净。
  • count 是要复制的数目,根据 cp.b、cp.w、cp.l 分别以字节、字、长字 为单位。

crc32

# help crc32
crc32 - checksum calculation
Usage:
crc32 address count [addr]
	- compute CRC32 checksum [save at addr]
  • crc32 命令可以计算存储数据的校验和。
  • address 是需要校验的数据起始地址。
  • count 是要校验的数据字节数。
  • addr 用来指定保存结果的地址。

echo

# help echo
echo - echo args to console
Usage:
echo [args..]
	- echo args to console; 
  • echo 命令回显参数。

erase

# help erase
erase - erase FLASH memory
Usage:
erase start end
	- erase FLASH from addr 'start' to addr 'end'
erase start +len
	- erase FLASH from addr 'start' to the end of sect w/addr 'start'+'len'-1
erase N:SF[-SL]
	- erase sectors SF-SL in FLASH bank # N
erase bank N
	- erase FLASH bank # N
erase all
	- erase all FLASH banks
  • 按照起始地址和结束地址:start 必须是擦除块的起始地址;end 必须是擦除末尾块的结 束地址,这种方式最常用。
  • 按照bank和扇区:N 表示 Flash 的bank号,SF 表示擦除起始扇区号,SL 表示擦除结束扇区 号。
  • 擦除整个bank:擦除组号为 N 的整个bank。
  • 擦除全部 Flash :只要给出一 个 all 的参数即可。

nand

nand 命令可以通过不同的参数实现对 Nand Flash 的擦除、读、写操作。 常见的几种命令的含义如下:

# help nand
nand - NAND sub-system
Usage:
nand info 
	- show available NAND devices
nand device [dev] 
	- show or set current device
nand read 
	- addr off|partition size
nand write 
	- addr off|partition size read/write 'size' bytes starting at offset 'off' to/from memory address 'addr', skipping bad blocks.
nand erase [clean] [off size] 	
	- erase 'size' bytes from offset 'off' (entire device if not specified)
nand bad 
	- show bad blocks
nand dump[.oob] off 
	- dump page
nand scrub 
	- really clean NAND erasing bad blocks (UNSAFE)
nand markbad off [...] 
	- mark bad block(s) at offset (UNSAFE)
nand biterr off 
	- make a bit error at offset (UNSAFE)
  • nand erase:擦除 Nand Flash。
  • nand read:读取 Nand Flash,遇到 flash 坏块时会出错。
  • nand write:写 Nand Flash,nand write 命令遇到 flash 坏块时会出错。

flinfo

# help flinfo
flinfo - print FLASH memory information
Usage:
flinfo
	- print information for all FLASH memory banks
flinfo N
	- print information for FLASH memory bank #N
  • flinfo 命令打印全部 Flash 组的信息,也可以只打印其中某个组。一般嵌入式系统的 Flash 只有一个组。

go

# help go
go - start application at address 'addr'
Usage:
go addr [arg ...]
	- start application at address 'addr' passing 'arg' as arguments
  • go 命令可以执行应用程序。
  • addr 是要执行程序的入口地址。
  • arg 是传递给程序的参数,可以不用。

iminfo

# help iminfo
iminfo - print header information for application image
Usage:
iminfo addr [addr ...]
	- print header information for application image starting at address 'addr' in memory; this includes verification of the image contents (magic number, header and payload checksums)
  • iminfo 命令可以打印程序映像的开头信息,包含了映像内容的校验(序列号、头和校验和)。
  • addr 指定映像的起始地址。可选的参数是指定更多的映像地址。

loadb

# help loadb
loadb - load binary file over serial line (kermit mode)
Usage:
loadb [ off ] [ baud ]
	- load binary file over serial line with offset 'off' and baudrate 'baud'
  • loadb 命令可以通过串口线下载二进制格式文件。

loads

# help loads
loads - load S-Record file over serial line
Usage:
loads [ off ]
	- load S-Record file over serial line with offset off
  • loads 命令可以通过串口线下载 S-Record 格式文件。

mw

# help mw
mw - memory write (fill)
Usage:
mw[.b, .w, .l] address value [count]
  • mw 命令可以按照字节、字、长字写内存,.b、.w、.l 的用法与 cp 命令相同。
  • address 是要写的内存地址。
  • value 是要写的值。
  • count 是要写单位值的数目。

nfs

# help nfs
nfs - boot image via network using NFS protocol
Usage:
nfs [loadAddress] [[hostIPaddr:]bootfilename]
  • nfs 命令可以使用 NFS 网络协议通过网络启动映像。

printenv

# help printenv
printenv - print environment variables
Usage:
printenv
	- print values of all environment variables
printenv name ...
	- print value of environment variable 'name'
  • printenv 命令打印环境变量。可以打印全部环境变量,也可以只打印参数中列出的环境 变量。

protect

help protect
protect - enable or disable FLASH write protection
Usage:
protect on start end
	- protect FLASH from addr 'start' to addr 'end'
protect on start +len
	- protect FLASH from addr 'start' to end of sect w/addr 'start'+'len'-1
protect on N:SF[-SL]
	- protect sectors SF-SL in FLASH bank # N
protect on bank N
	- protect FLASH bank # N
protect on all
	- protect all FLASH banks
protect off start end
	- make FLASH from addr 'start' to addr 'end' writable
protect off start +len
	- make FLASH from addr 'start' to end of sect w/addr 'start'+'len'-1 wrtable
protect off N:SF[-SL]
	- make sectors SF-SL writable in FLASH bank # N
protect off bank N
	- make FLASH bank # N writable
protect off all
	- make all FLASH banks writabl
  • protect 命令是对 Flash 写保护的操作,可以使能和解除写保护
  • on 代表使能写保护;off 代表解除写保护。
  • start end是指定 Flash 写保护操作范围,与擦除的方式相同。

rarpboot

# help rarpboot
rarpboot - boot image via network using RARP/TFTP protocol
Usage:
rarpboot [loadAddress] [[hostIPaddr:]bootfilename]
  • rarpboot 命令可以使用 TFTP 协议通过网络启动映像,也就是把指定的文件下载到指定 地址,然后执行。

run

# help run
run - run commands in an environment variable
Usage:
run var [...]
	- run the commands in the environment variable(s) 'var'
  • run 命令可以执行环境变量中的命令,后面参数可以跟几个环境变量名

setenv

# help setenv
setenv - set environment variables
Usage:
setenv name value ...
	- set environment variable 'name' to 'value ...'
setenv name
	- delete environment variable 'name'
  • 如果没有第 2 个参数,表示删除这个环境变量

saveenv

# help saveenv
saveenv - save environment variables to persistent storage
Usage:
saveenv
  • saveenv 命令可以保存环境变量到存储设备。

sleep

help sleep
sleep - delay execution for some time
Usage:
sleep N
	- delay execution for N seconds 
  • sleep 命令可以延迟 N 秒执行,N为十进制数。

nm

# help nm
nm - memory modify (constant address)
Usage:
nm[.b, .w, .l] addres
  • nm 命令可以修改内存,可以按照字节、字、长字操作。
  • 参数 address 是要读出并且修改的内存地址

tftpboot

tftpboot - boot image via network using TFTP protocol
Usage:
tftpboot [loadAddress] [[hostIPaddr:]bootfilename]
  • tftpboot 命令可以通过使用 TFTP 协议在网络上下载二进制格式文件。
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Leon_George

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值