U-BOOT的常用命令
我们以JZ2440 V3开发板,采用U-BOOT 1.1.6版本,熟悉常用命令与环境变量
1、help命令
(1)查询所有的命令
OpenJTAG> help
? - alias for 'help'
autoscr - run script from memory
base - print or set address offset
bdinfo - print Board Info structure
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
chpart - change active partition
cmp - memory compare
coninfo - print console devices and information
cp - memory copy
crc32 - checksum calculation
date - get/set/reset date & time
dcache - enable or disable data cache
echo - echo args to console
erase - erase FLASH memory
flinfo - print FLASH memory information
fsinfo - print information about filesystems
fsload - load binary file from a filesystem image
go - start application at address 'addr'
help - print online help
icache - enable or disable instruction cache
iminfo - print header information for application image
imls - list all images found in flash
itest - return true/false on integer compare
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
menu - display a menu, to select the items to do something
mm - memory modify (auto-incrementing)
mtdparts- define flash/nand partitions
mtest - simple RAM test
mw - memory write (fill)
nand - NAND sub-system
nboot - boot from NAND device
nfs - boot image via network using NFS protocol
nm - memory modify (constant address)
ping - send ICMP ECHO_REQUEST to network host
printenv- print environment variables
protect - enable or disable FLASH write protection
rarpboot- boot image via network using RARP/TFTP protocol
reset - Perform RESET of the CPU
run - run commands in an environment variable
saveenv - save environment variables to persistent storage
setenv - set environment variables
sleep - delay execution for some time
suspend - suspend the board
tftpboot- boot image via network using TFTP protocol
usbslave - get file from host(PC)
version - print monitor version
(2)查询某一个命令的用法
help+命令的名称
OpenJTAG> help printenv
printenv
- print values of all environment variables
printenv name ...
- print value of environment variable 'name'
2、环境变量的操作命令
(1)如何理解环境变量:
环境变量就好像程序的全局变量一样。程序中任何地方都可以根据需要去调用或者更改环境变量(一般都是调用),环境变量和全局变量不同之处在于:全局变量的生命周期是在程序的一次运行当中,开始运行时诞生程序结束时死亡,下次运行程序时从头开始;但是环境变量被存储在Flash的另一块专门区域(Flash上有一个环境变量分区),一旦我们在程序中保存了该环境变量,那么下次开机时该环境变量的值将维持上一次更改保存后的值。
(2)环境变量如何参与程序运行
环境变量有2份,一份在Flash中,另一份在DDR中。uboot开机时一次性从Flash中读取全部环境变量到DDR中作为环境变量的初始化值,然后使用过程中都是用DDR中这一份,用户可以用saveenv指令将DDR中的环境变量重新写入Flash中去更新Flash中环境变量。下次开机时又会从Flash中再读一次。
(3)printenv/print
print命令不用带参数,作用是打印出系统中所有的环境变量。
OpenJTAG> print
bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200
bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0
bootdelay=2
baudrate=115200
ethaddr=08:00:3e:26:0a:5b
ipaddr=192.168.1.17
serverip=192.168.1.11
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial
mtdids=nand0=nandflash0
mtdparts=mtdparts=nandflash0:[email protected](bootloader),128k(params),2m(kernel),-(root)
partition=nand0,0
mtddevnum=0
mtddevname=bootloader
Environment size: 450/131068 bytes
(4)设置(添加/更改)环境变量:setenv/set
setenv name value ...
- set environment variable 'name' to 'value ...'
setenv name
- delete environment variable 'name'
OpenJTAG> set bootdelay 3
OpenJTAG> print
bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200
bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0
baudrate=115200
ethaddr=08:00:3e:26:0a:5b
ipaddr=192.168.1.17
serverip=192.168.1.11
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial
mtdids=nand0=nandflash0
mtdparts=mtdparts=nandflash0:[email protected](bootloader),128k(params),2m(kernel),-(root)
partition=nand0,0
mtddevnum=0
mtddevname=bootloader
bootdelay=3
(5)保存环境变量的更改:saveenv/save
上面操作只是更新了内存中的环境变量,但是flash中的环境变量还是原来的,下次开机时,bootdelay还是2。
saveenv/save命令不带参数,直接执行,作用是将内存中的环境变量的值同步保存到Flash中环境变量的分区。注意:环境变量的保存是整体的覆盖保存,也就是说内存中所有的环境变量都会整体的将Flash中环境变量分区中原来的内容整体覆盖。
3、内存操作指令:mm、mw、md
(1)DDR中是没有分区的(只听说过对硬盘、Flash进行分区,没听说过对内存进行分区····),但是内存使用时要注意,千万不能越界踩到别人了。因为uboot是一个裸机程序,不像操作系统会由系统整体管理所有内存,系统负责分配和管理,系统会保证内存不会随便越界。然后裸机程序中uboot并不管理所有内存,内存是散的随便用的,所以如果程序员(使用uboot的人)自己不注意就可能出现自己把自己的数据给覆盖了。
(2)md就是memory display,用来显示内存中的内容。
OpenJTAG> help md
md [.b, .w, .l] address [# of objects]
- memory display
其中
.b byte 以字节为单位进行操作
.w word 以双字为单位进行操作
.l long 以四字节为单位进行操作
OpenJTAG> md.b 30000000
30000000: 20 00 00 c0 00 00 00 c0 08 00 00 c0 08 00 00 c0 ...............
30000010: 10 00 00 c0 10 00 00 c0 18 00 00 c4 18 00 00 c0 ................
30000020: 20 40 00 c0 20 00 00 c0 28 00 10 c0 28 00 00 c8 @.. ...(...(...
30000030: 30 00 00 c0 30 00 00 c0 3a 00 20 c0 38 00 00 c0 0...0...:. .8...
30000040: 40 00 00 c0 40 00 00 c0 48 00 00 c0 48 00 00 c0 @[email protected]
30000050: 50 00 01 c4 50 00 00 c0 58 00 00 c0 50 00 00 c0 P...P...X...P...
OpenJTAG> md.w 30000000
30000000: 0020 c000 0000 c000 0008 c000 0008 c000 ...............
30000010: 0010 c000 0010 c000 0018 c400 0018 c000 ................
30000020: 4020 c000 0020 c000 0028 c010 0028 c800 @.. ...(...(...
30000030: 0030 c000 0030 c000 003a c020 0038 c000 0...0...:. .8...
30000040: 0040 c000 0040 c000 0048 c000 0048 c000 @[email protected]
30000050: 0050 c401 0050 c000 0058 c000 0050 c000 P...P...X...P...
30000060: 0060 c000 0060 c000 0068 c000 0068 c000 `...`...h...h...
OpenJTAG> md.l 30000000
30000000: c0000020 c0000000 c0000008 c0000008 ...............
30000010: c0000010 c0000010 c4000018 c0000018 ................
30000020: c0004020 c0000020 c0100028 c8000028 @.. ...(...(...
30000030: c0000030 c0000030 c020003a c0000038 0...0...:. .8...
30000040: c0000040 c0000040 c0000048 c0000048 @[email protected]
(3)mw就是memory write,将内容写到内存中
OpenJTAG> help mw
mw [.b, .w, .l] address value [count]
- write memory
(4)mm就是memory modify,修改内存中的某一块,说白了还是写内存(如果需要批量的逐个单元的修改内存,用mm最合适)
OpenJTAG> help mm
mm [.b, .w, .l] address
- memory modify, auto increment address
4、启动内核指令:bootm、go
(1)uboot的终极目标就是启动内核,启动内核在uboot中表现为一个指令,uboot命令行中调用这个指令就会启动内核(不管成功与否,所以这个指令是一条死路)。
(2)差别:bootm启动内核同时给内核传参,而go命令启动内核不传参。bootm其实才是正宗的启动内核的命令,一般情况下都用这个;go命令本来不是专为启动内核设计的,go命令内部其实就是一个函数指针指向一个内存地址然后直接调用那个函数,go命令的实质就是PC直接跳转到一个内存地址去运行而已。go命令可以用来在uboot中执行任何的裸机程序(有一种调试裸机程序的方法就是事先启动uboot,然后在uboot中去下载裸机程序,用go命令去执行裸机程序)
OpenJTAG> help bootm
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
在uboot命令里面,使用中括号括起来的是可选项。 add是我们内核存放的地址,arg是传给内核的参数
5.nandflash的操作命令
OpenJTAG> help nand
nand info - show available NAND devices
nand device [dev] - show or set current device
nand read[.jffs2] - addr off|partition size
nand write[.jffs2] - addr off|partiton size - read/write `size' bytes starting
at offset `off' to/from memory address `addr'
nand read.yaffs addr off size - read the `size' byte yaffs image starting
at offset `off' to memory address `addr'
nand write.yaffs addr off size - write the `size' byte yaffs image starting
at offset `off' from memory address `addr'
nand read.raw addr off size - read the `size' bytes starting
at offset `off' to memory address `addr', without oob and ecc
nand write.raw addr off size - write the `size' bytes starting
at offset `off' from memory address `addr', without oob and ecc
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 at offset (UNSAFE)
nand biterr off - make a bit error at offset (UNSAFE)
nand lock [tight] [status] - bring nand to lock state or display locked pages
nand unlock [offset] [size] - unlock section
部分参考朱友鹏老师课件
上一篇: 【转】将文中标点替换成空格(收藏留用)
下一篇: 文本分析学习笔记