2
0

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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,6 +49,8 @@ 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. @@ -612,6 +616,7 @@ int mtd_add_partition(struct mtd_info *m
  48. mutex_unlock(&mtd_partitions_mutex);
  49. add_mtd_device(&new->mtd);
  50. + mtd_partition_split(master, new);
  51. mtd_add_partition_attrs(new);
  52. @@ -644,6 +649,35 @@ int mtd_del_partition(struct mtd_info *m
  53. }
  54. EXPORT_SYMBOL_GPL(mtd_del_partition);
  55. +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
  56. +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
  57. +#else
  58. +#define SPLIT_FIRMWARE_NAME "unused"
  59. +#endif
  60. +
  61. +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
  62. +{
  63. +}
  64. +
  65. +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
  66. + int offset, int size)
  67. +{
  68. +}
  69. +
  70. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
  71. +{
  72. + static int rootfs_found = 0;
  73. +
  74. + if (rootfs_found)
  75. + return;
  76. +
  77. + if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
  78. + config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
  79. + split_firmware(master, part);
  80. +
  81. + arch_split_mtd_part(master, part->mtd.name, part->offset,
  82. + part->mtd.size);
  83. +}
  84. /*
  85. * This function, given a master MTD object and a partition table, creates
  86. * and registers slave MTD objects which are bound to the master according to
  87. @@ -675,6 +709,7 @@ int add_mtd_partitions(struct mtd_info *
  88. mutex_unlock(&mtd_partitions_mutex);
  89. add_mtd_device(&slave->mtd);
  90. + mtd_partition_split(master, slave);
  91. mtd_add_partition_attrs(slave);
  92. cur_offset = slave->offset + slave->mtd.size;
  93. --- a/include/linux/mtd/partitions.h
  94. +++ b/include/linux/mtd/partitions.h
  95. @@ -84,5 +84,7 @@ int mtd_add_partition(struct mtd_info *m
  96. long long offset, long long length);
  97. int mtd_del_partition(struct mtd_info *master, int partno);
  98. uint64_t mtd_get_device_size(const struct mtd_info *mtd);
  99. +extern void __weak arch_split_mtd_part(struct mtd_info *master,
  100. + const char *name, int offset, int size);
  101. #endif