]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cmd/fdt: Make fdt get value endian-safe for single-cell properties
authorAndreas Färber <afaerber@suse.de>
Mon, 9 Jan 2017 15:08:02 +0000 (16:08 +0100)
committerSimon Glass <sjg@chromium.org>
Sat, 14 Jan 2017 17:09:46 +0000 (10:09 -0700)
On a Raspberry Pi 2 disagreements on cell endianness can be observed:

  U-Boot> fdt print /soc/gpio@7e200000 phandle
  phandle = <0x0000000d>
  U-Boot> fdt get value myvar /soc/gpio@7e200000 phandle; printenv myvar
  myvar=0x0D000000

Fix this by always treating the pointer as BE and converting it in
fdt_value_setenv(), like its counterpart fdt_parse_prop() already does.

Consistently use fdt32_t, fdt32_to_cpu() and cpu_to_fdt32().

Fixes: bc80295 ("fdt: Add get commands to fdt")
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Gerald Van Baren <gvb@unssw.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Acked-by: Simon Glass <sjg@chromium.org>
cmd/fdt.c

index 6883e754edf867e4d3e8cb2baf3cb1f2cfbfb584..95dd673b957e45dca344367fe2f3c1d682f28418 100644 (file)
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -58,7 +58,7 @@ static int fdt_value_setenv(const void *nodep, int len, const char *var)
        else if (len == 4) {
                char buf[11];
 
-               sprintf(buf, "0x%08X", *(uint32_t *)nodep);
+               sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep));
                setenv(var, buf);
        } else if (len%4 == 0 && len <= 20) {
                /* Needed to print things like sha1 hashes. */
@@ -768,7 +768,7 @@ static int fdt_parse_prop(char * const *newval, int count, char *data, int *len)
 
                        cp = newp;
                        tmp = simple_strtoul(cp, &newp, 0);
-                       *(__be32 *)data = __cpu_to_be32(tmp);
+                       *(fdt32_t *)data = cpu_to_fdt32(tmp);
                        data  += 4;
                        *len += 4;