Skip to contentSkip to conversation

nvmem: u-boot-env: add Broadcom format support

PATCH In review Rafał Miłecki 2 participants 3 messages Oct 17, 2022 – Nov 11, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: u-boot-env: add Broadcom format support

From: Rafał Miłecki <[email protected]>

Broadcom uses U-Boot for a lot of their bcmbca familiy chipsets. They decided to store U-Boot environment data inside U-Boot partition and to use a custom header (with "uEnv" magic and env data length).

Add support for Broadcom's specific binding and their custom format.

Ref: c34f9f5499278 ("dt-bindings: nvmem: u-boot,env: add Broadcom's variant binding")

---
 drivers/nvmem/u-boot-env.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/nvmem/u-boot-env.c +14 -0
index 8e72d1bbd649..049330660fd7 100644
@@ -16,6 +16,7 @@
 enum u_boot_env_format {
 	U_BOOT_FORMAT_SINGLE,
 	U_BOOT_FORMAT_REDUNDANT,
+	U_BOOT_FORMAT_BROADCOM,
 };
 
 struct u_boot_env {
@@ -40,6 +41,13 @@ struct u_boot_env_image_redundant {
 	uint8_t data[];
 } __packed;
 
+struct u_boot_env_image_broadcom {
+	__le32 magic;
+	__le32 len;
+	__le32 crc32;
+	uint8_t data[0];
+} __packed;
+
 static int u_boot_env_read(void *context, unsigned int offset, void *val,
 			   size_t bytes)
 {
@@ -138,6 +146,11 @@ static int u_boot_env_parse(struct u_boot_env *priv)
 		crc32_data_offset = offsetof(struct u_boot_env_image_redundant, mark);
 		data_offset = offsetof(struct u_boot_env_image_redundant, data);
 		break;
+	case U_BOOT_FORMAT_BROADCOM:
+		crc32_offset = offsetof(struct u_boot_env_image_broadcom, crc32);
+		crc32_data_offset = offsetof(struct u_boot_env_image_broadcom, data);
+		data_offset = offsetof(struct u_boot_env_image_broadcom, data);
+		break;
 	}
 	crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));
 	crc32_data_len = priv->mtd->size - crc32_data_offset;
@@ -202,6 +215,7 @@ static const struct of_device_id u_boot_env_of_match_table[] = {
 	{ .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, },
 	{ .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
 	{ .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
+	{ .compatible = "brcm,env", .data = (void *)U_BOOT_FORMAT_BROADCOM, },
 	{},
 };
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 9 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Broadcom uses U-Boot for a lot of their bcmbca familiy chipsets. They decided to store U-Boot environment data inside U-Boot partition and to use a custom header (with "uEnv" magic and env data length).

Add support for Broadcom's specific binding and their custom format.

Ref: c34f9f5499278 ("dt-bindings: nvmem: u-boot,env: add Broadcom's variant binding")

This should be actually:
6b0584c19d87 ("dt-bindings: nvmem: u-boot,env: add Broadcom's variant binding")

Srinivas: could you fix it up while applying, please?

Quoted 51 lines
---
  drivers/nvmem/u-boot-env.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/nvmem/u-boot-env.c +14 -0
index 8e72d1bbd649..049330660fd7 100644
@@ -16,6 +16,7 @@
  enum u_boot_env_format {
  	U_BOOT_FORMAT_SINGLE,
  	U_BOOT_FORMAT_REDUNDANT,
+	U_BOOT_FORMAT_BROADCOM,
  };
 
  struct u_boot_env {
@@ -40,6 +41,13 @@ struct u_boot_env_image_redundant {
  	uint8_t data[];
  } __packed;
 
+struct u_boot_env_image_broadcom {
+	__le32 magic;
+	__le32 len;
+	__le32 crc32;
+	uint8_t data[0];
+} __packed;
+
  static int u_boot_env_read(void *context, unsigned int offset, void *val,
  			   size_t bytes)
  {
@@ -138,6 +146,11 @@ static int u_boot_env_parse(struct u_boot_env *priv)
  		crc32_data_offset = offsetof(struct u_boot_env_image_redundant, mark);
  		data_offset = offsetof(struct u_boot_env_image_redundant, data);
  		break;
+	case U_BOOT_FORMAT_BROADCOM:
+		crc32_offset = offsetof(struct u_boot_env_image_broadcom, crc32);
+		crc32_data_offset = offsetof(struct u_boot_env_image_broadcom, data);
+		data_offset = offsetof(struct u_boot_env_image_broadcom, data);
+		break;
  	}
  	crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));
  	crc32_data_len = priv->mtd->size - crc32_data_offset;
@@ -202,6 +215,7 @@ static const struct of_device_id u_boot_env_of_match_table[] = {
  	{ .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, },
  	{ .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
  	{ .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
+	{ .compatible = "brcm,env", .data = (void *)U_BOOT_FORMAT_BROADCOM, },
  	{},
  };
 
#2 lore raw
Quoted 7 lines · Rafał Miłecki
Quoted 6 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

Broadcom uses U-Boot for a lot of their bcmbca familiy chipsets. They decided to store U-Boot environment data inside U-Boot partition and to use a custom header (with "uEnv" magic and env data length).

Quoted 9 lines
Quoted 3 lines

Add support for Broadcom's specific binding and their custom format.

Ref: c34f9f5499278 ("dt-bindings: nvmem: u-boot,env: add Broadcom's variant binding")

This should be actually:
6b0584c19d87 ("dt-bindings: nvmem: u-boot,env: add Broadcom's variant binding")

Srinivas: could you fix it up while applying, please?

Applied with this change

--srini

Quoted 53 lines
Quoted 53 lines

---
  drivers/nvmem/u-boot-env.c | 14 ++++++++++++++

  1 file changed, 14 insertions(+)
drivers/nvmem/u-boot-env.c +13 -0
index 8e72d1bbd649..049330660fd7 100644
@@ -16,6 +16,7 @@
   enum u_boot_env_format {
       U_BOOT_FORMAT_SINGLE,
       U_BOOT_FORMAT_REDUNDANT,
+    U_BOOT_FORMAT_BROADCOM,
   };
   struct u_boot_env {
@@ -40,6 +41,13 @@ struct u_boot_env_image_redundant {
       uint8_t data[];
   } __packed;
+struct u_boot_env_image_broadcom {
+    __le32 magic;
+    __le32 len;
+    __le32 crc32;
+    uint8_t data[0];
+} __packed;
+
   static int u_boot_env_read(void *context, unsigned int offset, void *val,
                  size_t bytes)
   {
@@ -138,6 +146,11 @@ static int u_boot_env_parse(struct u_boot_env *priv)
           crc32_data_offset = offsetof(struct u_boot_env_image_redundant, mark);
           data_offset = offsetof(struct u_boot_env_image_redundant, data);
           break;
+    case U_BOOT_FORMAT_BROADCOM:
+        crc32_offset = offsetof(struct u_boot_env_image_broadcom, 
 crc32);
+        crc32_data_offset = offsetof(struct 
 u_boot_env_image_broadcom, data);
+        data_offset = offsetof(struct u_boot_env_image_broadcom, data);
+        break;
       }

      crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset)); crc32_data_len = priv->mtd->size - crc32_data_offset;

drivers/nvmem/u-boot-env.c +1 -0
@@ -202,6 +215,7 @@ static const struct of_device_id 
 u_boot_env_of_match_table[] = {
       { .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, },
       { .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
       { .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
+    { .compatible = "brcm,env", .data = (void 
 *)U_BOOT_FORMAT_BROADCOM, },
       {},

  };