在uboot里面添加环境变量使用run来执行并启动时自动执行run

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

<span style="font-size:14px;">mirror=sf probe 0;mw.b 82000000 ff F80000;tftp 0x82000000 
FWHI2104HF_20151106_DVR_R5104-AHD_2_2_8_0A_413221.flash;sf erase 0x80000 0xF80000;sf write 82000000 0x80000 0xF80000"</span>

然后使用run mirror命令来执行。


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

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

     /* 跳过uboot烧写镜像,防止弄坏uboot*/

<span style="font-size:14px;">#define CONFIG_BURNMIRROR "sf probe 0;mw.b 82000000 ff F80000;tftp 0x82000000 
FWHI2104HF_20151106_DVR_R5104-AHD_2_2_8_0A_413221.flash;sf erase 0x80000 0xF80000;sf write 820000000x80000 0xF80000"</span>

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

<span style="font-size:14px;">#ifdef CONFIG_BURNMIRROR 
"mirror=" CONFIG_BURNMIRROR         "\0"
#endif</span>

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

hisilicon # pri
mirror=sf probe 0;mw.b 82000000 ff F80000;tftp 0x82000000 FWHI2104HF_20151106_DVR_R5104-AHD_2_2_8_0A_413221.flash;sf erase 0x80000 0xF80000;sf write 82000000 0x80000 0xF80000
bootargs=mem=64M console=ttyAMA0,115200
bootcmd=setenv serverip 192.168.1.68;saveenv;run mirror 
bootdelay=1
baudrate=115200
ethaddr=00:00:23:34:45:66
ipaddr=192.168.1.10
netmask=255.255.255.0
bootfile="uImage"
stdin=serial
stdout=serial
stderr=serial
verify=n
ver=U-Boot 2010.06 (Nov 13 2015 - 17:47:53)
serverip=192.168.1.68


Environment size: 502/65532 bytes


二、            在uboot里面添加run命令

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

<span style="font-size:14px;">#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>

#if defined(CONFIG_CMD_RUN)
int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
	int i;

	if (argc < 2) {
		cmd_usage(cmdtp);
		return 1;
	}

	for (i=1; i<argc; ++i) {
		char *arg;

		if ((arg = getenv (argv[i])) == NULL) {
			printf ("## Error: \"%s\" not defined\n", argv[i]);
			return 1;
		}
#ifndef CONFIG_SYS_HUSH_PARSER
		if (run_command (arg, flag) == -1)
			return 1;
#else
		if (parse_string_outer(arg,
		    FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
			return 1;
#endif
	}
	return 0;
}

U_BOOT_CMD(
   boot,   1,  1, do_run,
   "boot default, i.e., run 'bootcmd'",
   ""
);  
#endif</span>

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,并烧录到单板


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值