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

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

uboot添加自定義命令的實(shí)現(xiàn)步驟_C 語(yǔ)言

作者:IT小生lkc ? 更新時(shí)間: 2022-12-15 編程語(yǔ)言

uboot簡(jiǎn)介

uboot 屬于bootloader的一種,是用來(lái)引導(dǎo)啟動(dòng)內(nèi)核的,它的最終目的就是:從flash中讀出內(nèi)核,放到內(nèi)存中,啟動(dòng)內(nèi)核。
它剛開(kāi)始被放到flash上,然后上電以后先執(zhí)行它,它會(huì)完成硬件初始化,設(shè)置處理器模式,關(guān)閉看門(mén)狗,屏蔽中斷,初始化sdram,設(shè)置棧,設(shè)置時(shí)鐘,從flash引導(dǎo)內(nèi)核到內(nèi)存,就好像我們PC上的BIOS一樣。最終將系統(tǒng)的軟硬件帶到一個(gè)合適的狀態(tài)。

實(shí)現(xiàn)步驟:

  • 1.uboot源碼下新建cmd/cmd_xx.c
  • 2.添加基本的命令和函數(shù)
  • 3.cmd下makefile添加 obj-y += cmd_update.o

頭文件:

#include <common.h>

#include <command.h>

函數(shù):

/*

    第一個(gè)參數(shù):添加的命令的名字

    第二個(gè)參數(shù):添加的命令最多有幾個(gè)參數(shù)(注意,假如你設(shè)置的參數(shù)個(gè)數(shù)是3,

              而實(shí)際的參數(shù)個(gè)數(shù)是4,那么執(zhí)行命令會(huì)輸出幫助信息的)

    第三個(gè)參數(shù):是否重復(fù)(1重復(fù),0不重復(fù))(即按下Enter鍵的時(shí)候,

              自動(dòng)執(zhí)行上次的命令)

    第四個(gè)參數(shù):執(zhí)行函數(shù),即運(yùn)行了命令具體做啥會(huì)在這個(gè)函數(shù)中體現(xiàn)出來(lái)

    第五個(gè)參數(shù):幫助信息(short)

    第六個(gè)參數(shù):幫助信息(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: 這是默認(rèn)設(shè)置,請(qǐng)?jiān)O(shè)置`customMade`, 打開(kāi)koroFileHeader查看配置 進(jìn)行設(shè)置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <common.h>
#include <command.h>
 
 
/*
    第一個(gè)參數(shù):添加的命令的名字
    第二個(gè)參數(shù):添加的命令最多有幾個(gè)參數(shù)(注意,假如你設(shè)置的參數(shù)個(gè)數(shù)是3,而實(shí)際的參數(shù)個(gè)數(shù)是4,那么執(zhí)行命令會(huì)輸出幫助信息的)
    第三個(gè)參數(shù):是否重復(fù)(1重復(fù),0不重復(fù))(即按下Enter鍵的時(shí)候,自動(dòng)執(zhí)行上次的命令)
    第四個(gè)參數(shù):執(zhí)行函數(shù),即運(yùn)行了命令具體做啥會(huì)在這個(gè)函數(shù)中體現(xiàn)出來(lái)
    第五個(gè)參數(shù):幫助信息(short)
    第六個(gè)參數(shù):幫助信息(long)
*/
static int do_update(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
    /* 判斷參數(shù)個(gè)數(shù) */
    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

欄目分類(lèi)
最近更新