devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] nvmem: layouts: u-boot-env: add optional "env-size" property
@ 2025-10-22 23:07 Jascha Sundaresan
  2025-10-26 22:30 ` Rob Herring (Arm)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jascha Sundaresan @ 2025-10-22 23:07 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, devicetree, linux-kernel, Jascha Sundaresan

Some devices reserve a larger NVMEM region for the U-Boot environment
than the actual environment data length used by U-Boot itself. The CRC32
in the U-Boot header is calculated over the smaller data length, causing
CRC validation to fail when Linux reads the full partition.

Allow an optional device tree property "env-size" to specify the
environment data size to use for CRC computation.

v2: add missing $ref line to DT binding

Signed-off-by: Jascha Sundaresan <flizarthanon@gmail.com>
---
Changes in v2:
 - Added missing "$ref" line to schema for env-size
 - Confirmed dt_binding_check passes

 .../devicetree/bindings/nvmem/layouts/u-boot,env.yaml      | 7 +++++++
 drivers/nvmem/layouts/u-boot-env.c                         | 4 +++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
index 56a8f55d4a09..e9e75c38bd11 100644
--- a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
+++ b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
@@ -46,6 +46,12 @@ properties:
     type: object
     description: Command to use for automatic booting
 
+  env-size:
+    description:
+      Size in bytes of the environment data used by U-Boot for CRC
+      calculation. If omitted, the full NVMEM region size is used.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
   ethaddr:
     type: object
     description: Ethernet interfaces base MAC address.
@@ -104,6 +110,7 @@ examples:
 
             partition-u-boot-env {
                 compatible = "brcm,env";
+                env-size = <0x20000>;
 
                 ethaddr {
                 };
diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c
index a27eeb08146f..ab32bf1291af 100644
--- a/drivers/nvmem/layouts/u-boot-env.c
+++ b/drivers/nvmem/layouts/u-boot-env.c
@@ -99,10 +99,12 @@ int u_boot_env_parse(struct device *dev, struct nvmem_device *nvmem,
 	uint32_t crc32;
 	uint32_t calc;
 	uint8_t *buf;
+	u32 env_size;
 	int bytes;
 	int err;
 
-	dev_size = nvmem_dev_size(nvmem);
+	dev_size = device_property_read_u32(dev, "env-size", &env_size) ?
+		nvmem_dev_size(nvmem) : (size_t)env_size;
 
 	buf = kzalloc(dev_size, GFP_KERNEL);
 	if (!buf) {
-- 
2.39.5


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

* Re: [PATCH v2] nvmem: layouts: u-boot-env: add optional "env-size" property
  2025-10-22 23:07 [PATCH v2] nvmem: layouts: u-boot-env: add optional "env-size" property Jascha Sundaresan
@ 2025-10-26 22:30 ` Rob Herring (Arm)
  2025-11-07 10:05 ` Jascha Sundaresan
  2025-11-10  7:35 ` Srinivas Kandagatla
  2 siblings, 0 replies; 4+ messages in thread
From: Rob Herring (Arm) @ 2025-10-26 22:30 UTC (permalink / raw)
  To: Jascha Sundaresan
  Cc: Rafał Miłecki, devicetree, Conor Dooley,
	Srinivas Kandagatla, linux-kernel, Krzysztof Kozlowski


On Thu, 23 Oct 2025 03:07:41 +0400, Jascha Sundaresan wrote:
> Some devices reserve a larger NVMEM region for the U-Boot environment
> than the actual environment data length used by U-Boot itself. The CRC32
> in the U-Boot header is calculated over the smaller data length, causing
> CRC validation to fail when Linux reads the full partition.
> 
> Allow an optional device tree property "env-size" to specify the
> environment data size to use for CRC computation.
> 
> v2: add missing $ref line to DT binding
> 
> Signed-off-by: Jascha Sundaresan <flizarthanon@gmail.com>
> ---
> Changes in v2:
>  - Added missing "$ref" line to schema for env-size
>  - Confirmed dt_binding_check passes
> 
>  .../devicetree/bindings/nvmem/layouts/u-boot,env.yaml      | 7 +++++++
>  drivers/nvmem/layouts/u-boot-env.c                         | 4 +++-
>  2 files changed, 10 insertions(+), 1 deletion(-)
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>


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

* Re: [PATCH v2] nvmem: layouts: u-boot-env: add optional "env-size" property
  2025-10-22 23:07 [PATCH v2] nvmem: layouts: u-boot-env: add optional "env-size" property Jascha Sundaresan
  2025-10-26 22:30 ` Rob Herring (Arm)
@ 2025-11-07 10:05 ` Jascha Sundaresan
  2025-11-10  7:35 ` Srinivas Kandagatla
  2 siblings, 0 replies; 4+ messages in thread
From: Jascha Sundaresan @ 2025-11-07 10:05 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Rafał Miłecki, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, devicetree, linux-kernel, Jascha Sundaresan

Hi Srinivas,

Friendly ping on this patch. Rob Herring reviewed it on Oct 26.
Are you planning to pick it up for the nvmem tree, or would you like me to resend?

Thanks,
Jascha

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

* Re: [PATCH v2] nvmem: layouts: u-boot-env: add optional "env-size" property
  2025-10-22 23:07 [PATCH v2] nvmem: layouts: u-boot-env: add optional "env-size" property Jascha Sundaresan
  2025-10-26 22:30 ` Rob Herring (Arm)
  2025-11-07 10:05 ` Jascha Sundaresan
@ 2025-11-10  7:35 ` Srinivas Kandagatla
  2 siblings, 0 replies; 4+ messages in thread
From: Srinivas Kandagatla @ 2025-11-10  7:35 UTC (permalink / raw)
  To: Rafał Miłecki, Jascha Sundaresan
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
	linux-kernel


On Thu, 23 Oct 2025 03:07:41 +0400, Jascha Sundaresan wrote:
> Some devices reserve a larger NVMEM region for the U-Boot environment
> than the actual environment data length used by U-Boot itself. The CRC32
> in the U-Boot header is calculated over the smaller data length, causing
> CRC validation to fail when Linux reads the full partition.
> 
> Allow an optional device tree property "env-size" to specify the
> environment data size to use for CRC computation.
> 
> [...]

Applied, thanks!

[1/1] nvmem: layouts: u-boot-env: add optional "env-size" property
      commit: 06e92afca89075628b12c9b4085b4cc7320081ac

Best regards,
-- 
Srinivas Kandagatla <srini@kernel.org>


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

end of thread, other threads:[~2025-11-10  7:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-22 23:07 [PATCH v2] nvmem: layouts: u-boot-env: add optional "env-size" property Jascha Sundaresan
2025-10-26 22:30 ` Rob Herring (Arm)
2025-11-07 10:05 ` Jascha Sundaresan
2025-11-10  7:35 ` Srinivas Kandagatla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).