]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
cmd: fix 'fdt get value'
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 23 Nov 2025 22:57:10 +0000 (23:57 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 5 Dec 2025 14:54:44 +0000 (08:54 -0600)
The 32bit cells of a device-tree property are big-endian. When printing
them via 0x08x we must first convert to the host endianness.

Remove the restriction to 20 bytes length. This would not allow to read an
SHA256 value.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
cmd/fdt.c
test/cmd/fdt.c

index a67c30b21d55dced7dba72e8ccdfbe3466ed820c..d6d5b9fdfd2f22a6c3d283159b4b3d09257e4735 100644 (file)
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -9,14 +9,15 @@
 
 #include <command.h>
 #include <env.h>
+#include <fdt_support.h>
 #include <image.h>
+#include <malloc.h>
+#include <mapmem.h>
+#include <asm/global_data.h>
+#include <asm/io.h>
 #include <linux/ctype.h>
 #include <linux/types.h>
-#include <asm/global_data.h>
 #include <linux/libfdt.h>
-#include <fdt_support.h>
-#include <mapmem.h>
-#include <asm/io.h>
 
 #define MAX_LEVEL      32              /* how deeply nested we will go */
 #define SCRATCHPAD     1024            /* bytes of scratchpad memory */
@@ -91,18 +92,21 @@ static int fdt_value_env_set(const void *nodep, int len,
 
                sprintf(buf, "0x%08X", fdt32_to_cpu(*(nodec + index)));
                env_set(var, buf);
-       } else if (len % 4 == 0 && len <= 20) {
+       } else {
                /* Needed to print things like sha1 hashes. */
-               char buf[41];
+               char *buf;
+               const unsigned int *nodec = (const unsigned int *)nodep;
                int i;
 
-               for (i = 0; i < len; i += sizeof(unsigned int))
+               buf = malloc(2 * len + 7);
+               if (!buf)
+                       return CMD_RET_FAILURE;
+               for (i = 0; i < len; i += 4)
                        sprintf(buf + (i * 2), "%08x",
-                               *(unsigned int *)(nodep + i));
+                               fdt32_to_cpu(*nodec++));
+               buf[2 * len] = 0;
                env_set(var, buf);
-       } else {
-               printf("error: unprintable value\n");
-               return 1;
+               free(buf);
        }
        return 0;
 }
index 4c3c6308ab461f63e68103cde4f350ddc7dd92de..8ce888770ac8721cd942d7ae0816b71879ecb289 100644 (file)
@@ -494,7 +494,7 @@ static int fdt_test_get_value_common(struct unit_test_state *uts,
         * longer is an error. This is a special case for handling hashes.
         */
        ut_assertok(fdt_test_get_value_string(uts, node, "regs", NULL,
-                                             "3412000000100000", 0));
+                                             "0000123400001000", 0));
 
        /* Test getting 0th element of $node node regs property */
        ut_assertok(fdt_test_get_value_string(uts, node, "regs", "0", NULL,