[uboot]在uboot里面添加环境变量使用run来执行

转自http://blog.csdn.net/yangzheng_yz/article/details/41038259

在移植uboot的时候,可以在uboot里面添加定义一些自己的环境变量,这些环境变量可以大大提高以后的工作效率,比如我在uboot里面添加如下环境变量:

bbl=sf probe 0;mw.b 82000000 ff 80000;loady0x82000000 uboot_logo.bin;sf erase 0 80000;sf write 82000000 0 80000

然后使用run命令来执行:

hisilicon # run bbl         

 KiB hi_sfc at : is now currentdevice
## Ready for binary (ymodem) download to0x82000000 at bps...
CCC
Starting ymodem transfer. Press Ctrl+C to cancel.
% KB KB/s :: Errors ## Total Size = 0x000379ec = Bytes
Erasing at 0x80000 -- % complete.
Writing at 0x80000 -- % complete.

那么这样就不用每次都输入很长的一串字符串,如:

hisilicon # sf probe 0;mw.b 82000000 ff80000;loady 0x82000000 uboot_logo.bin;sf erase 0 80000;sf write 82000000 080000

那么方法如下:

一、在uboot里面添加环境变量

1、  在u-boot-2010.06/include/configs目录下的xxx.h(xxx是board,如hi3520d.h)里面定义环境变量:

/* Burn bootloader, Linux kernel and rootfscommand */
#define CONFIG_BURNBL "sf probe 0;mw.b 82000000 ff80000;loady 0x82000000 uboot_logo.bin;sf erase 0 80000;sf write 82000000 0 8
"
#define CONFIG_BURNKERNEL"sf probe 0;mw.b 82000000 ff 480000;loady 82000000 root_cramfs.img;sferase 80000 0x480000;sf write 8200000
"
#define CONFIG_BURN_APP"sf probe 0;mw.b 82000000 ff 0xa00000;loady 82000000 app_jffs2.img;sferase 500000 0xa00000;sf write 82000000
0xa00000"
#define CONFIG_BURN_FLASH"sf probe 0;mw.b 82000000 ff 1000000;loady 0x82000000ZMD-PROGRAMMING-FLASH.binl;sf erase 0 1000000;sf writ
e " 

2、  然后在u-boot-2010.06/common目录下的evn_common.c里面添加如下代码:

#ifdef CONFIG_BURNBL       /* Burn bootloader image to SPIflash*/
"bbl=" CONFIG_BURNBL "\0"
#endif
#ifdef CONFIG_BURNKERNEL /* Burn kernel image to SPIflash*/
"blx="CONFIG_BURNKERNEL "\0"
#endif
#ifdef CONFIG_BURN_APP /* Burn APP image to SPIflash*/
"bapp= "CONFIG_BURN_APP "\0"
#endif
#ifdef CONFIG_BURN_FLASH /* Burn Flash APP image to SPIflash*/
"bfl="CONFIG_BURN_FLASH "\0"
#endif

3、  重新编译uboot,并烧录到单板,用printenv或pri可以看到已定义的环境变量:

hisilicon # pr

bootargs=mem=96M console=ttyAMA0,115200root=1f01 rootfstype=cramfsmtdparts=hi_sfc:512K(boot),4M(romfs),10M(app),1536K(config)
bootcmd=sf probe ;sf read 500000x1B6B2;decjpg;setvobg 0x00;stopvo0;startvo ;startvo ;startgx 0x86000000 ;sfread 0x84000000 0x80000 0x400000;cramfsload;bootm 0x82000000
bootdelay=
baudrate=
ethaddr=:::::
ipaddr=192.168.28.110
jpeg_addr=0x86000000
jpeg_size=0x1b6b2
vobuf=0x86000000
cramfsaddr=0x84000000
cramfsldaddr=0x82000000
serverip=192.168.28.100
netmask=255.255.255.0
bootfile=/boot/hikernel
bbl=sf probe ;mw.b82000000 ff ;loady 0x82000000 uboot_logo.bin;sf erase ;sf write82000000
blx=sf probe ;mw.b82000000 ff ;loady root_cramfs.img;sf erase 0x480000;sfwrite
bapp= sf probe ;mw.b82000000 ff 0xa00000;loady app_jffs2.img;sf erase 0xa00000;sfwrite 0xa00000
bfl=sf probe ;mw.b82000000 ff ;loady 0x82000000 ZMD-PROGRAMMING-FLASH.binl;sf erase ;sf write
stdin=serial
stdout=serial
stderr=serial
verify=n
ver=U-Boot 2010.06 (Nov - ::)
filesize=379EC Environment size: / bytes

二、            在uboot里面添加run命令

1、  在u-boot-2010.06/common目录下添加一个文件cmd_run.c,代码如下:

/*********************************************************************************
* Copyright: (C) 2014 YangZheng<yz2012ww@gmail.com>
* All rights reserved.
*
* Filename: cmd_run.c
* Description: This file
*
* Version: 1.0.0(11/11/2014~)
* Author: Yang Zheng<yz2012ww@gmail.com>
* ChangeLog: 1, Release initialversion on "11/11/2014 09:05:08 PM"
*
********************************************************************************/
#include <common.h>
#include <watchdog.h>
#include <command.h>
#include <image.h>
#include <malloc.h>
#include <u-boot/zlib.h>
#include <bzlib.h>
#include <environment.h>
#include <lmb.h>
#include <linux/ctype.h>
#include <asm/byteorder.h> int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char **argv)
{
if (argc < )
{
cmd_usage(cmdtp);
return ;
}
if (run_command (getenv (argv[]), flag)< )
{
return -;
} return ;
} U_BOOT_CMD(
boot, , , do_run
"boot default, i.e., run 'bootcmd'",
""
);

2、  然后在u-boot-2010.06/include/configs目录的xxx.h(xxx是board,如hi3520d.h)里面添加如下宏定义:

#define CONFIG_CMD_RUN

3、在u-boot-2010.06/common目录的Makefile中添加如下代码:

COBJS-$(CONFIG_CMD_RUN) += cmd_run.o

4、  重新编译uboot,并烧录到单板

三、 运行

hisilicon # run bbl

 KiB hi_sfc at : is now current device
## Ready for binary (ymodem) download to0x82000000 at bps...

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

Uboot-201507 am437x平台

uboot_2015.07/common/cli.c----->do_run()

在CONFIG_EXTRA_ENV_SETTINGS宏中添加update_qspi_flash

上一篇:Java toBinaryString()函数探究及Math.abs(-2147483648)=-2147483648原理探究


下一篇:MD5加密算法(java及js)