在uboot裏面添加環境變量使用run來執行


Author:楊正  Date2014.11.11   Email[email protected] QQ:1209758756

 

         在移植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         

16384 KiB hi_sfc at 0:0 is now currentdevice

## Ready for binary (ymodem) download to0x82000000 at 115200 bps...

CCC

Starting ymodem transfer.  Press Ctrl+C to cancel.

 100%     222 KB    6 KB/s 00:00:36       1 Errors

 

## Total Size      = 0x000379ec = 227820 Bytes

Erasing at 0x80000 -- 100% complete.

Writing at 0x80000 -- 100% 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

0000"

#define CONFIG_BURNKERNEL"sf probe 0;mw.b 82000000 ff 480000;loady 82000000 root_cramfs.img;sferase 80000 0x480000;sf write 8200000

0 80000 480000"

#define CONFIG_BURN_APP"sf probe 0;mw.b 82000000 ff 0xa00000;loady 82000000 app_jffs2.img;sferase 500000 0xa00000;sf write 82000000

 500000 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 82000000 0 1000000"

 

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 0;sf read 86000000 500000x1B6B2;decjpg;setvobg  0 0x00;stopvo0;startvo 0 4 15;startvo 0 32 15;startgx 0 0x86000000 2560 0 0 1280 1024;sfread 0x84000000 0x80000 0x400000;cramfsload;bootm 0x82000000

bootdelay=1

baudrate=115200

ethaddr=00:00:23:34:45:66

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 0;mw.b82000000 ff 80000;loady 0x82000000 uboot_logo.bin;sf erase 0 80000;sf write82000000 0 80000

blx=sf probe 0;mw.b82000000 ff 480000;loady 82000000 root_cramfs.img;sf erase 80000 0x480000;sfwrite 82000000 80000 480000

bapp= sf probe 0;mw.b82000000 ff 0xa00000;loady 82000000 app_jffs2.img;sf erase 500000 0xa00000;sfwrite 82000000 500000 0xa00000

bfl=sf probe 0;mw.b82000000 ff 1000000;loady 0x82000000 ZMD-PROGRAMMING-FLASH.binl;sf erase 01000000;sf write 82000000 0 1000000

stdin=serial

stdout=serial

stderr=serial

verify=n

ver=U-Boot 2010.06 (Nov 11 2014 - 21:27:51)

filesize=379EC

 

Environment size: 1202/65532 bytes

 

二、            在uboot裏面添加run命令

1、  在u-boot-2010.06/common目錄下添加一個文件cmd_run.c,代碼如下:

/*********************************************************************************                                                  

 *     Copyright:  (C) 2014 YangZheng<[email protected]

 *                  All rights reserved.

 *

 *      Filename:  cmd_run.c

 *   Description:  This file

 *                

 *       Version:  1.0.0(11/11/2014~)

 *        Author:  Yang Zheng<[email protected]>

 *     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 < 2)

   {

       cmd_usage(cmdtp);

       return 1;

   }

   if (run_command (getenv (argv[1]), flag)< 0)

    {

       return -1;

    }

 

   return 0;

}

U_BOOT_CMD(

   boot,   1,  1, 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

16384 KiB hi_sfc at 0:0 is now current device

## Ready for binary (ymodem) download to0x82000000 at 115200 bps...

C

 

發佈了70 篇原創文章 · 獲贊 21 · 訪問量 28萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章