add new flash map driver, some minor system code cleanup

SVN-Revision: 2564
This commit is contained in:
Waldemar Brodkorb 2005-11-29 01:37:34 +00:00
parent c789ee3f6b
commit 4dfc2c4cbc
2 changed files with 1260 additions and 233 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,7 @@
diff -Nur linux-2.6.12.5/drivers/mtd/maps/Kconfig linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig
--- linux-2.6.12.5/drivers/mtd/maps/Kconfig 2005-08-15 02:20:18.000000000 +0200
+++ linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig 2005-09-16 22:27:36.513533784 +0200
@@ -357,6 +357,12 @@
Mapping for the Flaga digital module. If you don't have one, ignore
this setting.
+config MTD_BCM47XX
+ tristate "BCM47xx flash device"
+ depends on MIPS && MTD_CFI && BCM947XX
+ help
+ Support for the flash chips on the BCM947xx board.
+
config MTD_BEECH
tristate "CFI Flash device mapped on IBM 405LP Beech"
depends on MTD_CFI && PPC32 && 40x && BEECH
diff -Nur linux-2.6.12.5/drivers/mtd/maps/Makefile linux-2.6.12.5-flash/drivers/mtd/maps/Makefile
--- linux-2.6.12.5/drivers/mtd/maps/Makefile 2005-08-15 02:20:18.000000000 +0200
+++ linux-2.6.12.5-flash/drivers/mtd/maps/Makefile 2005-09-16 22:27:01.110915800 +0200
@@ -31,6 +31,7 @@
obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
+obj-$(CONFIG_MTD_BCM47XX) += bcm47xx-flash.o
obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
obj-$(CONFIG_MTD_IPAQ) += ipaq-flash.o
obj-$(CONFIG_MTD_SBC_GXX) += sbc_gxx.o
diff -Nur linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c linux-2.6.12.5-flash/drivers/mtd/maps/bcm47xx-flash.c
--- linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.12.5-flash/drivers/mtd/maps/bcm47xx-flash.c 2005-09-16 22:26:41.470901536 +0200
@@ -0,0 +1,249 @@
+++ linux-2.6.12.5-flash/drivers/mtd/maps/bcm47xx-flash.c 2005-11-06 20:36:42.553198500 +0100
@@ -0,0 +1,329 @@
+/*
+ * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
+ * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
@ -63,7 +36,7 @@ diff -Nur linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c linux-2.6.12.5-flash/d
+ * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
+ *
+ * $Id$
+ * $Id: bcm47xx-flash.c,v 1.1 2004/10/21 07:18:31 jolt Exp $
+ *
+ * Flash mapping for BCM947XX boards
+ */
@ -82,13 +55,11 @@ diff -Nur linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c linux-2.6.12.5-flash/d
+#include <bcmnvram.h>
+#include <trxhdr.h>
+
+
+#ifdef CONFIG_MTD_PARTITIONS
+extern struct mtd_partition * init_mtd_partitions(struct mtd_info *mtd, size_t size);
+#endif
+
+#define CFE_SIZE 1024*384
+#define NVRAM_SIZE 1024*128
+
+#define WINDOW_ADDR 0x1c000000
+#define WINDOW_SIZE (0x400000*2)
+#define BUSWIDTH 2
@ -134,6 +105,47 @@ diff -Nur linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c linux-2.6.12.5-flash/d
+};
+
+static int __init
+find_cfe_size(struct mtd_info *mtd, size_t size)
+{
+ struct trx_header *trx;
+ unsigned char buf[512];
+ int off;
+ size_t len;
+ int cfe_size_flag;
+
+ trx = (struct trx_header *) buf;
+
+ cfe_size_flag=0;
+
+ for (off = (256*1024); off < size; off += mtd->erasesize) {
+ memset(buf, 0xe5, sizeof(buf));
+
+ /*
+ * Read into buffer
+ */
+ if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
+ len != sizeof(buf))
+ continue;
+
+ /* found a TRX header */
+ if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
+ goto done;
+ }
+ cfe_size_flag += 1;
+ }
+
+ printk(KERN_NOTICE
+ "%s: Couldn't find bootloader size\n",
+ mtd->name);
+ return -1;
+
+ done:
+ printk(KERN_NOTICE "bootloader size flag: %d\n", cfe_size_flag);
+ return cfe_size_flag;
+
+}
+
+static int __init
+find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
+{
+ struct trx_header *trx;
@ -179,34 +191,75 @@ diff -Nur linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c linux-2.6.12.5-flash/d
+init_mtd_partitions(struct mtd_info *mtd, size_t size)
+{
+
+ int cfe_size_flag;
+
+ cfe_size_flag = find_cfe_size(mtd,size);
+
+ /* if cfe_size_flag=0, cfe size is 256 kb, else 384 kb */
+
+ /* boot loader */
+ bcm947xx_parts[0].offset = 0;
+ bcm947xx_parts[0].size = CFE_SIZE;
+ if (cfe_size_flag == 0) {
+ bcm947xx_parts[0].size = 1024*256;
+ } else {
+ /* netgear wgt634u has 384 kb bootloader */
+ bcm947xx_parts[0].size = 1024*384;
+ }
+
+ /* nvram (old config partition) */
+ /* nvram */
+ if (cfe_size_flag == 0) {
+ bcm947xx_parts[3].offset = size - mtd->erasesize;
+ bcm947xx_parts[3].size = mtd->erasesize;
+ } else {
+ /* nvram (old 128kb config partition on netgear wgt634u) */
+ bcm947xx_parts[3].offset = bcm947xx_parts[0].size;
+ bcm947xx_parts[3].size = NVRAM_SIZE;
+ bcm947xx_parts[3].size = 1024*128;
+ }
+
+ /* Size linux (kernel and rootfs) */
+ /* linux (kernel and rootfs) */
+ if (cfe_size_flag == 0) {
+ bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
+ bcm947xx_parts[1].size = bcm947xx_parts[3].offset -
+ bcm947xx_parts[1].offset;
+ } else {
+ /* do not count the elf loader, which is on one sector */
+ bcm947xx_parts[1].offset = bcm947xx_parts[0].size + bcm947xx_parts[3].size + mtd->erasesize;
+ bcm947xx_parts[1].size = size - NVRAM_SIZE - bcm947xx_parts[0].size -
+ bcm947xx_parts[3].size - mtd->erasesize;
+ bcm947xx_parts[1].offset = bcm947xx_parts[0].size +
+ bcm947xx_parts[3].size + mtd->erasesize;
+ bcm947xx_parts[1].size = size -
+ bcm947xx_parts[0].size -
+ (2*bcm947xx_parts[3].size) -
+ mtd->erasesize;
+ }
+
+ /* Find and size rootfs */
+ /* find and size rootfs */
+ if (find_root(mtd,size,&bcm947xx_parts[2])==0) {
+ /* entirely jffs2 */
+ bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset - NVRAM_SIZE;
+ bcm947xx_parts[4].name = NULL;
+ if (cfe_size_flag == 0) {
+ bcm947xx_parts[2].size = bcm947xx_parts[3].offset -
+ bcm947xx_parts[2].offset;
+ } else {
+ bcm947xx_parts[2].size = size - bcm947xx_parts[2].offset -
+ bcm947xx_parts[3].size;
+ }
+ } else {
+ /* legacy setup */
+ /* calculate leftover flash, and assign it to the jffs2 partition */
+ bcm947xx_parts[4].offset = bcm947xx_parts[2].offset + bcm947xx_parts[2].size;
+ if (cfe_size_flag == 0) {
+ bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
+ bcm947xx_parts[2].size;
+ bcm947xx_parts[4].size = bcm947xx_parts[3].offset -
+ bcm947xx_parts[4].offset;
+ } else {
+ bcm947xx_parts[4].offset = bcm947xx_parts[2].offset +
+ bcm947xx_parts[2].size;
+ if ((bcm947xx_parts[4].offset % mtd->erasesize) > 0) {
+ bcm947xx_parts[4].offset += mtd->erasesize -
+ (bcm947xx_parts[4].offset % mtd->erasesize);
+ }
+ bcm947xx_parts[4].size = size - NVRAM_SIZE - bcm947xx_parts[4].offset;
+ bcm947xx_parts[4].size = size - bcm947xx_parts[3].size -
+ bcm947xx_parts[4].offset;
+ }
+ }
+
+ return bcm947xx_parts;
@ -278,3 +331,30 @@ diff -Nur linux-2.6.12.5/drivers/mtd/maps/bcm47xx-flash.c linux-2.6.12.5-flash/d
+
+module_init(init_bcm947xx_map);
+module_exit(cleanup_bcm947xx_map);
diff -Nur linux-2.6.12.5/drivers/mtd/maps/Kconfig linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig
--- linux-2.6.12.5/drivers/mtd/maps/Kconfig 2005-08-15 02:20:18.000000000 +0200
+++ linux-2.6.12.5-flash/drivers/mtd/maps/Kconfig 2005-09-16 22:27:36.000000000 +0200
@@ -357,6 +357,12 @@
Mapping for the Flaga digital module. If you don't have one, ignore
this setting.
+config MTD_BCM47XX
+ tristate "BCM47xx flash device"
+ depends on MIPS && MTD_CFI && BCM947XX
+ help
+ Support for the flash chips on the BCM947xx board.
+
config MTD_BEECH
tristate "CFI Flash device mapped on IBM 405LP Beech"
depends on MTD_CFI && PPC32 && 40x && BEECH
diff -Nur linux-2.6.12.5/drivers/mtd/maps/Makefile linux-2.6.12.5-flash/drivers/mtd/maps/Makefile
--- linux-2.6.12.5/drivers/mtd/maps/Makefile 2005-08-15 02:20:18.000000000 +0200
+++ linux-2.6.12.5-flash/drivers/mtd/maps/Makefile 2005-09-16 22:27:01.000000000 +0200
@@ -31,6 +31,7 @@
obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
+obj-$(CONFIG_MTD_BCM47XX) += bcm47xx-flash.o
obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
obj-$(CONFIG_MTD_IPAQ) += ipaq-flash.o
obj-$(CONFIG_MTD_SBC_GXX) += sbc_gxx.o