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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. From: Felix Fietkau <[email protected]>
  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 <[email protected]>
  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. @@ -11,6 +11,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,10 +29,12 @@
  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/err.h>
  42. #include <linux/of.h>
  43. #include "mtdcore.h"
  44. +#include "mtdsplit/mtdsplit.h"
  45. /* Our partition linked list */
  46. static LIST_HEAD(mtd_partitions);
  47. @@ -52,6 +54,8 @@ struct mtd_part {
  48. struct list_head list;
  49. };
  50. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
  51. +
  52. /*
  53. * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
  54. * the pointer to that structure.
  55. @@ -623,6 +627,7 @@ int mtd_add_partition(struct mtd_info *p
  56. mutex_unlock(&mtd_partitions_mutex);
  57. add_mtd_device(&new->mtd);
  58. + mtd_partition_split(parent, new);
  59. mtd_add_partition_attrs(new);
  60. @@ -701,6 +706,29 @@ int mtd_del_partition(struct mtd_info *m
  61. }
  62. EXPORT_SYMBOL_GPL(mtd_del_partition);
  63. +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
  64. +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
  65. +#else
  66. +#define SPLIT_FIRMWARE_NAME "unused"
  67. +#endif
  68. +
  69. +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
  70. +{
  71. +}
  72. +
  73. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
  74. +{
  75. + static int rootfs_found = 0;
  76. +
  77. + if (rootfs_found)
  78. + return;
  79. +
  80. + if (IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE) &&
  81. + !strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
  82. + !of_find_property(mtd_get_of_node(&part->mtd), "compatible", NULL))
  83. + split_firmware(master, part);
  84. +}
  85. +
  86. /*
  87. * This function, given a master MTD object and a partition table, creates
  88. * and registers slave MTD objects which are bound to the master according to
  89. @@ -732,6 +760,7 @@ int add_mtd_partitions(struct mtd_info *
  90. mutex_unlock(&mtd_partitions_mutex);
  91. add_mtd_device(&slave->mtd);
  92. + mtd_partition_split(master, slave);
  93. mtd_add_partition_attrs(slave);
  94. /* Look for subpartitions */
  95. parse_mtd_partitions(&slave->mtd, parts[i].types, NULL);