zoukankan      html  css  js  c++  java
  • uboot命令及添加命令

    include/command.h:

    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    CONFIG_SYS_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
    };

    typedef struct cmd_tbl_s    cmd_tbl_t;

    extern cmd_tbl_t  __u_boot_cmd_start;
    extern cmd_tbl_t  __u_boot_cmd_end;

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

    使用U_BOOT_CMD来注册进系统,链接脚本会把所有的cmd_tbl_t结构体放在相邻的地方。
    __u_boot_cmd_start 和__u_boot_cmd_end 分别对应命令结构体在内存中开始和结束的地址。

    接下来如何添加一条命令:

    修改5个地方:(以添加exit命令为例)

    1. /include/config_cmd_all.h    添加CONFIG_CMD_EXIT宏
    2. /include/config_cmd_default.h  同上
    3. /include/configs/smdk2410.h  添加宏   (以上头文件的修改,都是为了条件编译做准备的)
    4. /common/cmd_exit.c    具体实现命令的函数   (命令的实现与命令的注册都在这儿)
    5. /common/Makefile          把自己写的实现命令文件添加到Makefile

    1)实现命令的具体功能,在comman文件夹中建立对应的cmd_exit.c文件。

    2)如果要添加指令,首先为了能让系统找到该指令,所以要在命令表中注册一下。

    cmd_exit.c:

    #include <common.h>
    #include <command.h>

    int do_exit(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
    {
        int r;

        r = 0;
        if (argc > 1)
            r = simple_strtoul(argv[1], NULL, 10);

        return -r - 2;
    }

    U_BOOT_CMD(
        exit,    2,    1,    do_exit,
        "exit script",
        ""
    );

  • 相关阅读:
    toj 2819 Travel
    toj 2807 Number Sort
    zoj 2818 Prairie dogs IV
    zoj 1276 Optimal Array Multiplication Sequence
    toj 2802 Tom's Game
    toj 2798 Farey Sequence
    toj 2815 Searching Problem
    toj 2806 Replace Words
    toj 2794 Bus
    css截取字符
  • 原文地址:https://www.cnblogs.com/ht-beyond/p/4253299.html
Copyright © 2011-2022 走看看