ath79: add support for Huawei AP5030DN
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 808-v6.2-0006-nvmem-u-boot-env-add-Broadcom-format-support.patch
1 From ada84d07af6097b2addd18262668ce6cb9e15206 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Fri, 18 Nov 2022 06:39:27 +0000
4 Subject: [PATCH] nvmem: u-boot-env: add Broadcom format support
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Broadcom uses U-Boot for a lot of their bcmbca familiy chipsets. They
10 decided to store U-Boot environment data inside U-Boot partition and to
11 use a custom header (with "uEnv" magic and env data length).
12
13 Add support for Broadcom's specific binding and their custom format.
14
15 Ref: 6b0584c19d87 ("dt-bindings: nvmem: u-boot,env: add Broadcom's variant binding")
16 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
18 Link: https://lore.kernel.org/r/20221118063932.6418-9-srinivas.kandagatla@linaro.org
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 ---
21 drivers/nvmem/u-boot-env.c | 14 ++++++++++++++
22 1 file changed, 14 insertions(+)
23
24 --- a/drivers/nvmem/u-boot-env.c
25 +++ b/drivers/nvmem/u-boot-env.c
26 @@ -16,6 +16,7 @@
27 enum u_boot_env_format {
28 U_BOOT_FORMAT_SINGLE,
29 U_BOOT_FORMAT_REDUNDANT,
30 + U_BOOT_FORMAT_BROADCOM,
31 };
32
33 struct u_boot_env {
34 @@ -40,6 +41,13 @@ struct u_boot_env_image_redundant {
35 uint8_t data[];
36 } __packed;
37
38 +struct u_boot_env_image_broadcom {
39 + __le32 magic;
40 + __le32 len;
41 + __le32 crc32;
42 + uint8_t data[0];
43 +} __packed;
44 +
45 static int u_boot_env_read(void *context, unsigned int offset, void *val,
46 size_t bytes)
47 {
48 @@ -138,6 +146,11 @@ static int u_boot_env_parse(struct u_boo
49 crc32_data_offset = offsetof(struct u_boot_env_image_redundant, data);
50 data_offset = offsetof(struct u_boot_env_image_redundant, data);
51 break;
52 + case U_BOOT_FORMAT_BROADCOM:
53 + crc32_offset = offsetof(struct u_boot_env_image_broadcom, crc32);
54 + crc32_data_offset = offsetof(struct u_boot_env_image_broadcom, data);
55 + data_offset = offsetof(struct u_boot_env_image_broadcom, data);
56 + break;
57 }
58 crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));
59 crc32_data_len = priv->mtd->size - crc32_data_offset;
60 @@ -202,6 +215,7 @@ static const struct of_device_id u_boot_
61 { .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, },
62 { .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
63 { .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
64 + { .compatible = "brcm,env", .data = (void *)U_BOOT_FORMAT_BROADCOM, },
65 {},
66 };
67