Use the rewritten flash map driver, huge thanks nbd !
[openwrt/staging/chunkeey.git] / openwrt / target / linux / brcm63xx-2.6 / patches / 040-bcm963xx_flashmap.patch
1 diff -urN linux-2.6.17/drivers/mtd/maps/bcm963xx-flash.c linux-2.6.17-brcm63xx/drivers/mtd/maps/bcm963xx-flash.c
2 --- linux-2.6.17/drivers/mtd/maps/bcm963xx-flash.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.17-brcm63xx/drivers/mtd/maps/bcm963xx-flash.c 2006-08-03 16:29:52.000000000 +0200
4 @@ -0,0 +1,116 @@
5 +/*
6 + * $Id$
7 + * Copyright (C) 2006 Florian Fainelli
8 + * Copyright (C) $Date$ $Author$
9 + *
10 + * This program is free software; you can redistribute it and/or modify
11 + * it under the terms of the GNU General Public License as published by
12 + * the Free Software Foundation; either version 2 of the License, or
13 + * (at your option) any later version.
14 + *
15 + * This program is distributed in the hope that it will be useful,
16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 + * GNU General Public License for more details.
19 + *
20 + * You should have received a copy of the GNU General Public License
21 + * along with this program; if not, write to the Free Software
22 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 + */
24 +
25 +/* This is the BCM963xx flash map driver, in its actual state it only supports BCM96348 devices
26 + * this driver is able to manage both bootloader we found on these boards : CFE and RedBoot
27 + *
28 + * RedBoot :
29 + * - this bootloader allows us to parse partitions and therefore deduce the MTD partition table
30 + *
31 + * CFE :
32 + * - we have to use a "physically mapped flash" defined bellow
33 + *
34 + */
35 +
36 +#include <asm/io.h>
37 +#include <linux/init.h>
38 +#include <linux/mtd/map.h>
39 +#include <linux/mtd/mtd.h>
40 +#include <linux/mtd/partitions.h>
41 +
42 +#define WINDOW_ADDR 0x1e400000 /* Real address of the flash */
43 +#define WINDOW_SIZE 0x800000 /* Size of flash */
44 +#define BUSWIDTH 2 /* Buswidth */
45 +
46 +extern int boot_loader_type; /* For RedBoot / CFE detection */
47 +extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts, unsigned long fis_origin);
48 +static struct mtd_partition *parsed_parts;
49 +
50 +static void __exit bcm963xx_mtd_cleanup(void);
51 +
52 +static struct mtd_info *bcm963xx_mtd_info;
53 +
54 +static struct map_info bcm963xx_map = {
55 + .name = "bcm963xx",
56 + .size = WINDOW_SIZE,
57 + .bankwidth = BUSWIDTH,
58 + .phys = WINDOW_ADDR,
59 +};
60 +
61 +static struct mtd_partition bcm963xx_parts[] = {
62 + { name: "bootloader", size: 0, offset: 0, mask_flags: MTD_WRITEABLE },
63 + { name: "rootfs", size: 0, offset: 0},
64 + { name: "jffs2", size: 5 * 0x10000, offset: 57*0x10000}
65 +};
66 +
67 +static int __init bcm963xx_mtd_init(void)
68 +{
69 + printk("bcm963xx: 0x%08x at 0x%08x\n", WINDOW_SIZE, WINDOW_ADDR);
70 + bcm963xx_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
71 +
72 + if (!bcm963xx_map.virt) {
73 + printk("bcm963xx: Failed to ioremap\n");
74 + return -EIO;
75 + }
76 +
77 + simple_map_init(&bcm963xx_map);
78 +
79 + bcm963xx_mtd_info = do_map_probe("cfi_probe", &bcm963xx_map);
80 +
81 + if (bcm963xx_mtd_info) {
82 + bcm963xx_mtd_info->owner = THIS_MODULE;
83 + int parsed_nr_parts = 0;
84 + char * part_type;
85 +
86 +#ifdef CONFIG_MTD_REDBOOT_PARTS
87 + if (parsed_nr_parts == 0) {
88 + int ret = parse_redboot_partitions(bcm963xx_mtd_info, &parsed_parts, 0);
89 + if (ret > 0) {
90 + part_type = "RedBoot";
91 + parsed_nr_parts = ret;
92 + }
93 + }
94 +#endif
95 + add_mtd_partitions(bcm963xx_mtd_info, parsed_parts, parsed_nr_parts);
96 +
97 + return 0;
98 + }
99 + iounmap(bcm963xx_map.virt);
100 + return -ENXIO;
101 +}
102 +
103 +static void __exit bcm963xx_mtd_cleanup(void)
104 +{
105 + if (bcm963xx_mtd_info) {
106 + del_mtd_partitions(bcm963xx_mtd_info);
107 + map_destroy(bcm963xx_mtd_info);
108 + }
109 +
110 + if (bcm963xx_map.virt) {
111 + iounmap(bcm963xx_map.virt);
112 + bcm963xx_map.virt = 0;
113 + }
114 +}
115 +
116 +module_init(bcm963xx_mtd_init);
117 +module_exit(bcm963xx_mtd_cleanup);
118 +
119 +MODULE_LICENSE("GPL");
120 +MODULE_AUTHOR("Florian Fainelli");
121 diff -urN linux-2.6.17/drivers/mtd/maps/Kconfig linux-2.6.17-brcm63xx/drivers/mtd/maps/Kconfig
122 --- linux-2.6.17/drivers/mtd/maps/Kconfig 2006-06-18 03:49:35.000000000 +0200
123 +++ linux-2.6.17-brcm63xx/drivers/mtd/maps/Kconfig 2006-08-03 16:32:05.000000000 +0200
124 @@ -224,6 +224,13 @@
125 Flash memory access on 4G Systems MTX-1 Board. If you have one of
126 these boards and would like to use the flash chips on it, say 'Y'.
127
128 +config MTD_BCM963XX
129 + tristate "BCM963xx Flash device"
130 + depends on MIPS && MIPS_BRCM
131 + help
132 + Flash memory access on BCM963xx boards. Currently only works with
133 + RedBoot, CFE support coming soon.
134 +
135 config MTD_DILNETPC
136 tristate "CFI Flash device mapped on DIL/Net PC"
137 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT
138 diff -urN linux-2.6.17/drivers/mtd/maps/Makefile linux-2.6.17-brcm63xx/drivers/mtd/maps/Makefile
139 --- linux-2.6.17/drivers/mtd/maps/Makefile 2006-06-18 03:49:35.000000000 +0200
140 +++ linux-2.6.17-brcm63xx/drivers/mtd/maps/Makefile 2006-08-03 16:32:27.000000000 +0200
141 @@ -71,3 +71,4 @@
142 obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o
143 obj-$(CONFIG_MTD_MTX1) += mtx-1_flash.o
144 obj-$(CONFIG_MTD_TQM834x) += tqm834x.o
145 +obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o
146 diff -urN linux-2.6.17/drivers/mtd/redboot.c linux-2.6.17-brcm63xx/drivers/mtd/redboot.c
147 --- linux-2.6.17/drivers/mtd/redboot.c 2006-06-18 03:49:35.000000000 +0200
148 +++ linux-2.6.17-brcm63xx/drivers/mtd/redboot.c 2006-08-03 16:32:39.000000000 +0200
149 @@ -39,7 +39,7 @@
150 return 1;
151 }
152
153 -static int parse_redboot_partitions(struct mtd_info *master,
154 +int parse_redboot_partitions(struct mtd_info *master,
155 struct mtd_partition **pparts,
156 unsigned long fis_origin)
157 {
158 @@ -120,11 +120,19 @@
159 goto out;
160 }
161
162 + if (!fis_origin) {
163 + for (i = 0; i < numslots; i++) {
164 + if (!strncmp(buf[i].name, "RedBoot", 8)) {
165 + fis_origin = (buf[i].flash_base & (master->size << 1) - 1);
166 + }
167 + }
168 + }
169 +
170 for (i = 0; i < numslots; i++) {
171 struct fis_list *new_fl, **prev;
172
173 if (buf[i].name[0] == 0xff)
174 - continue;
175 + break;
176 if (!redboot_checksum(&buf[i]))
177 break;
178
179 @@ -135,11 +143,10 @@
180 goto out;
181 }
182 new_fl->img = &buf[i];
183 - if (fis_origin) {
184 - buf[i].flash_base -= fis_origin;
185 - } else {
186 - buf[i].flash_base &= master->size-1;
187 - }
188 + if (fis_origin) {
189 + buf[i].flash_base -= fis_origin;
190 + }
191 + buf[i].flash_base &= (master->size << 1) - 1;
192
193 /* I'm sure the JFFS2 code has done me permanent damage.
194 * I now think the following is _normal_