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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. @@ -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. @@ -668,6 +672,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. @@ -746,6 +751,29 @@ 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. +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
  75. +{
  76. + static int rootfs_found = 0;
  77. +
  78. + if (rootfs_found)
  79. + return;
  80. +
  81. + if (IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE) &&
  82. + !strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
  83. + !of_find_property(mtd_get_of_node(&part->mtd), "compatible", NULL))
  84. + split_firmware(master, part);
  85. +}
  86. +
  87. /*
  88. * This function, given a master MTD object and a partition table, creates
  89. * and registers slave MTD objects which are bound to the master according to
  90. @@ -777,6 +805,7 @@ int add_mtd_partitions(struct mtd_info *
  91. mutex_unlock(&mtd_partitions_mutex);
  92. add_mtd_device(&slave->mtd);
  93. + mtd_partition_split(master, slave);
  94. mtd_add_partition_attrs(slave);
  95. /* Look for subpartitions */
  96. parse_mtd_partitions(&slave->mtd, parts[i].types, NULL);