[U-Boot] [PATCH 3/4] Support run-time disabling of u-boot commands.

Josh Karabin gkarabin at vocollect.com
Tue May 26 22:14:26 CEST 2009


Change the command parsing code to ignore command table
entries with NULL names.  This makes it possible to disable a
command (say, for a supported but not connected memory) at
run time.

Signed-off-by: Josh Karabin <gkarabin at vocollect.com>
---
 common/command.c |   43 +++++++++++++++++++++++++------------------
 1 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/common/command.c b/common/command.c
index c9a3f5b..ef2cbfc 100644
--- a/common/command.c
+++ b/common/command.c
@@ -243,15 +243,19 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
 	if (argc == 1) {	/*show list of commands */
 		cmd_tbl_t *cmd_array[cmd_items];
 		int i, j, swaps;
+		int cmd_array_items;
 
 		/* Make array of commands from .uboot_cmd section */
 		cmdtp = cmd_start;
-		for (i = 0; i < cmd_items; i++) {
-			cmd_array[i] = cmdtp++;
+		for (i = 0, cmd_array_items = 0; i < cmd_items; i++) {
+			if (cmdtp->name) {
+				cmd_array[i] = cmdtp++;
+				cmd_array_items++;
+			}
 		}
 
 		/* Sort command list (trivial bubble sort) */
-		for (i = cmd_items - 1; i > 0; --i) {
+		for (i = cmd_array_items - 1; i > 0; --i) {
 			swaps = 0;
 			for (j = 0; j < i; ++j) {
 				if (strcmp (cmd_array[j]->name,
@@ -268,7 +272,7 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
 		}
 
 		/* print short help (usage) */
-		for (i = 0; i < cmd_items; i++) {
+		for (i = 0; i < cmd_array_items; i++) {
 			const char *usage = cmd_array[i]->usage;
 
 			/* allow user abort */
@@ -298,7 +302,7 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
 			}
 			putc ('\n');
 #else	/* no long help available */
-			if (cmdtp->usage)
+			if (cmdtp->name && cmdtp->usage)
 				printf ("%s - %s\n", cmdtp->name, cmdtp->usage);
 #endif	/* CONFIG_SYS_LONGHELP */
 		} else {
@@ -365,7 +369,7 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len)
 	for (cmdtp = table;
 	     cmdtp != table + table_len;
 	     cmdtp++) {
-		if (strncmp (cmd, cmdtp->name, len) == 0) {
+		if (cmdtp->name && (strncmp (cmd, cmdtp->name, len) == 0)) {
 			if (len == strlen (cmdtp->name))
 				return cmdtp;	/* full match */
 
@@ -453,7 +457,8 @@ static int complete_cmdv(int argc, char *argv[], char last_char, int maxv, char
 				cmdv[n_found++] = "...";
 				break;
 			}
-			cmdv[n_found++] = cmdtp->name;
+			if (cmdtp->name)
+				cmdv[n_found++] = cmdtp->name;
 		}
 		cmdv[n_found] = NULL;
 		return n_found;
@@ -483,20 +488,22 @@ static int complete_cmdv(int argc, char *argv[], char last_char, int maxv, char
 	/* return the partial matches */
 	for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
 
-		clen = strlen(cmdtp->name);
-		if (clen < len)
-			continue;
+		if (cmdtp->name) {
+			clen = strlen(cmdtp->name);
+			if (clen < len)
+				continue;
 
-		if (memcmp(cmd, cmdtp->name, len) != 0)
-			continue;
+			if (memcmp(cmd, cmdtp->name, len) != 0)
+				continue;
 
-		/* too many! */
-		if (n_found >= maxv - 2) {
-			cmdv[n_found++] = "...";
-			break;
-		}
+			/* too many! */
+			if (n_found >= maxv - 2) {
+				cmdv[n_found++] = "...";
+				break;
+			}
 
-		cmdv[n_found++] = cmdtp->name;
+			cmdv[n_found++] = cmdtp->name;
+		}
 	}
 
 	cmdv[n_found] = NULL;
-- 
1.6.0.6



More information about the U-Boot mailing list