免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1128 | 回复: 0

认识u-boot四、U-boot的使用(一) [复制链接]

论坛徽章:
0
发表于 2011-02-20 10:23 |显示全部楼层
我一贯认为:对于一个技术类的东西,你连用都不会用,那根本就不可能会开发。就好像一个人连Linux不会用,那还谈何开发Linux程序呢?
    同样的要开发和移植U-boot,首先要对U-boot有一定的了解,起码要会使用。
    所以这里我们首先熟悉一下U-boot的使用以及如何将U-boot烧入mini2440。
    当然在这之前首先必须保证你的板子上已经有了U-boot。如果没有那就先烧上一个吧。针对mini2440的U-boot-2009.11的bin文件我已经上传到了博客中,可以直接烧入,请到这里下载:

把它烧到mini2440的NAND或者NOR Flash的起始地址即可,你可以使用OpenJTAG下载烧写:
 
 
也可以用板上已有的boottloader烧写,也可以适用H-JTAG用并口烧(这是最直接最快的)。
 
常用的U-boot命令详解
 
    U-boot发展到现在,他的命令行模式已经非常接近Linux下的shell了,在我编译的U-boot-2009.11中的命令行模式模式下支持“Tab”键的命令补全和命令的历史记录功能。而且如果你输入的命令的前几个字符和别的命令不重复,那么你就只需要打这几个字符即可,比如我想看这个U-boot的版本号,命令就是“ version”,但是在所有的命令中没有其他任何一个的命令是由“v”开头的,所以只需要输入“v”即可。

[u-boot@MINI2440]# version

U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
[u-boot@MINI2440]# v

U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
[u-boot@MINI2440]# base
Base Address: 0x00000000
[u-boot@MINI2440]# ba
Base Address: 0x00000000

 

    由于U-boot支持的命令实在太多,一个一个细讲不现实,也没有必要。所以下面我挑一些烧写和引导常用命令介绍一下,其他的命令大家就举一反三,或者“help”吧!

(1)获取帮助
命令:help 或 ?
功能:查看当前U-boot版本中支持的所有命令。

[u-boot@MINI2440]# help
? - alias for 'help'
askenv - get environment variables from stdin
base - print or set address offset
bdinfo - print Board Info structure
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
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
dhcp - boot image via network using DHCP/TFTP protocol
echo - echo args to console
editenv - edit environment variable
eeprom - EEPROM sub-system
erase - erase FLASH memory
exit - exit script
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls - list files in a directory (default /)
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
i2c - I2C sub-system
icache - enable or disable instruction cache
iminfo - print header information for application image
imls - list all images found in flash
imxtract- extract a part of a multi-image
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
mm - memory modify (auto-incrementing address)
mmc - MMC sub-system
mtest - simple RAM read/write 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
reginfo - print register information
reset - Perform RESET of the CPU
run - run commands in an environment variable
saveenv - save environment variables to persistent storage
setenv - set environment variables
showvar - print local hushshell variables
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
unzip - unzip a memory region
usb - USB sub-system
usbboot - boot from USB device
version - print monitor version

 

如果你想获取某条命令的更详细的帮助,可以使用:

help <你想要查的指令>
或者 ? <你想要查的指令> 
甚至 h <你想要查的指令缩写>


以bmp指令为例:

[u-boot@MINI2440]# help bmp
bmp - manipulate BMP image data

Usage:
bmp info <imageAddr> - display image info
bmp display <imageAddr> [x y] - display image at x,y
[u-boot@MINI2440]# ? bmp
bmp - manipulate BMP image data

Usage:
bmp info <imageAddr> - display image info
bmp display <imageAddr> [x y] - display image at x,y
[u-boot@MINI2440]# h bm
bmp - manipulate BMP image data

Usage:
bmp info <imageAddr> - display image info
bmp display <imageAddr> [x y] - display image at x,y

(2)环境变量(environment variables,简称ENV)与相关指令
和shell类似,U-Boot也有环境变量。一些U-boot默认的环境变量如下:

 

   

   

bootdelay

执行自动启动(bootcmd中的命令)的等候秒数

baudrate

串口控制台的波特率

netmask

以太网的网络掩码

