【 u_boot 中新增命令】

uboot的所有命令都单独存放在“.u_boot_cmd”中,这一点从链接脚本中可以看出来,如图:

uboot会遍历“.u_boot_cmd”段中的所有命令,找到待执行的命令后运行对应的处理函数。命令以 cmd_tbl_t 结构的形式存在,common.h中定义,如图:

命令结构通过宏 U_BOOT_CMD 放入“.u_boot_cmd”段中,U_BOOT_CMD 在 common/common.h 中定义,如下:

如 “bootm” 命令在common/cmd_bootm.c中:

U_BOOT_CMD(
 	bootm,	CFG_MAXARGS,	1,	do_bootm,
 	"bootm   - boot application image from memory\n",
 	"[addr [arg ...]]\n    - boot application image stored in memory\n"
 	"\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
 	"\t'arg' can be the address of an initrd image\n"
#ifdef CONFIG_OF_FLAT_TREE
	"\tWhen booting a Linux kernel which requires a flat device-tree\n"
	"\ta third argument is required which is the address of the of the\n"
	"\tdevice-tree blob. To boot that kernel without an initrd image,\n"
	"\tuse a '-' for the second argument. If you do not pass a third\n"
	"\ta bd_info struct will be passed instead\n"
#endif
);

 

因此根据u_boot的规则,增加命令只需要增加一个c文件,在其中通过宏 U_BOOT_CMD 将命令放入“.u_boot_cmd”段中即可。以下是增加命令 hellotest 的过程:

1、增加 common/cmd_hellotest.c,内容如下:

#include <common.h>
#include <watchdog.h>
#include <command.h>
#include <image.h>
#include <malloc.h>
#include <zlib.h>
#include <bzlib.h>
#include <environment.h>
#include <asm/byteorder.h>


int do_hellotest (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	int i;
	
	printf("run hellotest ...\n");

	for (i = 0; i < argc; i++) {
		printf("argv[%d] = %s\n", i, argv[i]);
	}
	
	return 1;
}

U_BOOT_CMD(
 	hellotest,	CFG_MAXARGS,	1,	do_hellotest,
 	"hellotest   - just for test\n",
 	"test test test test ...\n"
);

2、在 common/Makefile 增加 cmd_hellotest.o 项目

3、重新编译

 

实际测试:

help 命令

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

stone8761

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值