在u-boot中添加命令hello
1. 在common目录下添加文件cmd_hello.c
#include <common.h>
#include <command.h>
int do_hello(cmd_tbl_t *cmdtp, int flag , int argc, char *argv[])
{
printf(“Hello World\n”);
}
U_BOOT_CMD(
hello, CONFIG_SYS_MAXARGS, 1, do_hello,
“hello - my hello command\n”,
“hello world\n”
);
2. 修改common/Makefile,添加如下内容
COBJS-y += cmd_hello.o
1. 在common目录下添加文件cmd_hello.c
#include <common.h>
#include <command.h>
int do_hello(cmd_tbl_t *cmdtp, int flag , int argc, char *argv[])
{
printf(“Hello World\n”);
}
U_BOOT_CMD(
hello, CONFIG_SYS_MAXARGS, 1, do_hello,
“hello - my hello command\n”,
“hello world\n”
);
2. 修改common/Makefile,添加如下内容
COBJS-y += cmd_hello.o
备注:
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage, help}
U_BOOT_CMD(name,maxargs,repeatable,command,"usage","help")
name: is the name of the commad. THIS IS NOT a string.
maxargs: the maximumn numbers of arguments this function takes
command: Function pointer (*cmd)(struct cmd_tbl_s *, int, int, char *[]);
usage: Short description. This is a string
help: long description. This is a string
每一个 U-Boot 命令有一个结构体来描述。结构体包含的成员变量:命令名称、最大参,数个数、重复数、命令执行函数、用法、帮助。
而相关命令的具体执行在uboot/common/cmd_xxxx.c文件中实现的。