b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | From 5b4eaafbeac472fc19049152f18e88aecb2b2829 Mon Sep 17 00:00:00 2001 |
| 2 | From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl> |
| 3 | Date: Mon, 17 Oct 2022 09:17:22 +0200 |
| 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 | --- |
| 19 | drivers/nvmem/u-boot-env.c | 14 ++++++++++++++ |
| 20 | 1 file changed, 14 insertions(+) |
| 21 | |
| 22 | --- a/drivers/nvmem/u-boot-env.c |
| 23 | +++ b/drivers/nvmem/u-boot-env.c |
| 24 | @@ -16,6 +16,7 @@ |
| 25 | enum u_boot_env_format { |
| 26 | U_BOOT_FORMAT_SINGLE, |
| 27 | U_BOOT_FORMAT_REDUNDANT, |
| 28 | + U_BOOT_FORMAT_BROADCOM, |
| 29 | }; |
| 30 | |
| 31 | struct u_boot_env { |
| 32 | @@ -40,6 +41,13 @@ struct u_boot_env_image_redundant { |
| 33 | uint8_t data[]; |
| 34 | } __packed; |
| 35 | |
| 36 | +struct u_boot_env_image_broadcom { |
| 37 | + __le32 magic; |
| 38 | + __le32 len; |
| 39 | + __le32 crc32; |
| 40 | + uint8_t data[0]; |
| 41 | +} __packed; |
| 42 | + |
| 43 | static int u_boot_env_read(void *context, unsigned int offset, void *val, |
| 44 | size_t bytes) |
| 45 | { |
| 46 | @@ -138,6 +146,11 @@ static int u_boot_env_parse(struct u_boo |
| 47 | crc32_data_offset = offsetof(struct u_boot_env_image_redundant, data); |
| 48 | data_offset = offsetof(struct u_boot_env_image_redundant, data); |
| 49 | break; |
| 50 | + case U_BOOT_FORMAT_BROADCOM: |
| 51 | + crc32_offset = offsetof(struct u_boot_env_image_broadcom, crc32); |
| 52 | + crc32_data_offset = offsetof(struct u_boot_env_image_broadcom, data); |
| 53 | + data_offset = offsetof(struct u_boot_env_image_broadcom, data); |
| 54 | + break; |
| 55 | } |
| 56 | crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset)); |
| 57 | crc32_data_len = priv->mtd->size - crc32_data_offset; |
| 58 | @@ -202,6 +215,7 @@ static const struct of_device_id u_boot_ |
| 59 | { .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, }, |
| 60 | { .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, }, |
| 61 | { .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, }, |
| 62 | + { .compatible = "brcm,env", .data = (void *)U_BOOT_FORMAT_BROADCOM, }, |
| 63 | {}, |
| 64 | }; |
| 65 | |