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
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/bcm963xx-flash.c linux-2.6.19.new/drivers/mtd/maps/bcm963xx-flash.c
27 --- linux-2.6.19/drivers/mtd/maps/bcm963xx-flash.c 1970-01-01 01:00:00.000000000 +0100
28 +++ linux-2.6.19.new/drivers/mtd/maps/bcm963xx-flash.c 2006-12-18 17:21:07.000000000 +0100
32 + * Copyright (C) 2006 Florian Fainelli <florian@openwrt.org>
33 + * Mike Albon <malbon@openwrt.org>
34 + * Copyright (C) $Date$ $Author$
36 + * This program is free software; you can redistribute it and/or modify
37 + * it under the terms of the GNU General Public License as published by
38 + * the Free Software Foundation; either version 2 of the License, or
39 + * (at your option) any later version.
41 + * This program is distributed in the hope that it will be useful,
42 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 + * GNU General Public License for more details.
46 + * You should have received a copy of the GNU General Public License
47 + * along with this program; if not, write to the Free Software
48 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
51 +/* This is the BCM963xx flash map driver, in its actual state it only supports BCM96348 devices
52 + * this driver is able to manage both bootloader we found on these boards : CFE and RedBoot
55 + * - this bootloader allows us to parse partitions and therefore deduce the MTD partition table
58 + * - CFE partitionning can be detected as for BCM947xx devices
63 +#include <linux/init.h>
64 +#include <linux/kernel.h>
65 +#include <linux/mtd/map.h>
66 +#include <linux/mtd/mtd.h>
67 +#include <linux/mtd/partitions.h>
68 +#include <linux/vmalloc.h>
71 +#define WINDOW_ADDR 0x1FC00000 /* Real address of the flash */
72 +#define WINDOW_SIZE 0x400000 /* Size of flash */
73 +#define BUSWIDTH 2 /* Buswidth */
74 +#define EXTENDED_SIZE 0xBFC00000 /* Extended flash address */
75 +#define IMAGE_LEN 10 /* Length of Length Field */
76 +#define ADDRESS_LEN 12 /* Length of Address field */
77 +#define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
79 +extern int boot_loader_type; /* For RedBoot / CFE detection */
80 +extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts, unsigned long fis_origin);
81 +static struct mtd_partition *parsed_parts;
83 +static void __exit bcm963xx_mtd_cleanup(void);
85 +static struct mtd_info *bcm963xx_mtd_info;
87 +static struct map_info bcm963xx_map = {
89 + .size = WINDOW_SIZE,
90 + .bankwidth = BUSWIDTH,
91 + .phys = WINDOW_ADDR,
95 +int parse_cfe_partitions( struct mtd_info *master, struct mtd_partition **pparts)
97 + int nrparts = 2, curpart = 0; // CFE and NVRAM always present.
98 + struct bcm963xx_cfe_map {
99 + unsigned char tagVersion[4]; // Version of the image tag
100 + unsigned char sig_1[20]; // Company Line 1
101 + unsigned char sig_2[14]; // Company Line 2
102 + unsigned char chipid[6]; // Chip this image is for
103 + unsigned char boardid[16]; // Board name
104 + unsigned char bigEndian[2]; // Map endianness -- 1 BE 0 LE
105 + unsigned char totalLength[IMAGE_LEN]; //Total length of image
106 + unsigned char cfeAddress[ADDRESS_LEN]; // Address in memory of CFE
107 + unsigned char cfeLength[IMAGE_LEN]; // Size of CFE
108 + unsigned char rootAddress[ADDRESS_LEN]; // Address in memory of rootfs
109 + unsigned char rootLength[IMAGE_LEN]; // Size of rootfs
110 + unsigned char kernelAddress[ADDRESS_LEN]; // Address in memory of kernel
111 + unsigned char kernelLength[IMAGE_LEN]; // Size of kernel
112 + unsigned char dualImage[2]; // Unused at present
113 + unsigned char inactiveFlag[2]; // Unused at present
114 + unsigned char reserved1[74]; // Reserved area not in use
115 + unsigned char imageCRC[4]; // CRC32 of images
116 + unsigned char reserved2[16]; // Unused at present
117 + unsigned char headerCRC[4]; // CRC32 of header excluding tagVersion
118 + unsigned char reserved3[16]; // Unused at present
120 + struct mtd_partition *parts;
123 + unsigned int rootfsaddr, kerneladdr, spareaddr;
124 + unsigned int rootfslen, kernellen, sparelen, totallen;
127 + // Allocate memory for buffer
128 + buf = vmalloc(sizeof(struct bcm963xx_cfe_map));
134 + ret = master->read(master,master->erasesize,sizeof(struct bcm963xx_cfe_map), &retlen, (void *)buf);
135 + if (retlen != sizeof(struct bcm963xx_cfe_map)){
139 + printk("bcm963xx: CFE boot tag found with version %s and board type %s.\n",buf->tagVersion,buf->boardid);
140 + // Get the values and calculate
141 + sscanf(buf->rootAddress,"%u", &rootfsaddr);
142 + rootfsaddr = rootfsaddr - EXTENDED_SIZE;
143 + sscanf(buf->rootLength, "%u", &rootfslen);
144 + sscanf(buf->kernelAddress, "%u", &kerneladdr);
145 + kerneladdr = kerneladdr - EXTENDED_SIZE;
146 + sscanf(buf->kernelLength, "%u", &kernellen);
147 + sscanf(buf->totalLength, "%u", &totallen);
148 + spareaddr = ROUNDUP(totallen,master->erasesize) + master->erasesize;
149 + sparelen = master->size - spareaddr - master->erasesize;
150 + // Determine number of partitions
152 + if (rootfslen > 0){
156 + if (kernellen > 0){
164 + // Ask kernel for more memory.
165 + parts = kmalloc(sizeof(*parts)*nrparts+10*nrparts, GFP_KERNEL);
170 + memset(parts,0,sizeof(*parts)*nrparts+10*nrparts);
171 + // Start building partition list
172 + parts[curpart].name = "CFE";
173 + parts[curpart].offset = 0;
174 + parts[curpart].size = master->erasesize;
176 + if (kernellen > 0){
177 + parts[curpart].name = "Kernel";
178 + parts[curpart].offset = kerneladdr;
179 + parts[curpart].size = kernellen;
182 + if (rootfslen > 0){
183 + parts[curpart].name = "Rootfs";
184 + parts[curpart].offset = rootfsaddr;
185 + parts[curpart].size = rootfslen;
189 + parts[curpart].name = "OpenWrt";
190 + parts[curpart].offset = spareaddr;
191 + parts[curpart].size = sparelen;
194 + parts[curpart].name = "NVRAM";
195 + parts[curpart].offset = master->size - master->erasesize;
196 + parts[curpart].size = master->erasesize;
197 + for (i = 0; i < nrparts; i++) {
198 + printk("bcm963xx: Partition %d is %s offset %x and length %x\n", i, parts[i].name, parts[i].offset, parts[i].size);
205 +static struct mtd_partition bcm963xx_parts[] = {
206 + { name: "bootloader", size: 0, offset: 0, mask_flags: MTD_WRITEABLE },
207 + { name: "rootfs", size: 0, offset: 0},
208 + { name: "jffs2", size: 5 * 0x10000, offset: 57*0x10000}
211 +static int bcm963xx_parts_size = sizeof(bcm963xx_parts) / sizeof(bcm963xx_parts[0]);
213 +static int bcm963xx_detect_cfe(struct mtd_info *master)
215 + int idoffset = 0x4e0;
216 + static char idstring[8] = "CFE1CFE1";
221 + ret = master->read(master, idoffset, 8, &retlen, (void *)buf);
222 + printk("bcm963xx: Read Signature value of %s\n", buf);
223 + return strcmp(idstring,buf);
226 +static int __init bcm963xx_mtd_init(void)
228 + printk("bcm963xx: 0x%08x at 0x%08x\n", WINDOW_SIZE, WINDOW_ADDR);
229 + bcm963xx_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
231 + if (!bcm963xx_map.virt) {
232 + printk("bcm963xx: Failed to ioremap\n");
236 + simple_map_init(&bcm963xx_map);
238 + bcm963xx_mtd_info = do_map_probe("cfi_probe", &bcm963xx_map);
240 + if (bcm963xx_mtd_info) {
241 + bcm963xx_mtd_info->owner = THIS_MODULE;
243 + //if (boot_loader_type == BOOT_CFE)
244 + if (bcm963xx_detect_cfe(bcm963xx_mtd_info) == 0)
246 + int parsed_nr_parts = 0;
248 + printk("bcm963xx: CFE bootloader detected\n");
249 + //add_mtd_device(bcm963xx_mtd_info);
250 + //add_mtd_partitions(bcm963xx_mtd_info, bcm963xx_parts, bcm963xx_parts_size);
251 + if (parsed_nr_parts == 0) {
252 + int ret = parse_cfe_partitions(bcm963xx_mtd_info, &parsed_parts);
255 + parsed_nr_parts = ret;
258 + add_mtd_partitions(bcm963xx_mtd_info, parsed_parts, parsed_nr_parts);
263 + int parsed_nr_parts = 0;
266 + if (bcm963xx_mtd_info->size > 0x00400000) {
267 + printk("Support for extended flash memory size : 0x%08X ; ONLY 64MBIT SUPPORT\n", bcm963xx_mtd_info->size);
268 + bcm963xx_map.virt = (unsigned long)(EXTENDED_SIZE);
271 +#ifdef CONFIG_MTD_REDBOOT_PARTS
272 + if (parsed_nr_parts == 0) {
273 + int ret = parse_redboot_partitions(bcm963xx_mtd_info, &parsed_parts, 0);
275 + part_type = "RedBoot";
276 + parsed_nr_parts = ret;
280 + add_mtd_partitions(bcm963xx_mtd_info, parsed_parts, parsed_nr_parts);
285 + iounmap(bcm963xx_map.virt);
289 +static void __exit bcm963xx_mtd_cleanup(void)
291 + if (bcm963xx_mtd_info) {
292 + del_mtd_partitions(bcm963xx_mtd_info);
293 + map_destroy(bcm963xx_mtd_info);
296 + if (bcm963xx_map.virt) {
297 + iounmap(bcm963xx_map.virt);
298 + bcm963xx_map.virt = 0;
302 +module_init(bcm963xx_mtd_init);
303 +module_exit(bcm963xx_mtd_cleanup);
305 +MODULE_LICENSE("GPL");
306 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org> Mike Albon <malbon@openwrt.org>");
307 diff -urN linux-2.6.19/drivers/mtd/redboot.c linux-2.6.19.new/drivers/mtd/redboot.c
308 --- linux-2.6.19/drivers/mtd/redboot.c 2006-12-18 17:09:14.000000000 +0100
309 +++ linux-2.6.19.new/drivers/mtd/redboot.c 2006-12-18 17:14:26.000000000 +0100
314 -static int parse_redboot_partitions(struct mtd_info *master,
315 +int parse_redboot_partitions(struct mtd_info *master,
316 struct mtd_partition **pparts,
317 unsigned long fis_origin)
324 + for (i = 0; i < numslots; i++) {
325 + if (!strncmp(buf[i].name, "RedBoot", 8)) {
326 + fis_origin = (buf[i].flash_base & (master->size << 1) - 1);
331 for (i = 0; i < numslots; i++) {
332 struct fis_list *new_fl, **prev;
335 new_fl->img = &buf[i];
337 buf[i].flash_base -= fis_origin;
339 - buf[i].flash_base &= master->size-1;
341 + buf[i].flash_base &= (master->size << 1) - 1;
343 /* I'm sure the JFFS2 code has done me permanent damage.
344 * I now think the following is _normal_