• 【uboot】uboot添加自定义命令


    实现步骤:

    1. 1.uboot源码下新建cmd/cmd_xx.c
    2. 2.添加基本的命令和函数
    3. 3.cmd下makefile添加 obj-y += cmd_update.o

    头文件:

    #include <common.h>

    #include <command.h>

    函数:

    /*

        第一个参数:添加的命令的名字

        第二个参数:添加的命令最多有几个参数(注意,假如你设置的参数个数是3,

                  而实际的参数个数是4,那么执行命令会输出帮助信息的)

        第三个参数:是否重复(1重复,0不重复)(即按下Enter键的时候,

                  自动执行上次的命令)

        第四个参数:执行函数,即运行了命令具体做啥会在这个函数中体现出来

        第五个参数:帮助信息(short)

        第六个参数:帮助信息(long)

    */

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

    {

            return 0;

    }

    添加命令update:

    // U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help)

    U_BOOT_CMD(update, 4, 0, do_update,

        "update command",

        " - check boot progress and timing\n"

        "update all\n"

        "update uboot \n"

        "update image \n"

        "update rootfs \n"

    );

    1. /*
    2. * @Author: error: git config user.name && git config user.email & please set dead value or install git
    3. * @Date: 2022-11-15 23:26:50
    4. * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
    5. * @LastEditTime: 2022-11-16 21:38:40
    6. * @FilePath: \uboot\cmd\cmd_update.c
    7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
    8. */
    9. #include
    10. #include
    11. /*
    12.     第一个参数:添加的命令的名字
    13.     第二个参数:添加的命令最多有几个参数(注意,假如你设置的参数个数是3,而实际的参数个数是4,那么执行命令会输出帮助信息的)
    14.     第三个参数:是否重复(1重复,0不重复)(即按下Enter键的时候,自动执行上次的命令)
    15.     第四个参数:执行函数,即运行了命令具体做啥会在这个函数中体现出来
    16.     第五个参数:帮助信息(short)
    17.     第六个参数:帮助信息(long)
    18. */
    19. static int do_update(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
    20. {
    21. /* 判断参数个数 */
    22. if (argc != 2)
    23. {
    24. printf("update params num err\n");
    25. return 1;
    26. }
    27. if (0 == strncmp("uboot", argv[0], sizeof("uboot")))
    28. {
    29. printf("update uboot success\n");
    30. }
    31. else if (0 == strncmp("image", argv[0], sizeof("image")))
    32. {
    33. printf("update image success\n");
    34. }
    35. else if (0 == strncmp("rootfs", argv[0], sizeof("rootfs")))
    36. {
    37. printf("update rootfs success\n");
    38. }
    39. return 0;
    40. }
    41. /*
    42. U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help)
    43. */
    44. U_BOOT_CMD(update, 4, 0, do_update,
    45. "update command",
    46. " - check boot progress and timing\n"
    47. "update all\n"
    48. "update uboot \n"
    49. "update image \n"
    50. "update rootfs \n"
    51. );

  • 相关阅读:
    【Java】 java | mqtt | 消息订阅 | 分组订阅 | 业务处理 | 正则表达式 | 通配符
    Vue学习笔记四
    数据库主从切换过程中Druid没法获取连接错误
    Nginx 配置 HTTPS 过程(+反向代理)
    C#的值类型和引用类型
    手机号码认证什么价格?手机号码认证怎样申请?
    6种最常用的3D点云语义分割AI模型对比
    个人编程笔记 - 子类和父类有同名的成员?
    f-string 格式化字符串的用法
    尚硅谷-JUC篇
  • 原文地址:https://blog.csdn.net/qq_20017379/article/details/127894303