zoukankan      html  css  js  c++  java
  • uboot 添加 自定义命令

    --- title: uboot-uboot 添加 自定义命令 date: 2020-05-13 16:51:38 categories: tags: - uboot - cmd - config ---

    章节描述:

    定制化uboot 的时偶尔需要添加自定义命令,本问介绍如何添加命令。

    步骤

    添加命令文件

    在common目录下,新建一个cmd_xx.c,需要添加的命令格式为:

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

    并在文件中使用 U_BOOT_CMD 宏进行有关说明 :

    U_BOOT_CMD(name, maxargs, repeatable, command, "usage","help")
    

    宏参数有6个:

    • 第一个参数:添加的命令的名字
    • 第二个参数:添加的命令最多有几个参数(注意,假如你设置的参数个数是3,而实际的参数个数是4,那么执行命令会输出帮助信息的)
    • 第三个参数:是否重复(1重复,0不重复)(即按下Enter键的时候,自动执行上次的命令)
    • 第四个参数:执行函数,即运行了命令具体做啥会在这个函数中体现出来
    • 第五个参数:帮助信息(short)
    • 第六个参数:帮助信息(long)

    最简单的命令文件的范例

    #include <command.h>
    #include <common.h>
    
    int do_hello(cmd_tbl_t *cmdtp,int flag,int argc,char *argv)
    {
        printf("my test 
    ");
        return 0;
    }
    
    U_BOOT_CMD(
    hello,1,0,do_hello,"usage:test
    ","help:test
    "
    );
    

    修改 Makefile

    修改 common/Makefile 在Makfile中添加一行:

    COBJS-y += cmd_xx.o 
    

    附录 : 宏U_BOOT_CMD 的解析

    #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}
    

    我们分段来看:

    命令所在的段:

    #define Struct_Section __attribute__ ((unused,section (".u_boot_cmd")))

    由定义可知该命令在链接的时候链接的地址或者说该命令存放的位置是u_boot_cmd section

    宏展开的结构体:

    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) */
      char  *help
    }
    
  • 相关阅读:
    网页连接无法打开可运行
    SET XACT_ABORT
    用Windows Live Writer写CSDN博客的步骤
    ATO,PTO
    什么是贸易顺差?
    ATO/MTO类机械制造业特点以及ERP需求分析(二)
    如何在早期版本的 Office 中打开并保存 Word 2007、Excel 2007 和 PowerPoint 2007 文件
    Alpha和Beta测试简介
    IIS6.0下 Asp网页访问出现500的问题
    合格的程序员
  • 原文地址:https://www.cnblogs.com/schips/p/uboot-add-custom-applet.html
Copyright © 2011-2022 走看看