1 --- a/drivers/mtd/Kconfig
2 +++ b/drivers/mtd/Kconfig
3 @@ -12,6 +12,23 @@ menuconfig MTD
7 +menu "OpenWrt specific MTD options"
9 +config MTD_ROOTFS_ROOT_DEV
10 + bool "Automatically set 'rootfs' partition to be root filesystem"
13 +config MTD_SPLIT_FIRMWARE
14 + bool "Automatically split firmware partition for kernel+rootfs"
17 +config MTD_SPLIT_FIRMWARE_NAME
18 + string "Firmware partition name"
19 + depends on MTD_SPLIT_FIRMWARE
25 tristate "MTD tests support (DANGEROUS)"
27 --- a/drivers/mtd/mtdpart.c
28 +++ b/drivers/mtd/mtdpart.c
30 #include <linux/kmod.h>
31 #include <linux/mtd/mtd.h>
32 #include <linux/mtd/partitions.h>
33 +#include <linux/magic.h>
35 #include <linux/err.h>
38 +#include "mtdsplit/mtdsplit.h"
40 /* Our partition linked list */
41 static LIST_HEAD(mtd_partitions);
42 @@ -52,6 +54,8 @@ struct mtd_part {
43 struct list_head list;
46 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
49 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
50 * the pointer to that structure.
51 @@ -678,6 +682,7 @@ int mtd_add_partition(struct mtd_info *p
52 mutex_unlock(&mtd_partitions_mutex);
54 add_mtd_device(&new->mtd);
55 + mtd_partition_split(parent, new);
57 mtd_add_partition_attrs(new);
59 @@ -756,6 +761,35 @@ int mtd_del_partition(struct mtd_info *m
61 EXPORT_SYMBOL_GPL(mtd_del_partition);
63 +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
64 +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
66 +#define SPLIT_FIRMWARE_NAME "unused"
69 +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
73 +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
74 + int offset, int size)
78 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
80 + static int rootfs_found = 0;
85 + if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
86 + IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE))
87 + split_firmware(master, part);
89 + arch_split_mtd_part(master, part->mtd.name, part->offset,
93 * This function, given a master MTD object and a partition table, creates
94 * and registers slave MTD objects which are bound to the master according to
95 @@ -787,6 +821,7 @@ int add_mtd_partitions(struct mtd_info *
96 mutex_unlock(&mtd_partitions_mutex);
98 add_mtd_device(&slave->mtd);
99 + mtd_partition_split(master, slave);
100 mtd_add_partition_attrs(slave);
102 mtd_parse_part(slave, parts[i].types);
103 --- a/include/linux/mtd/partitions.h
104 +++ b/include/linux/mtd/partitions.h
105 @@ -109,5 +109,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);