前言:
本帖是学习韦东山老师uboot教程,粗略总结的课堂笔记及自己感悟。如想深入了解uboot 启动过程,请绕路。
本节内容了解即可。
相关帖子:
1- 添加一个hello 命令--先体验
1.1- cmd_hello.c
在/u-boot-1.1.6/common路径下创建一个cmd_hello.c文件,给予文件777权限。
内容如下:
/*
* hello cmd
*/
#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[])
{
int index = 0;
for (index=0; index<argc; index++)
{
printf("%s(%d) argv[%d]:%s\n",__func__, __LINE__,index, argv[index]);
}
return 1;
}
U_BOOT_CMD(
hello_cmd, CFG_MAXARGS, 1, do_hello,
"\n hello - hello cmd test\n",
"this is hello world cmd print\n"
"\tjust for test\n"
);
1.2- 修改/u-boot-1.1.6/common/Makefile
增加cmd_hello文件编译到uboot中。
COBJS = 后面为需要编译的文件,仿照加上cmd_hello.o
1.3- 编译、烧录uboot.bin文件到开发板
1.4- 查看
开发板上电,倒数计时前按下空格,进入到uboot shell环境。
推出uboot menu菜单栏,进入到OpenJTAG> shell环境。
输入help可以看到我们的hello提示命令
输入调试命令测试:
OpenJTAG> hello
do_hello(21) argv[0]:hello
OpenJTAG> help hello
hello_cmd this is hello world cmd print
just for test
2- uboot cmd命令规则
参考boom命令 对应接口do_bootm(),比着写就好,没有什么内容。
/* bootm函数功能实现接口 */
int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
...
}
/* bootm相关宏封装 */
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
);
#ifdef CFG_LONGHELP
#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}
#else /* no long help info */
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \
cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}
#endif /* CFG_LONGHELP */
/* uboot cmd 涉及到的数据结构 */
typedef struct cmd_tbl_s cmd_tbl_t;
struct cmd_tbl_s {
char *name; /* Command Name */
int maxargs; /* maximum number of arguments */
int repeatable; /* autorepeat allowed? */
/* Implementation function */
int (*cmd)(struct cmd_tbl_s *, int, int, char *[]);
char *usage; /* Usage message (short) */
#ifdef CFG_LONGHELP
char *help; /* Help message (long) */
#endif
#ifdef CONFIG_AUTO_COMPLETE
/* do auto completion on the arguments */
int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]);
#endif
};
struct cmd_tbl_s数据结构参数含义参考:
Uboot命令U_BOOT_CMD分析
简单说明下:
repeatable : 按回车是否重复执行上次命令
*usage : helo中打印的短提示信息
*help : help cmd中打印的长提示信息