004自己添加一个uboot指令

uboot指令相关的代码在common目录下,我们进入common目录,模仿cmd_bootm.c实现一个指令

这个函数是指令功能函数

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

//这是一个宏定义
#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}


//name:指令的名称
//maxargs:最大的参数数量
//rep:是否可重复
//cmd:指令函数
//usage:短的帮助信息
//help:长的帮助信息

我们仿照这个文件实现一个cmd_hello.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_hello (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    printf("command:%s\n",cmdtp->name);
    int i;
    for(i=0;i<argc;i++)
    {
        printf("argv[%d]:%s\n",i,argv[i]);
    }

}

U_BOOT_CMD(
 	hello,	CFG_MAXARGS,	1,	do_hello,
 	"hello   -usage argv[1] argv[2] argv[3]..... \n", //短的帮助信息
 	"hello: long help.................................\n"
);

修改Makefile

编译烧写

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值