source: freewrt/target/linux/brcm-2.4/asus-wl500g-premium/patches/001-flash-map.patch@ 40e8ee8

Last change on this file since 40e8ee8 was 40e8ee8, checked in by Waldemar Brodkorb <wbx@…>, 19 years ago

move more packages, add netgear flash map driver

git-svn-id: svn://www.freewrt.org/branches/wbx-target-cleanup@550 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 10.9 KB
RevLine 
[40e8ee8]1diff -Nur linux-2.4.32/drivers/mtd/maps/Config.in linux-2.4.32-freewrt/drivers/mtd/maps/Config.in
2--- linux-2.4.32/drivers/mtd/maps/Config.in Fri Jun 13 16:51:34 2003
3+++ linux-2.4.32-freewrt/drivers/mtd/maps/Config.in Sun Aug 27 20:51:11 2006
4@@ -48,6 +48,7 @@
5 fi
6
7 if [ "$CONFIG_MIPS" = "y" ]; then
8+ dep_tristate ' CFI Flash device mapped on Broadcom BCM947XX boards' CONFIG_MTD_BCM947XX $CONFIG_MTD_CFI
9 dep_tristate ' Pb1000 MTD support' CONFIG_MTD_PB1000 $CONFIG_MIPS_PB1000
10 dep_tristate ' Pb1500 MTD support' CONFIG_MTD_PB1500 $CONFIG_MIPS_PB1500
11 dep_tristate ' Pb1100 MTD support' CONFIG_MTD_PB1100 $CONFIG_MIPS_PB1100
12diff -Nur linux-2.4.32/drivers/mtd/maps/Makefile linux-2.4.32-freewrt/drivers/mtd/maps/Makefile
13--- linux-2.4.32/drivers/mtd/maps/Makefile Fri Jun 13 16:51:34 2003
14+++ linux-2.4.32-freewrt/drivers/mtd/maps/Makefile Sun Aug 27 20:51:11 2006
15@@ -3,6 +3,8 @@
16 #
17 # $Id: Makefile,v 1.37 2003/01/24 14:26:38 dwmw2 Exp $
18
19+EXTRA_CFLAGS := -I$(TOPDIR)/arch/mips/bcm947xx/include
20+
21 BELOW25 := $(shell echo $(PATCHLEVEL) | sed s/[1234]/y/)
22
23 ifeq ($(BELOW25),y)
24@@ -10,6 +12,7 @@
25 endif
26
27 # Chip mappings
28+obj-$(CONFIG_MTD_BCM947XX) += bcm947xx-flash.o
29 obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
30 obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
31 obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o
32diff -Nur linux-2.4.32/drivers/mtd/maps/bcm947xx-flash.c linux-2.4.32-freewrt/drivers/mtd/maps/bcm947xx-flash.c
33--- linux-2.4.32/drivers/mtd/maps/bcm947xx-flash.c Thu Jan 1 01:00:00 1970
34+++ linux-2.4.32-freewrt/drivers/mtd/maps/bcm947xx-flash.c Sun Aug 27 21:07:17 2006
35@@ -0,0 +1,346 @@
36+/*
37+ * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
38+ * Copyright (C) 2006 Waldemar Brodkorb <wbx@freewrt.org>
39+ *
40+ * original functions for finding root filesystem from Mike Baker
41+ *
42+ * This program is free software; you can redistribute it and/or modify it
43+ * under the terms of the GNU General Public License as published by the
44+ * Free Software Foundation; either version 2 of the License, or (at your
45+ * option) any later version.
46+ *
47+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
48+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
49+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
50+ * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
53+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
54+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57+ *
58+ * You should have received a copy of the GNU General Public License along
59+ * with this program; if not, write to the Free Software Foundation, Inc.,
60+ * 675 Mass Ave, Cambridge, MA 02139, USA.
61+ *
62+ *
63+ * Copyright 2004, Broadcom Corporation
64+ * All Rights Reserved.
65+ *
66+ * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
67+ * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
68+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
69+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
70+ *
71+ * Flash mapping for BCM947XX boards
72+ *
73+ */
74+
75+#include <linux/module.h>
76+#include <linux/types.h>
77+#include <linux/kernel.h>
78+#include <asm/io.h>
79+#include <linux/mtd/mtd.h>
80+#include <linux/mtd/map.h>
81+#ifdef CONFIG_MTD_PARTITIONS
82+#include <linux/mtd/partitions.h>
83+#endif
84+#include <linux/config.h>
85+
86+#include <typedefs.h>
87+#include <osl.h>
88+#include <bcmnvram.h>
89+#include <bcmutils.h>
90+#include <sbconfig.h>
91+#include <sbchipc.h>
92+#include <sbutils.h>
93+#include <trxhdr.h>
94+
95+/* Global SB handle */
96+extern void *bcm947xx_sbh;
97+extern spinlock_t bcm947xx_sbh_lock;
98+
99+/* Convenience */
100+#define sbh bcm947xx_sbh
101+#define sbh_lock bcm947xx_sbh_lock
102+
103+#define WINDOW_ADDR 0x1fc00000
104+#define WINDOW_SIZE 0x400000
105+#define BUSWIDTH 2
106+
107+static struct mtd_info *bcm947xx_mtd;
108+
109+__u8 bcm947xx_map_read8(struct map_info *map, unsigned long ofs)
110+{
111+ if (map->map_priv_2 == 1)
112+ return __raw_readb(map->map_priv_1 + ofs);
113+
114+ u16 val = __raw_readw(map->map_priv_1 + (ofs & ~1));
115+ if (ofs & 1)
116+ return ((val >> 8) & 0xff);
117+ else
118+ return (val & 0xff);
119+}
120+
121+__u16 bcm947xx_map_read16(struct map_info *map, unsigned long ofs)
122+{
123+ return __raw_readw(map->map_priv_1 + ofs);
124+}
125+
126+__u32 bcm947xx_map_read32(struct map_info *map, unsigned long ofs)
127+{
128+ return __raw_readl(map->map_priv_1 + ofs);
129+}
130+
131+void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
132+{
133+ if (len==1) {
134+ memcpy_fromio(to, map->map_priv_1 + from, len);
135+ } else {
136+ int i;
137+ u16 *dest = (u16 *) to;
138+ u16 *src = (u16 *) (map->map_priv_1 + from);
139+ for (i = 0; i < (len / 2); i++) {
140+ dest[i] = src[i];
141+ }
142+ if (len & 1)
143+ *((u8 *)dest+len-1) = src[i] & 0xff;
144+ }
145+}
146+
147+void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
148+{
149+ __raw_writeb(d, map->map_priv_1 + adr);
150+ mb();
151+}
152+
153+void bcm947xx_map_write16(struct map_info *map, __u16 d, unsigned long adr)
154+{
155+ __raw_writew(d, map->map_priv_1 + adr);
156+ mb();
157+}
158+
159+void bcm947xx_map_write32(struct map_info *map, __u32 d, unsigned long adr)
160+{
161+ __raw_writel(d, map->map_priv_1 + adr);
162+ mb();
163+}
164+
165+void bcm947xx_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
166+{
167+ memcpy_toio(map->map_priv_1 + to, from, len);
168+}
169+
170+struct map_info bcm947xx_map = {
171+ name: "Physically mapped flash",
172+ size: WINDOW_SIZE,
173+ buswidth: BUSWIDTH,
174+ read8: bcm947xx_map_read8,
175+ read16: bcm947xx_map_read16,
176+ read32: bcm947xx_map_read32,
177+ copy_from: bcm947xx_map_copy_from,
178+ write8: bcm947xx_map_write8,
179+ write16: bcm947xx_map_write16,
180+ write32: bcm947xx_map_write32,
181+ copy_to: bcm947xx_map_copy_to
182+};
183+
184+#ifdef CONFIG_MTD_PARTITIONS
185+
186+static struct mtd_partition bcm947xx_parts[] = {
187+ { name: "cfe", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
188+ { name: "linux", offset: 0, size: 0, },
189+ { name: "rootfs", offset: 0, size: 0, },
190+ { name: "nvram", offset: 0, size: 0, },
191+ { name: "data", offset: 0, size: 0, },
192+ { name: "configfs", offset: 0, size: 0, },
193+ { name: NULL, },
194+};
195+
196+static int __init
197+find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
198+{
199+ struct trx_header *trx;
200+ unsigned char buf[512];
201+ int off;
202+ size_t len;
203+ int blocksize;
204+
205+ trx = (struct trx_header *) buf;
206+
207+ blocksize = mtd->erasesize;
208+ if (blocksize < 0x10000)
209+ blocksize = 0x10000;
210+
211+ for (off = (256*1024); off < size; off += blocksize) {
212+ memset(buf, 0xe5, sizeof(buf));
213+
214+ /*
215+ * Read into buffer
216+ */
217+ if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
218+ len != sizeof(buf))
219+ continue;
220+
221+ /* found a TRX header */
222+ if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
223+ part->offset = le32_to_cpu(trx->offsets[2]) ? :
224+ le32_to_cpu(trx->offsets[1]);
225+ part->size = le32_to_cpu(trx->len);
226+
227+ part->size -= part->offset;
228+ part->offset += off;
229+
230+ goto done;
231+ }
232+ }
233+
234+ printk(KERN_NOTICE
235+ "%s: Couldn't find root filesystem\n",
236+ mtd->name);
237+ return -1;
238+
239+ done:
240+ return part->size;
241+}
242+
243+struct mtd_partition * __init
244+init_mtd_partitions(struct mtd_info *mtd, size_t size)
245+{
246+
247+ /* boot loader 256 kB */
248+ bcm947xx_parts[0].offset = 0;
249+ bcm947xx_parts[0].size = 256*1024;
250+
251+ /* nvram */
252+ bcm947xx_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
253+ bcm947xx_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
254+
255+ /* configfs 128 kB before nvram */
256+ bcm947xx_parts[5].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize)
257+ - 128*1024;
258+ bcm947xx_parts[5].size = 128*1024;
259+
260+ /* linux (kernel and rootfs) */
261+ bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
262+ bcm947xx_parts[1].size = bcm947xx_parts[5].offset -
263+ bcm947xx_parts[1].offset;
264+
265+ /* find and size rootfs */
266+ if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
267+ /* entirely jffs2 */
268+ bcm947xx_parts[4].name = NULL;
269+ bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset -
270+ bcm947xx_parts[3].size - bcm947xx_parts[5].size;
271+ } else {
272+ /* calculate leftover flash and assign it to a jffs2 partition */
273+ bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
274+ bcm947xx_parts[2].size;
275+ if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
276+ bcm947xx_parts[4].offset += mtd->erasesize -
277+ (bcm947xx_parts[4].offset % mtd->erasesize);
278+ }
279+ bcm947xx_parts[4].size = bcm947xx_parts[5].offset -
280+ bcm947xx_parts[4].offset;
281+ }
282+ return bcm947xx_parts;
283+}
284+
285+#endif
286+
287+
288+mod_init_t init_bcm947xx_map(void)
289+{
290+ ulong flags;
291+ uint coreidx;
292+ chipcregs_t *cc;
293+ uint32 fltype;
294+ uint window_addr = 0, window_size = 0;
295+ size_t size;
296+ int ret = 0;
297+#ifdef CONFIG_MTD_PARTITIONS
298+ struct mtd_partition *parts;
299+ int i;
300+#endif
301+
302+ spin_lock_irqsave(&sbh_lock, flags);
303+ coreidx = sb_coreidx(sbh);
304+
305+ /* Check strapping option if chipcommon exists */
306+ if ((cc = sb_setcore(sbh, SB_CC, 0))) {
307+ fltype = readl(&cc->capabilities) & CAP_FLASH_MASK;
308+ if (fltype == PFLASH) {
309+ bcm947xx_map.map_priv_2 = 1;
310+ window_addr = 0x1c000000;
311+ bcm947xx_map.size = window_size = 32 * 1024 * 1024;
312+ if ((readl(&cc->flash_config) & CC_CFG_DS) == 0)
313+ bcm947xx_map.buswidth = 1;
314+ }
315+ } else {
316+ fltype = PFLASH;
317+ bcm947xx_map.map_priv_2 = 0;
318+ window_addr = WINDOW_ADDR;
319+ window_size = WINDOW_SIZE;
320+ }
321+
322+ sb_setcoreidx(sbh, coreidx);
323+ spin_unlock_irqrestore(&sbh_lock, flags);
324+
325+ if (fltype != PFLASH) {
326+ ret = -ENODEV;
327+ goto fail;
328+ }
329+
330+ bcm947xx_map.map_priv_1 = (unsigned long) ioremap(window_addr, window_size);
331+
332+ if (!bcm947xx_map.map_priv_1) {
333+ printk(KERN_ERR "Failed to ioremap\n");
334+ return -EIO;
335+ }
336+
337+ if (!(bcm947xx_mtd = do_map_probe("cfi_probe", &bcm947xx_map))) {
338+ printk(KERN_ERR "pflash: cfi_probe failed\n");
339+ iounmap((void *)bcm947xx_map.map_priv_1);
340+ return -ENXIO;
341+ }
342+
343+ bcm947xx_mtd->module = THIS_MODULE;
344+
345+ size = bcm947xx_mtd->size;
346+
347+ printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", size, window_addr);
348+
349+#ifdef CONFIG_MTD_PARTITIONS
350+ parts = init_mtd_partitions(bcm947xx_mtd, size);
351+ for (i = 0; parts[i].name; i++);
352+ ret = add_mtd_partitions(bcm947xx_mtd, parts, i);
353+ if (ret) {
354+ printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
355+ goto fail;
356+ }
357+#endif
358+
359+ return 0;
360+
361+ fail:
362+ if (bcm947xx_mtd)
363+ map_destroy(bcm947xx_mtd);
364+ if (bcm947xx_map.map_priv_1)
365+ iounmap((void *) bcm947xx_map.map_priv_1);
366+ bcm947xx_map.map_priv_1 = 0;
367+ return ret;
368+}
369+
370+mod_exit_t cleanup_bcm947xx_map(void)
371+{
372+#ifdef CONFIG_MTD_PARTITIONS
373+ del_mtd_partitions(bcm947xx_mtd);
374+#endif
375+ map_destroy(bcm947xx_mtd);
376+ iounmap((void *) bcm947xx_map.map_priv_1);
377+ bcm947xx_map.map_priv_1 = 0;
378+}
379+
380+module_init(init_bcm947xx_map);
381+module_exit(cleanup_bcm947xx_map);
Note: See TracBrowser for help on using the repository browser.