* JinHua Luo, GuangDong Linux Center, <luo.jinhua@gd-linux.com>
*/
+#define pr_fmt(fmt) "cli: %s: " fmt, __func__
+
#include <common.h>
#include <bootstage.h>
#include <cli.h>
#include <malloc.h>
#include <asm/global_data.h>
#include <dm/ofnode.h>
+#include <linux/errno.h>
#ifdef CONFIG_CMDLINE
/*
int run_commandf(const char *fmt, ...)
{
va_list args;
- char cmd[128];
- int i, ret;
+ int nbytes;
va_start(args, fmt);
- i = vsnprintf(cmd, sizeof(cmd), fmt, args);
+ /*
+ * 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);
- ret = run_command(cmd, 0);
-
- return ret;
+ 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);
}
/****************************************************************************/
#include <env.h>
#include <linker_lists.h>
+#include <linux/compiler_attributes.h>
+
#ifndef NULL
#define NULL 0
#endif
/**
* 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)
+ *
+ * The command cannot be larger than (CONFIG_SYS_CBSIZE - 1) characters.
+ *
+ * Return:
+ * Returns 0 on success, -EIO if internal output error occurred, -ENOSPC in
+ * case of 'fmt' string truncation, or != 0 on error, specific for
+ * run_command().
*/
-int run_commandf(const char *fmt, ...);
+int run_commandf(const char *fmt, ...) __printf(1, 2);
/**
* Run a list of commands separated by ; or even \0