在command.h中分析命令结构
#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);
就成功代替了手动执行上面的命令了
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow