linux/adm5120: add preliminary 2.6.37 kernel support
[openwrt.git] / target / linux / brcm63xx / patches-2.6.35 / 040-bcm963xx_flashmap.patch
1 From e734ace5baa04e0e8af1d4483475fbd6bd2b32a1 Mon Sep 17 00:00:00 2001
2 From: Axel Gembe <ago@bastart.eu.org>
3 Date: Mon, 12 May 2008 18:54:09 +0200
4 Subject: [PATCH] bcm963xx: flashmap support
5
6
7 Signed-off-by: Axel Gembe <ago@bastart.eu.org>
8 ---
9 drivers/mtd/maps/Kconfig | 7 +++++++
10 drivers/mtd/maps/Makefile | 1 +
11 drivers/mtd/redboot.c | 13 ++++++++++---
12 3 files changed, 18 insertions(+), 3 deletions(-)
13
14 --- a/drivers/mtd/maps/Kconfig
15 +++ b/drivers/mtd/maps/Kconfig
16 @@ -251,6 +251,13 @@ config MTD_NETtel
17 help
18 Support for flash chips on NETtel/SecureEdge/SnapGear boards.
19
20 +config MTD_BCM963XX
21 + tristate "BCM963xx Flash device"
22 + depends on MIPS && BCM63XX
23 + help
24 + Flash memory access on BCM963xx boards. Currently only works with
25 + RedBoot and CFE.
26 +
27 config MTD_DILNETPC
28 tristate "CFI Flash device mapped on DIL/Net PC"
29 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN
30 --- a/drivers/mtd/redboot.c
31 +++ b/drivers/mtd/redboot.c
32 @@ -39,7 +39,7 @@ static inline int redboot_checksum(struc
33 return 1;
34 }
35
36 -static int parse_redboot_partitions(struct mtd_info *master,
37 +int parse_redboot_partitions(struct mtd_info *master,
38 struct mtd_partition **pparts,
39 unsigned long fis_origin)
40 {
41 @@ -162,6 +162,14 @@ static int parse_redboot_partitions(stru
42 goto out;
43 }
44
45 + if (!fis_origin) {
46 + for (i = 0; i < numslots; i++) {
47 + if (!strncmp(buf[i].name, "RedBoot", 8)) {
48 + fis_origin = (buf[i].flash_base & (master->size << 1) - 1);
49 + }
50 + }
51 + }
52 +
53 for (i = 0; i < numslots; i++) {
54 struct fis_list *new_fl, **prev;
55
56 @@ -184,9 +192,8 @@ static int parse_redboot_partitions(stru
57 new_fl->img = &buf[i];
58 if (fis_origin) {
59 buf[i].flash_base -= fis_origin;
60 - } else {
61 - buf[i].flash_base &= master->size-1;
62 }
63 + buf[i].flash_base &= (master->size << 1) - 1;
64
65 /* I'm sure the JFFS2 code has done me permanent damage.
66 * I now think the following is _normal_
67 --- a/drivers/mtd/maps/Makefile
68 +++ b/drivers/mtd/maps/Makefile
69 @@ -59,3 +59,4 @@ obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-asy
70 obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o
71 obj-$(CONFIG_MTD_VMU) += vmu-flash.o
72 obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o
73 +obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o
74 --- /dev/null
75 +++ b/drivers/mtd/maps/bcm963xx-flash.c
76 @@ -0,0 +1,267 @@
77 +/*
78 + * Copyright (C) 2006-2008 Florian Fainelli <florian@openwrt.org>
79 + * Mike Albon <malbon@openwrt.org>
80 + *
81 + * This program is free software; you can redistribute it and/or modify
82 + * it under the terms of the GNU General Public License as published by
83 + * the Free Software Foundation; either version 2 of the License, or
84 + * (at your option) any later version.
85 + *
86 + * This program is distributed in the hope that it will be useful,
87 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
88 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89 + * GNU General Public License for more details.
90 + *
91 + * You should have received a copy of the GNU General Public License
92 + * along with this program; if not, write to the Free Software
93 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
94 + */
95 +
96 +#include <linux/init.h>
97 +#include <linux/kernel.h>
98 +#include <linux/mtd/map.h>
99 +#include <linux/mtd/mtd.h>
100 +#include <linux/mtd/partitions.h>
101 +#include <linux/slab.h>
102 +#include <linux/vmalloc.h>
103 +#include <linux/platform_device.h>
104 +
105 +#include <bcm_tag.h>
106 +#include <asm/io.h>
107 +
108 +#define BUSWIDTH 2 /* Buswidth */
109 +#define EXTENDED_SIZE 0xBFC00000 /* Extended flash address */
110 +
111 +#define PFX KBUILD_MODNAME ": "
112 +
113 +extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts, unsigned long fis_origin);
114 +static struct mtd_partition *parsed_parts;
115 +
116 +static struct mtd_info *bcm963xx_mtd_info;
117 +
118 +static struct map_info bcm963xx_map = {
119 + .name = "bcm963xx",
120 + .bankwidth = BUSWIDTH,
121 +};
122 +
123 +
124 +static int parse_cfe_partitions( struct mtd_info *master, struct mtd_partition **pparts)
125 +{
126 + int nrparts = 3, curpart = 0; /* CFE,NVRAM and global LINUX are always present. */
127 + struct bcm_tag *buf;
128 + struct mtd_partition *parts;
129 + int ret;
130 + size_t retlen;
131 + unsigned int rootfsaddr, kerneladdr, spareaddr;
132 + unsigned int rootfslen, kernellen, sparelen, totallen;
133 + int namelen = 0;
134 + int i;
135 + char *boardid;
136 + char *tagversion;
137 +
138 + /* Allocate memory for buffer */
139 + buf = vmalloc(sizeof(struct bcm_tag));
140 + if (!buf)
141 + return -ENOMEM;
142 +
143 + /* Get the tag */
144 + ret = master->read(master, master->erasesize, sizeof(struct bcm_tag), &retlen, (void *)buf);
145 + if (retlen != sizeof(struct bcm_tag)){
146 + vfree(buf);
147 + return -EIO;
148 + }
149 +
150 + sscanf(buf->kernelAddress, "%u", &kerneladdr);
151 + sscanf(buf->kernelLength, "%u", &kernellen);
152 + sscanf(buf->totalLength, "%u", &totallen);
153 + tagversion = &(buf->tagVersion[0]);
154 + boardid = &(buf->boardid[0]);
155 +
156 + printk(KERN_INFO PFX "CFE boot tag found with version %s and board type %s\n",tagversion, boardid);
157 +
158 + kerneladdr = kerneladdr - EXTENDED_SIZE;
159 + rootfsaddr = kerneladdr + kernellen;
160 + spareaddr = roundup(totallen, master->erasesize) + master->erasesize;
161 + sparelen = master->size - spareaddr - master->erasesize;
162 + rootfslen = spareaddr - rootfsaddr;
163 +
164 + /* Determine number of partitions */
165 + namelen = 8;
166 + if (rootfslen > 0){
167 + nrparts++;
168 + namelen =+ 6;
169 + };
170 + if (kernellen > 0) {
171 + nrparts++;
172 + namelen =+ 6;
173 + };
174 +
175 + /* Ask kernel for more memory */
176 + parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL);
177 + if (!parts) {
178 + vfree(buf);
179 + return -ENOMEM;
180 + };
181 +
182 + /* Start building partition list */
183 + parts[curpart].name = "CFE";
184 + parts[curpart].offset = 0;
185 + parts[curpart].size = master->erasesize;
186 + curpart++;
187 +
188 + if (kernellen > 0) {
189 + parts[curpart].name = "kernel";
190 + parts[curpart].offset = kerneladdr;
191 + parts[curpart].size = kernellen;
192 + curpart++;
193 + };
194 +
195 + if (rootfslen > 0) {
196 + parts[curpart].name = "rootfs";
197 + parts[curpart].offset = rootfsaddr;
198 + parts[curpart].size = rootfslen;
199 + if (sparelen > 0)
200 + parts[curpart].size += sparelen;
201 + curpart++;
202 + };
203 +
204 + parts[curpart].name = "nvram";
205 + parts[curpart].offset = master->size - master->erasesize;
206 + parts[curpart].size = master->erasesize;
207 +
208 + /* Global partition "linux" to make easy firmware upgrade */
209 + curpart++;
210 + parts[curpart].name = "linux";
211 + parts[curpart].offset = parts[0].size;
212 + parts[curpart].size = master->size - parts[0].size - parts[3].size;
213 +
214 + for (i = 0; i < nrparts; i++)
215 + printk(KERN_INFO PFX "Partition %d is %s offset %lx and length %lx\n", i, parts[i].name, (long unsigned int)(parts[i].offset), (long unsigned int)(parts[i].size));
216 +
217 + printk(KERN_INFO PFX "Spare partition is %x offset and length %x\n", spareaddr, sparelen);
218 + *pparts = parts;
219 + vfree(buf);
220 +
221 + return nrparts;
222 +};
223 +
224 +static int bcm963xx_detect_cfe(struct mtd_info *master)
225 +{
226 + int idoffset = 0x4e0;
227 + static char idstring[8] = "CFE1CFE1";
228 + char buf[9];
229 + int ret;
230 + size_t retlen;
231 +
232 + ret = master->read(master, idoffset, 8, &retlen, (void *)buf);
233 + buf[retlen] = 0;
234 + printk(KERN_INFO PFX "Read Signature value of %s\n", buf);
235 +
236 + return strncmp(idstring, buf, 8);
237 +}
238 +
239 +static int bcm963xx_probe(struct platform_device *pdev)
240 +{
241 + int err = 0;
242 + int parsed_nr_parts = 0;
243 + char *part_type;
244 + struct resource *r;
245 +
246 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
247 + bcm963xx_map.phys = r->start;
248 + bcm963xx_map.size = (r->end - r->start) + 1;
249 + bcm963xx_map.virt = ioremap(r->start, r->end - r->start + 1);
250 +
251 + if (!bcm963xx_map.virt) {
252 + printk(KERN_ERR PFX "Failed to ioremap\n");
253 + return -EIO;
254 + }
255 + printk(KERN_INFO PFX "0x%08lx at 0x%08x\n", bcm963xx_map.size, bcm963xx_map.phys);
256 +
257 + simple_map_init(&bcm963xx_map);
258 +
259 + bcm963xx_mtd_info = do_map_probe("cfi_probe", &bcm963xx_map);
260 + if (!bcm963xx_mtd_info) {
261 + printk(KERN_ERR PFX "Failed to probe using CFI\n");
262 + err = -EIO;
263 + goto err_probe;
264 + }
265 +
266 + bcm963xx_mtd_info->owner = THIS_MODULE;
267 +
268 + /* This is mutually exclusive */
269 + if (bcm963xx_detect_cfe(bcm963xx_mtd_info) == 0) {
270 + printk(KERN_INFO PFX "CFE bootloader detected\n");
271 + if (parsed_nr_parts == 0) {
272 + int ret = parse_cfe_partitions(bcm963xx_mtd_info, &parsed_parts);
273 + if (ret > 0) {
274 + part_type = "CFE";
275 + parsed_nr_parts = ret;
276 + }
277 + }
278 + } else {
279 + printk(KERN_INFO PFX "assuming RedBoot bootloader\n");
280 + if (bcm963xx_mtd_info->size > 0x00400000) {
281 + printk(KERN_INFO PFX "Support for extended flash memory size : 0x%lx ; ONLY 64MBIT SUPPORT\n", bcm963xx_mtd_info->size);
282 + bcm963xx_map.virt = (u32)(EXTENDED_SIZE);
283 + }
284 +
285 +#ifdef CONFIG_MTD_REDBOOT_PARTS
286 + if (parsed_nr_parts == 0) {
287 + int ret = parse_redboot_partitions(bcm963xx_mtd_info, &parsed_parts, 0);
288 + if (ret > 0) {
289 + part_type = "RedBoot";
290 + parsed_nr_parts = ret;
291 + }
292 + }
293 +#endif
294 + }
295 +
296 + return add_mtd_partitions(bcm963xx_mtd_info, parsed_parts, parsed_nr_parts);
297 +
298 +err_probe:
299 + iounmap(bcm963xx_map.virt);
300 + return err;
301 +}
302 +
303 +static int bcm963xx_remove(struct platform_device *pdev)
304 +{
305 + if (bcm963xx_mtd_info) {
306 + del_mtd_partitions(bcm963xx_mtd_info);
307 + map_destroy(bcm963xx_mtd_info);
308 + }
309 +
310 + if (bcm963xx_map.virt) {
311 + iounmap(bcm963xx_map.virt);
312 + bcm963xx_map.virt = 0;
313 + }
314 +
315 + return 0;
316 +}
317 +
318 +static struct platform_driver bcm63xx_mtd_dev = {
319 + .probe = bcm963xx_probe,
320 + .remove = bcm963xx_remove,
321 + .driver = {
322 + .name = "bcm963xx-flash",
323 + .owner = THIS_MODULE,
324 + },
325 +};
326 +
327 +static int __init bcm963xx_mtd_init(void)
328 +{
329 + return platform_driver_register(&bcm63xx_mtd_dev);
330 +}
331 +
332 +static void __exit bcm963xx_mtd_exit(void)
333 +{
334 + platform_driver_unregister(&bcm63xx_mtd_dev);
335 +}
336 +
337 +module_init(bcm963xx_mtd_init);
338 +module_exit(bcm963xx_mtd_exit);
339 +
340 +MODULE_LICENSE("GPL");
341 +MODULE_DESCRIPTION("Broadcom BCM63xx MTD partition parser/mapping for CFE and RedBoot");
342 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
343 +MODULE_AUTHOR("Mike Albon <malbon@openwrt.org>");
344 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
345 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
346 @@ -816,20 +816,6 @@ void __init board_setup(void)
347 panic("unexpected CPU for bcm963xx board");
348 }
349
350 -static struct mtd_partition mtd_partitions[] = {
351 - {
352 - .name = "cfe",
353 - .offset = 0x0,
354 - .size = 0x40000,
355 - }
356 -};
357 -
358 -static struct physmap_flash_data flash_data = {
359 - .width = 2,
360 - .nr_parts = ARRAY_SIZE(mtd_partitions),
361 - .parts = mtd_partitions,
362 -};
363 -
364 static struct resource mtd_resources[] = {
365 {
366 .start = 0, /* filled at runtime */
367 @@ -839,12 +825,9 @@ static struct resource mtd_resources[] =
368 };
369
370 static struct platform_device mtd_dev = {
371 - .name = "physmap-flash",
372 + .name = "bcm963xx-flash",
373 .resource = mtd_resources,
374 .num_resources = ARRAY_SIZE(mtd_resources),
375 - .dev = {
376 - .platform_data = &flash_data,
377 - },
378 };
379
380 static struct gpio_led_platform_data bcm63xx_led_data;
This page took 0.054237 seconds and 5 git commands to generate.