GNU/Linux - 在U-Boot代码中调用命令

1,包含inlucde/command.h头文件。

2,使用run_command、run_commandf或run_command_list函数。

int run_command(const char *cmd, int flag);

/**

* run_commandf() - Run a command created by a format string

*

* The command cannot be larger than 127 characters

*

* @fmt: printf() format string

* @...: Arguments to use (flag is always 0)

*/

int run_commandf(const char *fmt, ...);

/**

* Run a list of commands separated by ; or even \0

*

* Note that if 'len' is not -1, then the command does not need to be nul

* terminated, Memory will be allocated for the command in that case.

*

* @param cmd    List of commands to run, each separated bu semicolon

* @param len    Length of commands excluding terminator if known (-1 if not)

* @param flag    Execution flags (CMD_FLAG_...)

* Return: 0 on success, or != 0 on error.

*/

int run_command_list(const char *cmd, int len, int flag);

3, 一个是直接运行command,一个是使用printf格式来构造一个command并运行,最后一个是多个command一起运行,通过分号分隔。

4,Flag参数。

/*

* Command Flags:

*/

#define CMD_FLAG_REPEAT        0x0001    /* repeat last command        */

#define CMD_FLAG_BOOTD        0x0002    /* command is from bootd    */

#define CMD_FLAG_ENV        0x0004    /* command is from the environment */

大概意思,第一个是命令重复,第二个是和bootd命令相关,第三个和是environment相关的命令。

(bootd - boot default image, 就是boot命令,会从默认image启动,一般就是启动linux kernel image)

5,在代码里调用命令。

比如我想通过代码来控制某个GPIO:

run_command("gpio set GPIO2_11", 0);

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

夜流冰

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

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

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

打赏作者

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

抵扣说明:

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

余额充值