summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael C. Pratt <[email protected]>2026-09-03 00:29:58 +0000
committerTom Rini <[email protected]>2026-09-04 12:21:12 -0600
commit7bf077ec5733a230bbce34d8ce324f92d8c46cc1 (patch)
tree0b1526353959de9493d48bb473f83586fc53c76f
parent358c3dc571ee706d8c641cfb092a4b9bc19b9c60 (diff)
fw_env: use env-size property for nvmem layout device detection
Since Linux commit 5b2f8c133d98 ("nvmem: layouts: u-boot-env: add optional "env-size" property"), there is support for providing the size of the u-boot environment used by the bootloader to the layout NVMEM driver in order to calculate the CRC if the range is less than the partition size in a similar fashion that it would be provided in a fw_env.config file. Devicetree binary cells are always stored in big-endian, so endian translation is now necessary for this case. Reuse the buffer that holds the path for opening the compatible sysfs file for parsing this env-size property and possibly more in the future, as soon as the correct device is identified with the compatible property. Signed-off-by: Michael C. Pratt <[email protected]>
-rw-r--r--tools/env/fw_env.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 8810b0e94dc..7dd90b16b46 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -30,6 +30,7 @@
#include <u-boot/crc.h>
#include <unistd.h>
#include <dirent.h>
+#include <asm/byteorder.h>
#ifdef MTD_OLD
# include <stdint.h>
@@ -1714,6 +1715,7 @@ static int find_nvmem_device(void)
char comp[256];
char buf[32];
int bytes;
+ ulong layout_size = 0;
DIR *dir;
dir = opendir(path);
@@ -1771,6 +1773,9 @@ static int find_nvmem_device(void)
}
}
+ /* Remember the nvmem device path for parsing other properties. */
+ bytes = snprintf(comp, sizeof(comp), "%s/%s", path, dent->d_name);
+
next:
fclose(fp);
}
@@ -1779,6 +1784,8 @@ next:
if (nvmem) {
struct stat s;
+ FILE *fp;
+ size_t size;
stat(nvmem, &s);
@@ -1786,6 +1793,20 @@ next:
DEVOFFSET(0) = 0;
ENVSIZE(0) = s.st_size;
+ if (bytes > 0 && bytes < sizeof(comp)) {
+ strcat(comp, "/of_node/nvmem-layout/env-size");
+ fp = fopen(comp, "rb");
+ if (fp) {
+ fstat(fileno(fp), &s);
+ size = fread(&layout_size, s.st_size, 1, fp);
+ if (size == 1)
+ ENVSIZE(0) = __be32_to_cpu(layout_size);
+ fclose(fp);
+ }
+
+ comp[bytes] = '\0';
+ }
+
return 0;
}