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