1 diff -Nur linux-2.4.32/drivers/mtd/maps/bcm947xx-flash.c linux-2.4.32-flash/drivers/mtd/maps/bcm947xx-flash.c
2 --- linux-2.4.32/drivers/mtd/maps/bcm947xx-flash.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.4.32-flash/drivers/mtd/maps/bcm947xx-flash.c 2005-12-19 01:29:52.464670750 +0100
6 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
7 + * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
9 + * original functions for finding root filesystem from Mike Baker
11 + * This program is free software; you can redistribute it and/or modify it
12 + * under the terms of the GNU General Public License as published by the
13 + * Free Software Foundation; either version 2 of the License, or (at your
14 + * option) any later version.
16 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 + * You should have received a copy of the GNU General Public License along
28 + * with this program; if not, write to the Free Software Foundation, Inc.,
29 + * 675 Mass Ave, Cambridge, MA 02139, USA.
32 + * Copyright 2004, Broadcom Corporation
33 + * All Rights Reserved.
35 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
36 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
37 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
38 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
40 + * Flash mapping for BCM947XX boards
44 +#include <linux/module.h>
45 +#include <linux/types.h>
46 +#include <linux/kernel.h>
48 +#include <linux/mtd/mtd.h>
49 +#include <linux/mtd/map.h>
50 +#ifdef CONFIG_MTD_PARTITIONS
51 +#include <linux/mtd/partitions.h>
53 +#include <linux/config.h>
57 +#define WINDOW_ADDR 0x1c000000
58 +#define WINDOW_SIZE (0x400000*2)
61 +static struct mtd_info *bcm947xx_mtd;
63 +__u8 bcm947xx_map_read8(struct map_info *map, unsigned long ofs)
65 + if (map->map_priv_2 == 1)
66 + return __raw_readb(map->map_priv_1 + ofs);
68 + u16 val = __raw_readw(map->map_priv_1 + (ofs & ~1));
70 + return ((val >> 8) & 0xff);
72 + return (val & 0xff);
75 +__u16 bcm947xx_map_read16(struct map_info *map, unsigned long ofs)
77 + return __raw_readw(map->map_priv_1 + ofs);
80 +__u32 bcm947xx_map_read32(struct map_info *map, unsigned long ofs)
82 + return __raw_readl(map->map_priv_1 + ofs);
85 +void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
88 + memcpy_fromio(to, map->map_priv_1 + from, len);
91 + u16 *dest = (u16 *) to;
92 + u16 *src = (u16 *) (map->map_priv_1 + from);
93 + for (i = 0; i < (len / 2); i++) {
97 + *((u8 *)dest+len-1) = src[i] & 0xff;
101 +void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
103 + __raw_writeb(d, map->map_priv_1 + adr);
107 +void bcm947xx_map_write16(struct map_info *map, __u16 d, unsigned long adr)
109 + __raw_writew(d, map->map_priv_1 + adr);
113 +void bcm947xx_map_write32(struct map_info *map, __u32 d, unsigned long adr)
115 + __raw_writel(d, map->map_priv_1 + adr);
119 +void bcm947xx_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
121 + memcpy_toio(map->map_priv_1 + to, from, len);
124 +struct map_info bcm947xx_map = {
125 + name: "Physically mapped flash",
127 + buswidth: BUSWIDTH,
128 + read8: bcm947xx_map_read8,
129 + read16: bcm947xx_map_read16,
130 + read32: bcm947xx_map_read32,
131 + copy_from: bcm947xx_map_copy_from,
132 + write8: bcm947xx_map_write8,
133 + write16: bcm947xx_map_write16,
134 + write32: bcm947xx_map_write32,
135 + copy_to: bcm947xx_map_copy_to
138 +#ifdef CONFIG_MTD_PARTITIONS
140 +static struct mtd_partition bcm947xx_parts[] = {
141 + { name: "cfe", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
142 + { name: "linux", offset: 0, size: 0, },
143 + { name: "rootfs", offset: 0, size: 0, },
144 + { name: "nvram", offset: 0, size: 0, },
145 + { name: "OpenWrt", offset: 0, size: 0, },
150 +find_cfe_size(struct mtd_info *mtd, size_t size)
152 + struct trx_header *trx;
153 + unsigned char buf[512];
158 + trx = (struct trx_header *) buf;
162 + for (off = (256*1024); off < size; off += mtd->erasesize) {
163 + memset(buf, 0xe5, sizeof(buf));
168 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
169 + len != sizeof(buf))
172 + /* found a TRX header */
173 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
176 + cfe_size_flag += 1;
180 + "%s: Couldn't find bootloader size\n",
185 + printk(KERN_NOTICE "bootloader size flag: %d\n", cfe_size_flag);
186 + return cfe_size_flag;
191 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
193 + struct trx_header *trx;
194 + unsigned char buf[512];
198 + trx = (struct trx_header *) buf;
200 + for (off = (256*1024); off < size; off += mtd->erasesize) {
201 + memset(buf, 0xe5, sizeof(buf));
206 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
207 + len != sizeof(buf))
210 + /* found a TRX header */
211 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
212 + part->offset = le32_to_cpu(trx->offsets[2]) ? :
213 + le32_to_cpu(trx->offsets[1]);
214 + part->size = le32_to_cpu(trx->len);
216 + part->size -= part->offset;
217 + part->offset += off;
224 + "%s: Couldn't find root filesystem\n",
232 +struct mtd_partition * __init
233 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
238 + /* if cfe_size_flag=0, cfe size is 256 kb, else 384 kb */
239 + cfe_size_flag = find_cfe_size(mtd,size);
242 + bcm947xx_parts[0].offset = 0;
243 + if (cfe_size_flag == 0) {
244 + bcm947xx_parts[0].size = 1024*256;
246 + /* netgear wgt634u has 384 kb bootloader */
247 + bcm947xx_parts[0].size = 1024*384;
251 + if (cfe_size_flag == 0) {
252 + bcm947xx_parts[3].offset = size - mtd->erasesize;
254 + /* nvram (old 128kb config partition on netgear wgt634u) */
255 + bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
257 + bcm947xx_parts[3].size = mtd->erasesize;
259 + /* linux (kernel and rootfs) */
260 + if (cfe_size_flag == 0) {
261 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
262 + bcm947xx_parts[1].size = bcm947xx_parts[3].offset -
263 + bcm947xx_parts[1].offset;
265 + /* do not count the elf loader, which is on one block */
266 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size +
267 + bcm947xx_parts[3].size + mtd->erasesize;
268 + bcm947xx_parts[1].size = size -
269 + bcm947xx_parts[0].size -
270 + (2*bcm947xx_parts[3].size) -
274 + /* find and size rootfs */
275 + if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
276 + /* entirely jffs2 */
277 + bcm947xx_parts[4].name = NULL;
278 + bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset -
279 + bcm947xx_parts[3].size;
282 + /* calculate leftover flash, and assign it to the jffs2 partition */
283 + if (cfe_size_flag == 0) {
284 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
285 + bcm947xx_parts[2].size;
286 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
287 + bcm947xx_parts[4].offset += mtd->erasesize -
288 + (bcm947xx_parts[4].offset % mtd->erasesize);
290 + bcm947xx_parts[4].size = bcm947xx_parts[3].offset -
291 + bcm947xx_parts[4].offset;
293 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
294 + bcm947xx_parts[2].size;
295 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
296 + bcm947xx_parts[4].offset += mtd->erasesize -
297 + (bcm947xx_parts[4].offset % mtd->erasesize);
299 + bcm947xx_parts[4].size = size - bcm947xx_parts[3].size -
300 + bcm947xx_parts[4].offset;
304 + return bcm947xx_parts;
310 +mod_init_t init_bcm947xx_map(void)
314 +#ifdef CONFIG_MTD_PARTITIONS
315 + struct mtd_partition *parts;
319 + bcm947xx_map.map_priv_1 = (unsigned long) ioremap(WINDOW_ADDR, WINDOW_SIZE);
321 + if (!bcm947xx_map.map_priv_1) {
322 + printk(KERN_ERR "Failed to ioremap\n");
326 + if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
327 + printk(KERN_ERR "pflash: cfi_probe failed\n");
328 + iounmap((void *)bcm947xx_map.map_priv_1);
332 + bcm947xx_mtd->module = THIS_MODULE;
334 + size = bcm947xx_mtd->size;
336 + printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", size, WINDOW_ADDR);
338 +#ifdef CONFIG_MTD_PARTITIONS
339 + parts = init_mtd_partitions(bcm947xx_mtd, size);
340 + for (i = 0; parts[i].name; i++);
341 + ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
343 + printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
352 + map_destroy(bcm947xx_mtd);
353 + if (bcm947xx_map.map_priv_1)
354 + iounmap((void *) bcm947xx_map.map_priv_1);
355 + bcm947xx_map.map_priv_1 = 0;
359 +mod_exit_t cleanup_bcm947xx_map(void)
361 +#ifdef CONFIG_MTD_PARTITIONS
362 + del_mtd_partitions(bcm947xx_mtd);
364 + map_destroy(bcm947xx_mtd);
365 + iounmap((void *) bcm947xx_map.map_priv_1);
366 + bcm947xx_map.map_priv_1 = 0;
369 +module_init(init_bcm947xx_map);
370 +module_exit(cleanup_bcm947xx_map);
371 diff -Nur linux-2.4.32/drivers/mtd/maps/Config.in linux-2.4.32-flash/drivers/mtd/maps/Config.in
372 --- linux-2.4.32/drivers/mtd/maps/Config.in 2003-06-13 16:51:34.000000000 +0200
373 +++ linux-2.4.32-flash/drivers/mtd/maps/Config.in 2005-12-18 15:53:52.003277250 +0100
377 if [ "$CONFIG_MIPS" = "y" ]; then
378 + dep_tristate ' CFI Flash device mapped on Broadcom BCM947XX boards' CONFIG_MTD_BCM947XX $CONFIG_MTD_CFI
379 dep_tristate ' Pb1000 MTD support' CONFIG_MTD_PB1000 $CONFIG_MIPS_PB1000
380 dep_tristate ' Pb1500 MTD support' CONFIG_MTD_PB1500 $CONFIG_MIPS_PB1500
381 dep_tristate ' Pb1100 MTD support' CONFIG_MTD_PB1100 $CONFIG_MIPS_PB1100
382 diff -Nur linux-2.4.32/drivers/mtd/maps/Makefile linux-2.4.32-flash/drivers/mtd/maps/Makefile
383 --- linux-2.4.32/drivers/mtd/maps/Makefile 2003-06-13 16:51:34.000000000 +0200
384 +++ linux-2.4.32-flash/drivers/mtd/maps/Makefile 2005-12-18 15:54:39.022215750 +0100
387 # $Id: Makefile,v 1.37 2003/01/24 14:26:38 dwmw2 Exp $
389 +EXTRA_CFLAGS := -I$(TOPDIR)/arch/mips/bcm947xx/include
391 BELOW25 := $(shell echo $(PATCHLEVEL) | sed s/[1234]/y/)
398 +obj-$(CONFIG_MTD_BCM947XX) += bcm947xx-flash.o
399 obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
400 obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
401 obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o