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>
36 #include <linux/kconfig.h>
39 +#include "mtdsplit/mtdsplit.h"
41 /* Our partition linked list */
42 static LIST_HEAD(mtd_partitions);
43 @@ -47,6 +49,8 @@ struct mtd_part {
44 struct list_head list;
47 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
50 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
51 * the pointer to that structure with this macro.
52 @@ -612,6 +616,7 @@ int mtd_add_partition(struct mtd_info *m
53 mutex_unlock(&mtd_partitions_mutex);
55 add_mtd_device(&new->mtd);
56 + mtd_partition_split(master, new);
58 mtd_add_partition_attrs(new);
60 @@ -644,6 +649,35 @@ int mtd_del_partition(struct mtd_info *m
62 EXPORT_SYMBOL_GPL(mtd_del_partition);
64 +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
65 +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
67 +#define SPLIT_FIRMWARE_NAME "unused"
70 +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
74 +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
75 + int offset, int size)
79 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
81 + static int rootfs_found = 0;
86 + if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
87 + config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
88 + split_firmware(master, part);
90 + arch_split_mtd_part(master, part->mtd.name, part->offset,
94 * This function, given a master MTD object and a partition table, creates
95 * and registers slave MTD objects which are bound to the master according to
96 @@ -675,6 +709,7 @@ int add_mtd_partitions(struct mtd_info *
97 mutex_unlock(&mtd_partitions_mutex);
99 add_mtd_device(&slave->mtd);
100 + mtd_partition_split(master, slave);
101 mtd_add_partition_attrs(slave);
103 cur_offset = slave->offset + slave->mtd.size;
104 --- a/include/linux/mtd/partitions.h
105 +++ b/include/linux/mtd/partitions.h
106 @@ -84,5 +84,7 @@ int mtd_add_partition(struct mtd_info *m
107 long long offset, long long length);
108 int mtd_del_partition(struct mtd_info *master, int partno);
109 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
110 +extern void __weak arch_split_mtd_part(struct mtd_info *master,
111 + const char *name, int offset, int size);