openwrt-mirror/target/linux/generic/backport-6.12/010-v6.19-nvmem-layouts-u-boot-env-add-optional-env-size-property.patch
Jascha Sundaresan 46ab9f3f1c filogic: add support for Netgear EAX17
Hardware
--------

SOC:   MediaTek MT7981
RAM:   512MB DDR4
FLASH: 128MB SPI-NAND
WIFI:  Mediatek MT7915 (integrated) 2x2 802.11ax 2.4 / 5 GHz
ETH:   Mediatek MT7981 internal 1 GbE PHY
UART:  3V3 115200 8N1 (Pinout silkscreened / Do not connect VCC)

Installation
------------

1. Download the OpenWrt initramfs image. Copy the image to a TFTP server
2. Connect the TFTP server to the EAX17. Conect to the serial console,
   interrupt the autoboot process by pressing '0' when prompted.
3. Download & Boot the OpenWrt initramfs image.

   $ tftpboot openwrt.bin
   $ bootm

4. Wait for OpenWrt to boot. Transfer the sysupgrade image to the device
   using scp and install using sysupgrade.

   $ sysupgrade -n <path-to-sysupgrade.bin>

Signed-off-by: Jascha Sundaresan <flizarthanon@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/20354
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-11-24 00:57:19 +01:00

63 lines
2.2 KiB
Diff

From 06e92afca89075628b12c9b4085b4cc7320081ac Mon Sep 17 00:00:00 2001
From: Jascha Sundaresan <flizarthanon@gmail.com>
Date: Thu, 23 Oct 2025 03:07:41 +0400
Subject: nvmem: layouts: u-boot-env: add optional "env-size" property
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>
---
Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml | 7 +++++++
drivers/nvmem/layouts/u-boot-env.c | 4 +++-
2 files changed, 10 insertions(+), 1 deletion(-)
--- 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 {
};
--- 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,
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) {