2
0

405-mtd-old-firmware-uimage-splitter.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --- a/drivers/mtd/Kconfig
  2. +++ b/drivers/mtd/Kconfig
  3. @@ -27,6 +27,11 @@ config MTD_SPLIT_FIRMWARE_NAME
  4. depends on MTD_SPLIT_FIRMWARE
  5. default "firmware"
  6. +config MTD_UIMAGE_SPLIT
  7. + bool "Enable split support for firmware partitions containing a uImage"
  8. + depends on MTD_SPLIT_FIRMWARE
  9. + default y
  10. +
  11. source "drivers/mtd/mtdsplit/Kconfig"
  12. endmenu
  13. --- a/drivers/mtd/mtdpart.c
  14. +++ b/drivers/mtd/mtdpart.c
  15. @@ -682,6 +682,37 @@ mtd_pad_erasesize(struct mtd_info *mtd,
  16. return len;
  17. }
  18. +#define UBOOT_MAGIC 0x27051956
  19. +
  20. +static void split_uimage(struct mtd_info *master, struct mtd_part *part)
  21. +{
  22. + struct {
  23. + __be32 magic;
  24. + __be32 pad[2];
  25. + __be32 size;
  26. + } hdr;
  27. + size_t len;
  28. +
  29. + if (mtd_read(master, part->offset, sizeof(hdr), &len, (void *) &hdr))
  30. + return;
  31. +
  32. + if (len != sizeof(hdr) || hdr.magic != cpu_to_be32(UBOOT_MAGIC))
  33. + return;
  34. +
  35. + len = be32_to_cpu(hdr.size) + 0x40;
  36. + len = mtd_pad_erasesize(master, part->offset, len);
  37. + if (len + master->erasesize > part->mtd.size)
  38. + return;
  39. +
  40. + if (config_enabled(CONFIG_MTD_SPLIT_UIMAGE_FW))
  41. + pr_err("Dedicated partitioner didn't split firmware partition, please fill a bug report!\n");
  42. + else
  43. + pr_warn("Support for built-in firmware splitter will be removed, please use CONFIG_MTD_SPLIT_UIMAGE_FW\n");
  44. +
  45. + __mtd_add_partition(master, "rootfs", part->offset + len,
  46. + part->mtd.size - len, false);
  47. +}
  48. +
  49. #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
  50. #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
  51. #else
  52. @@ -690,7 +721,14 @@ mtd_pad_erasesize(struct mtd_info *mtd,
  53. static void split_firmware(struct mtd_info *master, struct mtd_part *part)
  54. {
  55. - run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
  56. + int ret;
  57. +
  58. + ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
  59. + if (ret > 0)
  60. + return;
  61. +
  62. + if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
  63. + split_uimage(master, part);
  64. }
  65. void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,