uboot 添加hello命令 分类: arm-linux-Ubunt...

平台: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

#endif


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

#define CONFIG_CMD_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节中,可以在连接脚本找到这个节。

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/mao0504/p/4706688.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值