1
0

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Subject: make rootfs split/detection more generic - patch can be moved to generic-2.6 after testing on other platforms
  3. lede-commit: 328e660b31f0937d52c5ae3d6e7029409918a9df
  4. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  5. ---
  6. drivers/mtd/Kconfig | 17 +++++++++++++++++
  7. drivers/mtd/mtdpart.c | 35 +++++++++++++++++++++++++++++++++++
  8. include/linux/mtd/partitions.h | 2 ++
  9. 3 files changed, 54 insertions(+)
  10. --- a/drivers/mtd/Kconfig
  11. +++ b/drivers/mtd/Kconfig
  12. @@ -12,6 +12,23 @@ menuconfig MTD
  13. if MTD
  14. +menu "OpenWrt specific MTD options"
  15. +
  16. +config MTD_ROOTFS_ROOT_DEV
  17. + bool "Automatically set 'rootfs' partition to be root filesystem"
  18. + default y
  19. +
  20. +config MTD_SPLIT_FIRMWARE
  21. + bool "Automatically split firmware partition for kernel+rootfs"
  22. + default y
  23. +
  24. +config MTD_SPLIT_FIRMWARE_NAME
  25. + string "Firmware partition name"
  26. + depends on MTD_SPLIT_FIRMWARE
  27. + default "firmware"
  28. +
  29. +endmenu
  30. +
  31. config MTD_TESTS
  32. tristate "MTD tests support (DANGEROUS)"
  33. depends on m
  34. --- a/drivers/mtd/mtdpart.c
  35. +++ b/drivers/mtd/mtdpart.c
  36. @@ -29,11 +29,13 @@
  37. #include <linux/kmod.h>
  38. #include <linux/mtd/mtd.h>
  39. #include <linux/mtd/partitions.h>
  40. +#include <linux/magic.h>
  41. #include <linux/of.h>
  42. #include <linux/err.h>
  43. #include <linux/of.h>
  44. #include "mtdcore.h"
  45. +#include "mtdsplit/mtdsplit.h"
  46. /* Our partition linked list */
  47. static LIST_HEAD(mtd_partitions);
  48. @@ -53,6 +55,8 @@ struct mtd_part {
  49. struct list_head list;
  50. };
  51. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
  52. +
  53. /*
  54. * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
  55. * the pointer to that structure.
  56. @@ -658,6 +662,7 @@ int mtd_add_partition(struct mtd_info *p
  57. mutex_unlock(&mtd_partitions_mutex);
  58. add_mtd_device(&new->mtd);
  59. + mtd_partition_split(parent, new);
  60. mtd_add_partition_attrs(new);
  61. @@ -736,6 +741,35 @@ int mtd_del_partition(struct mtd_info *m
  62. }
  63. EXPORT_SYMBOL_GPL(mtd_del_partition);
  64. +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
  65. +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
  66. +#else
  67. +#define SPLIT_FIRMWARE_NAME "unused"
  68. +#endif
  69. +
  70. +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
  71. +{
  72. +}
  73. +
  74. +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
  75. + int offset, int size)
  76. +{
  77. +}
  78. +
  79. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
  80. +{
  81. + static int rootfs_found = 0;
  82. +
  83. + if (rootfs_found)
  84. + return;
  85. +
  86. + if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
  87. + IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE))
  88. + split_firmware(master, part);
  89. +
  90. + arch_split_mtd_part(master, part->mtd.name, part->offset,
  91. + part->mtd.size);
  92. +}
  93. /*
  94. * This function, given a master MTD object and a partition table, creates
  95. * and registers slave MTD objects which are bound to the master according to
  96. @@ -767,6 +801,7 @@ int add_mtd_partitions(struct mtd_info *
  97. mutex_unlock(&mtd_partitions_mutex);
  98. add_mtd_device(&slave->mtd);
  99. + mtd_partition_split(master, slave);
  100. mtd_add_partition_attrs(slave);
  101. /* Look for subpartitions */
  102. parse_mtd_partitions(&slave->mtd, parts[i].types, NULL);
  103. --- a/include/linux/mtd/partitions.h
  104. +++ b/include/linux/mtd/partitions.h
  105. @@ -110,5 +110,7 @@ int mtd_add_partition(struct mtd_info *m
  106. long long offset, long long length);
  107. int mtd_del_partition(struct mtd_info *master, int partno);
  108. uint64_t mtd_get_device_size(const struct mtd_info *mtd);
  109. +extern void __weak arch_split_mtd_part(struct mtd_info *master,
  110. + const char *name, int offset, int size);
  111. #endif