bc402a2c119c9f05dee736d6638c364d3869cfa0
[openwrt/openwrt.git] / target / linux / generic / patches-4.9 / 400-mtd-add-rootfs-split-support.patch
1 --- a/drivers/mtd/Kconfig
2 +++ b/drivers/mtd/Kconfig
3 @@ -12,6 +12,23 @@ menuconfig MTD
4
5 if MTD
6
7 +menu "OpenWrt specific MTD options"
8 +
9 +config MTD_ROOTFS_ROOT_DEV
10 + bool "Automatically set 'rootfs' partition to be root filesystem"
11 + default y
12 +
13 +config MTD_SPLIT_FIRMWARE
14 + bool "Automatically split firmware partition for kernel+rootfs"
15 + default y
16 +
17 +config MTD_SPLIT_FIRMWARE_NAME
18 + string "Firmware partition name"
19 + depends on MTD_SPLIT_FIRMWARE
20 + default "firmware"
21 +
22 +endmenu
23 +
24 config MTD_TESTS
25 tristate "MTD tests support (DANGEROUS)"
26 depends on m
27 --- a/drivers/mtd/mtdpart.c
28 +++ b/drivers/mtd/mtdpart.c
29 @@ -29,10 +29,12 @@
30 #include <linux/kmod.h>
31 #include <linux/mtd/mtd.h>
32 #include <linux/mtd/partitions.h>
33 +#include <linux/magic.h>
34 #include <linux/of.h>
35 #include <linux/err.h>
36
37 #include "mtdcore.h"
38 +#include "mtdsplit/mtdsplit.h"
39
40 /* Our partition linked list */
41 static LIST_HEAD(mtd_partitions);
42 @@ -52,6 +54,8 @@ struct mtd_part {
43 struct list_head list;
44 };
45
46 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
47 +
48 /*
49 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
50 * the pointer to that structure.
51 @@ -649,6 +653,7 @@ int mtd_add_partition(struct mtd_info *p
52 mutex_unlock(&mtd_partitions_mutex);
53
54 add_mtd_device(&new->mtd);
55 + mtd_partition_split(parent, new);
56
57 mtd_add_partition_attrs(new);
58
59 @@ -718,6 +723,35 @@ int mtd_del_partition(struct mtd_info *m
60 }
61 EXPORT_SYMBOL_GPL(mtd_del_partition);
62
63 +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
64 +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
65 +#else
66 +#define SPLIT_FIRMWARE_NAME "unused"
67 +#endif
68 +
69 +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
70 +{
71 +}
72 +
73 +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
74 + int offset, int size)
75 +{
76 +}
77 +
78 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
79 +{
80 + static int rootfs_found = 0;
81 +
82 + if (rootfs_found)
83 + return;
84 +
85 + if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
86 + IS_ENABLED(CONFIG_MTD_SPLIT_FIRMWARE))
87 + split_firmware(master, part);
88 +
89 + arch_split_mtd_part(master, part->mtd.name, part->offset,
90 + part->mtd.size);
91 +}
92 /*
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 @@ -749,6 +783,7 @@ int add_mtd_partitions(struct mtd_info *
96 mutex_unlock(&mtd_partitions_mutex);
97
98 add_mtd_device(&slave->mtd);
99 + mtd_partition_split(master, slave);
100 mtd_add_partition_attrs(slave);
101
102 cur_offset = slave->offset + slave->mtd.size;
103 --- a/include/linux/mtd/partitions.h
104 +++ b/include/linux/mtd/partitions.h
105 @@ -102,5 +102,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);
111
112 #endif