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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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,11 +29,13 @@
  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 <linux/kconfig.h>
  35. #include "mtdcore.h"
  36. +#include "mtdsplit/mtdsplit.h"
  37. /* Our partition linked list */
  38. static LIST_HEAD(mtd_partitions);
  39. @@ -47,13 +49,14 @@ struct mtd_part {
  40. struct list_head list;
  41. };
  42. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
  43. +
  44. /*
  45. * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
  46. * the pointer to that structure with this macro.
  47. */
  48. #define PART(x) ((struct mtd_part *)(x))
  49. -
  50. /*
  51. * MTD methods which simply translate the effective address and pass through
  52. * to the _real_ device.
  53. @@ -579,8 +582,10 @@ static int mtd_add_partition_attrs(struc
  54. return ret;
  55. }
  56. -int mtd_add_partition(struct mtd_info *master, const char *name,
  57. - long long offset, long long length)
  58. +
  59. +static int
  60. +__mtd_add_partition(struct mtd_info *master, const char *name,
  61. + long long offset, long long length, bool dup_check)
  62. {
  63. struct mtd_partition part;
  64. struct mtd_part *new;
  65. @@ -612,6 +617,7 @@ int mtd_add_partition(struct mtd_info *m
  66. mutex_unlock(&mtd_partitions_mutex);
  67. add_mtd_device(&new->mtd);
  68. + mtd_partition_split(master, new);
  69. mtd_add_partition_attrs(new);
  70. @@ -619,6 +625,12 @@ int mtd_add_partition(struct mtd_info *m
  71. }
  72. EXPORT_SYMBOL_GPL(mtd_add_partition);
  73. +int mtd_add_partition(struct mtd_info *master, const char *name,
  74. + long long offset, long long length)
  75. +{
  76. + return __mtd_add_partition(master, name, offset, length, true);
  77. +}
  78. +
  79. int mtd_del_partition(struct mtd_info *master, int partno)
  80. {
  81. struct mtd_part *slave, *next;
  82. @@ -644,6 +656,35 @@ int mtd_del_partition(struct mtd_info *m
  83. }
  84. EXPORT_SYMBOL_GPL(mtd_del_partition);
  85. +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
  86. +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
  87. +#else
  88. +#define SPLIT_FIRMWARE_NAME "unused"
  89. +#endif
  90. +
  91. +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
  92. +{
  93. +}
  94. +
  95. +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
  96. + int offset, int size)
  97. +{
  98. +}
  99. +
  100. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
  101. +{
  102. + static int rootfs_found = 0;
  103. +
  104. + if (rootfs_found)
  105. + return;
  106. +
  107. + if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
  108. + config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
  109. + split_firmware(master, part);
  110. +
  111. + arch_split_mtd_part(master, part->mtd.name, part->offset,
  112. + part->mtd.size);
  113. +}
  114. /*
  115. * This function, given a master MTD object and a partition table, creates
  116. * and registers slave MTD objects which are bound to the master according to
  117. @@ -673,6 +714,7 @@ int add_mtd_partitions(struct mtd_info *
  118. mutex_unlock(&mtd_partitions_mutex);
  119. add_mtd_device(&slave->mtd);
  120. + mtd_partition_split(master, slave);
  121. mtd_add_partition_attrs(slave);
  122. cur_offset = slave->offset + slave->mtd.size;
  123. --- a/include/linux/mtd/partitions.h
  124. +++ b/include/linux/mtd/partitions.h
  125. @@ -84,5 +84,7 @@ int mtd_add_partition(struct mtd_info *m
  126. long long offset, long long length);
  127. int mtd_del_partition(struct mtd_info *master, int partno);
  128. uint64_t mtd_get_device_size(const struct mtd_info *mtd);
  129. +extern void __weak arch_split_mtd_part(struct mtd_info *master,
  130. + const char *name, int offset, int size);
  131. #endif