5381e2f6cc7a5183c9d65da3449feafba46e46fa
[openwrt.git] / target / linux / brcm47xx / patches-3.3 / 050-mtd-add-bcm47xx-part-parser.patch
1 --- a/drivers/mtd/Kconfig
2 +++ b/drivers/mtd/Kconfig
3 @@ -172,6 +172,13 @@ config MTD_MYLOADER_PARTS
4           You will still need the parsing functions to be called by the driver
5           for your particular device. It won't happen automatically.
6  
7 +config MTD_BCM47XX_PARTS
8 +       tristate "BCM47XX partitioning support"
9 +       default y
10 +       depends on BCM47XX
11 +       ---help---
12 +         bcm47XX partitioning support
13 +
14  comment "User Modules And Translation Layers"
15  
16  config MTD_CHAR
17 --- a/drivers/mtd/Makefile
18 +++ b/drivers/mtd/Makefile
19 @@ -13,6 +13,7 @@ obj-$(CONFIG_MTD_AFS_PARTS)   += afs.o
20  obj-$(CONFIG_MTD_AR7_PARTS)    += ar7part.o
21  obj-$(CONFIG_MTD_BCM63XX_PARTS)        += bcm63xxpart.o
22  obj-$(CONFIG_MTD_MYLOADER_PARTS) += myloader.o
23 +obj-$(CONFIG_MTD_BCM47XX_PARTS)        += bcm47xxpart.o
24  
25  # 'Users' - code which presents functionality to userspace.
26  obj-$(CONFIG_MTD_CHAR)         += mtdchar.o
27 --- /dev/null
28 +++ b/drivers/mtd/bcm47xxpart.c
29 @@ -0,0 +1,542 @@
30 +/*
31 + *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
32 + *  Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
33 + *  Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
34 + *
35 + *  original functions for finding root filesystem from Mike Baker
36 + *
37 + *  This program is free software; you can redistribute  it and/or modify it
38 + *  under  the terms of  the GNU General  Public License as published by the
39 + *  Free Software Foundation;  either version 2 of the  License, or (at your
40 + *  option) any later version.
41 + *
42 + *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
43 + *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
44 + *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
45 + *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
46 + *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 + *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
48 + *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
49 + *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
50 + *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
51 + *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 + *
53 + *  You should have received a copy of the  GNU General Public License along
54 + *  with this program; if not, write  to the Free Software Foundation, Inc.,
55 + *  675 Mass Ave, Cambridge, MA 02139, USA.
56 + *
57 + *  Copyright 2001-2003, Broadcom Corporation
58 + *  All Rights Reserved.
59 + *
60 + *  THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
61 + *  KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
62 + *  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
63 + *  FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
64 + *
65 + *  Flash mapping for BCM947XX boards
66 + */
67 +
68 +#define pr_fmt(fmt) "bcm47xx_part: " fmt
69 +#include <linux/init.h>
70 +#include <linux/module.h>
71 +#include <linux/types.h>
72 +#include <linux/kernel.h>
73 +#include <linux/sched.h>
74 +#include <linux/wait.h>
75 +#include <linux/mtd/mtd.h>
76 +#include <linux/mtd/partitions.h>
77 +#include <linux/crc32.h>
78 +#include <linux/io.h>
79 +#include <asm/mach-bcm47xx/nvram.h>
80 +#include <asm/mach-bcm47xx/bcm47xx.h>
81 +#include <asm/fw/cfe/cfe_api.h>
82 +
83 +
84 +#define TRX_MAGIC      0x30524448      /* "HDR0" */
85 +#define TRX_VERSION    1
86 +#define TRX_MAX_LEN    0x3A0000
87 +#define TRX_NO_HEADER  1               /* Do not write TRX header */
88 +#define TRX_GZ_FILES   0x2     /* Contains up to TRX_MAX_OFFSET individual gzip files */
89 +#define TRX_MAX_OFFSET 3
90 +
91 +struct trx_header {
92 +       u32 magic;              /* "HDR0" */
93 +       u32 len;                /* Length of file including header */
94 +       u32 crc32;              /* 32-bit CRC from flag_version to end of file */
95 +       u32 flag_version;       /* 0:15 flags, 16:31 version */
96 +       u32 offsets[TRX_MAX_OFFSET];    /* Offsets of partitions from start of header */
97 +};
98 +
99 +/* for Edimax Print servers which use an additional header
100 + * then the firmware on flash looks like :
101 + * EDIMAX HEADER | TRX HEADER
102 + * As this header is 12 bytes long we have to handle it
103 + * and skip it to find the TRX header
104 + */
105 +#define EDIMAX_PS_HEADER_MAGIC 0x36315350 /*  "PS16"  */
106 +#define EDIMAX_PS_HEADER_LEN   0xc /* 12 bytes long for edimax header */
107 +
108 +#define NVRAM_SPACE 0x8000
109 +
110 +#define ROUTER_NETGEAR_WGR614L         1
111 +#define ROUTER_NETGEAR_WNR834B         2
112 +#define ROUTER_NETGEAR_WNDR3300                3
113 +#define ROUTER_NETGEAR_WNR3500L                4
114 +#define ROUTER_SIMPLETECH_SIMPLESHARE  5
115 +#define ROUTER_NETGEAR_WNDR3400                6
116 +
117 +static int
118 +find_cfe_size(struct mtd_info *mtd)
119 +{
120 +       struct trx_header *trx;
121 +       unsigned char buf[512];
122 +       int off;
123 +       size_t len;
124 +       int blocksize;
125 +
126 +       trx = (struct trx_header *) buf;
127 +
128 +       blocksize = mtd->erasesize;
129 +       if (blocksize < 0x10000)
130 +               blocksize = 0x10000;
131 +
132 +       for (off = (128*1024); off < mtd->size; off += blocksize) {
133 +               memset(buf, 0xe5, sizeof(buf));
134 +
135 +               /*
136 +                * Read into buffer
137 +                */
138 +               if (mtd->read(mtd, off, sizeof(buf), &len, buf) ||
139 +                   len != sizeof(buf))
140 +                       continue;
141 +
142 +               if (le32_to_cpu(trx->magic) == EDIMAX_PS_HEADER_MAGIC) {
143 +                       if (mtd->read(mtd, off + EDIMAX_PS_HEADER_LEN,
144 +                           sizeof(buf), &len, buf) || len != sizeof(buf)) {
145 +                               continue;
146 +                       } else {
147 +                               pr_notice("Found edimax header\n");
148 +                       }
149 +               }
150 +
151 +               /* found a TRX header */
152 +               if (le32_to_cpu(trx->magic) == TRX_MAGIC)
153 +                       goto found;
154 +       }
155 +
156 +       pr_notice("%s: Couldn't find bootloader size\n", mtd->name);
157 +       return -1;
158 +
159 + found:
160 +       pr_notice("bootloader size: %d\n", off);
161 +       return off;
162 +
163 +}
164 +
165 +/*
166 + * Copied from mtdblock.c
167 + *
168 + * Cache stuff...
169 + *
170 + * Since typical flash erasable sectors are much larger than what Linux's
171 + * buffer cache can handle, we must implement read-modify-write on flash
172 + * sectors for each block write requests.  To avoid over-erasing flash sectors
173 + * and to speed things up, we locally cache a whole flash sector while it is
174 + * being written to until a different sector is required.
175 + */
176 +
177 +static void erase_callback(struct erase_info *done)
178 +{
179 +       wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;
180 +       wake_up(wait_q);
181 +}
182 +
183 +static int erase_write(struct mtd_info *mtd, unsigned long pos,
184 +                       int len, const char *buf)
185 +{
186 +       struct erase_info erase;
187 +       DECLARE_WAITQUEUE(wait, current);
188 +       wait_queue_head_t wait_q;
189 +       size_t retlen;
190 +       int ret;
191 +
192 +       /*
193 +        * First, let's erase the flash block.
194 +        */
195 +
196 +       init_waitqueue_head(&wait_q);
197 +       erase.mtd = mtd;
198 +       erase.callback = erase_callback;
199 +       erase.addr = pos;
200 +       erase.len = len;
201 +       erase.priv = (u_long)&wait_q;
202 +
203 +       set_current_state(TASK_INTERRUPTIBLE);
204 +       add_wait_queue(&wait_q, &wait);
205 +
206 +       ret = mtd->erase(mtd, &erase);
207 +       if (ret) {
208 +               set_current_state(TASK_RUNNING);
209 +               remove_wait_queue(&wait_q, &wait);
210 +               pr_warn("erase of region [0x%lx, 0x%x] on \"%s\" failed\n",
211 +                       pos, len, mtd->name);
212 +               return ret;
213 +       }
214 +
215 +       schedule();  /* Wait for erase to finish. */
216 +       remove_wait_queue(&wait_q, &wait);
217 +
218 +       /*
219 +        * Next, write data to flash.
220 +        */
221 +
222 +       ret = mtd->write(mtd, pos, len, &retlen, buf);
223 +       if (ret)
224 +               return ret;
225 +       if (retlen != len)
226 +               return -EIO;
227 +       return 0;
228 +}
229 +
230 +
231 +static int
232 +find_dual_image_off(struct mtd_info *mtd)
233 +{
234 +       struct trx_header trx;
235 +       int off, blocksize;
236 +       size_t len;
237 +
238 +       blocksize = mtd->erasesize;
239 +       if (blocksize < 0x10000)
240 +               blocksize = 0x10000;
241 +
242 +       for (off = (128*1024); off < mtd->size; off += blocksize) {
243 +               memset(&trx, 0xe5, sizeof(trx));
244 +               /*
245 +               * Read into buffer
246 +               */
247 +               if (mtd->read(mtd, off, sizeof(trx), &len, (char *) &trx) ||
248 +                   len != sizeof(trx))
249 +                       continue;
250 +               /* found last TRX header */
251 +               if (le32_to_cpu(trx.magic) == TRX_MAGIC) {
252 +                       if (le32_to_cpu(trx.flag_version >> 16) == 2) {
253 +                               pr_notice("dual image TRX header found\n");
254 +                               return mtd->size / 2;
255 +                       } else {
256 +                               return 0;
257 +                       }
258 +               }
259 +       }
260 +       return 0;
261 +}
262 +
263 +
264 +static int
265 +find_root(struct mtd_info *mtd, struct mtd_partition *part)
266 +{
267 +       struct trx_header trx, *trx2;
268 +       unsigned char buf[512], *block;
269 +       int off, blocksize, trxoff = 0;
270 +       u32 i, crc = ~0;
271 +       size_t len;
272 +       bool edimax = false;
273 +
274 +       blocksize = mtd->erasesize;
275 +       if (blocksize < 0x10000)
276 +               blocksize = 0x10000;
277 +
278 +       for (off = (128*1024); off < mtd->size; off += blocksize) {
279 +               memset(&trx, 0xe5, sizeof(trx));
280 +
281 +               /*
282 +                * Read into buffer
283 +                */
284 +               if (mtd->read(mtd, off, sizeof(trx), &len, (char *) &trx) ||
285 +                   len != sizeof(trx))
286 +                       continue;
287 +
288 +               /* found an edimax header */
289 +               if (le32_to_cpu(trx.magic) == EDIMAX_PS_HEADER_MAGIC) {
290 +                       /* read the correct trx header */
291 +                       if (mtd->read(mtd, off + EDIMAX_PS_HEADER_LEN,
292 +                           sizeof(trx), &len, (char *) &trx) ||
293 +                           len != sizeof(trx)) {
294 +                               continue;
295 +                       } else {
296 +                               pr_notice("Found an edimax ps header\n");
297 +                               edimax = true;
298 +                       }
299 +               }
300 +
301 +               /* found a TRX header */
302 +               if (le32_to_cpu(trx.magic) == TRX_MAGIC) {
303 +                       part->offset = le32_to_cpu(trx.offsets[2]) ? :
304 +                               le32_to_cpu(trx.offsets[1]);
305 +                       part->size = le32_to_cpu(trx.len);
306 +
307 +                       part->size -= part->offset;
308 +                       part->offset += off;
309 +                       if (edimax) {
310 +                               off += EDIMAX_PS_HEADER_LEN;
311 +                               trxoff = EDIMAX_PS_HEADER_LEN;
312 +                       }
313 +
314 +                       goto found;
315 +               }
316 +       }
317 +
318 +       pr_warn("%s: Couldn't find root filesystem\n",
319 +              mtd->name);
320 +       return -1;
321 +
322 + found:
323 +       pr_notice("TRX offset : %x\n", trxoff);
324 +       if (part->size == 0)
325 +               return 0;
326 +
327 +       if (mtd->read(mtd, part->offset, sizeof(buf), &len, buf) || len != sizeof(buf))
328 +               return 0;
329 +
330 +       /* Move the fs outside of the trx */
331 +       part->size = 0;
332 +
333 +       if (trx.len != part->offset + part->size - off) {
334 +               /* Update the trx offsets and length */
335 +               trx.len = part->offset + part->size - off;
336 +
337 +               /* Update the trx crc32 */
338 +               for (i = (u32) &(((struct trx_header *)NULL)->flag_version); i <= trx.len; i += sizeof(buf)) {
339 +                       if (mtd->read(mtd, off + i, sizeof(buf), &len, buf) || len != sizeof(buf))
340 +                               return 0;
341 +                       crc = crc32_le(crc, buf, min(sizeof(buf), trx.len - i));
342 +               }
343 +               trx.crc32 = crc;
344 +
345 +               /* read first eraseblock from the trx */
346 +               block = kmalloc(mtd->erasesize, GFP_KERNEL);
347 +               trx2 = (struct trx_header *) block;
348 +               if (mtd->read(mtd, off - trxoff, mtd->erasesize, &len, block) || len != mtd->erasesize) {
349 +                       pr_err("Error accessing the first trx eraseblock\n");
350 +                       return 0;
351 +               }
352 +
353 +               pr_notice("Updating TRX offsets and length:\n");
354 +               pr_notice("old trx = [0x%08x, 0x%08x, 0x%08x], len=0x%08x crc32=0x%08x\n", trx2->offsets[0], trx2->offsets[1], trx2->offsets[2], trx2->len, trx2->crc32);
355 +               pr_notice("new trx = [0x%08x, 0x%08x, 0x%08x], len=0x%08x crc32=0x%08x\n",   trx.offsets[0],   trx.offsets[1],   trx.offsets[2],   trx.len, trx.crc32);
356 +
357 +               /* Write updated trx header to the flash */
358 +               memcpy(block + trxoff, &trx, sizeof(trx));
359 +               if (mtd->unlock)
360 +                       mtd->unlock(mtd, off - trxoff, mtd->erasesize);
361 +               erase_write(mtd, off - trxoff, mtd->erasesize, block);
362 +               if (mtd->sync)
363 +                       mtd->sync(mtd);
364 +               kfree(block);
365 +               pr_notice("Done\n");
366 +       }
367 +
368 +       return part->size;
369 +}
370 +
371 +static int get_router(void)
372 +{
373 +       char buf[20];
374 +       u32 boardnum = 0;
375 +       u16 boardtype = 0;
376 +       u16 boardrev = 0;
377 +       u32 boardflags = 0;
378 +       u16 sdram_init = 0;
379 +       u16 cardbus = 0;
380 +       u16 strev = 0;
381 +
382 +       if (nvram_getenv("boardnum", buf, sizeof(buf)) >= 0)
383 +               boardnum = simple_strtoul(buf, NULL, 0);
384 +       if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0)
385 +               boardtype = simple_strtoul(buf, NULL, 0);
386 +       if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
387 +               boardrev = simple_strtoul(buf, NULL, 0);
388 +       if (nvram_getenv("boardflags", buf, sizeof(buf)) >= 0)
389 +               boardflags = simple_strtoul(buf, NULL, 0);
390 +       if (nvram_getenv("sdram_init", buf, sizeof(buf)) >= 0)
391 +               sdram_init = simple_strtoul(buf, NULL, 0);
392 +       if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
393 +               cardbus = simple_strtoul(buf, NULL, 0);
394 +       if (nvram_getenv("st_rev", buf, sizeof(buf)) >= 0)
395 +               strev = simple_strtoul(buf, NULL, 0);
396 +
397 +       if ((boardnum == 8 || boardnum == 01)
398 +         && boardtype == 0x0472 && cardbus == 1) {
399 +               /* Netgear WNR834B, Netgear WNR834Bv2 */
400 +               return ROUTER_NETGEAR_WNR834B;
401 +       }
402 +
403 +       if (boardnum == 01 && boardtype == 0x0472 && boardrev == 0x23) {
404 +               /* Netgear WNDR-3300 */
405 +               return ROUTER_NETGEAR_WNDR3300;
406 +       }
407 +
408 +       if ((boardnum == 83258 || boardnum == 01)
409 +         && boardtype == 0x048e
410 +         && (boardrev == 0x11 || boardrev == 0x10)
411 +         && boardflags == 0x750
412 +         && sdram_init == 0x000A) {
413 +               /* Netgear WGR614v8/L/WW 16MB ram, cfe v1.3 or v1.5 */
414 +               return ROUTER_NETGEAR_WGR614L;
415 +       }
416 +
417 +       if ((boardnum == 1 || boardnum == 3500)
418 +         && boardtype == 0x04CF
419 +         && (boardrev == 0x1213 || boardrev == 02)) {
420 +               /* Netgear WNR3500v2/U/L */
421 +               return ROUTER_NETGEAR_WNR3500L;
422 +       }
423 +
424 +       if (boardnum == 1 && boardtype == 0xb4cf && boardrev == 0x1100) {
425 +               /* Netgear WNDR3400 */
426 +               return ROUTER_NETGEAR_WNDR3400;
427 +       }
428 +
429 +       if (boardtype == 0x042f
430 +         && boardrev == 0x10
431 +         && boardflags == 0
432 +         && strev == 0x11) {
433 +               /* Simpletech Simpleshare */
434 +               return ROUTER_SIMPLETECH_SIMPLESHARE;
435 +       }
436 +
437 +       return 0;
438 +}
439 +
440 +static int parse_bcm47xx_partitions(struct mtd_info *mtd,
441 +                                   struct mtd_partition **pparts,
442 +                                   struct mtd_part_parser_data *data)
443 +{
444 +       int cfe_size;
445 +       int dual_image_offset = 0;
446 +       /* e.g Netgear 0x003e0000-0x003f0000 : "board_data", we exclude this
447 +        * part from our mapping to prevent overwriting len/checksum on e.g.
448 +        * Netgear WGR614v8/L/WW
449 +        */
450 +       int custom_data_size = 0;
451 +       struct mtd_partition *bcm47xx_parts;
452 +
453 +       cfe_size = find_cfe_size(mtd);
454 +       if (cfe_size < 0)
455 +               return 0;
456 +
457 +       bcm47xx_parts = kzalloc(sizeof(struct mtd_partition) * 6, GFP_KERNEL);
458 +
459 +       bcm47xx_parts[0].name = "cfe";
460 +       bcm47xx_parts[1].name = "linux";
461 +       bcm47xx_parts[2].name = "rootfs";
462 +       bcm47xx_parts[3].name = "nvram";
463 +
464 +       /* boot loader */
465 +       bcm47xx_parts[0].mask_flags = MTD_WRITEABLE;
466 +       bcm47xx_parts[0].offset = 0;
467 +       bcm47xx_parts[0].size   = cfe_size;
468 +
469 +       /* nvram */
470 +       if (cfe_size != 384 * 1024) {
471 +
472 +               switch (get_router()) {
473 +               case ROUTER_NETGEAR_WGR614L:
474 +               case ROUTER_NETGEAR_WNR834B:
475 +               case ROUTER_NETGEAR_WNDR3300:
476 +               case ROUTER_NETGEAR_WNR3500L:
477 +               case ROUTER_NETGEAR_WNDR3400:
478 +                       /* Netgear: checksum is @ 0x003AFFF8 for 4M flash or checksum
479 +                        * is @ 0x007AFFF8 for 8M flash
480 +                        */
481 +                       custom_data_size = mtd->erasesize;
482 +
483 +                       bcm47xx_parts[3].offset = mtd->size - roundup(NVRAM_SPACE, mtd->erasesize);
484 +                       bcm47xx_parts[3].size   = roundup(NVRAM_SPACE, mtd->erasesize);
485 +
486 +                       /* Place CFE board_data into a partition */
487 +                       bcm47xx_parts[4].name = "board_data";
488 +                       bcm47xx_parts[4].offset = bcm47xx_parts[3].offset - custom_data_size;
489 +                       bcm47xx_parts[4].size   = custom_data_size;
490 +                       break;
491 +
492 +               case ROUTER_SIMPLETECH_SIMPLESHARE:
493 +                       /* Fixup Simpletech Simple share nvram  */
494 +
495 +                       pr_notice("Setting up simpletech nvram\n");
496 +                       custom_data_size = mtd->erasesize;
497 +
498 +                       bcm47xx_parts[3].offset = mtd->size - roundup(NVRAM_SPACE, mtd->erasesize) * 2;
499 +                       bcm47xx_parts[3].size   = roundup(NVRAM_SPACE, mtd->erasesize);
500 +
501 +                       /* Place backup nvram into a partition */
502 +                       bcm47xx_parts[4].name = "nvram_copy";
503 +                       bcm47xx_parts[4].offset = mtd->size - roundup(NVRAM_SPACE, mtd->erasesize);
504 +                       bcm47xx_parts[4].size   = roundup(NVRAM_SPACE, mtd->erasesize);
505 +                       break;
506 +
507 +               default:
508 +                       bcm47xx_parts[3].offset = mtd->size - roundup(NVRAM_SPACE, mtd->erasesize);
509 +                       bcm47xx_parts[3].size   = roundup(NVRAM_SPACE, mtd->erasesize);
510 +               }
511 +
512 +       } else {
513 +               /* nvram (old 128kb config partition on netgear wgt634u) */
514 +               bcm47xx_parts[3].offset = bcm47xx_parts[0].size;
515 +               bcm47xx_parts[3].size   = roundup(NVRAM_SPACE, mtd->erasesize);
516 +       }
517 +
518 +       /* dual image offset*/
519 +       pr_notice("Looking for dual image\n");
520 +       dual_image_offset = find_dual_image_off(mtd);
521 +       /* linux (kernel and rootfs) */
522 +       if (cfe_size != 384 * 1024) {
523 +               if (get_router() == ROUTER_SIMPLETECH_SIMPLESHARE) {
524 +                       bcm47xx_parts[1].offset = bcm47xx_parts[0].size;
525 +                       bcm47xx_parts[1].size   = bcm47xx_parts[4].offset - dual_image_offset -
526 +                               bcm47xx_parts[1].offset - custom_data_size;
527 +               } else {
528 +                       bcm47xx_parts[1].offset = bcm47xx_parts[0].size;
529 +                       bcm47xx_parts[1].size   = bcm47xx_parts[3].offset - dual_image_offset -
530 +                               bcm47xx_parts[1].offset - custom_data_size;
531 +               }
532 +       } else {
533 +               /* do not count the elf loader, which is on one block */
534 +               bcm47xx_parts[1].offset = bcm47xx_parts[0].size +
535 +                       bcm47xx_parts[3].size + mtd->erasesize;
536 +               bcm47xx_parts[1].size   = mtd->size -
537 +                       bcm47xx_parts[0].size -
538 +                       (2*bcm47xx_parts[3].size) -
539 +                       mtd->erasesize - custom_data_size;
540 +       }
541 +
542 +       /* find and size rootfs */
543 +       find_root(mtd, &bcm47xx_parts[2]);
544 +       bcm47xx_parts[2].size = mtd->size - dual_image_offset -
545 +                               bcm47xx_parts[2].offset -
546 +                               bcm47xx_parts[3].size - custom_data_size;
547 +       *pparts = bcm47xx_parts;
548 +       return bcm47xx_parts[4].name == NULL ? 4 : 5;
549 +}
550 +
551 +static struct mtd_part_parser bcm47xx_parser = {
552 +       .owner = THIS_MODULE,
553 +       .parse_fn = parse_bcm47xx_partitions,
554 +       .name = "bcm47xx",
555 +};
556 +
557 +static int __init bcm47xx_parser_init(void)
558 +{
559 +       return register_mtd_parser(&bcm47xx_parser);
560 +}
561 +
562 +static void __exit bcm47xx_parser_exit(void)
563 +{
564 +       deregister_mtd_parser(&bcm47xx_parser);
565 +}
566 +
567 +module_init(bcm47xx_parser_init);
568 +module_exit(bcm47xx_parser_exit);
569 +
570 +MODULE_LICENSE("GPL");
571 +MODULE_DESCRIPTION("Parsing code for flash partitions on bcm47xx SoCs");