1 diff -urN linux-2.6.19/drivers/mtd/maps/Kconfig linux-2.6.19.new/drivers/mtd/maps/Kconfig
2 --- linux-2.6.19/drivers/mtd/maps/Kconfig 2006-11-29 22:57:37.000000000 +0100
3 +++ linux-2.6.19.new/drivers/mtd/maps/Kconfig 2006-12-18 17:21:07.000000000 +0100
5 Flash memory access on 4G Systems MTX-1 Board. If you have one of
6 these boards and would like to use the flash chips on it, say 'Y'.
9 + tristate "BCM963xx Flash device"
10 + depends on MIPS && BCM963XX
12 + Flash memory access on BCM963xx boards. Currently only works with
13 + RedBoot, CFE support coming soon.
16 tristate "CFI Flash device mapped on DIL/Net PC"
17 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT
18 diff -urN linux-2.6.19/drivers/mtd/maps/Makefile linux-2.6.19.new/drivers/mtd/maps/Makefile
19 --- linux-2.6.19/drivers/mtd/maps/Makefile 2006-11-29 22:57:37.000000000 +0100
20 +++ linux-2.6.19.new/drivers/mtd/maps/Makefile 2006-12-18 17:21:07.000000000 +0100
22 obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o
23 obj-$(CONFIG_MTD_MTX1) += mtx-1_flash.o
24 obj-$(CONFIG_MTD_TQM834x) += tqm834x.o
25 +obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o
26 diff -urN linux-2.6.19/drivers/mtd/maps/Makefile.orig linux-2.6.19.new/drivers/mtd/maps/Makefile.orig
27 --- linux-2.6.19/drivers/mtd/maps/Makefile.orig 1970-01-01 01:00:00.000000000 +0100
28 +++ linux-2.6.19.new/drivers/mtd/maps/Makefile.orig 2006-11-29 22:57:37.000000000 +0100
31 +# linux/drivers/maps/Makefile
33 +# $Id: Makefile.common,v 1.34 2005/11/07 11:14:26 gleixner Exp $
35 +ifeq ($(CONFIG_MTD_COMPLEX_MAPPINGS),y)
36 +obj-$(CONFIG_MTD) += map_funcs.o
40 +obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
41 +obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
42 +obj-$(CONFIG_MTD_BAST) += bast-flash.o
43 +obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o
44 +obj-$(CONFIG_MTD_CSTM_MIPS_IXX) += cstm_mips_ixx.o
45 +obj-$(CONFIG_MTD_DC21285) += dc21285.o
46 +obj-$(CONFIG_MTD_DILNETPC) += dilnetpc.o
47 +obj-$(CONFIG_MTD_L440GX) += l440gx.o
48 +obj-$(CONFIG_MTD_AMD76XROM) += amd76xrom.o
49 +obj-$(CONFIG_MTD_ICHXROM) += ichxrom.o
50 +obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o
51 +obj-$(CONFIG_MTD_LUBBOCK) += lubbock-flash.o
52 +obj-$(CONFIG_MTD_MAINSTONE) += mainstone-flash.o
53 +obj-$(CONFIG_MTD_MBX860) += mbx860.o
54 +obj-$(CONFIG_MTD_CEIVA) += ceiva.o
55 +obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o
56 +obj-$(CONFIG_MTD_PHYSMAP) += physmap.o
57 +obj-$(CONFIG_MTD_PNC2000) += pnc2000.o
58 +obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
59 +obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
60 +obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
61 +obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
62 +obj-$(CONFIG_MTD_IPAQ) += ipaq-flash.o
63 +obj-$(CONFIG_MTD_SBC_GXX) += sbc_gxx.o
64 +obj-$(CONFIG_MTD_SC520CDP) += sc520cdp.o
65 +obj-$(CONFIG_MTD_NETSC520) += netsc520.o
66 +obj-$(CONFIG_MTD_TS5500) += ts5500_flash.o
67 +obj-$(CONFIG_MTD_SUN_UFLASH) += sun_uflash.o
68 +obj-$(CONFIG_MTD_VMAX) += vmax301.o
69 +obj-$(CONFIG_MTD_SCx200_DOCFLASH)+= scx200_docflash.o
70 +obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o
71 +obj-$(CONFIG_MTD_OCELOT) += ocelot.o
72 +obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o
73 +obj-$(CONFIG_MTD_PCI) += pci.o
74 +obj-$(CONFIG_MTD_ALCHEMY) += alchemy-flash.o
75 +obj-$(CONFIG_MTD_LASAT) += lasat.o
76 +obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o
77 +obj-$(CONFIG_MTD_EDB7312) += edb7312.o
78 +obj-$(CONFIG_MTD_IMPA7) += impa7.o
79 +obj-$(CONFIG_MTD_FORTUNET) += fortunet.o
80 +obj-$(CONFIG_MTD_REDWOOD) += redwood.o
81 +obj-$(CONFIG_MTD_UCLINUX) += uclinux.o
82 +obj-$(CONFIG_MTD_NETtel) += nettel.o
83 +obj-$(CONFIG_MTD_SCB2_FLASH) += scb2_flash.o
84 +obj-$(CONFIG_MTD_EBONY) += ebony.o
85 +obj-$(CONFIG_MTD_OCOTEA) += ocotea.o
86 +obj-$(CONFIG_MTD_BEECH) += beech-mtd.o
87 +obj-$(CONFIG_MTD_ARCTIC) += arctic-mtd.o
88 +obj-$(CONFIG_MTD_WALNUT) += walnut.o
89 +obj-$(CONFIG_MTD_H720X) += h720x-flash.o
90 +obj-$(CONFIG_MTD_SBC8240) += sbc8240.o
91 +obj-$(CONFIG_MTD_NOR_TOTO) += omap-toto-flash.o
92 +obj-$(CONFIG_MTD_MPC1211) += mpc1211.o
93 +obj-$(CONFIG_MTD_IXP4XX) += ixp4xx.o
94 +obj-$(CONFIG_MTD_IXP2000) += ixp2000.o
95 +obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o
96 +obj-$(CONFIG_MTD_DMV182) += dmv182.o
97 +obj-$(CONFIG_MTD_SHARP_SL) += sharpsl-flash.o
98 +obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o
99 +obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o
100 +obj-$(CONFIG_MTD_MTX1) += mtx-1_flash.o
101 +obj-$(CONFIG_MTD_TQM834x) += tqm834x.o
102 diff -urN linux-2.6.19/drivers/mtd/maps/bcm963xx-flash.c linux-2.6.19.new/drivers/mtd/maps/bcm963xx-flash.c
103 --- linux-2.6.19/drivers/mtd/maps/bcm963xx-flash.c 1970-01-01 01:00:00.000000000 +0100
104 +++ linux-2.6.19.new/drivers/mtd/maps/bcm963xx-flash.c 2006-12-18 17:21:07.000000000 +0100
108 + * Copyright (C) 2006 Florian Fainelli
109 + * Copyright (C) $Date$ $Author$
111 + * This program is free software; you can redistribute it and/or modify
112 + * it under the terms of the GNU General Public License as published by
113 + * the Free Software Foundation; either version 2 of the License, or
114 + * (at your option) any later version.
116 + * This program is distributed in the hope that it will be useful,
117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
119 + * GNU General Public License for more details.
121 + * You should have received a copy of the GNU General Public License
122 + * along with this program; if not, write to the Free Software
123 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
126 +/* This is the BCM963xx flash map driver, in its actual state it only supports BCM96348 devices
127 + * this driver is able to manage both bootloader we found on these boards : CFE and RedBoot
130 + * - this bootloader allows us to parse partitions and therefore deduce the MTD partition table
133 + * - we have to use a "physically mapped flash" defined bellow
138 +#include <linux/init.h>
139 +#include <linux/kernel.h>
140 +#include <linux/mtd/map.h>
141 +#include <linux/mtd/mtd.h>
142 +#include <linux/mtd/partitions.h>
143 +#include <linux/vmalloc.h>
146 +#define WINDOW_ADDR 0x1FC00000 /* Real address of the flash */
147 +#define WINDOW_SIZE 0x400000 /* Size of flash */
148 +#define BUSWIDTH 2 /* Buswidth */
149 +#define EXTENDED_SIZE 0xBFC00000 /* Extended flash address */
150 +#define IMAGE_LEN 10 /* Length of Length Field */
151 +#define ADDRESS_LEN 12 /* Length of Address field */
152 +#define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
154 +extern int boot_loader_type; /* For RedBoot / CFE detection */
155 +extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts, unsigned long fis_origin);
156 +static struct mtd_partition *parsed_parts;
158 +static void __exit bcm963xx_mtd_cleanup(void);
160 +static struct mtd_info *bcm963xx_mtd_info;
162 +static struct map_info bcm963xx_map = {
163 + .name = "bcm963xx",
164 + .size = WINDOW_SIZE,
165 + .bankwidth = BUSWIDTH,
166 + .phys = WINDOW_ADDR,
170 +int parse_cfe_partitions( struct mtd_info *master, struct mtd_partition **pparts)
172 + int nrparts = 2, curpart = 0; // CFE and NVRAM always present.
173 + struct bcm963xx_cfe_map {
174 + unsigned char tagVersion[4]; // Version of the image tag
175 + unsigned char sig_1[20]; // Company Line 1
176 + unsigned char sig_2[14]; // Company Line 2
177 + unsigned char chipid[6]; // Chip this image is for
178 + unsigned char boardid[16]; // Board name
179 + unsigned char bigEndian[2]; // Map endianness -- 1 BE 0 LE
180 + unsigned char totalLength[IMAGE_LEN]; //Total length of image
181 + unsigned char cfeAddress[ADDRESS_LEN]; // Address in memory of CFE
182 + unsigned char cfeLength[IMAGE_LEN]; // Size of CFE
183 + unsigned char rootAddress[ADDRESS_LEN]; // Address in memory of rootfs
184 + unsigned char rootLength[IMAGE_LEN]; // Size of rootfs
185 + unsigned char kernelAddress[ADDRESS_LEN]; // Address in memory of kernel
186 + unsigned char kernelLength[IMAGE_LEN]; // Size of kernel
187 + unsigned char dualImage[2]; // Unused at present
188 + unsigned char inactiveFlag[2]; // Unused at present
189 + unsigned char reserved1[74]; // Reserved area not in use
190 + unsigned char imageCRC[4]; // CRC32 of images
191 + unsigned char reserved2[16]; // Unused at present
192 + unsigned char headerCRC[4]; // CRC32 of header excluding tagVersion
193 + unsigned char reserved3[16]; // Unused at present
195 + struct mtd_partition *parts;
198 + unsigned int rootfsaddr, kerneladdr, spareaddr;
199 + unsigned int rootfslen, kernellen, sparelen, totallen;
202 + // Allocate memory for buffer
203 + buf = vmalloc(sizeof(struct bcm963xx_cfe_map));
209 + ret = master->read(master,master->erasesize,sizeof(struct bcm963xx_cfe_map), &retlen, (void *)buf);
210 + if (retlen != sizeof(struct bcm963xx_cfe_map)){
214 + printk("bcm963xx: CFE boot tag found with version %s and board type %s.\n",buf->tagVersion,buf->boardid);
215 + // Get the values and calculate
216 + sscanf(buf->rootAddress,"%u", &rootfsaddr);
217 + rootfsaddr = rootfsaddr - EXTENDED_SIZE;
218 + sscanf(buf->rootLength, "%u", &rootfslen);
219 + sscanf(buf->kernelAddress, "%u", &kerneladdr);
220 + kerneladdr = kerneladdr - EXTENDED_SIZE;
221 + sscanf(buf->kernelLength, "%u", &kernellen);
222 + sscanf(buf->totalLength, "%u", &totallen);
223 + spareaddr = ROUNDUP(totallen,master->erasesize) + master->erasesize;
224 + sparelen = master->size - spareaddr - master->erasesize;
225 + // Determine number of partitions
227 + if (rootfslen > 0){
231 + if (kernellen > 0){
239 + // Ask kernel for more memory.
240 + parts = kmalloc(sizeof(*parts)*nrparts+10*nrparts, GFP_KERNEL);
245 + memset(parts,0,sizeof(*parts)*nrparts+10*nrparts);
246 + // Start building partition list
247 + parts[curpart].name = "CFE";
248 + parts[curpart].offset = 0;
249 + parts[curpart].size = master->erasesize;
251 + if (kernellen > 0){
252 + parts[curpart].name = "Kernel";
253 + parts[curpart].offset = kerneladdr;
254 + parts[curpart].size = kernellen;
257 + if (rootfslen > 0){
258 + parts[curpart].name = "Rootfs";
259 + parts[curpart].offset = rootfsaddr;
260 + parts[curpart].size = rootfslen;
264 + parts[curpart].name = "OpenWrt";
265 + parts[curpart].offset = spareaddr;
266 + parts[curpart].size = sparelen;
269 + parts[curpart].name = "NVRAM";
270 + parts[curpart].offset = master->size - master->erasesize;
271 + parts[curpart].size = master->erasesize;
272 + for (i = 0; i < nrparts; i++) {
273 + printk("bcm963xx: Partition %d is %s offset %x and length %x\n", i, parts[i].name, parts[i].offset, parts[i].size);
280 +static struct mtd_partition bcm963xx_parts[] = {
281 + { name: "bootloader", size: 0, offset: 0, mask_flags: MTD_WRITEABLE },
282 + { name: "rootfs", size: 0, offset: 0},
283 + { name: "jffs2", size: 5 * 0x10000, offset: 57*0x10000}
286 +static int bcm963xx_parts_size = sizeof(bcm963xx_parts) / sizeof(bcm963xx_parts[0]);
288 +static int bcm963xx_detect_cfe(struct mtd_info *master)
290 + int idoffset = 0x4e0;
291 + static char idstring[8] = "CFE1CFE1";
296 + ret = master->read(master, idoffset, 8, &retlen, (void *)buf);
297 + printk("bcm963xx: Read Signature value of %s\n", buf);
298 + return strcmp(idstring,buf);
301 +static int __init bcm963xx_mtd_init(void)
303 + printk("bcm963xx: 0x%08x at 0x%08x\n", WINDOW_SIZE, WINDOW_ADDR);
304 + bcm963xx_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
306 + if (!bcm963xx_map.virt) {
307 + printk("bcm963xx: Failed to ioremap\n");
311 + simple_map_init(&bcm963xx_map);
313 + bcm963xx_mtd_info = do_map_probe("cfi_probe", &bcm963xx_map);
315 + if (bcm963xx_mtd_info) {
316 + bcm963xx_mtd_info->owner = THIS_MODULE;
318 + //if (boot_loader_type == BOOT_CFE)
319 + if (bcm963xx_detect_cfe(bcm963xx_mtd_info) == 0)
321 + int parsed_nr_parts = 0;
323 + printk("bcm963xx: CFE bootloader detected\n");
324 + //add_mtd_device(bcm963xx_mtd_info);
325 + //add_mtd_partitions(bcm963xx_mtd_info, bcm963xx_parts, bcm963xx_parts_size);
326 + if (parsed_nr_parts == 0) {
327 + int ret = parse_cfe_partitions(bcm963xx_mtd_info, &parsed_parts);
330 + parsed_nr_parts = ret;
333 + add_mtd_partitions(bcm963xx_mtd_info, parsed_parts, parsed_nr_parts);
338 + int parsed_nr_parts = 0;
341 + if (bcm963xx_mtd_info->size > 0x00400000) {
342 + printk("Support for extended flash memory size : 0x%08X ; ONLY 64MBIT SUPPORT\n", bcm963xx_mtd_info->size);
343 + bcm963xx_map.virt = (unsigned long)(EXTENDED_SIZE);
346 +#ifdef CONFIG_MTD_REDBOOT_PARTS
347 + if (parsed_nr_parts == 0) {
348 + int ret = parse_redboot_partitions(bcm963xx_mtd_info, &parsed_parts, 0);
350 + part_type = "RedBoot";
351 + parsed_nr_parts = ret;
355 + add_mtd_partitions(bcm963xx_mtd_info, parsed_parts, parsed_nr_parts);
360 + iounmap(bcm963xx_map.virt);
364 +static void __exit bcm963xx_mtd_cleanup(void)
366 + if (bcm963xx_mtd_info) {
367 + del_mtd_partitions(bcm963xx_mtd_info);
368 + map_destroy(bcm963xx_mtd_info);
371 + if (bcm963xx_map.virt) {
372 + iounmap(bcm963xx_map.virt);
373 + bcm963xx_map.virt = 0;
377 +module_init(bcm963xx_mtd_init);
378 +module_exit(bcm963xx_mtd_cleanup);
380 +MODULE_LICENSE("GPL");
381 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
382 diff -urN linux-2.6.19/drivers/mtd/redboot.c linux-2.6.19.new/drivers/mtd/redboot.c
383 --- linux-2.6.19/drivers/mtd/redboot.c 2006-12-18 17:09:14.000000000 +0100
384 +++ linux-2.6.19.new/drivers/mtd/redboot.c 2006-12-18 17:14:26.000000000 +0100
389 -static int parse_redboot_partitions(struct mtd_info *master,
390 +int parse_redboot_partitions(struct mtd_info *master,
391 struct mtd_partition **pparts,
392 unsigned long fis_origin)
399 + for (i = 0; i < numslots; i++) {
400 + if (!strncmp(buf[i].name, "RedBoot", 8)) {
401 + fis_origin = (buf[i].flash_base & (master->size << 1) - 1);
406 for (i = 0; i < numslots; i++) {
407 struct fis_list *new_fl, **prev;
410 new_fl->img = &buf[i];
412 buf[i].flash_base -= fis_origin;
414 - buf[i].flash_base &= master->size-1;
416 + buf[i].flash_base &= (master->size << 1) - 1;
418 /* I'm sure the JFFS2 code has done me permanent damage.
419 * I now think the following is _normal_