日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

uboot添加自定義命令的實現步驟_C 語言

作者:IT小生lkc ? 更新時間: 2022-12-15 編程語言

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"
);

原文鏈接:https://blog.csdn.net/qq_20017379/article/details/127894303

欄目分類
最近更新