400-mtd-add-rootfs-split-support.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. --- a/drivers/mtd/Kconfig
  2. +++ b/drivers/mtd/Kconfig
  3. @@ -12,6 +12,23 @@ menuconfig MTD
  4. if MTD
  5. +menu "OpenWrt specific MTD options"
  6. +
  7. +config MTD_ROOTFS_ROOT_DEV
  8. + bool "Automatically set 'rootfs' partition to be root filesystem"
  9. + default y
  10. +
  11. +config MTD_SPLIT_FIRMWARE
  12. + bool "Automatically split firmware partition for kernel+rootfs"
  13. + default y
  14. +
  15. +config MTD_SPLIT_FIRMWARE_NAME
  16. + string "Firmware partition name"
  17. + depends on MTD_SPLIT_FIRMWARE
  18. + default "firmware"
  19. +
  20. +endmenu
  21. +
  22. config MTD_TESTS
  23. tristate "MTD tests support (DANGEROUS)"
  24. depends on m
  25. --- a/drivers/mtd/mtdpart.c
  26. +++ b/drivers/mtd/mtdpart.c
  27. @@ -29,10 +29,12 @@
  28. #include <linux/kmod.h>
  29. #include <linux/mtd/mtd.h>
  30. #include <linux/mtd/partitions.h>
  31. +#include <linux/magic.h>
  32. #include <linux/of.h>
  33. #include <linux/err.h>
  34. #include "mtdcore.h"
  35. +#include "mtdsplit/mtdsplit.h"
  36. /* Our partition linked list */
  37. static LIST_HEAD(mtd_partitions);
  38. @@ -46,6 +48,8 @@ struct mtd_part {
  39. struct list_head list;
  40. };
  41. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
  42. +
  43. /*
  44. * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
  45. * the pointer to that structure.
  46. @@ -650,6 +654,7 @@ int mtd_add_partition(struct mtd_info *m
  47. mutex_unlock(&mtd_partitions_mutex);
  48. add_mtd_device(&new->mtd);
  49. + mtd_partition_split(master, new);
  50. mtd_add_partition_attrs(new);
  51. @@ -682,6 +687,35 @@ int mtd_del_partition(struct mtd_info *m
  52. }
  53. EXPORT_SYMBOL_GPL(mtd_del_partition);
  54. +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
  55. +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
  56. +#else
  57. +#define SPLIT_FIRMWARE_NAME "unused"
  58. +#endif
  59. +
  60. +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
  61. +{
  62. +}
  63. +
  64. +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
  65. + int offset, int size)
  66. +{
  67. +}
  68. +
  69. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
  70. +{
  71. + static int rootfs_found = 0;
  72. +
  73. + if (rootfs_found)
  74. + return;
  75. +
  76. + if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
  77. + IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE))
  78. + split_firmware(master, part);
  79. +
  80. + arch_split_mtd_part(master, part->mtd.name, part->offset,
  81. + part->mtd.size);
  82. +}
  83. /*
  84. * This function, given a master MTD object and a partition table, creates
  85. * and registers slave MTD objects which are bound to the master according to
  86. @@ -713,6 +747,7 @@ int add_mtd_partitions(struct mtd_info *
  87. mutex_unlock(&mtd_partitions_mutex);
  88. add_mtd_device(&slave->mtd);
  89. + mtd_partition_split(master, slave);
  90. mtd_add_partition_attrs(slave);
  91. cur_offset = slave->offset + slave->mtd.size;
  92. --- a/include/linux/mtd/partitions.h
  93. +++ b/include/linux/mtd/partitions.h
  94. @@ -101,5 +101,7 @@ int mtd_add_partition(struct mtd_info *m
  95. long long offset, long long length);
  96. int mtd_del_partition(struct mtd_info *master, int partno);
  97. uint64_t mtd_get_device_size(const struct mtd_info *mtd);
  98. +extern void __weak arch_split_mtd_part(struct mtd_info *master,
  99. + const char *name, int offset, int size);
  100. #endif