1.在 common 目录下,新建一个文件 cmd_hello.c,输入如下代码:
#include<command.h>
#include<common.h>
static int do_hello(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
printf (“hello world!\ \ n”);
return 0;
}
U_BOOT_CMD(
hello, 1, 0, do_hello,
" short description. This is a string.\ n",
" long description. This is a string.\ n"
);
上述代码中,U_BOOT_CMD 为 u-boot 新建命令使用的宏定义,一共有 6 个参数,具体介绍如下:
a.第一个参数:该命令的名称
b.第二个参数:该命令的参数的个数
c.第三个参数:按下 enter 键后是否重复执行该命令
d.第四个参数:该命令对应的回调函数
e.第五个参数:该命令的短帮助信息
f.第六个参数:该命令的长帮助信息
2.在 common/Makefile 中添加编译选项:
COBJS-y += cmd_hello.o
3.重新编译 u-boot 即可
在u-boot 中自定义命令
最新推荐文章于 2024-03-05 14:37:42 发布
本文介绍了如何在U-Boot中使用U_BOOT_CMD宏定义创建一个新的命令hello,包括代码编写、参数解释、Makefile配置及编译步骤。重点讲解了cmd_hello.c文件的结构和common目录下的Makefile设置。
摘要由CSDN通过智能技术生成