kernel/3.18: update to version 3.18.25
[openwrt/openwrt.git] / target / linux / generic / patches-4.1 / 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,11 +29,13 @@
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 #include <linux/kconfig.h>
37
38 #include "mtdcore.h"
39 +#include "mtdsplit/mtdsplit.h"
40
41 /* Our partition linked list */
42 static LIST_HEAD(mtd_partitions);
43 @@ -47,13 +49,14 @@ struct mtd_part {
44 struct list_head list;
45 };
46
47 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
48 +
49 /*
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 */
53 #define PART(x) ((struct mtd_part *)(x))
54
55 -
56 /*
57 * MTD methods which simply translate the effective address and pass through
58 * to the _real_ device.
59 @@ -579,8 +582,10 @@ static int mtd_add_partition_attrs(struc
60 return ret;
61 }
62
63 -int mtd_add_partition(struct mtd_info *master, const char *name,
64 - long long offset, long long length)
65 +
66 +static int
67 +__mtd_add_partition(struct mtd_info *master, const char *name,
68 + long long offset, long long length, bool dup_check)
69 {
70 struct mtd_partition part;
71 struct mtd_part *new;
72 @@ -612,6 +617,7 @@ int mtd_add_partition(struct mtd_info *m
73 mutex_unlock(&mtd_partitions_mutex);
74
75 add_mtd_device(&new->mtd);
76 + mtd_partition_split(master, new);
77
78 mtd_add_partition_attrs(new);
79
80 @@ -619,6 +625,12 @@ int mtd_add_partition(struct mtd_info *m
81 }
82 EXPORT_SYMBOL_GPL(mtd_add_partition);
83
84 +int mtd_add_partition(struct mtd_info *master, const char *name,
85 + long long offset, long long length)
86 +{
87 + return __mtd_add_partition(master, name, offset, length, true);
88 +}
89 +
90 int mtd_del_partition(struct mtd_info *master, int partno)
91 {
92 struct mtd_part *slave, *next;
93 @@ -644,6 +656,35 @@ int mtd_del_partition(struct mtd_info *m
94 }
95 EXPORT_SYMBOL_GPL(mtd_del_partition);
96
97 +#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
98 +#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
99 +#else
100 +#define SPLIT_FIRMWARE_NAME "unused"
101 +#endif
102 +
103 +static void split_firmware(struct mtd_info *master, struct mtd_part *part)
104 +{
105 +}
106 +
107 +void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
108 + int offset, int size)
109 +{
110 +}
111 +
112 +static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
113 +{
114 + static int rootfs_found = 0;
115 +
116 + if (rootfs_found)
117 + return;
118 +
119 + if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
120 + config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
121 + split_firmware(master, part);
122 +
123 + arch_split_mtd_part(master, part->mtd.name, part->offset,
124 + part->mtd.size);
125 +}
126 /*
127 * This function, given a master MTD object and a partition table, creates
128 * and registers slave MTD objects which are bound to the master according to
129 @@ -673,6 +714,7 @@ int add_mtd_partitions(struct mtd_info *
130 mutex_unlock(&mtd_partitions_mutex);
131
132 add_mtd_device(&slave->mtd);
133 + mtd_partition_split(master, slave);
134 mtd_add_partition_attrs(slave);
135
136 cur_offset = slave->offset + slave->mtd.size;
137 --- a/include/linux/mtd/partitions.h
138 +++ b/include/linux/mtd/partitions.h
139 @@ -84,5 +84,7 @@ int mtd_add_partition(struct mtd_info *m
140 long long offset, long long length);
141 int mtd_del_partition(struct mtd_info *master, int partno);
142 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
143 +extern void __weak arch_split_mtd_part(struct mtd_info *master,
144 + const char *name, int offset, int size);
145
146 #endif