]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nvmem: layouts: u-boot-env: add optional "env-size" property
authorJascha Sundaresan <flizarthanon@gmail.com>
Fri, 14 Nov 2025 11:06:32 +0000 (11:06 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Nov 2025 17:06:22 +0000 (18:06 +0100)
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>
Link: https://patch.msgid.link/20251114110636.143268-5-srini@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
drivers/nvmem/layouts/u-boot-env.c

index 56a8f55d4a096cae1e95642bc6b8a461ca097434..e9e75c38bd119e94921e5d4387ed132280224787 100644 (file)
@@ -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 {
                 };
index a27eeb08146f15f6b2979b6336431a8e031f6660..ab32bf1291af325c3e144a4c3805c758b8bcc780 100644 (file)
@@ -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) {