uboot添加自定义命令的实现步骤

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

uboot添加自定义命令的实现步骤

IT小生lkc   2022-11-22 我要评论

uboot简介

uboot 属于bootloader的一种,是用来引导启动内核的,它的最终目的就是:从flash中读出内核,放到内存中,启动内核。
它刚开始被放到flash上,然后上电以后先执行它,它会完成硬件初始化,设置处理器模式,关闭看门狗,屏蔽中断,初始化sdram,设置栈,设置时钟,从flash引导内核到内存,就好像我们PC上的BIOS一样。最终将系统的软硬件带到一个合适的状态。

实现步骤:

  • 1.uboot源码下新建cmd/cmd_xx.c
  • 2.添加基本的命令和函数
  • 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"
);
/*
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-11-15 23:26:50
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-11-16 21:38:40
 * @FilePath: \uboot\cmd\cmd_update.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#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[])
{
    /* 判断参数个数 */
    if (argc != 2)
    {
        printf("update params num err\n");
        return 1;
    }
 
    if (0 == strncmp("uboot", argv[0], sizeof("uboot")))
    {
        printf("update uboot success\n");
    }
    else if (0 == strncmp("image", argv[0], sizeof("image")))
    {
        printf("update image success\n");
    }
    else if (0 == strncmp("rootfs", argv[0], sizeof("rootfs")))
    {
        printf("update rootfs success\n");
    }
 
    return 0;
}
 
/* 
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"
);

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们