[U-Boot] [PATCH 4/6] main: Exclude getline code when CONFIG_CMDLINE is not defined
Simon Glass
sjg at chromium.org
Mon Mar 24 16:51:09 CET 2014
It would be better to split common/main.c into a few chunks: readline, the
standard parser and the real main. However such a change is fairly invasive.
For now, use #ifdef to remove the unwanted code.
This helps to reduce the image size by removing unwanted code.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
common/command.c | 7 +++++++
common/main.c | 26 ++++++++++++++++++++------
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/common/command.c b/common/command.c
index 180ce27..dd09d08 100644
--- a/common/command.c
+++ b/common/command.c
@@ -481,6 +481,7 @@ void fixup_cmdtable(cmd_tbl_t *cmdtp, int size)
}
#endif
+#ifdef CONFIG_CMDLINE
/**
* Call a command function. This should be the only route in U-Boot to call
* a command, so that we can track whether we are waiting for input or
@@ -501,11 +502,14 @@ static int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
debug("Command failed, result=%d", result);
return result;
}
+#endif /* CONFIG_CMDLINE */
enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
int *repeatable, ulong *ticks)
{
enum command_ret_t rc = CMD_RET_SUCCESS;
+
+#ifdef CONFIG_CMDLINE
cmd_tbl_t *cmdtp;
/* Look up command in command table */
@@ -543,6 +547,9 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
}
if (rc == CMD_RET_USAGE)
rc = cmd_usage(cmdtp);
+#else
+ rc = board_run_command(argv[0]);
+#endif
return rc;
}
diff --git a/common/main.c b/common/main.c
index cb021d3..2fdea01 100644
--- a/common/main.c
+++ b/common/main.c
@@ -45,7 +45,9 @@ void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progre
char console_buffer[CONFIG_SYS_CBSIZE + 1]; /* console I/O buffer */
+#ifdef CONFIG_CMDLINE
static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen);
+#endif
static const char erase_seq[] = "\b \b"; /* erase sequence */
static const char tab_seq[] = " "; /* used to expand TABs */
@@ -421,7 +423,7 @@ static void process_boot_delay(void)
void main_loop(void)
{
-#ifndef CONFIG_SYS_HUSH_PARSER
+#if defined(CONFIG_CMDLINE) && !defined(CONFIG_SYS_HUSH_PARSER)
static char lastcommand[CONFIG_SYS_CBSIZE] = { 0, };
int len;
int rc = 1;
@@ -464,8 +466,9 @@ void main_loop(void)
# ifdef CONFIG_AUTOBOOT_KEYED
int prev = disable_ctrlc(1); /* disable Control C checking */
# endif
-
+#ifdef CONFIG_CMDLINE
run_command_list(p, -1, 0);
+#endif
# ifdef CONFIG_AUTOBOOT_KEYED
disable_ctrlc(prev); /* restore Control C checking */
@@ -483,6 +486,7 @@ void main_loop(void)
/*
* Main Loop for Monitor Command Processing
*/
+#ifdef CONFIG_CMDLINE
#ifdef CONFIG_SYS_HUSH_PARSER
parse_file_outer();
/* This point is never reached */
@@ -528,7 +532,8 @@ void main_loop(void)
lastcommand[0] = 0;
}
}
-#endif /*CONFIG_SYS_HUSH_PARSER*/
+#endif /* CONFIG_SYS_HUSH_PARSER */
+#endif /* CONFIG_CMDLINE */
}
#ifdef CONFIG_BOOT_RETRY_TIME
@@ -983,6 +988,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
/****************************************************************************/
+#ifdef CONFIG_CMDLINE
/*
* Prompt for input and read a line.
* If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0,
@@ -1211,10 +1217,10 @@ int parse_line (char *line, char *argv[])
debug_parser("parse_line: nargs=%d\n", nargs);
return (nargs);
}
-
+#endif /* CONFIG_CMDLINE */
/****************************************************************************/
-#ifndef CONFIG_SYS_HUSH_PARSER
+#if !defined(CONFIG_SYS_HUSH_PARSER) && defined(CONFIG_CMDLINE)
static void process_macros (const char *input, char *output)
{
char c, prev;
@@ -1433,6 +1439,7 @@ static int builtin_run_command(const char *cmd, int flag)
*/
int run_command(const char *cmd, int flag)
{
+#ifdef CONFIG_CMDLINE
#ifndef CONFIG_SYS_HUSH_PARSER
/*
* builtin_run_command can return 0 or 1 for success, so clean up
@@ -1446,9 +1453,12 @@ int run_command(const char *cmd, int flag)
return parse_string_outer(cmd,
FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP);
#endif
+#else
+ return board_run_command(cmd);
+#endif
}
-#ifndef CONFIG_SYS_HUSH_PARSER
+#if !defined(CONFIG_SYS_HUSH_PARSER) && defined(CONFIG_CMDLINE)
/**
* Execute a list of command separated by ; or \n using the built-in parser.
*
@@ -1493,6 +1503,7 @@ static int builtin_run_command_list(char *cmd, int flag)
int run_command_list(const char *cmd, int len, int flag)
{
+#ifdef CONFIG_CMDLINE
int need_buff = 1;
char *buff = (char *)cmd; /* cast away const */
int rcode = 0;
@@ -1530,6 +1541,9 @@ int run_command_list(const char *cmd, int len, int flag)
#endif
return rcode;
+#else
+ return board_run_command(cmd);
+#endif
}
/****************************************************************************/
--
1.9.1.423.g4596e3a
More information about the U-Boot
mailing list