u-boot 简单使用手册
转自:http://blog.mcuol.com/User/kaizi/Article/56894_1.htm
1.u-boot 简介

-----------------------------------------------------------------

1.u-boot

2.它有两种模式
   引导模式(用于引导OS)
   下载模式(用于开发,在u-boot启动按任意键)进入控制台。
    在控制台执行 boot 命令,则进入引导模式去引导OS。
   
2.u-boot 控制台常用命令

--------------------------------------------------------------------

  help 显示帮助命令

  boot 用引导常数来引导OS。

  bootm 从内存引导OS。.

  bootp/tftpboot 从TFTP/BOOTP服务器引导OS

 

  go 从某一个地址开始直接运行程序

  mtdparts 管理flash上的分区

  ping 简单发送一个ICMP包测试。

  printenv 打印环境变量

  setenv 设置环境变量

  saveenv 把内存的环境变量存到flash上的param分区.

 

  usbslave 从USB下载文件 (PC机要运行dnw)

  version 显示u-boot 版本

  

4. 设置环境变量  printenv 打印环境变量

    

bootargs=noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0
bootcmd=nboot 0x32000000 kernel; bootm 0x32000000
bootdelay=0
baudrate=115200
ethaddr=0a:1b:2c:3d:4e:5f
ipaddr=192.168.1.6
serverip=192.168.1.8
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial
mtdids=nand0=nandflash0
mtdparts=mtdparts=nandflash0:256k@0(bios),128k(params),128k(toc),512k(eboot),1024k(log)
partition=nand0,0
mtddevnum=0
mtddevname=bios
Environment size: 453/131068 bytes

  经常修改是 bootargs (Linux 启动参数)
         ipaddr (开发板IP地址)
         serverip( 默认tftp/NFS/...下载主机)

    setenv 命令只是改变内存的环境变量值,如果不调用saveenv,下次的设置仍然是旧的配置。
   
    设置开发板的ip
      u-boot>setenv ipaddr 192.168.1.8    设置引导参数,注意引导参数内部带有空格,所以必须加""
   
      setenv bootargs "..." 

 

  自定义环境变量

      除了预定义的环境变量外,u-boot还支持自定义环境变量。直接采用setenv var_name var_value 即可.在其它的变量中直接用 $(var_name)

  比如两个启动模式,一种是本地启动的引导参数,一种是网络NFS引导参数。在调试阶段需要经常切算参数。可以预先做好两个bootarg_nfs bootarg_flash 可以在设置在

      setenv bootargs $({bootarg_nfs}     
5.从tftp引导操作系统    5.1 在PC机安装TFTP服务器
    5.2 配置网络让开发板与PC机在同一子网,并且网线相连
         设置服务器ip  setenv serverip 192.168.1.100

    5.3 在u-boot ping主机
            ping 192.168.1.100
           dm9000 i/o: 0x20000300, id: 0x90000a46
            MAC: 0a:1b:2c:3d:4e:5f
           host 192.168.1.100 is alive

    5.4 把操作系统映像uImage放入PC机的/tftpboot
        直接编译的OS Image称为 zImage
        u-boot需要一些额外的引导信息(64byte),用mkimage来处理,处理后的image 称为uImage
        
     5.5 在开发板运行tftpboot命令
        在不使用MMU情况下,第一块SDRAM的起始物理地址是 0x30000000
        把uImage 下载到0x3200000地址上。
       
          tftp 0x32000000 uImage    4.6 用bootm 启动内存内核

 

dm9000 i/o: 0x20000300, id: 0x90000a46

MAC: 0a:1b:2c:3d:4e:5f

TFTP from server 192.168.1.100; our IP address is 192.168.1.50

Filename ''uImage''.

Load address: 0x32000000

Loading: T #################################################################

         #################################################################

         #########

done

Bytes transferred = 2021620 (1ed8f4 hex)

    
    bootm 0x32000000

## Booting image at 32000000 ...

   Image Name:  

   Created:      2009-06-18  18:50:52 UTC

   Image Type:   ARM Linux Kernel Image (uncompressed)

   Data Size:    2021556 Bytes =  1.9 MB

   Load Address: 30008000

   Entry Point:  30008040

   Verifying Checksum ... OK

OK

 6.启动时自动用tftp引导

    

    从本地引导

            bootcmd=nand read.i c0008000 80000 500000;bootm c0008000

 

从tftp的引导的命令

     setenv bootcmd "tftp 50008000 uImage;bootm 50008000"

  mini6410修改的uboot,直接使用zImage

    

 

 7.用NFS远程引导根文件系统 
    6.1 把文件系统的tar 解压到一个目录,并将这个目录设为NFS目录.
    6.2 在本地测试一下NFS路径是否可用
       mount -t nfs 192.168.1.8:/home/rootfs /mnt/nfs
      
    6.3 让u-boot通知内核不要从本地引导文件系统,而且从远程NFS引导.方法是修改bootargs
     本地引导参数.
     bootargs=noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0
    
     NFS引导参数
       console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.8:/home/rootfs ip=192.168.1.6       ip是开发板IP,注意要环境变量IP一致,还要保证LINUX启动后也要设这个IP。否则NFS在执行一半后会中断。
       Linux 引导后IP是在 /home/rootfs/etc/init.d/rcS中设置.在其中加一句 ifconfig eth0 192.168.1.6 测试发现,如果使用标准的网络设置脚本 ifconfig-eth0 将会造成NFS启动中断,如果在启动文件使用这个命令,需要换成ifconfig eth0 命令

       最后在控制台上用如下命令设置
      setenv bootargs ""
     
      setenv bootargs "console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.8:/home/rootfs ip=192.168.1.6"
       
    
    

  

 

4附录
   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''
boot_noos - boot User Program
boot_zImage - boot Linux ''s zImage
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
eboot  - Run Wince Ethernet Bootloader(eboot)
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
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
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
tftpboot- boot image via network using TFTP protocol
usbslave - get file from host(PC)
version - print monitor version
wince [ram] - Run Wince from flash or ram
    

 

tftp 0x30000000 u-boot.bin
nand erase 0 0x100000
nand write 0x30000000 0 0x100000

tftp 0x30000000 uImage
nand erase 0x100000 0x200000
nand write 0x30000000 0x100000 0x200000

reset
boot