1 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
2 --- linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.12.5-flash/drivers/mtd/maps/bcm47xx-flash.c 2005-11-29 12:50:51.416656000 +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.
31 + * Copyright 2001-2003, Broadcom Corporation
32 + * All Rights Reserved.
34 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
35 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
36 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
37 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
39 + * $Id: bcm47xx-flash.c,v 1.1 2004/10/21 07:18:31 jolt Exp $
41 + * Flash mapping for BCM947XX boards
44 +#include <linux/init.h>
45 +#include <linux/module.h>
46 +#include <linux/types.h>
47 +#include <linux/kernel.h>
49 +#include <linux/mtd/mtd.h>
50 +#include <linux/mtd/map.h>
51 +#include <linux/mtd/partitions.h>
52 +#include <linux/config.h>
53 +#include <typedefs.h>
54 +#include <bcmutils.h>
55 +#include <bcmnvram.h>
59 +#ifdef CONFIG_MTD_PARTITIONS
60 +extern struct mtd_partition * init_mtd_partitions(struct mtd_info *mtd, size_t size);
63 +#define WINDOW_ADDR 0x1c000000
64 +#define WINDOW_SIZE (0x400000*2)
67 +static struct mtd_info *bcm947xx_mtd;
69 +static void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
71 +#define MIPS_MEMCPY_ALIGN 4
75 + if ((len >= MIPS_MEMCPY_ALIGN) && (!(from & (MIPS_MEMCPY_ALIGN - 1))) && (!(((unsigned int)to & (MIPS_MEMCPY_ALIGN - 1))))) {
76 + done = len & ~(MIPS_MEMCPY_ALIGN - 1);
77 + memcpy_fromio(to, map->virt + from, done);
79 + while (done < len) {
80 + ret = map->read(map, from + done);
81 + transfer = len - done;
82 + if (transfer > map->bankwidth)
83 + transfer = map->bankwidth;
84 + memcpy((void *)((unsigned long)to + done), &ret.x[0], transfer);
89 +static struct map_info bcm947xx_map = {
90 + name: "Physically mapped flash",
92 + bankwidth: BUSWIDTH,
96 +#ifdef CONFIG_MTD_PARTITIONS
98 +static struct mtd_partition bcm947xx_parts[] = {
99 + { name: "cfe", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
100 + { name: "linux", offset: 0, size: 0, },
101 + { name: "rootfs", offset: 0, size: 0, },
102 + { name: "nvram", offset: 0, size: 0, },
103 + { name: "OpenWrt", offset: 0, size: 0, },
108 +find_cfe_size(struct mtd_info *mtd, size_t size)
110 + struct trx_header *trx;
111 + unsigned char buf[512];
116 + trx = (struct trx_header *) buf;
120 + for (off = (256*1024); off < size; off += mtd->erasesize) {
121 + memset(buf, 0xe5, sizeof(buf));
126 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
127 + len != sizeof(buf))
130 + /* found a TRX header */
131 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
134 + cfe_size_flag += 1;
138 + "%s: Couldn't find bootloader size\n",
143 + printk(KERN_NOTICE "bootloader size flag: %d\n", cfe_size_flag);
144 + return cfe_size_flag;
149 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
151 + struct trx_header *trx;
152 + unsigned char buf[512];
156 + trx = (struct trx_header *) buf;
158 + for (off = (256*1024); off < size; off += mtd->erasesize) {
159 + memset(buf, 0xe5, sizeof(buf));
164 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
165 + len != sizeof(buf))
168 + /* found a TRX header */
169 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
170 + part->offset = le32_to_cpu(trx->offsets[2]) ? :
171 + le32_to_cpu(trx->offsets[1]);
172 + part->size = le32_to_cpu(trx->len);
174 + part->size -= part->offset;
175 + part->offset += off;
182 + "%s: Couldn't find root filesystem\n",
190 +struct mtd_partition * __init
191 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
196 + cfe_size_flag = find_cfe_size(mtd,size);
198 + /* if cfe_size_flag=0, cfe size is 256 kb, else 384 kb */
201 + bcm947xx_parts[0].offset = 0;
202 + if (cfe_size_flag == 0) {
203 + bcm947xx_parts[0].size = 1024*256;
205 + /* netgear wgt634u has 384 kb bootloader */
206 + bcm947xx_parts[0].size = 1024*384;
210 + if (cfe_size_flag == 0) {
211 + bcm947xx_parts[3].offset = size - mtd->erasesize;
212 + bcm947xx_parts[3].size = mtd->erasesize;
214 + /* nvram (old 128kb config partition on netgear wgt634u) */
215 + bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
216 + bcm947xx_parts[3].size = 1024*128;
219 + /* linux (kernel and rootfs) */
220 + if (cfe_size_flag == 0) {
221 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
222 + bcm947xx_parts[1].size = bcm947xx_parts[3].offset -
223 + bcm947xx_parts[1].offset;
225 + /* do not count the elf loader, which is on one block */
226 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size +
227 + bcm947xx_parts[3].size + mtd->erasesize;
228 + bcm947xx_parts[1].size = size -
229 + bcm947xx_parts[0].size -
230 + (2*bcm947xx_parts[3].size) -
234 + /* find and size rootfs */
235 + if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
236 + /* entirely jffs2 */
237 + bcm947xx_parts[4].name = NULL;
238 + if (cfe_size_flag == 0) {
239 + bcm947xx_parts[2].size = bcm947xx_parts[3].offset -
240 + bcm947xx_parts[2].offset;
242 + bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset -
243 + bcm947xx_parts[3].size;
247 + /* calculate leftover flash, and assign it to the jffs2 partition */
248 + if (cfe_size_flag == 0) {
249 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
250 + bcm947xx_parts[2].size;
251 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
252 + bcm947xx_parts[4].offset += mtd->erasesize -
253 + (bcm947xx_parts[4].offset % mtd->erasesize);
255 + bcm947xx_parts[4].size = bcm947xx_parts[3].offset -
256 + bcm947xx_parts[4].offset;
258 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
259 + bcm947xx_parts[2].size;
260 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
261 + bcm947xx_parts[4].offset += mtd->erasesize -
262 + (bcm947xx_parts[4].offset % mtd->erasesize);
264 + bcm947xx_parts[4].size = size - bcm947xx_parts[3].size -
265 + bcm947xx_parts[4].offset;
269 + return bcm947xx_parts;
272 +EXPORT_SYMBOL(init_mtd_partitions);
275 +int __init init_bcm947xx_map(void)
279 +#ifdef CONFIG_MTD_PARTITIONS
280 + struct mtd_partition *parts;
284 + bcm947xx_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
286 + if (!bcm947xx_map.virt) {
287 + printk("Failed to ioremap\n");
290 + simple_map_init(&bcm947xx_map);
292 + bcm947xx_map.copy_from = bcm947xx_map_copy_from;
294 + if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
295 + printk("Failed to do_map_probe\n");
296 + iounmap((void *)bcm947xx_map.virt);
300 + bcm947xx_mtd->owner = THIS_MODULE;
302 + size = bcm947xx_mtd->size;
304 + printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", bcm947xx_mtd->size, WINDOW_ADDR);
306 +#ifdef CONFIG_MTD_PARTITIONS
307 + parts = init_mtd_partitions(bcm947xx_mtd, size);
308 + for (i = 0; parts[i].name; i++);
309 + ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
311 + printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
320 + map_destroy(bcm947xx_mtd);
321 + if (bcm947xx_map.map_priv_1)
322 + iounmap((void *) bcm947xx_map.map_priv_1);
323 + bcm947xx_map.map_priv_1 = 0;
327 +void __exit cleanup_bcm947xx_map(void)
329 +#ifdef CONFIG_MTD_PARTITIONS
330 + del_mtd_partitions(bcm947xx_mtd);
332 + map_destroy(bcm947xx_mtd);
333 + iounmap((void *)bcm947xx_map.virt);
336 +module_init(init_bcm947xx_map);
337 +module_exit(cleanup_bcm947xx_map);
338 diff -Nur linux-2.6.12.5/drivers/mtd/maps/Kconfig linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig
339 --- linux-2.6.12.5/drivers/mtd/maps/Kconfig 2005-08-15 02:20:18.000000000 +0200
340 +++ linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig 2005-09-16 22:27:36.000000000 +0200
342 Mapping for the Flaga digital module. If you don't have one, ignore
346 + tristate "BCM47xx flash device"
347 + depends on MIPS && MTD_CFI && BCM947XX
349 + Support for the flash chips on the BCM947xx board.
352 tristate "CFI Flash device mapped on IBM 405LP Beech"
353 depends on MTD_CFI && PPC32 && 40x && BEECH
354 diff -Nur linux-2.6.12.5/drivers/mtd/maps/Makefile linux-2.6.12.5-flash/drivers/mtd/maps/Makefile
355 --- linux-2.6.12.5/drivers/mtd/maps/Makefile 2005-08-15 02:20:18.000000000 +0200
356 +++ linux-2.6.12.5-flash/drivers/mtd/maps/Makefile 2005-09-16 22:27:01.000000000 +0200
358 obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
359 obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
360 obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
361 +obj-$(CONFIG_MTD_BCM47XX) += bcm47xx-flash.o
362 obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
363 obj-$(CONFIG_MTD_IPAQ) += ipaq-flash.o
364 obj-$(CONFIG_MTD_SBC_GXX) += sbc_gxx.o