天天看点

uboot 添加hello命令

平台:mpc8315(powerpc)

1.在/common/ 目录下创建自己的文件,最好前缀为cmd_. 

 cmd_hello.c

*********************************************************

#include<command.h>

#include<common.h>

#ifdef config_cmd_hello

int do_hello(cmd_tbl_t *cmdtp,int flag,int argc,char *argv)

{

        printf("my test \n");

        return 0;

}

u_boot_cmd(

hello,1,0,do_hello,"usage:test\n","help:test\n"

);

#endif

2.在当前目录下修改makefile

 在目标变量最后面添加:

#ifdef config_cmd_hello 

cobjs-y += cmd_hello.o

3.在头文件mpc83xx.h中添加对config_cmd_hello的定义

#define config_cmd_hello

编译下载后,在uboot中运行hello:

uboot 添加hello命令

4.u_boot_cmd

它的定义在include/command.h中,

/**********************************************************/

#define struct_section  __attribute__((unused, section(".u_boot_cmd"), aligned(4)))

#define u_boot_cmd_mkent_complete(name,maxargs,rep,cmd,usage,help,comp) \

        {#name, maxargs, rep, cmd, usage, _cmd_help(help) _cmd_complete(comp)}

#define u_boot_cmd_complete(name,maxargs,rep,cmd,usage,help,comp) \

        cmd_tbl_t __u_boot_cmd_##name struct_section = \

            u_boot_cmd_mkent_complete(name,maxargs,rep,cmd,usage,help,comp)

#define u_boot_cmd(name,maxargs,rep,cmd,usage,help) \

        u_boot_cmd_complete(name,maxargs,rep,cmd,usage,help,null)

/*******************************************************/

展开就是:#define u_boot_cmd(hello,1,0,do_hello,"usage:test\n","help:test\n") 

cmd_tbl_t __u_boot_cmd_hello __attribute__((unused, section(".u_boot_cmd"), aligned(4)))

 = {hello, 1, 0, do_hello, "usage:test\n","help:test\n" }

这儿定义了属性,就是所有的命令都存储在.u_boot_cmd节中,可以在连接脚本找到这个节。