uboot添加自定義命令的實現(xiàn)步驟
uboot簡介
uboot 屬于bootloader的一種,是用來引導(dǎo)啟動內(nèi)核的,它的最終目的就是:從flash中讀出內(nèi)核,放到內(nèi)存中,啟動內(nèi)核。
它剛開始被放到flash上,然后上電以后先執(zhí)行它,它會完成硬件初始化,設(shè)置處理器模式,關(guān)閉看門狗,屏蔽中斷,初始化sdram,設(shè)置棧,設(shè)置時鐘,從flash引導(dǎo)內(nèi)核到內(nèi)存,就好像我們PC上的BIOS一樣。最終將系統(tǒng)的軟硬件帶到一個合適的狀態(tài)。
實現(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ù):
/* 第一個參數(shù):添加的命令的名字 第二個參數(shù):添加的命令最多有幾個參數(shù)(注意,假如你設(shè)置的參數(shù)個數(shù)是3, 而實際的參數(shù)個數(shù)是4,那么執(zhí)行命令會輸出幫助信息的) 第三個參數(shù):是否重復(fù)(1重復(fù),0不重復(fù))(即按下Enter鍵的時候, 自動執(zhí)行上次的命令) 第四個參數(shù):執(zhí)行函數(shù),即運行了命令具體做啥會在這個函數(shù)中體現(xiàn)出來 第五個參數(shù):幫助信息(short) 第六個參數(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è)置,請設(shè)置`customMade`, 打開koroFileHeader查看配置 進(jìn)行設(shè)置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #include <common.h> #include <command.h> /* 第一個參數(shù):添加的命令的名字 第二個參數(shù):添加的命令最多有幾個參數(shù)(注意,假如你設(shè)置的參數(shù)個數(shù)是3,而實際的參數(shù)個數(shù)是4,那么執(zhí)行命令會輸出幫助信息的) 第三個參數(shù):是否重復(fù)(1重復(fù),0不重復(fù))(即按下Enter鍵的時候,自動執(zhí)行上次的命令) 第四個參數(shù):執(zhí)行函數(shù),即運行了命令具體做啥會在這個函數(shù)中體現(xiàn)出來 第五個參數(shù):幫助信息(short) 第六個參數(shù):幫助信息(long) */ static int do_update(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { /* 判斷參數(shù)個數(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" );
到此這篇關(guān)于uboot添加自定義命令的實現(xiàn)步驟的文章就介紹到這了,更多相關(guān)uboot添加自定義命令內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
opencv3/C++ 使用Tracker實現(xiàn)簡單目標(biāo)跟蹤
今天小編就為大家分享一篇opencv3/C++ 使用Tracker實現(xiàn)簡單目標(biāo)跟蹤,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12