[U-Boot] [PATCH 2/6] Refactor command macros so they can compile to nothing
Simon Glass
sjg at chromium.org
Mon Mar 24 16:51:07 CET 2014
Commands are declared entirely within a macro, like this:
U_BOOT_CMD(...);
Sub-commands are not the same. At present the U_BOOT_CMD_MKENT() macro is
used within an array declaration, but the array itself is not handled by
macros. We have this:
static cmd_tbl_t table[] = {
U_BOOT_CMD_MKENT(...),
U_BOOT_CMD_MKENT(...),
};
There are two problems with this. The first is that it requires knowledge
of the command type (a minor issue). The second is that it is not possible
to make sub-commands compile to nothing if we want to.
Introduce a new syntax which matches U_BOOT_CMD() as follows:
U_BOOT_SUBCMD_START
U_BOOT_CMD_MKENT(...)
U_BOOT_CMD_MKENT(...)
U_BOOT_SUBCMD_END
Note that the U_BOOT_CMD_MKENT() lines no longer have a comma at the end.
It would be possible to put a semicolon after U_BOOT_SUBCMD_END, but it
seems syntactically odd to do so.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
board/inka4x0/inkadiag.c | 12 ++++----
board/intercontrol/digsy_mtc/cmd_mtc.c | 20 ++++++-------
common/cmd_bmp.c | 8 +++---
common/cmd_bootm.c | 22 +++++++-------
common/cmd_bootstage.c | 10 +++----
common/cmd_clk.c | 6 ++--
common/cmd_demo.c | 10 +++----
common/cmd_i2c.c | 34 +++++++++++-----------
common/cmd_nvedit.c | 32 ++++++++++-----------
common/cmd_onenand.c | 23 ++++++++-------
common/cmd_pxe.c | 6 ++--
common/cmd_sandbox.c | 14 ++++-----
common/cmd_sound.c | 8 +++---
common/cmd_spl.c | 14 ++++-----
common/cmd_tpm.c | 52 +++++++++++++++++-----------------
drivers/gpio/pca953x.c | 14 ++++-----
drivers/gpio/tca642x.c | 14 ++++-----
drivers/misc/ds4510.c | 24 ++++++++--------
include/command.h | 37 +++++++++++++++++++-----
test/dm/cmd_dm.c | 10 +++----
20 files changed, 197 insertions(+), 173 deletions(-)
diff --git a/board/inka4x0/inkadiag.c b/board/inka4x0/inkadiag.c
index 0bd12ec..56978b4 100644
--- a/board/inka4x0/inkadiag.c
+++ b/board/inka4x0/inkadiag.c
@@ -416,17 +416,17 @@ static int do_inkadiag_buzzer(cmd_tbl_t *cmdtp, int flag, int argc,
static int do_inkadiag_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-cmd_tbl_t cmd_inkadiag_sub[] = {
+U_BOOT_SUBCMD_START(cmd_inkadiag_sub)
U_BOOT_CMD_MKENT(io, 1, 1, do_inkadiag_io, "read digital input",
- "<drawer1|drawer2|other> [value] - get or set specified signal"),
+ "<drawer1|drawer2|other> [value] - get or set specified signal")
U_BOOT_CMD_MKENT(serial, 4, 1, do_inkadiag_serial, "test serial port",
"<num> <mode> <baudrate> <msg> - test uart num [0..11] in mode\n"
- "and baudrate with msg"),
+ "and baudrate with msg")
U_BOOT_CMD_MKENT(buzzer, 2, 1, do_inkadiag_buzzer, "activate buzzer",
- "<period> <freq> - turn buzzer on for period ms with freq hz"),
+ "<period> <freq> - turn buzzer on for period ms with freq hz")
U_BOOT_CMD_MKENT(help, 4, 1, do_inkadiag_help, "get help",
- "[command] - get help for command"),
-};
+ "[command] - get help for command")
+U_BOOT_SUBCMD_END
static int do_inkadiag_help(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[]) {
diff --git a/board/intercontrol/digsy_mtc/cmd_mtc.c b/board/intercontrol/digsy_mtc/cmd_mtc.c
index f17ec55..1138a7a 100644
--- a/board/intercontrol/digsy_mtc/cmd_mtc.c
+++ b/board/intercontrol/digsy_mtc/cmd_mtc.c
@@ -292,32 +292,32 @@ static int do_mtc_state(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
static int do_mtc_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-cmd_tbl_t cmd_mtc_sub[] = {
+U_BOOT_SUBCMD_START(cmd_mtc_sub)
U_BOOT_CMD_MKENT(led, 3, 1, do_mtc_led,
"set state of leds",
"[ledname] [state] [blink]\n"
" - lednames: diag can1 can2 can3 can4 usbpwr usbbusy user1 user2\n"
" - state: off red green orange\n"
- " - blink: blink interval in 100ms steps (1 - 10; 0 = static)\n"),
+ " - blink: blink interval in 100ms steps (1 - 10; 0 = static)\n")
U_BOOT_CMD_MKENT(key, 0, 1, do_mtc_key,
- "returns state of user key", ""),
+ "returns state of user key", "")
U_BOOT_CMD_MKENT(version, 0, 1, do_mtc_version,
- "returns firmware version of supervisor uC", ""),
+ "returns firmware version of supervisor uC", "")
U_BOOT_CMD_MKENT(appreg, 1, 1, do_mtc_appreg,
"reads or writes appreg value and stores in environment "
"variable 'appreg'",
- "[value] - value (1 - 255) to write to appreg"),
+ "[value] - value (1 - 255) to write to appreg")
U_BOOT_CMD_MKENT(digin, 1, 1, do_mtc_digin,
"returns state of digital input",
- "<channel_num> - get state of digital input (1 or 2)\n"),
+ "<channel_num> - get state of digital input (1 or 2)\n")
U_BOOT_CMD_MKENT(digout, 2, 1, do_mtc_digout,
"sets digital outputs",
- "<on|off> <on|off>- set state of digital output 1 and 2\n"),
+ "<on|off> <on|off>- set state of digital output 1 and 2\n")
U_BOOT_CMD_MKENT(state, 0, 1, do_mtc_state,
- "displays state", ""),
+ "displays state", "")
U_BOOT_CMD_MKENT(help, 4, 1, do_mtc_help, "get help",
- "[command] - get help for command\n"),
-};
+ "[command] - get help for command\n")
+U_BOOT_SUBCMD_END
static int do_mtc_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
diff --git a/common/cmd_bmp.c b/common/cmd_bmp.c
index cc904c2..aa650c9 100644
--- a/common/cmd_bmp.c
+++ b/common/cmd_bmp.c
@@ -131,10 +131,10 @@ static int do_bmp_display(cmd_tbl_t * cmdtp, int flag, int argc, char * const ar
return (bmp_display(addr, x, y));
}
-static cmd_tbl_t cmd_bmp_sub[] = {
- U_BOOT_CMD_MKENT(info, 3, 0, do_bmp_info, "", ""),
- U_BOOT_CMD_MKENT(display, 5, 0, do_bmp_display, "", ""),
-};
+U_BOOT_SUBCMD_START(cmd_bmp_sub)
+ U_BOOT_CMD_MKENT(info, 3, 0, do_bmp_info, "", "")
+ U_BOOT_CMD_MKENT(display, 5, 0, do_bmp_display, "", "")
+U_BOOT_SUBCMD_END
#ifdef CONFIG_NEEDS_MANUAL_RELOC
void bmp_reloc(void) {
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 14d504b..093f1b8 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -521,30 +521,30 @@ static int do_bootm_standalone(int flag, int argc, char * const argv[],
/* we overload the cmd field with our state machine info instead of a
* function pointer */
-static cmd_tbl_t cmd_bootm_sub[] = {
+U_BOOT_SUBCMD_START(cmd_bootm_sub)
U_BOOT_CMD_MKENT_COMPLETE(start, 0, 1, cmd_dummy, "", "", NULL,
- BOOTM_STATE_START),
+ BOOTM_STATE_START)
U_BOOT_CMD_MKENT_COMPLETE(loados, 0, 1, cmd_dummy, "", "", NULL,
- BOOTM_STATE_LOADOS),
+ BOOTM_STATE_LOADOS)
#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
U_BOOT_CMD_MKENT_COMPLETE(ramdisk, 0, 1, cmd_dummy, "", "", NULL,
- BOOTM_STATE_RAMDISK),
+ BOOTM_STATE_RAMDISK)
#endif
#ifdef CONFIG_OF_LIBFDT
U_BOOT_CMD_MKENT_COMPLETE(fdt, 0, 1, cmd_dummy, "", "", NULL,
- BOOTM_STATE_FDT),
+ BOOTM_STATE_FDT)
#endif
U_BOOT_CMD_MKENT_COMPLETE(cmdline, 0, 1, cmd_dummy, "", "", NULL,
- BOOTM_STATE_OS_CMDLINE),
+ BOOTM_STATE_OS_CMDLINE)
U_BOOT_CMD_MKENT_COMPLETE(bdt, 0, 1, cmd_dummy, "", "", NULL,
- BOOTM_STATE_OS_BD_T),
+ BOOTM_STATE_OS_BD_T)
U_BOOT_CMD_MKENT_COMPLETE(prep, 0, 1, cmd_dummy, "", "", NULL,
- BOOTM_STATE_OS_PREP),
+ BOOTM_STATE_OS_PREP)
U_BOOT_CMD_MKENT_COMPLETE(fake, 0, 1, cmd_dummy, "", "", NULL,
- BOOTM_STATE_OS_FAKE_GO),
+ BOOTM_STATE_OS_FAKE_GO)
U_BOOT_CMD_MKENT_COMPLETE(go, 0, 1, cmd_dummy, "", "", NULL,
- BOOTM_STATE_OS_GO),
-};
+ BOOTM_STATE_OS_GO)
+U_BOOT_SUBCMD_END
static int boot_selected_os(int argc, char * const argv[], int state,
bootm_headers_t *images, boot_os_fn *boot_fn)
diff --git a/common/cmd_bootstage.c b/common/cmd_bootstage.c
index 106894a..a6ea703 100644
--- a/common/cmd_bootstage.c
+++ b/common/cmd_bootstage.c
@@ -63,11 +63,11 @@ static int do_bootstage_stash(cmd_tbl_t *cmdtp, int flag, int argc,
return 0;
}
-static cmd_tbl_t cmd_bootstage_sub[] = {
- U_BOOT_CMD_MKENT(report, 2, 1, do_bootstage_report, "", ""),
- U_BOOT_CMD_MKENT(stash, 4, 0, do_bootstage_stash, "", ""),
- U_BOOT_CMD_MKENT(unstash, 4, 0, do_bootstage_stash, "", ""),
-};
+U_BOOT_SUBCMD_START(cmd_bootstage_sub)
+ U_BOOT_CMD_MKENT(report, 2, 1, do_bootstage_report, "", "")
+ U_BOOT_CMD_MKENT(stash, 4, 0, do_bootstage_stash, "", "")
+ U_BOOT_CMD_MKENT(unstash, 4, 0, do_bootstage_stash, "", "")
+U_BOOT_SUBCMD_END
/*
* Process a bootstage sub-command
diff --git a/common/cmd_clk.c b/common/cmd_clk.c
index 6d3d46a..c63bae5 100644
--- a/common/cmd_clk.c
+++ b/common/cmd_clk.c
@@ -19,9 +19,9 @@ static int do_clk_dump(cmd_tbl_t *cmdtp, int flag, int argc,
return soc_clk_dump();
}
-static cmd_tbl_t cmd_clk_sub[] = {
- U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
-};
+U_BOOT_SUBCMD_START(cmd_clk_sub)
+ U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", "")
+U_BOOT_SUBCMD_END
static int do_clk(cmd_tbl_t *cmdtp, int flag, int argc,
char *const argv[])
diff --git a/common/cmd_demo.c b/common/cmd_demo.c
index a3bba7f..a6446dd 100644
--- a/common/cmd_demo.c
+++ b/common/cmd_demo.c
@@ -58,11 +58,11 @@ int do_demo_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return cmd_process_error(cmdtp, ret);
}
-static cmd_tbl_t demo_commands[] = {
- U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""),
- U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""),
- U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""),
-};
+U_BOOT_SUBCMD_START(demo_commands)
+ U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", "")
+ U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", "")
+ U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", "")
+U_BOOT_SUBCMD_END
static int do_demo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
index ebce7d4..1401835 100644
--- a/common/cmd_i2c.c
+++ b/common/cmd_i2c.c
@@ -1529,32 +1529,32 @@ static int do_i2c_reset(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv
return 0;
}
-static cmd_tbl_t cmd_i2c_sub[] = {
+U_BOOT_SUBCMD_START(cmd_i2c_sub)
#if defined(CONFIG_SYS_I2C)
- U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
+ U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", "")
#endif
- U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
+ U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", "")
#if defined(CONFIG_SYS_I2C) || \
defined(CONFIG_I2C_MULTI_BUS)
- U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""),
+ U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", "")
#endif /* CONFIG_I2C_MULTI_BUS */
#if defined(CONFIG_I2C_EDID)
- U_BOOT_CMD_MKENT(edid, 1, 1, do_edid, "", ""),
+ U_BOOT_CMD_MKENT(edid, 1, 1, do_edid, "", "")
#endif /* CONFIG_I2C_EDID */
- U_BOOT_CMD_MKENT(loop, 3, 1, do_i2c_loop, "", ""),
- U_BOOT_CMD_MKENT(md, 3, 1, do_i2c_md, "", ""),
- U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", ""),
- U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", ""),
- U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""),
- U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
- U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
- U_BOOT_CMD_MKENT(write, 5, 0, do_i2c_write, "", ""),
- U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
+ U_BOOT_CMD_MKENT(loop, 3, 1, do_i2c_loop, "", "")
+ U_BOOT_CMD_MKENT(md, 3, 1, do_i2c_md, "", "")
+ U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", "")
+ U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", "")
+ U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", "")
+ U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", "")
+ U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", "")
+ U_BOOT_CMD_MKENT(write, 5, 0, do_i2c_write, "", "")
+ U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", "")
#if defined(CONFIG_CMD_SDRAM)
- U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""),
+ U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", "")
#endif
- U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", ""),
-};
+ U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", "")
+U_BOOT_SUBCMD_END
#ifdef CONFIG_NEEDS_MANUAL_RELOC
void i2c_reloc(void) {
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index a09263c..8603e36 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -1080,42 +1080,42 @@ static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
/*
* New command line interface: "env" command with subcommands
*/
-static cmd_tbl_t cmd_env_sub[] = {
+U_BOOT_SUBCMD_START(cmd_env_sub)
#if defined(CONFIG_CMD_ASKENV)
- U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
+ U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", "")
#endif
- U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
- U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
+ U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", "")
+ U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", "")
#if defined(CONFIG_CMD_EDITENV)
- U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
+ U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", "")
#endif
#if defined(CONFIG_CMD_ENV_CALLBACK)
- U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
+ U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", "")
#endif
#if defined(CONFIG_CMD_ENV_FLAGS)
- U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
+ U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", "")
#endif
#if defined(CONFIG_CMD_EXPORTENV)
- U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
+ U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", "")
#endif
#if defined(CONFIG_CMD_GREPENV)
- U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
+ U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", "")
#endif
#if defined(CONFIG_CMD_IMPORTENV)
- U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
+ U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", "")
#endif
- U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
+ U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", "")
#if defined(CONFIG_CMD_RUN)
- U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
+ U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", "")
#endif
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
- U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
+ U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", "")
#endif
- U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
+ U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", "")
#if defined(CONFIG_CMD_ENV_EXISTS)
- U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""),
+ U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", "")
#endif
-};
+U_BOOT_SUBCMD_END
#if defined(CONFIG_NEEDS_MANUAL_RELOC)
void env_reloc(void)
diff --git a/common/cmd_onenand.c b/common/cmd_onenand.c
index 06cc140..2b17aff 100644
--- a/common/cmd_onenand.c
+++ b/common/cmd_onenand.c
@@ -546,17 +546,18 @@ static int do_onenand_markbad(cmd_tbl_t * cmdtp, int flag, int argc, char * cons
return ret;
}
-static cmd_tbl_t cmd_onenand_sub[] = {
- U_BOOT_CMD_MKENT(info, 1, 0, do_onenand_info, "", ""),
- U_BOOT_CMD_MKENT(bad, 1, 0, do_onenand_bad, "", ""),
- U_BOOT_CMD_MKENT(read, 4, 0, do_onenand_read, "", ""),
- U_BOOT_CMD_MKENT(write, 4, 0, do_onenand_write, "", ""),
- U_BOOT_CMD_MKENT(write.yaffs, 4, 0, do_onenand_write, "", ""),
- U_BOOT_CMD_MKENT(erase, 3, 0, do_onenand_erase, "", ""),
- U_BOOT_CMD_MKENT(test, 3, 0, do_onenand_test, "", ""),
- U_BOOT_CMD_MKENT(dump, 2, 0, do_onenand_dump, "", ""),
- U_BOOT_CMD_MKENT(markbad, CONFIG_SYS_MAXARGS, 0, do_onenand_markbad, "", ""),
-};
+U_BOOT_SUBCMD_START(cmd_onenand_sub)
+ U_BOOT_CMD_MKENT(info, 1, 0, do_onenand_info, "", "")
+ U_BOOT_CMD_MKENT(bad, 1, 0, do_onenand_bad, "", "")
+ U_BOOT_CMD_MKENT(read, 4, 0, do_onenand_read, "", "")
+ U_BOOT_CMD_MKENT(write, 4, 0, do_onenand_write, "", "")
+ U_BOOT_CMD_MKENT(write.yaffs, 4, 0, do_onenand_write, "", "")
+ U_BOOT_CMD_MKENT(erase, 3, 0, do_onenand_erase, "", "")
+ U_BOOT_CMD_MKENT(test, 3, 0, do_onenand_test, "", "")
+ U_BOOT_CMD_MKENT(dump, 2, 0, do_onenand_dump, "", "")
+ U_BOOT_CMD_MKENT(markbad, CONFIG_SYS_MAXARGS, 0, do_onenand_markbad,
+ "", "")
+U_BOOT_SUBCMD_END
#ifdef CONFIG_NEEDS_MANUAL_RELOC
void onenand_reloc(void) {
diff --git a/common/cmd_pxe.c b/common/cmd_pxe.c
index 3483328..16ffdab 100644
--- a/common/cmd_pxe.c
+++ b/common/cmd_pxe.c
@@ -1557,10 +1557,10 @@ do_pxe_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 0;
}
-static cmd_tbl_t cmd_pxe_sub[] = {
- U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""),
+U_BOOT_SUBCMD_START(cmd_pxe_sub)
+ U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", "")
U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "")
-};
+U_BOOT_SUBCMD_END
int do_pxe(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
diff --git a/common/cmd_sandbox.c b/common/cmd_sandbox.c
index 00982b1..50470ea 100644
--- a/common/cmd_sandbox.c
+++ b/common/cmd_sandbox.c
@@ -85,13 +85,13 @@ static int do_sandbox_info(cmd_tbl_t *cmdtp, int flag, int argc,
return 0;
}
-static cmd_tbl_t cmd_sandbox_sub[] = {
- U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""),
- U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""),
- U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""),
- U_BOOT_CMD_MKENT(bind, 3, 0, do_sandbox_bind, "", ""),
- U_BOOT_CMD_MKENT(info, 3, 0, do_sandbox_info, "", ""),
-};
+U_BOOT_SUBCMD_START(cmd_sandbox_sub)
+ U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", "")
+ U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", "")
+ U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", "")
+ U_BOOT_CMD_MKENT(bind, 3, 0, do_sandbox_bind, "", "")
+ U_BOOT_CMD_MKENT(info, 3, 0, do_sandbox_info, "", "")
+U_BOOT_SUBCMD_END
static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
diff --git a/common/cmd_sound.c b/common/cmd_sound.c
index f5dd8bc..7f02191 100644
--- a/common/cmd_sound.c
+++ b/common/cmd_sound.c
@@ -47,10 +47,10 @@ static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
return 0;
}
-static cmd_tbl_t cmd_sound_sub[] = {
- U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
- U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""),
-};
+U_BOOT_SUBCMD_START(cmd_sound_sub)
+ U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", "")
+ U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", "")
+U_BOOT_SUBCMD_END
/* process sound command */
static int do_sound(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
diff --git a/common/cmd_spl.c b/common/cmd_spl.c
index 057764a..59dfb99 100644
--- a/common/cmd_spl.c
+++ b/common/cmd_spl.c
@@ -94,10 +94,10 @@ static int call_bootm(int argc, char * const argv[], const char *subcommand[])
return 0;
}
-static cmd_tbl_t cmd_spl_export_sub[] = {
- U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", ""),
- U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", ""),
-};
+U_BOOT_SUBCMD_START(cmd_spl_export_sub)
+ U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)SPL_EXPORT_FDT, "", "")
+ U_BOOT_CMD_MKENT(atags, 0, 1, (void *)SPL_EXPORT_ATAGS, "", "")
+U_BOOT_SUBCMD_END
static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
@@ -133,9 +133,9 @@ static int spl_export(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 0;
}
-static cmd_tbl_t cmd_spl_sub[] = {
- U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", ""),
-};
+U_BOOT_SUBCMD_START(cmd_spl_sub)
+ U_BOOT_CMD_MKENT(export, 0, 1, (void *)SPL_EXPORT, "", "")
+U_BOOT_SUBCMD_END
static int do_spl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index 0294952..35e0be4 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -606,58 +606,58 @@ TPM_COMMAND_NO_ARG(tpm_end_oiap)
#define MAKE_TPM_CMD_ENTRY(cmd) \
U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")
-static cmd_tbl_t tpm_commands[] = {
+U_BOOT_SUBCMD_START(tpm_commands)
U_BOOT_CMD_MKENT(init, 0, 1,
- do_tpm_init, "", ""),
+ do_tpm_init, "", "")
U_BOOT_CMD_MKENT(startup, 0, 1,
- do_tpm_startup, "", ""),
+ do_tpm_startup, "", "")
U_BOOT_CMD_MKENT(self_test_full, 0, 1,
- do_tpm_self_test_full, "", ""),
+ do_tpm_self_test_full, "", "")
U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
- do_tpm_continue_self_test, "", ""),
+ do_tpm_continue_self_test, "", "")
U_BOOT_CMD_MKENT(force_clear, 0, 1,
- do_tpm_force_clear, "", ""),
+ do_tpm_force_clear, "", "")
U_BOOT_CMD_MKENT(physical_enable, 0, 1,
- do_tpm_physical_enable, "", ""),
+ do_tpm_physical_enable, "", "")
U_BOOT_CMD_MKENT(physical_disable, 0, 1,
- do_tpm_physical_disable, "", ""),
+ do_tpm_physical_disable, "", "")
U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
- do_tpm_nv_define_space, "", ""),
+ do_tpm_nv_define_space, "", "")
U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
- do_tpm_nv_read_value, "", ""),
+ do_tpm_nv_read_value, "", "")
U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
- do_tpm_nv_write_value, "", ""),
+ do_tpm_nv_write_value, "", "")
U_BOOT_CMD_MKENT(extend, 0, 1,
- do_tpm_extend, "", ""),
+ do_tpm_extend, "", "")
U_BOOT_CMD_MKENT(pcr_read, 0, 1,
- do_tpm_pcr_read, "", ""),
+ do_tpm_pcr_read, "", "")
U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
- do_tpm_tsc_physical_presence, "", ""),
+ do_tpm_tsc_physical_presence, "", "")
U_BOOT_CMD_MKENT(read_pubek, 0, 1,
- do_tpm_read_pubek, "", ""),
+ do_tpm_read_pubek, "", "")
U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
- do_tpm_physical_set_deactivated, "", ""),
+ do_tpm_physical_set_deactivated, "", "")
U_BOOT_CMD_MKENT(get_capability, 0, 1,
- do_tpm_get_capability, "", ""),
+ do_tpm_get_capability, "", "")
U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
- do_tpm_raw_transfer, "", ""),
+ do_tpm_raw_transfer, "", "")
U_BOOT_CMD_MKENT(nv_define, 0, 1,
- do_tpm_nv_define, "", ""),
+ do_tpm_nv_define, "", "")
U_BOOT_CMD_MKENT(nv_read, 0, 1,
- do_tpm_nv_read, "", ""),
+ do_tpm_nv_read, "", "")
U_BOOT_CMD_MKENT(nv_write, 0, 1,
- do_tpm_nv_write, "", ""),
+ do_tpm_nv_write, "", "")
#ifdef CONFIG_TPM_AUTH_SESSIONS
U_BOOT_CMD_MKENT(oiap, 0, 1,
- do_tpm_oiap, "", ""),
+ do_tpm_oiap, "", "")
U_BOOT_CMD_MKENT(end_oiap, 0, 1,
- do_tpm_end_oiap, "", ""),
+ do_tpm_end_oiap, "", "")
U_BOOT_CMD_MKENT(load_key2_oiap, 0, 1,
- do_tpm_load_key2_oiap, "", ""),
+ do_tpm_load_key2_oiap, "", "")
U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1,
- do_tpm_get_pub_key_oiap, "", ""),
+ do_tpm_get_pub_key_oiap, "", "")
#endif /* CONFIG_TPM_AUTH_SESSIONS */
-};
+U_BOOT_SUBCMD_END
static int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index 7371cd4..2ce5866 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -205,15 +205,15 @@ static int pca953x_info(uint8_t chip)
}
#endif /* CONFIG_CMD_PCA953X_INFO */
-cmd_tbl_t cmd_pca953x[] = {
- U_BOOT_CMD_MKENT(device, 3, 0, (void *)PCA953X_CMD_DEVICE, "", ""),
- U_BOOT_CMD_MKENT(output, 4, 0, (void *)PCA953X_CMD_OUTPUT, "", ""),
- U_BOOT_CMD_MKENT(input, 3, 0, (void *)PCA953X_CMD_INPUT, "", ""),
- U_BOOT_CMD_MKENT(invert, 4, 0, (void *)PCA953X_CMD_INVERT, "", ""),
+U_BOOT_SUBCMD_START(cmd_pca953x)
+ U_BOOT_CMD_MKENT(device, 3, 0, (void *)PCA953X_CMD_DEVICE, "", "")
+ U_BOOT_CMD_MKENT(output, 4, 0, (void *)PCA953X_CMD_OUTPUT, "", "")
+ U_BOOT_CMD_MKENT(input, 3, 0, (void *)PCA953X_CMD_INPUT, "", "")
+ U_BOOT_CMD_MKENT(invert, 4, 0, (void *)PCA953X_CMD_INVERT, "", "")
#ifdef CONFIG_CMD_PCA953X_INFO
- U_BOOT_CMD_MKENT(info, 2, 0, (void *)PCA953X_CMD_INFO, "", ""),
+ U_BOOT_CMD_MKENT(info, 2, 0, (void *)PCA953X_CMD_INFO, "", "")
#endif
-};
+U_BOOT_SUBCMD_END
int do_pca953x(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
diff --git a/drivers/gpio/tca642x.c b/drivers/gpio/tca642x.c
index 6386835..c750020 100644
--- a/drivers/gpio/tca642x.c
+++ b/drivers/gpio/tca642x.c
@@ -212,13 +212,13 @@ static int tca642x_info(uchar chip)
return 0;
}
-cmd_tbl_t cmd_tca642x[] = {
- U_BOOT_CMD_MKENT(device, 3, 0, (void *)TCA642X_CMD_DEVICE, "", ""),
- U_BOOT_CMD_MKENT(output, 4, 0, (void *)TCA642X_CMD_OUTPUT, "", ""),
- U_BOOT_CMD_MKENT(input, 3, 0, (void *)TCA642X_CMD_INPUT, "", ""),
- U_BOOT_CMD_MKENT(invert, 4, 0, (void *)TCA642X_CMD_INVERT, "", ""),
- U_BOOT_CMD_MKENT(info, 2, 0, (void *)TCA642X_CMD_INFO, "", ""),
-};
+U_BOOT_SUBCMD_START(cmd_tca642x)
+ U_BOOT_CMD_MKENT(device, 3, 0, (void *)TCA642X_CMD_DEVICE, "", "")
+ U_BOOT_CMD_MKENT(output, 4, 0, (void *)TCA642X_CMD_OUTPUT, "", "")
+ U_BOOT_CMD_MKENT(input, 3, 0, (void *)TCA642X_CMD_INPUT, "", "")
+ U_BOOT_CMD_MKENT(invert, 4, 0, (void *)TCA642X_CMD_INVERT, "", "")
+ U_BOOT_CMD_MKENT(info, 2, 0, (void *)TCA642X_CMD_INFO, "", "")
+U_BOOT_SUBCMD_END
int do_tca642x(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
diff --git a/drivers/misc/ds4510.c b/drivers/misc/ds4510.c
index aa893c3..e6b16a0 100644
--- a/drivers/misc/ds4510.c
+++ b/drivers/misc/ds4510.c
@@ -254,24 +254,24 @@ static int ds4510_info(uint8_t chip)
}
#endif /* CONFIG_CMD_DS4510_INFO */
-cmd_tbl_t cmd_ds4510[] = {
- U_BOOT_CMD_MKENT(device, 3, 0, (void *)DS4510_CMD_DEVICE, "", ""),
- U_BOOT_CMD_MKENT(nv, 3, 0, (void *)DS4510_CMD_NV, "", ""),
- U_BOOT_CMD_MKENT(output, 4, 0, (void *)DS4510_CMD_OUTPUT, "", ""),
- U_BOOT_CMD_MKENT(input, 3, 0, (void *)DS4510_CMD_INPUT, "", ""),
- U_BOOT_CMD_MKENT(pullup, 4, 0, (void *)DS4510_CMD_PULLUP, "", ""),
+U_BOOT_SUBCMD_START(cmd_ds4510)
+ U_BOOT_CMD_MKENT(device, 3, 0, (void *)DS4510_CMD_DEVICE, "", "")
+ U_BOOT_CMD_MKENT(nv, 3, 0, (void *)DS4510_CMD_NV, "", "")
+ U_BOOT_CMD_MKENT(output, 4, 0, (void *)DS4510_CMD_OUTPUT, "", "")
+ U_BOOT_CMD_MKENT(input, 3, 0, (void *)DS4510_CMD_INPUT, "", "")
+ U_BOOT_CMD_MKENT(pullup, 4, 0, (void *)DS4510_CMD_PULLUP, "", "")
#ifdef CONFIG_CMD_DS4510_INFO
- U_BOOT_CMD_MKENT(info, 2, 0, (void *)DS4510_CMD_INFO, "", ""),
+ U_BOOT_CMD_MKENT(info, 2, 0, (void *)DS4510_CMD_INFO, "", "")
#endif
#ifdef CONFIG_CMD_DS4510_RST
- U_BOOT_CMD_MKENT(rstdelay, 3, 0, (void *)DS4510_CMD_RSTDELAY, "", ""),
+ U_BOOT_CMD_MKENT(rstdelay, 3, 0, (void *)DS4510_CMD_RSTDELAY, "", "")
#endif
#ifdef CONFIG_CMD_DS4510_MEM
- U_BOOT_CMD_MKENT(eeprom, 6, 0, (void *)DS4510_CMD_EEPROM, "", ""),
- U_BOOT_CMD_MKENT(seeprom, 6, 0, (void *)DS4510_CMD_SEEPROM, "", ""),
- U_BOOT_CMD_MKENT(sram, 6, 0, (void *)DS4510_CMD_SRAM, "", ""),
+ U_BOOT_CMD_MKENT(eeprom, 6, 0, (void *)DS4510_CMD_EEPROM, "", "")
+ U_BOOT_CMD_MKENT(seeprom, 6, 0, (void *)DS4510_CMD_SEEPROM, "", "")
+ U_BOOT_CMD_MKENT(sram, 6, 0, (void *)DS4510_CMD_SRAM, "", "")
#endif
-};
+U_BOOT_SUBCMD_END
int do_ds4510(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
diff --git a/include/command.h b/include/command.h
index 53ec853..1a3871f 100644
--- a/include/command.h
+++ b/include/command.h
@@ -170,20 +170,43 @@ int cmd_process(int flag, int argc, char * const argv[],
# define _CMD_HELP(x)
#endif
-#define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
- _usage, _help, _comp, _info) \
+/*
+ * These macros help declare commands. They are set up in such as way that
+ * it is possible to completely remove all commands when CONFIG_CMDLINE is
+ * not defined.
+ *
+ * Usage is:
+ * U_BOOT_SUBCMD_START(name)
+ * U_BOOT_CMD_MKENT(...) (or U_BOOT_CMD_MKENT_COMPLETE)
+ * U_BOOT_CMD_MKENT(...)
+ * ...
+ * U_BOOT_SUBCMD_END
+ *
+ * We need to ensure that a command is placed between each entry
+ */
+#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, \
+ _help, _comp, _info) \
{ #_name, _maxargs, (_rep) << CMD_INFO_REPEATABLE_SHIFT | (_info), \
_cmd, _usage, _CMD_HELP(_help) _CMD_COMPLETE(_comp) }
-#define U_BOOT_CMD_MKENT(_name, _maxargs, _rep, _cmd, _usage, _help) \
- U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
- _usage, _help, NULL, 0)
+/* Add a comma to separate lines */
+#define U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, \
+ _help, _comp, _info) \
+ U_BOOT_CMD_MKENT_LINE(_name, _maxargs, _rep, _cmd, _usage, \
+ _help, _comp, _info),
+/* Here we want a semicolon after the (single) entry */
#define U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, \
_comp, _info) \
ll_entry_declare(cmd_tbl_t, _name, cmd) = \
- U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
- _usage, _help, _comp, _info);
+ U_BOOT_CMD_MKENT_LINE(_name, _maxargs, _rep, _cmd, \
+ _usage, _help, _comp, _info);
+
+#define U_BOOT_CMD_MKENT(_name, _maxargs, _rep, _cmd, _usage, _help) \
+ U_BOOT_CMD_MKENT_COMPLETE(_name, _maxargs, _rep, _cmd, \
+ _usage, _help, NULL, 0)
#define U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help) \
U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, \
diff --git a/test/dm/cmd_dm.c b/test/dm/cmd_dm.c
index a03fe20..8395429 100644
--- a/test/dm/cmd_dm.c
+++ b/test/dm/cmd_dm.c
@@ -99,11 +99,11 @@ static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
return dm_test_main();
}
-static cmd_tbl_t test_commands[] = {
- U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
- U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
- U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
-};
+U_BOOT_SUBCMD_START(test_commands)
+ U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", "")
+ U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", "")
+ U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", "")
+U_BOOT_SUBCMD_END
static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
--
1.9.1.423.g4596e3a
More information about the U-Boot
mailing list