aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut+renesas@mailbox.org>2023-03-02 04:08:23 +0100
committerSimon Glass <sjg@chromium.org>2023-03-09 08:50:47 -0800
commit4e6d0305506ccb347401f770bed8f35e4c56aac2 (patch)
treea521ddc20878e451aa67f526e28d7341c87780c5
parentb363da1c26c96a831d3ffcbd1d4997ec3d340009 (diff)
downloadu-boot-4e6d0305506ccb347401f770bed8f35e4c56aac2.zip
u-boot-4e6d0305506ccb347401f770bed8f35e4c56aac2.tar.gz
u-boot-4e6d0305506ccb347401f770bed8f35e4c56aac2.tar.bz2
cmd: fdt: Add support for integer arrays in fdt get value with index
Currently any integer array value is set as long up-to-40 character hexadecimal string into environment variable when extracted from an FDT using 'fdt get value path prop index', because the support for handling integer arrays is not implemented, and fdt_value_env_set() code falls back into the hash handling behavior instead. Implement this support simply by checking whether user supplied any index. If index is set and the property length is multiple of four, then this is an integer array, and the code would extract value at specified index. There is a subtle change where default index is set to -1 instead of 0. This is OK, since the only place which checks for index to be less or equal zero is the string array handling code in fdt_value_env_set() and that code would work perfectly well with index -1 too. Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--cmd/fdt.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/cmd/fdt.c b/cmd/fdt.c
index f2576ab..f38fe90 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -77,7 +77,17 @@ static int fdt_value_env_set(const void *nodep, int len,
sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep));
env_set(var, buf);
- } else if (len%4 == 0 && len <= 20) {
+ } else if (len % 4 == 0 && index >= 0) {
+ /* Needed to print integer arrays. */
+ const unsigned int *nodec = (const unsigned int *)nodep;
+ char buf[11];
+
+ if (index * 4 >= len)
+ return 1;
+
+ sprintf(buf, "0x%08X", fdt32_to_cpu(*(nodec + index)));
+ env_set(var, buf);
+ } else if (len % 4 == 0 && len <= 20) {
/* Needed to print things like sha1 hashes. */
char buf[41];
int i;
@@ -448,7 +458,7 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
working_fdt, nodeoffset, prop, &len);
if (nodep && len >= 0) {
if (subcmd[0] == 'v') {
- int index = 0;
+ int index = -1;
int ret;
if (len == 0) {