source: src/linux/brcm/linux.v24_2/drivers/mtd/maps/bcm947xx-flash.c @ 12146

Last change on this file since 12146 was 12146, checked in by BrainSlayer, 4 years ago

Math error

File size: 17.7 KB
Line 
1/*
2 *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
3 *  Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
4 *  Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
5 *
6 *  original functions for finding root filesystem from Mike Baker
7 *
8 *  This program is free software; you can redistribute  it and/or modify it
9 *  under  the terms of  the GNU General  Public License as published by the
10 *  Free Software Foundation;  either version 2 of the  License, or (at your
11 *  option) any later version.
12 *
13 *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
14 *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
15 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
16 *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
17 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
19 *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
21 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 *  You should have received a copy of the  GNU General Public License along
25 *  with this program; if not, write  to the Free Software Foundation, Inc.,
26 *  675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 *
29 * Copyright 2004, Broadcom Corporation
30 * All Rights Reserved.
31 *
32 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
33 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
34 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
35 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
36 *
37 * Flash mapping for BCM947XX boards
38 *
39 */
40
41#include <linux/module.h>
42#include <linux/types.h>
43#include <linux/kernel.h>
44#include <linux/wait.h>
45#include <linux/mtd/mtd.h>
46#include <linux/mtd/map.h>
47#ifdef CONFIG_MTD_PARTITIONS
48#include <linux/mtd/partitions.h>
49#endif
50#include <linux/config.h>
51#include <linux/squashfs_fs.h>
52#include <linux/jffs2.h>
53#include <linux/crc32.h>
54#include <asm/io.h>
55
56#include <typedefs.h>
57#include <osl.h>
58#include <bcmnvram.h>
59#include <bcmutils.h>
60#include <sbconfig.h>
61#include <sbchipc.h>
62#include <sbutils.h>
63#include <trxhdr.h>
64
65/* Global SB handle */
66extern void *bcm947xx_sbh;
67extern spinlock_t bcm947xx_sbh_lock;
68
69/* Convenience */
70#define sbh bcm947xx_sbh
71#define sbh_lock bcm947xx_sbh_lock
72
73#define WINDOW_ADDR 0x1fc00000
74#define WINDOW_SIZE 0x400000
75#define BUSWIDTH 2
76
77static struct mtd_info *bcm947xx_mtd;
78
79__u8 bcm947xx_map_read8(struct map_info *map, unsigned long ofs)
80{
81        if (map->map_priv_2 == 1)
82                return __raw_readb(map->map_priv_1 + ofs);
83
84        u16 val = __raw_readw(map->map_priv_1 + (ofs & ~1));
85        if (ofs & 1)
86                return ((val >> 8) & 0xff);
87        else
88                return (val & 0xff);
89}
90
91__u16 bcm947xx_map_read16(struct map_info *map, unsigned long ofs)
92{
93        return __raw_readw(map->map_priv_1 + ofs);
94}
95
96__u32 bcm947xx_map_read32(struct map_info *map, unsigned long ofs)
97{
98        return __raw_readl(map->map_priv_1 + ofs);
99}
100
101void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
102{
103        if (len==1) {
104                memcpy_fromio(to, map->map_priv_1 + from, len);
105        } else {
106                int i;
107                u16 *dest = (u16 *) to;
108                u16 *src  = (u16 *) (map->map_priv_1 + from);
109                for (i = 0; i < (len / 2); i++) {
110                        dest[i] = src[i];
111                }
112                if (len & 1)
113                        *((u8 *)dest+len-1) = src[i] & 0xff;
114        }
115}
116
117void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
118{
119        __raw_writeb(d, map->map_priv_1 + adr);
120        mb();
121}
122
123void bcm947xx_map_write16(struct map_info *map, __u16 d, unsigned long adr)
124{
125        __raw_writew(d, map->map_priv_1 + adr);
126        mb();
127}
128
129void bcm947xx_map_write32(struct map_info *map, __u32 d, unsigned long adr)
130{
131        __raw_writel(d, map->map_priv_1 + adr);
132        mb();
133}
134
135void bcm947xx_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
136{
137        memcpy_toio(map->map_priv_1 + to, from, len);
138}
139
140struct map_info bcm947xx_map = {
141        name: "Physically mapped flash",
142        size: WINDOW_SIZE,
143        buswidth: BUSWIDTH,
144        read8: bcm947xx_map_read8,
145        read16: bcm947xx_map_read16,
146        read32: bcm947xx_map_read32,
147        copy_from: bcm947xx_map_copy_from,
148        write8: bcm947xx_map_write8,
149        write16: bcm947xx_map_write16,
150        write32: bcm947xx_map_write32,
151        copy_to: bcm947xx_map_copy_to
152};
153
154#ifdef CONFIG_MTD_PARTITIONS
155
156static struct mtd_partition bcm947xx_parts[] = {
157        { name: "cfe",  offset: 0, size: 0, },
158        { name: "linux", offset: 0, size: 0, },
159        { name: "rootfs", offset: 0, size: 0, },
160        { name: "nvram", offset: 0, size: 0, },
161        { name: "ddwrt", offset: 0, size: 0, },
162        { name: NULL, },
163};
164
165static int __init
166find_cfe_size(struct mtd_info *mtd, size_t size)
167{
168        struct trx_header *trx;
169        unsigned char buf[512];
170        int off;
171        size_t len;
172        int blocksize;
173
174        trx = (struct trx_header *) buf;
175
176        blocksize = mtd->erasesize;
177        if (blocksize < 0x10000)
178                blocksize = 0x10000;
179//      printk(KERN_EMERG "blocksize is %d\n",blocksize);
180        for (off = 0; off < size; off += 64*1024) {
181                memset(buf, 0xe5, sizeof(buf));
182//              printk(KERN_EMERG "scan at 0x%08x\n",off);
183                /*
184                 * Read into buffer
185                 */
186                if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
187                    len != sizeof(buf))
188                        continue;
189
190                /* found a TRX header */
191                if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
192                        goto found;
193                }
194        }
195
196        printk(KERN_EMERG
197               "%s: Couldn't find bootloader size\n",
198               mtd->name);
199        return -1;
200
201 found:
202        printk(KERN_EMERG  "bootloader size: %d\n", off);
203        return off;
204
205}
206
207/*
208 * Copied from mtdblock.c
209 *
210 * Cache stuff...
211 *
212 * Since typical flash erasable sectors are much larger than what Linux's
213 * buffer cache can handle, we must implement read-modify-write on flash
214 * sectors for each block write requests.  To avoid over-erasing flash sectors
215 * and to speed things up, we locally cache a whole flash sector while it is
216 * being written to until a different sector is required.
217 */
218
219static void erase_callback(struct erase_info *done)
220{
221        wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;
222        wake_up(wait_q);
223}
224
225static int erase_write (struct mtd_info *mtd, unsigned long pos,
226                        int len, const char *buf)
227{
228        struct erase_info erase;
229        DECLARE_WAITQUEUE(wait, current);
230        wait_queue_head_t wait_q;
231        size_t retlen;
232        int ret;
233
234        /*
235         * First, let's erase the flash block.
236         */
237
238        init_waitqueue_head(&wait_q);
239        erase.mtd = mtd;
240        erase.callback = erase_callback;
241        erase.addr = pos;
242        erase.len = len;
243        erase.priv = (u_long)&wait_q;
244
245        set_current_state(TASK_INTERRUPTIBLE);
246        add_wait_queue(&wait_q, &wait);
247
248        ret = MTD_ERASE(mtd, &erase);
249        if (ret) {
250                set_current_state(TASK_RUNNING);
251                remove_wait_queue(&wait_q, &wait);
252                printk (KERN_WARNING "erase of region [0x%lx, 0x%x] "
253                                     "on \"%s\" failed\n",
254                        pos, len, mtd->name);
255                return ret;
256        }
257
258        schedule();  /* Wait for erase to finish. */
259        remove_wait_queue(&wait_q, &wait);
260
261        /*
262         * Next, writhe data to flash.
263         */
264
265        ret = MTD_WRITE (mtd, pos, len, &retlen, buf);
266        if (ret)
267                return ret;
268        if (retlen != len)
269                return -EIO;
270        return 0;
271}
272
273
274
275
276static int __init
277find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
278{
279        struct trx_header trx, *trx2;
280        unsigned char buf[512], *block;
281        int off, blocksize;
282        u32 i, crc = ~0;
283        size_t len;
284        struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
285
286        blocksize = mtd->erasesize;
287        if (blocksize < 0x10000)
288                blocksize = 0x10000;
289
290        for (off = 0; off < size; off += 64*1024) {
291                memset(&trx, 0xe5, sizeof(trx));
292//              printk(KERN_EMERG "scan root at 0x%08x\n",off);
293
294                /*
295                 * Read into buffer
296                 */
297                if (MTD_READ(mtd, off, sizeof(trx), &len, (char *) &trx) ||
298                    len != sizeof(trx))
299                        continue;
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
310                        goto found;
311                }
312        }
313
314        printk(KERN_EMERG
315               "%s: Couldn't find root filesystem\n",
316               mtd->name);
317        return -1;
318
319 found:
320        if (part->size == 0)
321                return 0;
322       
323        if (MTD_READ(mtd, part->offset, sizeof(buf), &len, buf) || len != sizeof(buf))
324                return 0;
325
326        if (*((__u32 *) buf) == SQUASHFS_MAGIC) {
327                printk(KERN_EMERG  "%s: Filesystem type: squashfs, size=0x%x\n", mtd->name, (u32) sb->bytes_used);
328
329                /* Update the squashfs partition size based on the superblock info */
330                part->size = sb->bytes_used;
331                //part->size = part->size + 1024; /* uncomment for belkin v2000 ! */
332                len = part->offset + part->size;
333                len +=  (mtd->erasesize - 1);
334                len &= ~(mtd->erasesize - 1);
335                part->size = len - part->offset;
336                printk(KERN_EMERG "partition size = %d\n",part->size);
337        } else if (*((__u16 *) buf) == JFFS2_MAGIC_BITMASK) {
338                printk(KERN_EMERG  "%s: Filesystem type: jffs2\n", mtd->name);
339
340                /* Move the squashfs outside of the trx */
341                part->size = 0;
342        } else {
343                printk(KERN_EMERG  "%s: Filesystem type: unknown\n", mtd->name);
344                return 0;
345        }
346
347        if (trx.len != part->offset + part->size - off) {
348                /* Update the trx offsets and length */
349                trx.len = part->offset + part->size - off;
350//              printk(KERN_EMERG "update crc32\n");
351                /* Update the trx crc32 */
352                for (i = (u32) &(((struct trx_header *)NULL)->flag_version); i <= trx.len; i += sizeof(buf)) {
353//                      printk(KERN_EMERG "read from %d\n",off + i);
354                        if (MTD_READ(mtd, off + i, sizeof(buf), &len, buf) || len != sizeof(buf))
355                                return 0;
356                        crc = crc32_le(crc, buf, min(sizeof(buf), trx.len - i));
357                }
358                trx.crc32 = crc;
359
360//                      printk(KERN_EMERG "malloc\n",off + i);
361                /* read first eraseblock from the trx */
362                trx2 = block = vmalloc(mtd->erasesize);
363                if (MTD_READ(mtd, off, mtd->erasesize, &len, block) || len != mtd->erasesize) {
364                        printk(KERN_EMERG "Error accessing the first trx eraseblock\n");
365                        vfree(block);
366                        return 0;
367                }
368               
369                printk(KERN_EMERG "Updating TRX offsets and length:\n");
370                printk(KERN_EMERG "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);
371                printk(KERN_EMERG "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);
372
373                /* Write updated trx header to the flash */
374                memcpy(block, &trx, sizeof(trx));
375                if (mtd->unlock)
376                        mtd->unlock(mtd, off, mtd->erasesize);
377                erase_write(mtd, off, mtd->erasesize, block);
378                if (mtd->sync)
379                        mtd->sync(mtd);
380                vfree(block);
381                printk(KERN_EMERG "Done\n");
382               
383                /* Write fake Netgear checksum to the flash */         
384                uint boardnum = bcm_strtoul( nvram_safe_get( "boardnum" ), NULL, 0 );
385                if ( (boardnum == 83258 || boardnum == 01)  //or 001 or 0x01
386                && (nvram_match("boardtype", "0x048e") || nvram_match("boardtype", "0x48E"))
387                && (nvram_match("boardrev", "0x11") || nvram_match("boardrev", "0x10"))
388                && (nvram_match("boardflags", "0x750") || nvram_match("boardflags", "0x0750"))
389                &&  nvram_match ("sdram_init", "0x000A") ) {
390#define WGR614_CHECKSUM_BLOCK_START    0x003A0000
391#define WGR614_CHECKSUM_OFF            0x003AFFF8
392#define WGR614_FAKE_LEN                0x00000004  //we fake checksum only over 4 bytes (HDR0)
393#define WGR614_FAKE_CHK                0x02C0010E
394                /*
395                 * Read into buffer
396                 */
397                block = vmalloc(mtd->erasesize);
398                if (MTD_READ(mtd, WGR614_CHECKSUM_BLOCK_START, mtd->erasesize, &len, block) ||
399                    len != mtd->erasesize) {
400                        printk(KERN_EMERG "Error accessing the WGR614 checksum eraseblock\n");
401                        vfree(block);
402                        }
403                        else {
404                        char imageInfo[8];
405                        u32 fake_len = le32_to_cpu(WGR614_FAKE_LEN);
406                        u32 fake_chk = le32_to_cpu(WGR614_FAKE_CHK);
407                        memcpy(&imageInfo[0], (char *)&fake_len, 4);
408                        memcpy(&imageInfo[4], (char *)&fake_chk, 4);
409                        char *tmp;     
410                        tmp = block + ((WGR614_CHECKSUM_OFF - WGR614_CHECKSUM_BLOCK_START) % mtd->erasesize);
411                        memcpy( tmp, imageInfo, sizeof( imageInfo ) );
412                        if (mtd->unlock)
413                                mtd->unlock(mtd, WGR614_CHECKSUM_BLOCK_START, mtd->erasesize);
414                        erase_write(mtd, WGR614_CHECKSUM_BLOCK_START, mtd->erasesize, block);
415                        if (mtd->sync)
416                                mtd->sync(mtd);
417                        vfree(block);
418                        printk(KERN_EMERG "Done fixing WGR614 checksum\n");               
419                        }
420                }       
421               
422               
423        }
424       
425        return part->size;
426}
427
428struct mtd_partition * __init
429init_mtd_partitions(struct mtd_info *mtd, size_t size)
430{
431        int cfe_size;
432
433        int board_data_size = 0; // e.g Netgear 0x003e0000-0x003f0000 : "board_data", we exclude this part from our mapping
434        int jffs_exclude_size = 0;  // to prevent overwriting len/checksum on e.g. Netgear WGR614v8/L/WW
435       
436        uint boardnum = bcm_strtoul( nvram_safe_get( "boardnum" ), NULL, 0 );   
437               
438        if ( (boardnum == 8 || boardnum == 01)
439          && nvram_match ("boardtype", "0x0472")
440          && nvram_match ("cardbus", "1") ) {
441                board_data_size = 0x10000;  //Netgear WNR834B, Netgear WNR834Bv2
442        }
443
444        if ( boardnum == 01
445          && nvram_match ("boardtype", "0x0472")
446          && nvram_match ("boardrev", "0x23") ) {
447                board_data_size = 0x10000;  //Netgear WNDR-3300
448        }       
449       
450        if ( (boardnum == 83258 || boardnum == 01)  //or 001 or 0x01
451          && (nvram_match("boardtype", "0x048e") || nvram_match("boardtype", "0x48E"))
452          && (nvram_match("boardrev", "0x11") || nvram_match("boardrev", "0x10"))
453          && (nvram_match("boardflags", "0x750") || nvram_match("boardflags", "0x0750"))
454          &&  nvram_match ("sdram_init", "0x000A") ) {
455                board_data_size = 4 * 0x10000;  //Netgear WGR614v8/L/WW 16MB ram, cfe v1.3 or v1.5
456                jffs_exclude_size = 0x10000;    //checksum is @ 0x003AFFF8
457        }                                                                                                                               
458
459        if ((cfe_size = find_cfe_size(mtd,size)) < 0)
460                return NULL;
461
462        /* boot loader */
463        bcm947xx_parts[0].offset = 0;
464        bcm947xx_parts[0].size   = cfe_size;
465
466        /* nvram */
467        if (cfe_size != 384 * 1024) {
468                bcm947xx_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
469                bcm947xx_parts[3].size   = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
470        } else {
471                /* nvram (old 128kb config partition on netgear wgt634u) */
472                bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
473                bcm947xx_parts[3].size   = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
474        }
475
476        /* linux (kernel and rootfs) */
477        if (cfe_size != 384 * 1024) {
478                bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
479                bcm947xx_parts[1].size   = (bcm947xx_parts[3].offset - bcm947xx_parts[1].offset) - board_data_size;
480        } else {
481                /* do not count the elf loader, which is on one block */
482                bcm947xx_parts[1].offset = bcm947xx_parts[0].size +
483                        bcm947xx_parts[3].size + mtd->erasesize;
484                bcm947xx_parts[1].size   = (((size - bcm947xx_parts[0].size) - (2*bcm947xx_parts[3].size)) - mtd->erasesize) - board_data_size;
485        }
486
487        /* find and size rootfs */
488        if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
489                /* entirely jffs2 */
490                bcm947xx_parts[4].name = NULL;
491                bcm947xx_parts[2].size = (size - bcm947xx_parts[2].offset) - bcm947xx_parts[3].size;
492        } else {
493                /* legacy setup */
494                /* calculate leftover flash, and assign it to the jffs2 partition */
495                if (cfe_size != 384 * 1024) {
496                        bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
497                                bcm947xx_parts[2].size;
498                        if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
499                                bcm947xx_parts[4].offset += mtd->erasesize -
500                                        (bcm947xx_parts[4].offset % mtd->erasesize);
501                        }
502                        bcm947xx_parts[4].size = ((bcm947xx_parts[3].offset - bcm947xx_parts[4].offset) - board_data_size) - jffs_exclude_size;
503                } else {
504                        bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
505                                bcm947xx_parts[2].size;
506                        if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
507                                bcm947xx_parts[4].offset += mtd->erasesize -
508                                        (bcm947xx_parts[4].offset % mtd->erasesize);
509                        }
510                        bcm947xx_parts[4].size = (((size - bcm947xx_parts[3].size) - bcm947xx_parts[4].offset) - board_data_size) - jffs_exclude_size;
511                }
512                /* do not make zero size jffs2 partition  */
513                if (bcm947xx_parts[4].size < mtd->erasesize) {
514                        bcm947xx_parts[4].name = NULL;
515                }
516        }
517
518        return bcm947xx_parts;
519}
520
521#endif
522
523
524mod_init_t init_bcm947xx_map(void)
525{
526        ulong flags;
527        uint coreidx;
528        chipcregs_t *cc;
529        uint32 fltype;
530        uint window_addr = 0, window_size = 0;
531        size_t size;
532        int ret = 0;
533#ifdef CONFIG_MTD_PARTITIONS
534        struct mtd_partition *parts;
535        int i;
536#endif
537
538        spin_lock_irqsave(&sbh_lock, flags);
539        coreidx = sb_coreidx(sbh);
540
541        /* Check strapping option if chipcommon exists */
542        if ((cc = sb_setcore(sbh, SB_CC, 0))) {
543                fltype = readl(&cc->capabilities) & CC_CAP_FLASH_MASK;
544                if (fltype == PFLASH) {
545                        bcm947xx_map.map_priv_2 = 1;
546                        window_addr = 0x1c000000;
547                        bcm947xx_map.size = window_size = 32 * 1024 * 1024;
548                        if ((readl(&cc->flash_config) & CC_CFG_DS) == 0)
549                                bcm947xx_map.buswidth = 1;
550                }
551        } else {
552                fltype = PFLASH;
553                bcm947xx_map.map_priv_2 = 0;
554                window_addr = WINDOW_ADDR;
555                window_size = WINDOW_SIZE;
556        }
557
558        sb_setcoreidx(sbh, coreidx);
559        spin_unlock_irqrestore(&sbh_lock, flags);
560
561        if (fltype != PFLASH) {
562                printk(KERN_ERR "pflash: found no supported devices\n");
563                ret = -ENODEV;
564                goto fail;
565        }
566
567        bcm947xx_map.map_priv_1 = (unsigned long) ioremap(window_addr, window_size);
568
569        if (!bcm947xx_map.map_priv_1) {
570                printk(KERN_ERR "Failed to ioremap\n");
571                return -EIO;
572        }
573
574        if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
575                printk(KERN_ERR "pflash: cfi_probe failed\n");
576                iounmap((void *)bcm947xx_map.map_priv_1);
577                return -ENXIO;
578        }
579
580        bcm947xx_mtd->module = THIS_MODULE;
581
582        size = bcm947xx_mtd->size;
583
584        printk(KERN_EMERG "Flash device: 0x%x at 0x%x\n", size, window_addr);
585
586#ifdef CONFIG_MTD_PARTITIONS
587        parts = init_mtd_partitions(bcm947xx_mtd, size);
588        for (i = 0; parts[i].name; i++);
589        ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
590        if (ret) {
591                printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
592                goto fail;
593        }
594#endif
595
596        return 0;
597
598 fail:
599        if (bcm947xx_mtd)
600                map_destroy(bcm947xx_mtd);
601        if (bcm947xx_map.map_priv_1)
602                iounmap((void *) bcm947xx_map.map_priv_1);
603        bcm947xx_map.map_priv_1 = 0;
604        return ret;
605}
606
607mod_exit_t cleanup_bcm947xx_map(void)
608{
609#ifdef CONFIG_MTD_PARTITIONS
610        del_mtd_partitions(bcm947xx_mtd);
611#endif
612        map_destroy(bcm947xx_mtd);
613        iounmap((void *) bcm947xx_map.map_priv_1);
614        bcm947xx_map.map_priv_1 = 0;
615}
616
617module_init(init_bcm947xx_map);
618module_exit(cleanup_bcm947xx_map);
Note: See TracBrowser for help on using the repository browser.