812-v6.2-0006-nvmem-u-boot-env-add-Broadcom-format-support.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. From ada84d07af6097b2addd18262668ce6cb9e15206 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  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. Broadcom uses U-Boot for a lot of their bcmbca familiy chipsets. They
  9. decided to store U-Boot environment data inside U-Boot partition and to
  10. use a custom header (with "uEnv" magic and env data length).
  11. Add support for Broadcom's specific binding and their custom format.
  12. Ref: 6b0584c19d87 ("dt-bindings: nvmem: u-boot,env: add Broadcom's variant binding")
  13. Signed-off-by: Rafał Miłecki <[email protected]>
  14. Signed-off-by: Srinivas Kandagatla <[email protected]>
  15. Link: https://lore.kernel.org/r/[email protected]
  16. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  17. ---
  18. drivers/nvmem/u-boot-env.c | 14 ++++++++++++++
  19. 1 file changed, 14 insertions(+)
  20. --- a/drivers/nvmem/u-boot-env.c
  21. +++ b/drivers/nvmem/u-boot-env.c
  22. @@ -16,6 +16,7 @@
  23. enum u_boot_env_format {
  24. U_BOOT_FORMAT_SINGLE,
  25. U_BOOT_FORMAT_REDUNDANT,
  26. + U_BOOT_FORMAT_BROADCOM,
  27. };
  28. struct u_boot_env {
  29. @@ -40,6 +41,13 @@ struct u_boot_env_image_redundant {
  30. uint8_t data[];
  31. } __packed;
  32. +struct u_boot_env_image_broadcom {
  33. + __le32 magic;
  34. + __le32 len;
  35. + __le32 crc32;
  36. + uint8_t data[0];
  37. +} __packed;
  38. +
  39. static int u_boot_env_read(void *context, unsigned int offset, void *val,
  40. size_t bytes)
  41. {
  42. @@ -138,6 +146,11 @@ static int u_boot_env_parse(struct u_boo
  43. crc32_data_offset = offsetof(struct u_boot_env_image_redundant, data);
  44. data_offset = offsetof(struct u_boot_env_image_redundant, data);
  45. break;
  46. + case U_BOOT_FORMAT_BROADCOM:
  47. + crc32_offset = offsetof(struct u_boot_env_image_broadcom, crc32);
  48. + crc32_data_offset = offsetof(struct u_boot_env_image_broadcom, data);
  49. + data_offset = offsetof(struct u_boot_env_image_broadcom, data);
  50. + break;
  51. }
  52. crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));
  53. crc32_data_len = priv->mtd->size - crc32_data_offset;
  54. @@ -202,6 +215,7 @@ static const struct of_device_id u_boot_
  55. { .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, },
  56. { .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
  57. { .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
  58. + { .compatible = "brcm,env", .data = (void *)U_BOOT_FORMAT_BROADCOM, },
  59. {},
  60. };