您的位置:首页 > 其它

U-boot中怎么添加配置菜单选项

2015-11-03 13:45 441 查看
在command.h中分析命令结构

/* 这是定义一个结构的属性,将其放在.u_boot_cmd这个段当中,相当于.data/.bss这些段 */

#define Struct_Section  __attribute__ ((unused,section (".u_boot_cmd")))   

#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help)

 cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}

这样一来,凡通过U_BOOT_CMD定义的cmd_tbl_t变量会全部被放在.u_boot_cmd段当中(可以看UBOOT的链接脚本xxx.lds),具体怎么放是链接器的工作。

name :  命令的名字

maxargs:最大的参数

rep:是否可重复发命令

usage:短帮助信息

help:长帮助信息

增加一个hello命令,具体格式如下:把这个hello_common.c放在commoc文件夹下面

/*参考cmd_bootm.c文件*/

#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_hello (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])

{

  printf("hello world!\n");

  return 0;

}

U_BOOT_CMD(
hello,CONFIG_SYS_MAXARGS,1,do_hello,
"just for test"
"boot application image from memory",

);

在do_hello中就可以利用run_command(const char * cmd, int flag)函数来运行我们的u-boot命令,这样就方便很多了,比如:

 char cmd_buf[200];

 strcpy(cmd_buf, "nfs 30008000 172.16.148.114:/work/nfs_root/uImage");

 run_command(cmd_buf, 0);

就成功代替了手动执行上面的命令了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: