All of lore.kernel.org
 help / color / mirror / Atom feed
From: srini@kernel.org
To: gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org,
	Jascha Sundaresan <flizarthanon@gmail.com>,
	"Rob Herring (Arm)" <robh@kernel.org>,
	Srinivas Kandagatla <srini@kernel.org>
Subject: [PATCH 4/8] nvmem: layouts: u-boot-env: add optional "env-size" property
Date: Fri, 14 Nov 2025 11:06:32 +0000	[thread overview]
Message-ID: <20251114110636.143268-5-srini@kernel.org> (raw)
In-Reply-To: <20251114110636.143268-1-srini@kernel.org>

From: Jascha Sundaresan <flizarthanon@gmail.com>

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>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
 .../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.51.0


  parent reply	other threads:[~2025-11-14 11:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-14 11:06 [PATCH 0/8] nvmem: patches for 6.19 srini
2025-11-14 11:06 ` [PATCH 1/8] dt-bindings: nvmem: qfprom: Add sa8775p compatible srini
2025-11-14 11:06 ` [PATCH 2/8] dt-bindings: nvmem: Support MediaTek MT8189 evb board efuse srini
2025-11-14 11:06 ` [PATCH 3/8] nvmem: Add driver for the eeprom in qnap-mcu controllers srini
2025-11-26 13:42   ` Andy Shevchenko
2025-11-14 11:06 ` srini [this message]
2025-11-14 11:06 ` [PATCH 5/8] dt-bindings: nvmem: mediatek: efuse: Add compatible for MT8189 SoC srini
2025-11-14 11:06 ` [PATCH 6/8] dt-bindings: nvmem: don't check node names srini
2025-11-14 11:06 ` [PATCH 7/8] dt-bindings: nvmem: imx-ocotp: Add support for i.MX94 srini
2025-11-14 11:06 ` [PATCH 8/8] nvmem: imx-ocotp-ele: Add i.MX94 OCOTP support srini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251114110636.143268-5-srini@kernel.org \
    --to=srini@kernel.org \
    --cc=flizarthanon@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.