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