1 diff -Nur linux-2.6.12.5/drivers/mtd/maps/Kconfig linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig
2 --- linux-2.6.12.5/drivers/mtd/maps/Kconfig 2005-08-15 02:20:18.000000000 +0200
3 +++ linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig 2005-09-16 22:27:36.513533784 +0200
5 Mapping for the Flaga digital module. If you don't have one, ignore
9 + tristate "BCM47xx flash device"
10 + depends on MIPS && MTD_CFI && BCM947XX
12 + Support for the flash chips on the BCM947xx board.
15 tristate "CFI Flash device mapped on IBM 405LP Beech"
16 depends on MTD_CFI && PPC32 && 40x && BEECH
17 diff -Nur linux-2.6.12.5/drivers/mtd/maps/Makefile linux-2.6.12.5-flash/drivers/mtd/maps/Makefile
18 --- linux-2.6.12.5/drivers/mtd/maps/Makefile 2005-08-15 02:20:18.000000000 +0200
19 +++ linux-2.6.12.5-flash/drivers/mtd/maps/Makefile 2005-09-16 22:27:01.110915800 +0200
21 obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
22 obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
23 obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
24 +obj-$(CONFIG_MTD_BCM47XX) += bcm47xx-flash.o
25 obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
26 obj-$(CONFIG_MTD_IPAQ) += ipaq-flash.o
27 obj-$(CONFIG_MTD_SBC_GXX) += sbc_gxx.o
28 diff -Nur linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c linux-2.6.12.5-flash/drivers/mtd/maps/bcm47xx-flash.c
29 --- linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c 1970-01-01 01:00:00.000000000 +0100
30 +++ linux-2.6.12.5-flash/drivers/mtd/maps/bcm47xx-flash.c 2005-09-16 22:26:41.470901536 +0200
33 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
34 + * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
36 + * original functions for finding root filesystem from Mike Baker
38 + * This program is free software; you can redistribute it and/or modify it
39 + * under the terms of the GNU General Public License as published by the
40 + * Free Software Foundation; either version 2 of the License, or (at your
41 + * option) any later version.
43 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
44 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
45 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
46 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
47 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
49 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
50 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
52 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 + * You should have received a copy of the GNU General Public License along
55 + * with this program; if not, write to the Free Software Foundation, Inc.,
56 + * 675 Mass Ave, Cambridge, MA 02139, USA.
58 + * Copyright 2001-2003, Broadcom Corporation
59 + * All Rights Reserved.
61 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
62 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
63 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
64 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
68 + * Flash mapping for BCM947XX boards
71 +#include <linux/init.h>
72 +#include <linux/module.h>
73 +#include <linux/types.h>
74 +#include <linux/kernel.h>
76 +#include <linux/mtd/mtd.h>
77 +#include <linux/mtd/map.h>
78 +#include <linux/mtd/partitions.h>
79 +#include <linux/config.h>
80 +#include <typedefs.h>
81 +#include <bcmutils.h>
82 +#include <bcmnvram.h>
85 +#ifdef CONFIG_MTD_PARTITIONS
86 +extern struct mtd_partition * init_mtd_partitions(struct mtd_info *mtd, size_t size);
89 +#define CFE_SIZE 1024*384
90 +#define NVRAM_SIZE 1024*128
92 +#define WINDOW_ADDR 0x1c000000
93 +#define WINDOW_SIZE (0x400000*2)
96 +static struct mtd_info *bcm947xx_mtd;
98 +static void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
100 +#define MIPS_MEMCPY_ALIGN 4
104 + if ((len >= MIPS_MEMCPY_ALIGN) && (!(from & (MIPS_MEMCPY_ALIGN - 1))) && (!(((unsigned int)to & (MIPS_MEMCPY_ALIGN - 1))))) {
105 + done = len & ~(MIPS_MEMCPY_ALIGN - 1);
106 + memcpy_fromio(to, map->virt + from, done);
108 + while (done < len) {
109 + ret = map->read(map, from + done);
110 + transfer = len - done;
111 + if (transfer > map->bankwidth)
112 + transfer = map->bankwidth;
113 + memcpy((void *)((unsigned long)to + done), &ret.x[0], transfer);
118 +static struct map_info bcm947xx_map = {
119 + name: "Physically mapped flash",
121 + bankwidth: BUSWIDTH,
125 +#ifdef CONFIG_MTD_PARTITIONS
127 +static struct mtd_partition bcm947xx_parts[] = {
128 + { name: "cfe", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
129 + { name: "linux", offset: 0, size: 0, },
130 + { name: "rootfs", offset: 0, size: 0, },
131 + { name: "nvram", offset: 0, size: 0, },
132 + { name: "OpenWrt", offset: 0, size: 0, },
137 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
139 + struct trx_header *trx;
140 + unsigned char buf[512];
144 + trx = (struct trx_header *) buf;
146 + for (off = (256*1024); off < size; off += mtd->erasesize) {
147 + memset(buf, 0xe5, sizeof(buf));
152 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
153 + len != sizeof(buf))
156 + /* found a TRX header */
157 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
158 + part->offset = le32_to_cpu(trx->offsets[2]) ? :
159 + le32_to_cpu(trx->offsets[1]);
160 + part->size = le32_to_cpu(trx->len);
162 + part->size -= part->offset;
163 + part->offset += off;
170 + "%s: Couldn't find root filesystem\n",
178 +struct mtd_partition * __init
179 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
183 + bcm947xx_parts[0].offset = 0;
184 + bcm947xx_parts[0].size = CFE_SIZE;
186 + /* nvram (old config partition) */
187 + bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
188 + bcm947xx_parts[3].size = NVRAM_SIZE;
190 + /* Size linux (kernel and rootfs) */
191 + /* do not count the elf loader, which is on one sector */
192 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size + bcm947xx_parts[3].size + mtd->erasesize;
193 + bcm947xx_parts[1].size = size - NVRAM_SIZE - bcm947xx_parts[0].size -
194 + bcm947xx_parts[3].size - mtd->erasesize;
196 + /* Find and size rootfs */
197 + if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
198 + /* entirely jffs2 */
199 + bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset - NVRAM_SIZE;
200 + bcm947xx_parts[4].name = NULL;
203 + /* calculate leftover flash, and assign it to the jffs2 partition */
204 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset + bcm947xx_parts[2].size;
205 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
206 + bcm947xx_parts[4].offset += mtd->erasesize -
207 + (bcm947xx_parts[4].offset % mtd->erasesize);
209 + bcm947xx_parts[4].size = size - NVRAM_SIZE - bcm947xx_parts[4].offset;
212 + return bcm947xx_parts;
215 +EXPORT_SYMBOL(init_mtd_partitions);
218 +int __init init_bcm947xx_map(void)
222 +#ifdef CONFIG_MTD_PARTITIONS
223 + struct mtd_partition *parts;
227 + bcm947xx_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
229 + if (!bcm947xx_map.virt) {
230 + printk("Failed to ioremap\n");
233 + simple_map_init(&bcm947xx_map);
235 + bcm947xx_map.copy_from = bcm947xx_map_copy_from;
237 + if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
238 + printk("Failed to do_map_probe\n");
239 + iounmap((void *)bcm947xx_map.virt);
243 + bcm947xx_mtd->owner = THIS_MODULE;
245 + size = bcm947xx_mtd->size;
247 + printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", bcm947xx_mtd->size, WINDOW_ADDR);
249 +#ifdef CONFIG_MTD_PARTITIONS
250 + parts = init_mtd_partitions(bcm947xx_mtd, size);
251 + for (i = 0; parts[i].name; i++);
252 + ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
254 + printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
263 + map_destroy(bcm947xx_mtd);
264 + if (bcm947xx_map.map_priv_1)
265 + iounmap((void *) bcm947xx_map.map_priv_1);
266 + bcm947xx_map.map_priv_1 = 0;
270 +void __exit cleanup_bcm947xx_map(void)
272 +#ifdef CONFIG_MTD_PARTITIONS
273 + del_mtd_partitions(bcm947xx_mtd);
275 + map_destroy(bcm947xx_mtd);
276 + iounmap((void *)bcm947xx_map.virt);
279 +module_init(init_bcm947xx_map);
280 +module_exit(cleanup_bcm947xx_map);