[U-Boot] [PATCH 3/6] Add CONFIG_CMDLINE to allow removal of all commands

Simon Glass sjg at chromium.org
Mon Mar 24 16:51:08 CET 2014


A large chunk of the U-Boot code is the command line. For some applications
this is not needed, since the boot can be controlled by a board-specific
hard-coded boot procedure. This saves a significant amount of space.

This makes U-Boot proper look a little more like SPL in terms of size.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 README                     |  8 ++++++++
 arch/x86/cpu/u-boot.lds    |  4 ++++
 common/cmd_cbfs.c          |  3 ++-
 common/cmd_help.c          |  4 ++++
 common/command.c           |  2 ++
 common/main.c              |  6 ++++++
 include/command.h          | 30 ++++++++++++++++++++++++++++++
 include/config_defaults.h  |  2 ++
 include/config_fallbacks.h |  7 +++++++
 9 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/README b/README
index 216f0c7..28c79fb 100644
--- a/README
+++ b/README
@@ -1035,6 +1035,14 @@ The following options need to be configured:
 
 		XXX - this list needs to get updated!
 
+- Removal of commands
+		If no commands are needed to boot, you can undefine
+		CONFIG_CMDLINE in your board config file to remove them.
+		In this case, the command line will not be available, and
+		when U-Boot wants to execute the boot command (on start-up)
+		it will call board_run_command() instead. This can reduce
+		image size significantly for very simple boot procedures.
+
 - Regular expression support:
 		CONFIG_REGEX
 		If this variable is defined, U-Boot is linked against
