[U-Boot] [PATCH] cmd_fdt.c: fix parse of byte streams and strings

Jerry Van Baren gvb.uboot at gmail.com
Fri Sep 11 02:23:27 CEST 2009


Hi Ken,

Ken MacLeod wrote:
> Commit 4abd844d8e extended the fdt command parser to handle property
> strings which are split across multiple arguments but it was broken for
> byte streams and strings.  This patch fixes those.
> 
> Signed-off-by: Ken MacLeod <ken at bitsko.slc.ut.us>

Thanks for the patch.  Andy's patch 4abd844d8e says...
-----------------------------------------------------------------------
While I was in there, I extended the fdt command parser to handle 
property strings which are split across multiple arguments:

 > fdt set /ethernet at f00 interrupts < 33 2 34 2 36 2 >
 > fdt p /ethernet at f00
ethernet at f00 {
     interrupts = <0x21 0x2 0x22 0x2 0x24 0x2>;
};
-----------------------------------------------------------------------

If understand Andy's changes correctly, what use to be
   fdt set /ethernet at f00 interrupts "<33 2 34 2 36 2>"
is now
   fdt set /ethernet at f00 interrupts < 33 2 34 2 36 2 >

and you carried this forward to handle byte streams:
   fdt set /ethernet at f00 interrupts "[33 2 34 2 36 2]"
becomes
   fdt set /ethernet at f00 interrupts [ 33 2 34 2 36 2 ]
and
   fdt set /ethernet at f00 interrupts "this is a string"
can now handle multiple strings (words) by concatenating them with 
spaces (quoted strings still work the same as before because of hush's 
argument parsing)
   fdt set /ethernet at f00 interrupts this is a string

Best regards,
gvb

> ---
>  common/cmd_fdt.c |   11 +++++++++--
>  1 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c
> index 8683772..f0a8f0e 100644
> --- a/common/cmd_fdt.c
> +++ b/common/cmd_fdt.c
> @@ -580,7 +580,7 @@ static int fdt_parse_prop(char **newval, int count, char *data, int *len)
>  			*len    = *len + 1;
>  			while (*newp == ' ')
>  				newp++;
> -			if (*newp != '\0')
> +			if (*newp == '\0')
>  				newp = newval[++stridx];
>  		}
>  		if (*newp != ']') {
> @@ -593,10 +593,17 @@ static int fdt_parse_prop(char **newval, int count, char *data, int *len)
>  		 * convenience (including the terminating '\0').
>  		 */
>  		while (stridx < count) {
> -			*len = strlen(newp) + 1;
> +			size_t length = strlen(newp);
>  			strcpy(data, newp);
> +			data += length;
> +			*len += length;
>  			newp = newval[++stridx];
> +			if (stridx < count) {
> +				*data++ = ' ';
> +				*len += 1;
> +			}
>  		}
> +		*len += 1;
>  	}
>  	return 0;
>  }



More information about the U-Boot mailing list