run 命令可以用于运行环境变量的中定义的命令,run bootcmd 可以运行bootcmd中启动命令
作用:可以运行我们自定义的环境变量
include/command.h
common/cli.c
/*** board_run_command() - Fallback function to execute a command** When no command line features are enabled in U-Boot, this function is* called to execute a command. Typically the function can look at the* command and perform a few very specific tasks, such as booting the* system in a particular way.** This function is only used when CONFIG_CMDLINE is not enabled.** In normal situations this function should not return, since U-Boot will* simply hang.** @cmdline: Command line string to execute* @return 0 if OK, 1 for error*/
int board_run_command(const char *cmdline);int run_command(const char *cmd, int flag);
int run_command_repeatable(const char *cmd, int flag);/*** 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);/** Run a command using the selected parser.** @param cmd Command to run* @param flag Execution flags (CMD_FLAG_...)* @return 0 on success, or != 0 on error.*/
int run_command(const char *cmd, int flag)
{
#if !CONFIG_IS_ENABLED(HUSH_PARSER)/** cli_run_command can return 0 or 1 for success, so clean up* its result.*/if (cli_simple_run_command(cmd, flag) == -1)return 1;return 0;
#elseint hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP;if (flag & CMD_FLAG_ENV)hush_flags |= FLAG_CONT_ON_NEWLINE;return parse_string_outer(cmd, hush_flags);
#endif
}
例子(1)
env set mybootflash " sf probe 0;sf read 0x50000000 0x0100000 0x900000; bootm 0x50000000 "
saveenvenv set mybootnet " mw.b 0x50000000 0xff 0x900000; tftp 0x50000000 uImage; bootm 0x50000000"
saveenvrun mybootnet
run mybootflash
例子(2)在代码中使用
char *p;
p = env_get("mybootnet");
run_command(p,0);/* We come here after U-Boot is initialised and ready to process commands */
void main_loop(void)
{const char *s;char *p;p = env_get("mybootnet");if(p){printf(" main_loop run_command(p,0) \r\n");run_command(p,0);}bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");if (IS_ENABLED(CONFIG_VERSION_VARIABLE))env_set("ver", version_string); /* set version variable */cli_init();if (IS_ENABLED(CONFIG_USE_PREBOOT))run_preboot_environment_command();if (IS_ENABLED(CONFIG_UPDATE_TFTP))update_tftp(0UL, NULL, NULL);s = bootdelay_process();if (cli_process_fdt(&s))cli_secure_boot_cmd(s);autoboot_command(s);cli_loop();panic("No CLI available");
}