From 21fbda84b39a64fe74c1e34e4ff6e070a9ba200e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 23 Nov 2025 23:57:10 +0100 Subject: cmd: fix 'fdt get value' 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 --- cmd/fdt.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'cmd') diff --git a/cmd/fdt.c b/cmd/fdt.c index a67c30b21d5..d6d5b9fdfd2 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -9,14 +9,15 @@ #include #include +#include #include +#include +#include +#include +#include #include #include -#include #include -#include -#include -#include #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; } -- cgit v1.2.3