ar7: drop 3.14 support
[15.05/openwrt.git] / target / linux / adm5120 / patches-3.14 / 050-revert_rootfs_splits.patch
1 Index: linux-3.14.27/drivers/mtd/mtdpart.c
2 ===================================================================
3 --- linux-3.14.27.orig/drivers/mtd/mtdpart.c
4 +++ linux-3.14.27/drivers/mtd/mtdpart.c
5 @@ -29,11 +29,9 @@
6  #include <linux/kmod.h>
7  #include <linux/mtd/mtd.h>
8  #include <linux/mtd/partitions.h>
9 -#include <linux/magic.h>
10  #include <linux/err.h>
11  
12  #include "mtdcore.h"
13 -#include "mtdsplit/mtdsplit.h"
14  
15  #define MTD_ERASE_PARTIAL      0x8000 /* partition only covers parts of an erase block */
16  
17 @@ -49,14 +47,13 @@ struct mtd_part {
18         struct list_head list;
19  };
20  
21 -static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
22 -
23  /*
24   * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
25   * the pointer to that structure with this macro.
26   */
27  #define PART(x)  ((struct mtd_part *)(x))
28  
29 +
30  /*
31   * MTD methods which simply translate the effective address and pass through
32   * to the _real_ device.
33 @@ -509,12 +506,14 @@ static struct mtd_part *allocate_partiti
34         if (slave->offset == MTDPART_OFS_APPEND)
35                 slave->offset = cur_offset;
36         if (slave->offset == MTDPART_OFS_NXTBLK) {
37 -               /* Round up to next erasesize */
38 -               slave->offset = mtd_roundup_to_eb(cur_offset, master);
39 -               if (slave->offset != cur_offset)
40 +               slave->offset = cur_offset;
41 +               if (mtd_mod_by_eb(cur_offset, master) != 0) {
42 +                       /* Round up to next erasesize */
43 +                       slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
44                         printk(KERN_NOTICE "Moving partition %d: "
45                                "0x%012llx -> 0x%012llx\n", partno,
46                                (unsigned long long)cur_offset, (unsigned long long)slave->offset);
47 +               }
48         }
49         if (slave->offset == MTDPART_OFS_RETAIN) {
50                 slave->offset = cur_offset;
51 @@ -616,10 +615,8 @@ out_register:
52         return slave;
53  }
54  
55 -
56 -static int
57 -__mtd_add_partition(struct mtd_info *master, const char *name,
58 -                   long long offset, long long length, bool dup_check)
59 +int mtd_add_partition(struct mtd_info *master, const char *name,
60 +                     long long offset, long long length)
61  {
62         struct mtd_partition part;
63         struct mtd_part *p, *new;
64 @@ -651,24 +648,21 @@ __mtd_add_partition(struct mtd_info *mas
65         end = offset + length;
66  
67         mutex_lock(&mtd_partitions_mutex);
68 -       if (dup_check) {
69 -               list_for_each_entry(p, &mtd_partitions, list)
70 -                       if (p->master == master) {
71 -                               if ((start >= p->offset) &&
72 -                                   (start < (p->offset + p->mtd.size)))
73 -                                       goto err_inv;
74 -
75 -                               if ((end >= p->offset) &&
76 -                                   (end < (p->offset + p->mtd.size)))
77 -                                       goto err_inv;
78 -                       }
79 -       }
80 +       list_for_each_entry(p, &mtd_partitions, list)
81 +               if (p->master == master) {
82 +                       if ((start >= p->offset) &&
83 +                           (start < (p->offset + p->mtd.size)))
84 +                               goto err_inv;
85 +
86 +                       if ((end >= p->offset) &&
87 +                           (end < (p->offset + p->mtd.size)))
88 +                               goto err_inv;
89 +               }
90  
91         list_add(&new->list, &mtd_partitions);
92         mutex_unlock(&mtd_partitions_mutex);
93  
94         add_mtd_device(&new->mtd);
95 -       mtd_partition_split(master, new);
96  
97         return ret;
98  err_inv:
99 @@ -678,12 +672,6 @@ err_inv:
100  }
101  EXPORT_SYMBOL_GPL(mtd_add_partition);
102  
103 -int mtd_add_partition(struct mtd_info *master, const char *name,
104 -                     long long offset, long long length)
105 -{
106 -       return __mtd_add_partition(master, name, offset, length, true);
107 -}
108 -
109  int mtd_del_partition(struct mtd_info *master, int partno)
110  {
111         struct mtd_part *slave, *next;
112 @@ -707,166 +695,6 @@ int mtd_del_partition(struct mtd_info *m
113  }
114  EXPORT_SYMBOL_GPL(mtd_del_partition);
115  
116 -static int
117 -run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
118 -{
119 -       struct mtd_partition *parts;
120 -       int nr_parts;
121 -       int i;
122 -
123 -       nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, &parts,
124 -                                               NULL);
125 -       if (nr_parts <= 0)
126 -               return nr_parts;
127 -
128 -       if (WARN_ON(!parts))
129 -               return 0;
130 -
131 -       for (i = 0; i < nr_parts; i++) {
132 -               /* adjust partition offsets */
133 -               parts[i].offset += slave->offset;
134 -
135 -               __mtd_add_partition(slave->master,
136 -                                   parts[i].name,
137 -                                   parts[i].offset,
138 -                                   parts[i].size,
139 -                                   false);
140 -       }
141 -
142 -       kfree(parts);
143 -
144 -       return nr_parts;
145 -}
146 -
147 -static inline unsigned long
148 -mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
149 -{
150 -       unsigned long mask = mtd->erasesize - 1;
151 -
152 -       len += offset & mask;
153 -       len = (len + mask) & ~mask;
154 -       len -= offset & mask;
155 -       return len;
156 -}
157 -
158 -static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
159 -{
160 -       size_t squashfs_len;
161 -       int len, ret;
162 -
163 -       ret = mtd_get_squashfs_len(master, offset, &squashfs_len);
164 -       if (ret)
165 -               return ret;
166 -
167 -       len = mtd_pad_erasesize(master, offset, squashfs_len);
168 -       *split_offset = offset + len;
169 -
170 -       return 0;
171 -}
172 -
173 -static void split_rootfs_data(struct mtd_info *master, struct mtd_part *part)
174 -{
175 -       unsigned int split_offset = 0;
176 -       unsigned int split_size;
177 -       int ret;
178 -
179 -       ret = split_squashfs(master, part->offset, &split_offset);
180 -       if (ret)
181 -               return;
182 -
183 -       if (split_offset <= 0)
184 -               return;
185 -
186 -       if (config_enabled(CONFIG_MTD_SPLIT_SQUASHFS_ROOT))
187 -               pr_err("Dedicated partitioner didn't create \"rootfs_data\" partition, please fill a bug report!\n");
188 -       else
189 -               pr_warn("Support for built-in \"rootfs_data\" splitter will be removed, please use CONFIG_MTD_SPLIT_SQUASHFS_ROOT\n");
190 -
191 -       split_size = part->mtd.size - (split_offset - part->offset);
192 -       printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=0x%x, len=0x%x\n",
193 -               ROOTFS_SPLIT_NAME, split_offset, split_size);
194 -
195 -       __mtd_add_partition(master, ROOTFS_SPLIT_NAME, split_offset,
196 -                           split_size, false);
197 -}
198 -
199 -#define UBOOT_MAGIC    0x27051956
200 -
201 -static void split_uimage(struct mtd_info *master, struct mtd_part *part)
202 -{
203 -       struct {
204 -               __be32 magic;
205 -               __be32 pad[2];
206 -               __be32 size;
207 -       } hdr;
208 -       size_t len;
209 -
210 -       if (mtd_read(master, part->offset, sizeof(hdr), &len, (void *) &hdr))
211 -               return;
212 -
213 -       if (len != sizeof(hdr) || hdr.magic != cpu_to_be32(UBOOT_MAGIC))
214 -               return;
215 -
216 -       len = be32_to_cpu(hdr.size) + 0x40;
217 -       len = mtd_pad_erasesize(master, part->offset, len);
218 -       if (len + master->erasesize > part->mtd.size)
219 -               return;
220 -
221 -       if (config_enabled(CONFIG_MTD_SPLIT_UIMAGE_FW))
222 -               pr_err("Dedicated partitioner didn't split firmware partition, please fill a bug report!\n");
223 -       else
224 -               pr_warn("Support for built-in firmware splitter will be removed, please use CONFIG_MTD_SPLIT_UIMAGE_FW\n");
225 -
226 -       __mtd_add_partition(master, "rootfs", part->offset + len,
227 -                           part->mtd.size - len, false);
228 -}
229 -
230 -#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
231 -#define SPLIT_FIRMWARE_NAME    CONFIG_MTD_SPLIT_FIRMWARE_NAME
232 -#else
233 -#define SPLIT_FIRMWARE_NAME    "unused"
234 -#endif
235 -
236 -static void split_firmware(struct mtd_info *master, struct mtd_part *part)
237 -{
238 -       int ret;
239 -
240 -       ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
241 -       if (ret > 0)
242 -               return;
243 -
244 -       if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
245 -               split_uimage(master, part);
246 -}
247 -
248 -void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
249 -                                int offset, int size)
250 -{
251 -}
252 -
253 -static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
254 -{
255 -       static int rootfs_found = 0;
256 -
257 -       if (rootfs_found)
258 -               return;
259 -
260 -       if (!strcmp(part->mtd.name, "rootfs")) {
261 -               int num = run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
262 -
263 -               if (num <= 0 && config_enabled(CONFIG_MTD_ROOTFS_SPLIT))
264 -                       split_rootfs_data(master, part);
265 -
266 -               rootfs_found = 1;
267 -       }
268 -
269 -       if (!strcmp(part->mtd.name, SPLIT_FIRMWARE_NAME) &&
270 -           config_enabled(CONFIG_MTD_SPLIT_FIRMWARE))
271 -               split_firmware(master, part);
272 -
273 -       arch_split_mtd_part(master, part->mtd.name, part->offset,
274 -                           part->mtd.size);
275 -}
276  /*
277   * This function, given a master MTD object and a partition table, creates
278   * and registers slave MTD objects which are bound to the master according to
279 @@ -896,7 +724,6 @@ int add_mtd_partitions(struct mtd_info *
280                 mutex_unlock(&mtd_partitions_mutex);
281  
282                 add_mtd_device(&slave->mtd);
283 -               mtd_partition_split(master, slave);
284  
285                 cur_offset = slave->offset + slave->mtd.size;
286         }
287 @@ -926,30 +753,6 @@ static struct mtd_part_parser *get_parti
288  
289  #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
290  
291 -static struct mtd_part_parser *
292 -get_partition_parser_by_type(enum mtd_parser_type type,
293 -                            struct mtd_part_parser *start)
294 -{
295 -       struct mtd_part_parser *p, *ret = NULL;
296 -
297 -       spin_lock(&part_parser_lock);
298 -
299 -       p = list_prepare_entry(start, &part_parsers, list);
300 -       if (start)
301 -               put_partition_parser(start);
302 -
303 -       list_for_each_entry_continue(p, &part_parsers, list) {
304 -               if (p->type == type && try_module_get(p->owner)) {
305 -                       ret = p;
306 -                       break;
307 -               }
308 -       }
309 -
310 -       spin_unlock(&part_parser_lock);
311 -
312 -       return ret;
313 -}
314 -
315  void register_mtd_parser(struct mtd_part_parser *p)
316  {
317         spin_lock(&part_parser_lock);
318 @@ -1023,38 +826,6 @@ int parse_mtd_partitions(struct mtd_info
319         return ret;
320  }
321  
322 -int parse_mtd_partitions_by_type(struct mtd_info *master,
323 -                                enum mtd_parser_type type,
324 -                                struct mtd_partition **pparts,
325 -                                struct mtd_part_parser_data *data)
326 -{
327 -       struct mtd_part_parser *prev = NULL;
328 -       int ret = 0;
329 -
330 -       while (1) {
331 -               struct mtd_part_parser *parser;
332 -
333 -               parser = get_partition_parser_by_type(type, prev);
334 -               if (!parser)
335 -                       break;
336 -
337 -               ret = (*parser->parse_fn)(master, pparts, data);
338 -
339 -               if (ret > 0) {
340 -                       put_partition_parser(parser);
341 -                       printk(KERN_NOTICE
342 -                              "%d %s partitions found on MTD device %s\n",
343 -                              ret, parser->name, master->name);
344 -                       break;
345 -               }
346 -
347 -               prev = parser;
348 -       }
349 -
350 -       return ret;
351 -}
352 -EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
353 -
354  int mtd_is_partition(const struct mtd_info *mtd)
355  {
356         struct mtd_part *part;