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