ethaddr

以太网的MAC地址

bootfile

默认的下载文件名

bootargs

传递给Linux内核的启动参数

bootcmd

自动启动时执行命令

serverip

TFTP服务器端的IP地址

ipaddr

本地的IP地址

stdin

标准输入设备,一般是串口

stdout

标准输出,一般是串口,也可是LCDVGA

stderr

标准出错,一般是串口,也可是LCDVGA

 

要看到你的板上的ENV值可使用printenv命令,例如我的板子:

 

[u-boot@MINI2440]# printenv
bootargs=noinitrd root=/dev/nfs rw nfsroot=192.168.0.1:/home/tekkaman/working/nfs/rootfs ip=192.168.0.2:192.168.0.1::255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M
bootcmd=nfs 0x30008000 192.168.0.1:/home/tekkaman/working/nfs/zImage.img;bootm
bootdelay=1
baudrate=115200
ethaddr=08:08:11:18:12:27
ipaddr=192.168.0.2
serverip=192.168.0.1
gatewayip=192.168.0.1
netmask=255.255.255.0
tekkaman=bmp d 70000
 stdin=serial
stdout=serial
stderr=serial
ethact=dm9000

Environment size: 470/131068 bytes


      你会发现有些有的ENV我没有,还有一个“tekkaman”的ENV。原因是如果你没有设置这个环境变量就不会打印出,你也可以自己定义ENV,并在命令中使用${ENV}来调用它。同时你也可以删除这个ENV。设置ENV的命令是setenv,格式为:

 

setenv name value


第1个参数是环境变量的名称。
第2个参数是要设置的值,如果没有第2个参数,表示删除这个环境变量。

例如:我先将”tekkaman”参数删除,再设置,最后在一个命令串中调用。

[u-boot@MINI2440]# printenv tekkaman
tekkaman=bmp d 70000
[u-boot@MINI2440]# setenv tekkaman
[u-boot@MINI2440]# printenv tekkaman
## Error: "tekkaman" not defined
[u-boot@MINI2440]# setenv tekkaman echo "I am Tekkaman Ninja!"
[u-boot@MINI2440]# printenv tekkaman
tekkaman=echo I am Tekkaman 
[u-boot@MINI2440]# echo I Love Linux ;${tekkaman}
I Love Linux
I am Tekkaman

 

当你设置了ENV,它只保存在内存中,如果你要它保存在存放ENV的固态存储器中,请使用:saveenv。

 

[u-boot@MINI2440]# saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x6000000000002 -- 0% complete.
Writing to Nand... done

如果在启动的时候会看到U-boot打印出:“Warning - bad CRC, using default environment”,说明U-boot没有在存放ENV的固态存储器中找到有效的ENV,只好使用你在编译的时候定义的默认ENV。如果U-boot存放ENV的固态存储器的驱动是OK的,那么只要运行 saveenv就可以把默认ENV写入固态存储器,下次启动就不会有这个警告了。
       ENV可以放在许多固体存储器中,对于mini2440来说Nor Flash、Nand Flash或EEPROM都可以,就看你如何配置了(include/configs下的配置文件)。例如:
      Nor Flash

#define CONFIG_ENV_IS_IN_FLASH 1
#define CONFIG_ENV_OFFSET 0X40000
#define CONFIG_ENV_SIZE            0x20000    /* Total Size of Environment Sector */

Nand Flash: 

#define CONFIG_ENV_IS_IN_NAND 1
#define CONFIG_ENV_OFFSET 0X40000
#define CONFIG_ENV_SIZE            0x20000    /* Total Size of Environment Sector */

EEPROM:

#define CONFIG_ENV_IS_IN_EEPROM 1 /* use EEPROM for environment vars */
#define CONFIG_ENV_OFFSET 0x000 /* environment starts at offset 0 */
#define CONFIG_ENV_SIZE     0x400 /* 1KB */


CONFIG_ENV_OFFSET是在整个存储器中的偏移地址;
CONFIG_ENV_SIZE是指其使用的大小。

 注意 CONFIG_ENV_OFFSET和 CONFIG_ENV_SIZE 的设置,不要覆盖了其他分区。

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP