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
4 lede-commit: 328e660b31f0937d52c5ae3d6e7029409918a9df
5 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 drivers/mtd/Kconfig | 17 +++++++++++++++++
8 drivers/mtd/mtdpart.c | 35 +++++++++++++++++++++++++++++++++++
9 include/linux/mtd/partitions.h | 2 ++
10 3 files changed, 54 insertions(+)
12 --- a/drivers/mtd/Kconfig
13 +++ b/drivers/mtd/Kconfig
14 @@ -12,6 +12,23 @@ menuconfig MTD
18 +menu "OpenWrt specific MTD options"
20 +config MTD_ROOTFS_ROOT_DEV
21 + bool "Automatically set 'rootfs' partition to be root filesystem"
24 +config MTD_SPLIT_FIRMWARE
25 + bool "Automatically split firmware partition for kernel+rootfs"
28 +config MTD_SPLIT_FIRMWARE_NAME
29 + string "Firmware partition name"
30 + depends on MTD_SPLIT_FIRMWARE
36 tristate "MTD tests support (DANGEROUS)"
38 --- a/drivers/mtd/mtdpart.c
39 +++ b/drivers/mtd/mtdpart.c
41 #include <linux/kmod.h>
42 #include <linux/mtd/mtd.h>
43 #include <linux/mtd/partitions.h>
44 +#include <linux/magic.h>
46 #include <linux/err.h>
50 +#include "mtdsplit/mtdsplit.h"
52 /* Our partition linked list */
53 static LIST_HEAD(mtd_partitions);
54 @@ -53,6 +55,8 @@ struct mtd_part {
55 struct list_head list;
58 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
61 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
62 * the pointer to that structure.
63 @@ -658,6 +662,7 @@ int mtd_add_partition(struct mtd_info *p
64 mutex_unlock(&mtd_partitions_mutex);
66 add_mtd_device(&new->mtd);
67 + mtd_partition_split(parent, new);
69 mtd_add_partition_attrs(new);
71 @@ -736,6 +741,36 @@ int mtd_del_partition(struct mtd_info *m
73 EXPORT_SYMBOL_GPL(mtd_del_partition);
75 +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
76 +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
78 +#define SPLIT_FIRMWARE_NAME "unused"
81 +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
85 +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
86 + int offset, int size)
90 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
92 + static int rootfs_found = 0;
97 + if (IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE) &&
98 + !strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
99 + !of_find_property(mtd_get_of_node(&part->mtd), "compatible", NULL))
100 + split_firmware(master, part);
102 + arch_split_mtd_part(master, part->mtd.name, part->offset,
106 * This function, given a master MTD object and a partition table, creates
107 * and registers slave MTD objects which are bound to the master according to
108 @@ -767,6 +802,7 @@ int add_mtd_partitions(struct mtd_info *
109 mutex_unlock(&mtd_partitions_mutex);
111 add_mtd_device(&slave->mtd);
112 + mtd_partition_split(master, slave);
113 mtd_add_partition_attrs(slave);
114 /* Look for subpartitions */
115 parse_mtd_partitions(&slave->mtd, parts[i].types, NULL);
116 --- a/include/linux/mtd/partitions.h
117 +++ b/include/linux/mtd/partitions.h
118 @@ -110,5 +110,7 @@ int mtd_add_partition(struct mtd_info *m
119 long long offset, long long length);
120 int mtd_del_partition(struct mtd_info *master, int partno);
121 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
122 +extern void __weak arch_split_mtd_part(struct mtd_info *master,
123 + const char *name, int offset, int size);