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

Wolfgang Denk wd at denx.de
Tue May 26 23:11:55 CEST 2009


Dear Josh Karabin,

In message <2d0c4b7840d573c666484662662fbb953f59cfba.1243367498.git.gkarabi n at vocollect.com> you wrote:
> 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;

I think cmd_array_items can be avoided.

>  		/* 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++;
> +			}
>  		}

I don't think this is needed. You will not have any NULL entries in
the .uboot_cmd section.

> @@ -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;

Change the logic here. Instead of adding yet another indentation level
write:

		if (!cmdtp->name))
			continue;


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Include the success of others in your dreams for your own success.


More information about the U-Boot mailing list