Skip to contentSkip to conversation

fw_env: allow detection of NVMEM device using layout node compatible string

PATCH RESEND In review Michael C. Pratt 2 participants 2 messages Sep 2 – Sep 5

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 fw_env: allow detection of NVMEM device using layout node compatible string

Ever since the transition from a separate NVMEM driver to the layout driver in Linux commit 5f15811286af ("nvmem: layouts: add U-Boot env layout"), it is very common within devicetree to have the compatible string "u-boot,env" in the nested nvmem-layout node instead of the parent partition node.

This allows u-boot tools to detect the u-boot environment on a partition that is also using the layout driver for NVMEM cells.

---
 tools/env/fw_env.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/env/fw_env.c +8 -1
index 49a068d91cc..8810b0e94dc 100644
@@ -1737,7 +1737,14 @@ static int find_nvmem_device(void)
 
 		fp = fopen(comp, "r");
 		if (!fp) {
-			continue;
+			bytes = snprintf(comp, sizeof(comp), "%s/%s/of_node/nvmem-layout/compatible",
+					 path, dent->d_name);
+			if (bytes < 0 || bytes == sizeof(comp))
+				continue;
+
+			fp = fopen(comp, "r");
+			if (!fp)
+				continue;
 		}
 
 		if (fstat(fileno(fp), &s)) {
Signature · 1 line
2.30.2
#1 lore raw
Quoted 9 lines · Michael C. Pratt

Ever since the transition from a separate NVMEM driver to the layout driver in Linux commit 5f15811286af ("nvmem: layouts: add U-Boot env layout"), it is very common within devicetree to have the compatible string "u-boot,env" in the nested nvmem-layout node instead of the parent partition node.

This allows u-boot tools to detect the u-boot environment on a partition that is also using the layout driver for NVMEM cells.

[...]

Applied to u-boot/main, thanks!

[1/1] fw_env: allow detection of NVMEM device using layout node compatible string

      commit: 358c3dc571ee706d8c641cfb092a4b9bc19b9c60
Signature · 1 line
Tom