807-v6.1-0011-nvmem-u-boot-env-fix-crc32_data_offset-on-redundant-.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From ee424f7d3960152f5f862bbb6943e59828dc7917 Mon Sep 17 00:00:00 2001
  2. From: Christian Lamparter <[email protected]>
  3. Date: Fri, 4 Nov 2022 17:52:03 +0100
  4. Subject: [PATCH] nvmem: u-boot-env: fix crc32_data_offset on redundant
  5. u-boot-env
  6. The Western Digital MyBook Live (PowerPC 464/APM82181)
  7. has a set of redundant u-boot-env. Loading up the driver
  8. the following error:
  9. | u_boot_env: Invalid calculated CRC32: 0x4f8f2c86 (expected: 0x98b14514)
  10. | u_boot_env: probe of partition@1e000 failed with error -22
  11. Looking up the userspace libubootenv utilities source [0],
  12. it looks like the "mark" or "flag" is not part of the
  13. crc32 sum... which is unfortunate :(
  14. |static int libuboot_load(struct uboot_ctx *ctx)
  15. |{
  16. |[...]
  17. | if (ctx->redundant) {
  18. | [...]
  19. | offsetdata = offsetof(struct uboot_env_redund, data);
  20. | [...] //-----^^
  21. | }
  22. | usable_envsize = ctx->size - offsetdata;
  23. | buf[0] = malloc(bufsize);
  24. |[...]
  25. | for (i = 0; i < copies; i++) {
  26. | data = (uint8_t *)(buf[i] + offsetdata);
  27. | uint32_t crc;
  28. |
  29. | ret = devread(ctx, i, buf[i]);
  30. | [...]
  31. | crc = *(uint32_t *)(buf[i] + offsetcrc);
  32. | dev->crc = crc32(0, (uint8_t *)data, usable_envsize);
  33. |
  34. [0] https://github.com/sbabic/libubootenv/blob/master/src/uboot_env.c#L951
  35. Fixes: d5542923f200 ("nvmem: add driver handling U-Boot environment variables")
  36. Signed-off-by: Christian Lamparter <[email protected]>
  37. Link: https://lore.kernel.org/r/70a16eae113e08db2390b76e174f4837caa135c3.1667580636.git.chunkeey@gmail.com
  38. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  39. ---
  40. drivers/nvmem/u-boot-env.c | 2 +-
  41. 1 file changed, 1 insertion(+), 1 deletion(-)
  42. --- a/drivers/nvmem/u-boot-env.c
  43. +++ b/drivers/nvmem/u-boot-env.c
  44. @@ -135,7 +135,7 @@ static int u_boot_env_parse(struct u_boo
  45. break;
  46. case U_BOOT_FORMAT_REDUNDANT:
  47. crc32_offset = offsetof(struct u_boot_env_image_redundant, crc32);
  48. - crc32_data_offset = offsetof(struct u_boot_env_image_redundant, mark);
  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. }