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
编译烧写