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

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