Chinaunix首页 | 论坛 | 博客
  • 博客访问: 192598
  • 博文数量: 44
  • 博客积分: 1515
  • 博客等级: 上尉
  • 技术积分: 480
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-06 16:39
文章分类

全部博文(44)

文章存档

2013年(3)

2012年(2)

2011年(2)

2009年(20)

2008年(17)

我的朋友

分类: LINUX

2008-07-23 17:14:06

在开发板中烧写uboot是一件很烦的事情,如果uboot能实现bubt命令,则会很方便。
1在cmd_confdefs.h 定义
#define CFG_CMD_BUBT    0x8000000000000000ULL    /* bubt support        */可以更改该值,不能与其他命令的标志位冲突。

同时修改宏CONFIG_COMMANDS,添加bubt命令标志位:
#define CONFIG_COMMANDS    (CFG_CMD_DHCP | CFG_CMD_NET | CFG_CMD_PING | CFG_CMD_BDI | CFG_CMD_MEMORY | CFG_CMD_FLASH | CFG_CMD_ENV | CFG_CMD_LOADB|CFG_CMD_BUBT)

定义宏:
#define CFG_MONITOR_BASE X (X根据实际情况确定,比如CFG_FLASH_BASE)
#define CFG_MONITOR_LEN (252>>10)(其他值也可以)

在我们的开发板,这些宏定义:
#define CFG_MONITOR_BASE  CFG_FLASH_BASE
#define CFG_MONITOR_LEN (252>>10)(其他值也可以)
#define CFG_MONITOR_IMAGE_OFFSET 0
另外要定义环境变量的大小以及偏移地址
 
2添加文件:cmd_bubt.c
/*in bubt.c*/
#if (CONFIG_COMMANDS & CFG_CMD_RUN)
int do_run (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
U_BOOT_CMD(
    run,    CFG_MAXARGS,    1,    do_run,
    "run     - run commands in an environment variable\n",
    "var [...]\n"
    "    - run the commands in the environment variable(s) 'var'\n"
);
#endif  /* CFG_CMD_RUN */
#if (CONFIG_COMMANDS & CFG_CMD_BUBT)
static unsigned int flash_in_which_sec(flash_info_t *fl,unsigned int offset)
{
    unsigned int sec_num;
    if(NULL == fl)
        return 0xFFFFFFFF;

    for( sec_num = 0; sec_num < fl->sector_count ; sec_num++){
        /* If last sector*/
        if (sec_num == fl->sector_count -1)
        {
            if((offset >= fl->start[sec_num] - fl->start[0]) &&
               (offset < fl->size) )
            {
                return sec_num;
            }

        }
        else
        {
            if((offset >= fl->start[sec_num] - fl->start[0]) &&
               (offset < fl->start[sec_num + 1] - fl->start[0]) )
            {
                return sec_num;
            }

        }
    }
    /* return illegal sector Number */
    return 0xFFFFFFFF;

}

/*******************************************************************************
burn a u-boot.bin on the Boot Flash
********************************************************************************/
extern flash_info_t flash_info[];       /* info for FLASH chips */
#include

int burn_uboot_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    int filesize;
    unsigned int s_first,s_end,env_sec;
    extern char console_buffer[];


    s_first = flash_in_which_sec(&flash_info[0],
                                CFG_MONITOR_BASE - flash_info[0].start[0]);
    s_end = flash_in_which_sec(&flash_info[0],
                                CFG_MONITOR_BASE + CFG_MONITOR_LEN -1 - flash_info[0].start[0]);

    env_sec = flash_in_which_sec(&flash_info[0],
                                CFG_ENV_ADDR - flash_info[0].start[0]);


    load_addr = 0x100000;
    if(argc == 2) {
        copy_filename (BootFile, argv[1], sizeof(BootFile));
    }
    else {
        copy_filename (BootFile, "u-boot.bin", sizeof(BootFile));
        printf("using default file \"u-boot.bin\" \n");
    }
 
    if ((filesize = NetLoop(TFTP)) < 0)
        return 0;
 
    printf("Un-Protect Flash Monitor space\n");
    flash_protect (FLAG_PROTECT_CLEAR,
               CFG_MONITOR_BASE,
               CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
               &flash_info[0]);

    printf("Override Env parameters? (y/n)");
    readline(" ");
    if( strcmp(console_buffer,"Y") == 0 ||
        strcmp(console_buffer,"yes") == 0 ||
        strcmp(console_buffer,"y") == 0 ) {

        flash_protect (FLAG_PROTECT_CLEAR,
                   flash_info[0].start[env_sec],
                   flash_info[0].start[env_sec] + CFG_ENV_SECT_SIZE - 1,
                   &flash_info[0]);

        printf("Erase Env parameters sector %d... ",env_sec);
        flash_erase(&flash_info[0], env_sec, env_sec);

        flash_protect (FLAG_PROTECT_SET,
                   flash_info[0].start[env_sec],
                   flash_info[0].start[env_sec] + CFG_ENV_SECT_SIZE - 1,
                   &flash_info[0]);

    }

    printf("Erase %d - %d sectors... ",s_first,s_end);
    flash_erase(&flash_info[0], s_first, s_end);

    printf("Copy to Flash... ");

    flash_write ( (uchar *)0x100000 + CFG_MONITOR_IMAGE_OFFSET,
                  CFG_MONITOR_BASE,
                  filesize - CFG_MONITOR_IMAGE_OFFSET);

    printf("done\nProtect Flash Monitor space\n");
    flash_protect (FLAG_PROTECT_SET,
               CFG_MONITOR_BASE,
               CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
               &flash_info[0]);

    return 1;
}

U_BOOT_CMD(
        bubt,      2,     1,      burn_uboot_cmd,
        "bubt    - Burn an image on the Boot Flash.\n",
        " file-name \n"
        "\tBurn a binary image on the Boot Flash, default file-name is u-boot.bin .\n"
);
#endif

3 添加和修改Makefile文件
4 编译 烧写


后记:
我们所使用的开发板环境变量的偏移地址是:0x40000,uboot的使用空间为1M,如果改成512K的话,该函数需要修改。
阅读(3930) | 评论(1) | 转发(0) |
0

上一篇:关于堆的困惑

下一篇:delphix 使用心得1

给主人留下些什么吧!~~

chinaunix网友2009-07-08 20:03:33

这样是简单多了 用run命令来运行一个下载uboot的环境变量是不是更简单些啊 这样还不用专门添个命令 设置一个下载的环境变量就可以了 run upgradeuboot upgradeuboot包括tftp,protect off,erase,cp,protect on