All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] fw_env: use env-size property for nvmem layout device detection
@ 2026-09-03  0:29 Michael C. Pratt
  2026-09-05  0:14 ` Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Michael C. Pratt @ 2026-09-03  0:29 UTC (permalink / raw)
  To: u-boot
  Cc: Michael C. Pratt, Tom Rini, Rafał Miłecki,
	Christian Marangi

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 <mcpratt@pm.me>
---
 tools/env/fw_env.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

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;
 	}
 
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-05  0:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-03  0:29 [PATCH v2] fw_env: use env-size property for nvmem layout device detection Michael C. Pratt
2026-09-05  0:14 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.