uboot分析之命令

本文介绍了如何在UBOOT命令行中增加一个helloworld命令,包括在cmd目录下创建cmd_hello.c文件,定义命令执行函数do_hello,并在makefile中更新编译目标。该过程涉及到C编程、命令行接口和嵌入式系统开发。
摘要由CSDN通过智能技术生成

uboot增加命令
run_command实现增加一个hello world:
1.cd ./u-boot/cmd 目录创建一个文件cmd_hello.c
2.添加基本的命令和函数

/*
 * @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_hello(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	int i;
 	printf("hello world");
 	for(i = 0 ; i < argc; i++)
 	{
 		printf("argv[%d]:%s\n",i,argv[i]);
 	}
 
    return 0;
}
 
/* 
U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help) 
*/	
U_BOOT_CMD(hello, 4, 0, do_hello,
	"hello command",
	" - check boot progress and timing\n"
	"hello,long help ...................."
);

3.cmd下makefile添加 obj-y += cmd_update.o

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

<( ̄︶ ̄)Okay.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值