U_BOOT_CMD命令的实现

本文介绍U-Boot中定义命令的宏定义方法及结构体cmd_tbl_s的使用细节。通过宏定义简化了U-Boot命令的创建过程,并展示了如何通过具体的例子实现命令的定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

宏定义,用于定义一个U_BOOT命令
#define U_BOOT_CMD(name,maxargs,rep,cmd,usage) /
  cmd_tbl_t __u_boot_cmd_##name Struct_Section = {#name, maxargs, rep, cmd, usage}

#define Struct_Section  __attribute__ ((unused,section (".u_boot_cmd")))//设置属性,存在.u_boot_cmd段中


Struct cmd_tbl_s:

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) */
    char        *help;      /* Help  message    (long)  */
#ifdef CONFIG_AUTO_COMPLETE
    /* do auto completion on the arguments */
    int     (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]);
#endif
};

typedef struct cmd_tbl_s    cmd_tbl_t;

例如:

U_BOOT_CMD(
    bootm,    CONFIG_SYS_MAXARGS,    1,    do_bootm,
    "boot application image from memory", bootm_help_text
);
展开后:

cmd_tbl_t __u_boot_cmd_##namebootm Struct_Section__attribute__ ((unused,section (".u_boot_cmd"))) = 
{#name"bootm", maxargs16, rep1, cmddo_bootm, usage"boot application image from memory"}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值