+// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
* Add to readline cmdline-editing by
* (C) Copyright 2005
* JinHua Luo, GuangDong Linux Center, <luo.jinhua@gd-linux.com>
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
+#define pr_fmt(fmt) "cli: %s: " fmt, __func__
+
#include <common.h>
+#include <bootstage.h>
#include <cli.h>
#include <cli_hush.h>
+#include <command.h>
#include <console.h>
+#include <env.h>
#include <fdtdec.h>
+#include <hang.h>
#include <malloc.h>
-
-DECLARE_GLOBAL_DATA_PTR;
+#include <asm/global_data.h>
+#include <dm/ofnode.h>
+#include <linux/errno.h>
#ifdef CONFIG_CMDLINE
/*
*
* @param cmd Command to run
* @param flag Execution flags (CMD_FLAG_...)
- * @return 0 on success, or != 0 on error.
+ * Return: 0 on success, or != 0 on error.
*/
int run_command(const char *cmd, int flag)
{
-#ifndef CONFIG_HUSH_PARSER
+#if !IS_ENABLED(CONFIG_HUSH_PARSER)
/*
* cli_run_command can return 0 or 1 for success, so clean up
* its result.
*
* @param cmd Command to run
* @param flag Execution flags (CMD_FLAG_...)
- * @return 0 (not repeatable) or 1 (repeatable) on success, -1 on error.
+ * Return: 0 (not repeatable) or 1 (repeatable) on success, -1 on error.
*/
int run_command_repeatable(const char *cmd, int flag)
{
return 0;
#endif
}
+#else
+__weak int board_run_command(const char *cmdline)
+{
+ printf("## Commands are disabled. Please enable CONFIG_CMDLINE.\n");
+
+ return 1;
+}
#endif /* CONFIG_CMDLINE */
int run_command_list(const char *cmd, int len, int flag)
return rcode;
}
+int run_commandf(const char *fmt, ...)
+{
+ va_list args;
+ int nbytes;
+
+ va_start(args, fmt);
+ /*
+ * Limit the console_buffer space being used to CONFIG_SYS_CBSIZE,
+ * because its last byte is used to fit the replacement of \0 by \n\0
+ * in underlying hush parser
+ */
+ nbytes = vsnprintf(console_buffer, CONFIG_SYS_CBSIZE, fmt, args);
+ va_end(args);
+
+ if (nbytes < 0) {
+ pr_debug("I/O internal error occurred.\n");
+ return -EIO;
+ } else if (nbytes >= CONFIG_SYS_CBSIZE) {
+ pr_debug("'fmt' size:%d exceeds the limit(%d)\n",
+ nbytes, CONFIG_SYS_CBSIZE);
+ return -ENOSPC;
+ }
+ return run_command(console_buffer, 0);
+}
+
/****************************************************************************/
#if defined(CONFIG_CMD_RUN)
-int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_run(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
- int i;
+ int i, ret;
if (argc < 2)
return CMD_RET_USAGE;
for (i = 1; i < argc; ++i) {
char *arg;
- arg = getenv(argv[i]);
+ arg = env_get(argv[i]);
if (arg == NULL) {
printf("## Error: \"%s\" not defined\n", argv[i]);
return 1;
}
- if (run_command(arg, flag | CMD_FLAG_ENV) != 0)
- return 1;
+ ret = run_command(arg, flag | CMD_FLAG_ENV);
+ if (ret)
+ return ret;
}
return 0;
}
bool cli_process_fdt(const char **cmdp)
{
/* Allow the fdt to override the boot command */
- char *env = fdtdec_get_config_string(gd->fdt_blob, "bootcmd");
+ const char *env = ofnode_conf_read_str("bootcmd");
if (env)
*cmdp = env;
/*
* Always use 'env' in this case, since bootsecure requres that the
* bootcmd was specified in the FDT too.
*/
- return fdtdec_get_config_int(gd->fdt_blob, "bootsecure", 0) != 0;
+ return ofnode_conf_read_int("bootsecure", 0);
}
/*
void cli_secure_boot_cmd(const char *cmd)
{
#ifdef CONFIG_CMDLINE
- cmd_tbl_t *cmdtp;
+ struct cmd_tbl *cmdtp;
#endif
int rc;
void cli_loop(void)
{
+ bootstage_mark(BOOTSTAGE_ID_ENTER_CLI_LOOP);
#ifdef CONFIG_HUSH_PARSER
parse_file_outer();
/* This point is never reached */