1 diff -Nur linux-2.6.15-rc5/drivers/mtd/maps/bcm47xx-flash.c linux-2.6.15-rc5-flash/drivers/mtd/maps/bcm47xx-flash.c
2 --- linux-2.6.15-rc5/drivers/mtd/maps/bcm47xx-flash.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.15-rc5-flash/drivers/mtd/maps/bcm47xx-flash.c 2005-12-19 00:33:31.276241000 +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 + * Flash mapping for BCM947XX boards
42 +#include <linux/init.h>
43 +#include <linux/module.h>
44 +#include <linux/types.h>
45 +#include <linux/kernel.h>
47 +#include <linux/mtd/mtd.h>
48 +#include <linux/mtd/map.h>
49 +#ifdef CONFIG_MTD_PARTITIONS
50 +#include <linux/mtd/partitions.h>
52 +#include <linux/config.h>
56 +#define WINDOW_ADDR 0x1c000000
57 +#define WINDOW_SIZE (0x400000*2)
60 +static struct mtd_info *bcm947xx_mtd;
62 +static void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
64 +#define MIPS_MEMCPY_ALIGN 4
68 + if ((len >= MIPS_MEMCPY_ALIGN) && (!(from & (MIPS_MEMCPY_ALIGN - 1))) && (!(((unsigned int)to & (MIPS_MEMCPY_ALIGN - 1))))) {
69 + done = len & ~(MIPS_MEMCPY_ALIGN - 1);
70 + memcpy_fromio(to, map->virt + from, done);
72 + while (done < len) {
73 + ret = map->read(map, from + done);
74 + transfer = len - done;
75 + if (transfer > map->bankwidth)
76 + transfer = map->bankwidth;
77 + memcpy((void *)((unsigned long)to + done), &ret.x[0], transfer);
82 +static struct map_info bcm947xx_map = {
83 + name: "Physically mapped flash",
85 + bankwidth: BUSWIDTH,
89 +#ifdef CONFIG_MTD_PARTITIONS
91 +static struct mtd_partition bcm947xx_parts[] = {
92 + { name: "cfe", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
93 + { name: "linux", offset: 0, size: 0, },
94 + { name: "rootfs", offset: 0, size: 0, },
95 + { name: "nvram", offset: 0, size: 0, },
96 + { name: "OpenWrt", offset: 0, size: 0, },
101 +find_cfe_size(struct mtd_info *mtd, size_t size)
103 + struct trx_header *trx;
104 + unsigned char buf[512];
109 + trx = (struct trx_header *) buf;
113 + for (off = (256*1024); off < size; off += mtd->erasesize) {
114 + memset(buf, 0xe5, sizeof(buf));
119 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
120 + len != sizeof(buf))
123 + /* found a TRX header */
124 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
127 + cfe_size_flag += 1;
131 + "%s: Couldn't find bootloader size\n",
136 + printk(KERN_NOTICE "bootloader size flag: %d\n", cfe_size_flag);
137 + return cfe_size_flag;
142 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
144 + struct trx_header *trx;
145 + unsigned char buf[512];
149 + trx = (struct trx_header *) buf;
151 + for (off = (256*1024); off < size; off += mtd->erasesize) {
152 + memset(buf, 0xe5, sizeof(buf));
157 + if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
158 + len != sizeof(buf))
161 + /* found a TRX header */
162 + if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
163 + part->offset = le32_to_cpu(trx->offsets[2]) ? :
164 + le32_to_cpu(trx->offsets[1]);
165 + part->size = le32_to_cpu(trx->len);
167 + part->size -= part->offset;
168 + part->offset += off;
175 + "%s: Couldn't find root filesystem\n",
183 +struct mtd_partition * __init
184 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
189 + /* if cfe_size_flag=0, cfe size is 256 kb, else 384 kb */
190 + cfe_size_flag = find_cfe_size(mtd, size);
193 + bcm947xx_parts[0].offset = 0;
194 + if (cfe_size_flag == 0) {
195 + bcm947xx_parts[0].size = 1024*256;
197 + /* netgear wgt634u has 384 kb bootloader */
198 + bcm947xx_parts[0].size = 1024*384;
202 + if (cfe_size_flag == 0) {
203 + bcm947xx_parts[3].offset = size - mtd->erasesize;
205 + /* nvram (old 128kb config partition on netgear wgt634u) */
206 + bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
208 + bcm947xx_parts[3].size = mtd->erasesize;
210 + /* linux (kernel and rootfs) */
211 + if (cfe_size_flag == 0) {
212 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
213 + bcm947xx_parts[1].size = bcm947xx_parts[3].offset -
214 + bcm947xx_parts[1].offset;
216 + /* do not count the elf loader, which is on one block */
217 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size +
218 + bcm947xx_parts[3].size + mtd->erasesize;
219 + bcm947xx_parts[1].size = size -
220 + bcm947xx_parts[0].size -
221 + (2*bcm947xx_parts[3].size) -
225 + /* find and size rootfs */
226 + if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
227 + /* entirely jffs2 */
228 + bcm947xx_parts[4].name = NULL;
229 + bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset -
230 + bcm947xx_parts[3].size;
233 + /* calculate leftover flash, and assign it to the jffs2 partition */
234 + if (cfe_size_flag == 0) {
235 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
236 + bcm947xx_parts[2].size;
237 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
238 + bcm947xx_parts[4].offset += mtd->erasesize -
239 + (bcm947xx_parts[4].offset % mtd->erasesize);
241 + bcm947xx_parts[4].size = bcm947xx_parts[3].offset -
242 + bcm947xx_parts[4].offset;
244 + bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
245 + bcm947xx_parts[2].size;
246 + if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
247 + bcm947xx_parts[4].offset += mtd->erasesize -
248 + (bcm947xx_parts[4].offset % mtd->erasesize);
250 + bcm947xx_parts[4].size = size - bcm947xx_parts[3].size -
251 + bcm947xx_parts[4].offset;
255 + return bcm947xx_parts;
259 +int __init init_bcm947xx_map(void)
263 +#ifdef CONFIG_MTD_PARTITIONS
264 + struct mtd_partition *parts;
268 + bcm947xx_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
270 + if (!bcm947xx_map.virt) {
271 + printk("Failed to ioremap\n");
274 + simple_map_init(&bcm947xx_map);
276 + bcm947xx_map.copy_from = bcm947xx_map_copy_from;
278 + if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
279 + printk("Failed to do_map_probe\n");
280 + iounmap((void *)bcm947xx_map.virt);
284 + bcm947xx_mtd->owner = THIS_MODULE;
286 + size = bcm947xx_mtd->size;
288 + printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", size, WINDOW_ADDR);
290 +#ifdef CONFIG_MTD_PARTITIONS
291 + parts = init_mtd_partitions(bcm947xx_mtd, size);
292 + for (i = 0; parts[i].name; i++);
293 + ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
295 + printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
303 + map_destroy(bcm947xx_mtd);
304 + if (bcm947xx_map.virt)
305 + iounmap((void *)bcm947xx_map.virt);
306 + bcm947xx_map.virt = 0;
310 +void __exit cleanup_bcm947xx_map(void)
312 +#ifdef CONFIG_MTD_PARTITIONS
313 + del_mtd_partitions(bcm947xx_mtd);
315 + map_destroy(bcm947xx_mtd);
316 + iounmap((void *)bcm947xx_map.virt);
319 +module_init(init_bcm947xx_map);
320 +module_exit(cleanup_bcm947xx_map);
321 diff -Nur linux-2.6.15-rc5/drivers/mtd/maps/Kconfig linux-2.6.15-rc5-flash/drivers/mtd/maps/Kconfig
322 --- linux-2.6.15-rc5/drivers/mtd/maps/Kconfig 2005-12-04 06:10:42.000000000 +0100
323 +++ linux-2.6.15-rc5-flash/drivers/mtd/maps/Kconfig 2005-12-18 19:36:11.555087000 +0100
325 Mapping for the Flaga digital module. If you don't have one, ignore
329 + tristate "BCM47xx flash device"
330 + depends on MIPS && MTD_CFI && BCM947XX
332 + Support for the flash chips on the BCM947xx board.
335 tristate "CFI Flash device mapped on IBM 405LP Beech"
336 depends on MTD_CFI && BEECH
337 diff -Nur linux-2.6.15-rc5/drivers/mtd/maps/Makefile linux-2.6.15-rc5-flash/drivers/mtd/maps/Makefile
338 --- linux-2.6.15-rc5/drivers/mtd/maps/Makefile 2005-12-04 06:10:42.000000000 +0100
339 +++ linux-2.6.15-rc5-flash/drivers/mtd/maps/Makefile 2005-12-18 19:36:11.555087000 +0100
341 obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
342 obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
343 obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
344 +obj-$(CONFIG_MTD_BCM47XX) += bcm47xx-flash.o
345 obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
346 obj-$(CONFIG_MTD_IPAQ) += ipaq-flash.o
347 obj-$(CONFIG_MTD_SBC_GXX) += sbc_gxx.o