diff --git a/arch/x86/cpu/u-boot.lds b/arch/x86/cpu/u-boot.lds
index f48bff5..9720286 100644
--- a/arch/x86/cpu/u-boot.lds
+++ b/arch/x86/cpu/u-boot.lds
@@ -12,6 +12,10 @@ ENTRY(_start)
 
 SECTIONS
 {
+#ifndef CONFIG_CMDLINE
+	/DISCARD/ : { *(.u_boot_list_2_cmd_*) }
+#endif
+
 	. = CONFIG_SYS_TEXT_BASE;	/* Location of bootcode in flash */
 	__text_start = .;
 	.text  : { *(.text*); }
diff --git a/common/cmd_cbfs.c b/common/cmd_cbfs.c
index 35d8a7a..5f1add8 100644
--- a/common/cmd_cbfs.c
+++ b/common/cmd_cbfs.c
@@ -44,7 +44,8 @@ U_BOOT_CMD(
 	"      CBFS is in. It defaults to 0xFFFFFFFF\n"
 );
 
-int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+static int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc,
+			  char *const argv[])
 {
 	const struct cbfs_cachenode *file;
 	unsigned long offset;
diff --git a/common/cmd_help.c b/common/cmd_help.c
index 6ff494d..701ae7e 100644
--- a/common/cmd_help.c
+++ b/common/cmd_help.c
@@ -10,9 +10,13 @@
 
 static int do_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
+#ifdef CONFIG_CMDLINE
 	cmd_tbl_t *start = ll_entry_start(cmd_tbl_t, cmd);
 	const int len = ll_entry_count(cmd_tbl_t, cmd);
 	return _do_help(start, len, cmdtp, flag, argc, argv);
+#else
+	return 0;
+#endif
 }
 
 U_BOOT_CMD(
diff --git a/common/command.c b/common/command.c
index 35c9d71..180ce27 100644
--- a/common/command.c
+++ b/common/command.c
@@ -87,6 +87,7 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
  */
 cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
 {
+#ifdef CONFIG_CMDLINE
 	cmd_tbl_t *cmdtp;
 	cmd_tbl_t *cmdtp_temp = table;	/*Init value */
 	const char *p;
@@ -115,6 +116,7 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
 	if (n_found == 1) {			/* exactly one match */
 		return cmdtp_temp;
 	}
+#endif /* CONFIG_CMDLINE */
 
 	return NULL;	/* not found or ambiguous command */
 }
diff --git a/common/main.c b/common/main.c
index 8b6f274..cb021d3 100644
--- a/common/main.c
+++ b/common/main.c
@@ -270,7 +270,9 @@ static int abortboot(int bootdelay)
 #if defined(CONFIG_BOOTDELAY) && defined(CONFIG_OF_CONTROL)
 static void secure_boot_cmd(char *cmd)
 {
+#ifdef CONFIG_CMDLINE
 	cmd_tbl_t *cmdtp;
+#endif
 	int rc;
 
 	if (!cmd) {
@@ -282,6 +284,7 @@ static void secure_boot_cmd(char *cmd)
 	disable_ctrlc(1);
 
 	/* Find the command directly. */
+#ifdef CONFIG_CMDLINE
 	cmdtp = find_cmd(cmd);
 	if (!cmdtp) {
 		printf("## Error: \"%s\" not defined\n", cmd);
@@ -290,6 +293,9 @@ static void secure_boot_cmd(char *cmd)
 
 	/* Run the command, forcing no flags and faking argc and argv. */
 	rc = (cmdtp->cmd)(cmdtp, 0, 1, &cmd);
+#else
+	rc = board_run_command(cmd);
+#endif
 
 	/* Shouldn't ever return from boot command. */
 	printf("## Error: \"%s\" returned (code %d)\n", cmd, rc);
diff --git a/include/command.h b/include/command.h
index 1a3871f..9f507d9 100644
--- a/include/command.h
+++ b/include/command.h
@@ -184,6 +184,7 @@ int cmd_process(int flag, int argc, char * const argv[],
  *
  * We need to ensure that a command is placed between each entry
  */
+#ifdef CONFIG_CMDLINE
 #define U_BOOT_SUBCMD_START(name)	static cmd_tbl_t name[] = {
 #define U_BOOT_SUBCMD_END		};
 #define U_BOOT_CMD_MKENT_LINE(_name, _maxargs, _rep, _cmd, _usage,	\
@@ -203,6 +204,26 @@ int cmd_process(int flag, int argc, char * const argv[],
 	ll_entry_declare(cmd_tbl_t, _name, cmd) =			\
 		U_BOOT_CMD_MKENT_LINE(_name, _maxargs, _rep, _cmd,	\
 			_usage, _help, _comp, _info);
+#else
+#define U_BOOT_SUBCMD_START(name)	static cmd_tbl_t name[] = {};
+#define U_BOOT_SUBCMD_END
+
+#define _CMD_REMOVE(_name, _cmd)					\
+	int __remove_ ## _name(void)					\
+	{								\
+		if (0)							\
+			_cmd(NULL, 0, 0, NULL);				\
+		return 0;						\
+	}
+#define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, _usage,	\
+				  _help, _comp, _info)			\
+	_CMD_REMOVE(_name ## _cmd, _cmd)
+
+#define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help,	\
+			    _comp, _info)				\
+	_CMD_REMOVE(sub_ ## _name, _cmd)
+
+#endif /* CONFIG_CMDLINE */
 
 #define U_BOOT_CMD_MKENT(_name, _maxargs, _rep, _cmd, _usage, _help)	\
 	U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd,		\
@@ -223,6 +244,15 @@ static inline int cmd_dummy(cmd_tbl_t *cmdtp, int flag, int argc,
 	return 0;
 }
 
+/*
+ * When there is no U-Boot command line, the board must provide a way of
+ * executing commands.
+ *
+ * @cmd:	Command string to execute
+ * @return Result of command, CMD_RET_...
+ */
+int board_run_command(const char *cmd);
+
 #endif	/* __ASSEMBLY__ */
 
 #endif	/* __COMMAND_H */
diff --git a/include/config_defaults.h b/include/config_defaults.h
index ad08c1d..913acaf 100644
--- a/include/config_defaults.h
+++ b/include/config_defaults.h
@@ -20,4 +20,6 @@
 #define CONFIG_ZLIB 1
 #define CONFIG_PARTITIONS 1
 
+#define CONFIG_CMDLINE
+
 #endif
diff --git a/include/config_fallbacks.h b/include/config_fallbacks.h
index d8339b2..8b11b54 100644
--- a/include/config_fallbacks.h
+++ b/include/config_fallbacks.h
@@ -63,4 +63,11 @@
 #define CONFIG_SYS_HZ		1000
 #endif
 
+#ifndef CONFIG_CMDLINE
+#undef CONFIG_CMDLINE_EDITING
+#undef CONFIG_SYS_LONGHELP
+#undef CONFIG_CMD_RUN
+#undef CONFIG_SYS_HUSH_PARSER
+#endif
+
 #endif	/* __CONFIG_FALLBACKS_H */
-- 
1.9.1.423.g4596e3a



More information about the U-Boot mailing list