From 85d34e1026065c340e2237e1d2ab56e868be86ec Mon Sep 17 00:00:00 2001 From: Leo C Date: Thu, 30 Aug 2018 09:01:40 +0200 Subject: [PATCH] new command: boot - boot default, i.e., run 'bootcmd' --- avr/cmd_run.c | 22 ++++++++++------------ avr/command_tbl.c | 5 +++++ include/cmd_run.h | 1 + 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/avr/cmd_run.c b/avr/cmd_run.c index 9c6f20f..6482d0b 100644 --- a/avr/cmd_run.c +++ b/avr/cmd_run.c @@ -1,5 +1,5 @@ /* - * (C) Copyright 2016 Leo C. + * (C) Copyright 2016, 2018 Leo C. * * SPDX-License-Identifier: GPL-2.0 */ @@ -12,15 +12,12 @@ #include "env.h" -command_ret_t do_run(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) +command_ret_t do_run(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag, int argc, char * const argv[]) { - int i; - (void) cmdtp; - if (argc < 2) return CMD_RET_USAGE; - for (i = 1; i < argc; ++i) { + for (int i = 1; i < argc; ++i) { char *arg; arg = getenv_str(argv[i]); @@ -35,13 +32,16 @@ command_ret_t do_run(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const return CMD_RET_SUCCESS; } -static int source(FIL *fp, uint_fast8_t flag, int argc, char * const argv[]) +command_ret_t do_bootd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag, int argc UNUSED, char * const argv[] UNUSED) +{ + return run_command(getenv_str("bootcmd"), flag); +} + +static int source(FIL *fp, uint_fast8_t flag, int argc UNUSED, char * const argv[] UNUSED) { int lineno = 0; int res = 0; - (void)argc; (void)argv; - while (!f_eof(fp) && !f_error(fp) && !res) { lineno++; if (f_gets(console_buffer, CONFIG_SYS_CBSIZE, fp)) { @@ -62,13 +62,11 @@ static int source(FIL *fp, uint_fast8_t flag, int argc, char * const argv[]) return !f_eof(fp) || res; } -command_ret_t do_source(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]) +command_ret_t do_source(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag, int argc, char * const argv[]) { FIL File; int res; - (void) cmdtp; - if (argc < 2) return CMD_RET_USAGE; diff --git a/avr/command_tbl.c b/avr/command_tbl.c index 1226180..d93294b 100644 --- a/avr/command_tbl.c +++ b/avr/command_tbl.c @@ -100,6 +100,11 @@ CMD_TBL_ITEM_COMPLETE( " - run the commands in the environment variable(s) 'var'", var_complete ), +CMD_TBL_ITEM( + boot, 1, 1, do_bootd, + "boot default, i.e., run 'bootcmd'", + "" +), CMD_TBL_ITEM_COMPLETE( source, CONFIG_SYS_MAXARGS, 1, do_source, "run commands from a file", diff --git a/include/cmd_run.h b/include/cmd_run.h index 4691a55..fc81267 100644 --- a/include/cmd_run.h +++ b/include/cmd_run.h @@ -9,6 +9,7 @@ #include "command.h" +command_ret_t do_bootd(cmd_tbl_t *, uint_fast8_t, int, char * const []); command_ret_t do_source(cmd_tbl_t *, uint_fast8_t, int, char * const []); command_ret_t do_run(cmd_tbl_t *, uint_fast8_t, int, char * const []); -- 2.39.2