public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/2] fix detection of redboot fis partition table
@ 2004-10-29 13:50 Ian Campbell
  2004-11-22 11:08 ` David Woodhouse
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Campbell @ 2004-10-29 13:50 UTC (permalink / raw)
  To: linux-mtd

I think I sent this via our regular mail-server (that adds legal rubbish
to the bottom of mails) the first time so it won't get through to the
list. Apologies if it comes through twice.

Hi all,

The redboot partitioning code currently searches for a FIS table entry
named "RedBoot" (including the trailing \0) in one of the first three
entries to try and verify that the sector it is looking at really is a
FIS partition table.

Firstly it fails when RedBoot is stored in some other Flash chip such as
a boot PROM, in this case there is no "RedBoot" entry in the partition
table. However there will always be a "FIS directory" entry in any valid
FIS directory.
        
Secondly it can fail since the RedBoot entry is not always in the first
3 slots -- this can happen for example on an x86 based platform where
the processor expects the boot device to be at the top of memory rather
than the bottom and so RedBoot is at the end of the flash device.
Equally when using "FIS directory" as the entry to search for it very
likely is not in the first three since the directory is typically at the
end of the flash.

The patch (against BK) below sorts these out. Is it OK to commit to MTD
CVS and then send to Linus?

Ian.

%patch
Index: 2.6-bk/drivers/mtd/redboot.c
===================================================================
--- 2.6-bk.orig/drivers/mtd/redboot.c	2004-09-15 11:00:22.000000000 +0100
+++ 2.6-bk/drivers/mtd/redboot.c	2004-10-29 14:21:33.018453911 +0100
@@ -50,6 +50,7 @@
 	char *nullname;
 	int namelen = 0;
 	int nulllen = 0;
+	int numslots;
 #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
 	static char nullstring[] = "unallocated";
 #endif
@@ -71,12 +72,16 @@
 		goto out;
 	}
 
-	/* RedBoot image could appear in any of the first three slots */
-	for (i = 0; i < 3; i++) {
-		if (!memcmp(buf[i].name, "RedBoot", 8))
+	numslots = (master->erasesize / sizeof(struct fis_image_desc));
+	for (i = 0; i < numslots; i++) {
+		if (buf[i].name[0] == 0xff) {
+			i = numslots;
+			break;
+		}
+		if (!memcmp(buf[i].name, "FIS directory", 14))
 			break;
 	}
-	if (i == 3) {
+	if (i == numslots) {
 		/* Didn't find it */
 		printk(KERN_NOTICE "No RedBoot partition table detected in %s\n",
 		       master->name);
@@ -84,7 +89,7 @@
 		goto out;
 	}
 
-	for (i = 0; i < master->erasesize / sizeof(struct fis_image_desc); i++) {
+	for (i = 0; i < numslots; i++) {
 		struct fis_list *new_fl, **prev;
 
 		if (buf[i].name[0] == 0xff)



-- 
Ian Campbell, Senior Design Engineer
                                        Web: http://www.arcom.com
Arcom, Clifton Road, 			Direct: +44 (0)1223 403 465
Cambridge CB1 7EA, United Kingdom	Phone:  +44 (0)1223 411 200
-- 
Ian Campbell, Senior Design Engineer
                                        Web: http://www.arcom.com
Arcom, Clifton Road, 			Direct: +44 (0)1223 403 465
Cambridge CB1 7EA, United Kingdom	Phone:  +44 (0)1223 411 200

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] fix detection of redboot fis partition table
  2004-10-29 13:50 [PATCH 1/2] fix detection of redboot fis partition table Ian Campbell
@ 2004-11-22 11:08 ` David Woodhouse
  2004-11-22 11:40   ` Ian Campbell
  0 siblings, 1 reply; 4+ messages in thread
From: David Woodhouse @ 2004-11-22 11:08 UTC (permalink / raw)
  To: Ian Campbell; +Cc: linux-mtd

On Fri, 2004-10-29 at 14:50 +0100, Ian Campbell wrote:
> The patch (against BK) below sorts these out. Is it OK to commit to MTD
> CVS and then send to Linus?

Please commit them. I'll put them in the BK tree for pulling after
2.6.10 is released.

-- 
dwmw2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] fix detection of redboot fis partition table
  2004-11-22 11:08 ` David Woodhouse
@ 2004-11-22 11:40   ` Ian Campbell
  2004-11-22 11:42     ` David Woodhouse
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Campbell @ 2004-11-22 11:40 UTC (permalink / raw)
  To: David Woodhouse; +Cc: linux-mtd

On Mon, 2004-11-22 at 11:08 +0000, David Woodhouse wrote:
> On Fri, 2004-10-29 at 14:50 +0100, Ian Campbell wrote:
> > The patch (against BK) below sorts these out. Is it OK to commit to MTD
> > CVS and then send to Linus?
> 
> Please commit them. I'll put them in the BK tree for pulling after
> 2.6.10 is released.

Done. 

Would you object to my updating the sbc_gxx.c map driver as well? It has
gotten rather out of sync with the code we are currently running. 

The patch is pretty huge but I've attached it anyway... It adds support
for the SRAM device and updates the partitioning code, I think I also
lindented it at some point in the last couple of years as well.

Ian.

--- 2.6.orig/drivers/mtd/maps/sbc_gxx.c	2004-11-02 15:15:41.968615497 +0000
+++ 2.6/drivers/mtd/maps/sbc_gxx.c	2004-11-02 15:17:46.294907093 +0000
@@ -1,50 +1,47 @@
-/* sbc_gxx.c -- MTD map driver for Arcom Control Systems SBC-MediaGX,
-                SBC-GXm and SBC-GX1 series boards.
- 
-   Copyright (C) 2001 Arcom Control System Ltd
- 
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
- 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
- 
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-
-   $Id: sbc_gxx.c,v 1.32 2004/11/16 18:29:02 dwmw2 Exp $
-
-The SBC-MediaGX / SBC-GXx has up to 16 MiB of 
-Intel StrataFlash (28F320/28F640) in x8 mode.  
-
-This driver uses the CFI probe and Intel Extended Command Set drivers.
-
-The flash is accessed as follows:
-
-   16 KiB memory window at 0xdc000-0xdffff
-   
-   Two IO address locations for paging
-   
-   0x258
-       bit 0-7: address bit 14-21
-   0x259
-       bit 0-1: address bit 22-23
-       bit 7:   0 - reset/powered down
-                1 - device enabled
-
-The single flash device is divided into 3 partition which appear as 
-separate MTD devices.
-
-25/04/2001 AJL (Arcom)  Modified signon strings and partition sizes
-                        (to support bzImages up to 638KiB-ish)
-*/
-
-// Includes
+/* sbc_gxx.c -- MTD map driver for Arcom Control Systems SBC-GXx boards.
+ * 
+ *   Copyright (C) 2001-2004 Arcom Control System Ltd
+ * 
+ *   This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ * 
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ *  $Id: sbc_gxx.c,v 1.32 2004/11/16 18:29:02 dwmw2 Exp $
+ */
+
+/*
+ * The SBC-MediaGX / SBC-GXx has up to 16 MiB of 
+ * Intel StrataFlash (28F320/28F640) in x8 mode.  
+ *
+ * This driver uses the CFI probe and Intel Extended Command Set drivers.
+ *
+ * The flash is accessed as follows:
+ *
+ *   16 KiB memory window at 0xdc000-0xdffff
+ *
+ *   Two IO address locations for paging
+ *   
+ *   0x258
+ *       bit 0-7: address bit 14-21
+ *   0x259
+ *       bit 0-1: address bit 22-23
+ *       bit 6:   0 - select Flash
+ *                1 - select SRAM
+ *       bit 7:   0 - reset/powered down
+ *                1 - device enabled
+ *
+ * 
+ */
 
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -56,10 +53,7 @@
 #include <linux/mtd/map.h>
 #include <linux/mtd/partitions.h>
 
-// Defines
-
-// - Hardware specific
-
+/* location of flash memory window */
 #define WINDOW_START 0xdc000
 
 /* Number of bits in offset. */
@@ -73,66 +67,74 @@
 
 /* bit 7 of 0x259 must be 1 to enable device. */
 #define DEVICE_ENABLE 0x8000
+/* bit 6 of 0x259 must be 1 to select SRAM. */
+#define SELECT_SRAM 0x4000
 
-// - Flash / Partition sizing
-
-#define MAX_SIZE_KiB             16384
-#define BOOT_PARTITION_SIZE_KiB  768
-#define DATA_PARTITION_SIZE_KiB  1280
-#define APP_PARTITION_SIZE_KiB   6144
-
-// Globals
+#define SBC_GXX_FLASH 0
+#define SBC_GXX_SRAM  1
 
-static volatile int page_in_window = -1; // Current page in window.
+static volatile int page_in_window = -1;
 static void __iomem *iomapadr;
 static spinlock_t sbc_gxx_spin = SPIN_LOCK_UNLOCKED;
 
+#ifdef CONFIG_MTD_PARTITIONS
+static struct mtd_partition *mtd_parts;
+static int mtd_parts_nb;
+#endif
+
 /* partition_info gives details on the logical partitions that the split the 
  * single flash device into. If the size if zero we use up to the end of the
  * device. */
-static struct mtd_partition partition_info[]={
-    { .name = "SBC-GXx flash boot partition", 
-      .offset = 0, 
-      .size =   BOOT_PARTITION_SIZE_KiB*1024 },
-    { .name = "SBC-GXx flash data partition", 
-      .offset = BOOT_PARTITION_SIZE_KiB*1024, 
-      .size = (DATA_PARTITION_SIZE_KiB)*1024 },
-    { .name = "SBC-GXx flash application partition", 
-      .offset = (BOOT_PARTITION_SIZE_KiB+DATA_PARTITION_SIZE_KiB)*1024 }
+static struct mtd_partition partition_info[] = {
+	{
+		.name = "boot",
+		.offset = 0,
+		.size = 768 * 1024
+	},
+	{
+		.name = "filesystem",
+		.offset = 768 * 1024,
+		.size = 0
+	},
 };
 
-#define NUM_PARTITIONS 3
+const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
+
+#define NUM_PARTITIONS  (sizeof(partition_info)/sizeof(struct mtd_partition))
 
-static inline void sbc_gxx_page(struct map_info *map, unsigned long ofs)
+static inline void sbc_gxx_page(struct map_info *map, unsigned long ofs,
+				int sram)
 {
 	unsigned long page = ofs >> WINDOW_SHIFT;
 
-	if( page!=page_in_window ) {
-		outw( page | DEVICE_ENABLE, PAGE_IO );
+	if (page != page_in_window) {
+		if (sram == SBC_GXX_SRAM)
+			page |= SELECT_SRAM;
+		outw(page | DEVICE_ENABLE, PAGE_IO);
 		page_in_window = page;
 	}
 }
 
-
-static map_word sbc_gxx_read8(struct map_info *map, unsigned long ofs)
+static map_word sbc_gxx_read(struct map_info *map, unsigned long ofs)
 {
 	map_word ret;
 	spin_lock(&sbc_gxx_spin);
-	sbc_gxx_page(map, ofs);
+	sbc_gxx_page(map, ofs, map->map_priv_2);
 	ret.x[0] = readb(iomapadr + (ofs & WINDOW_MASK));
 	spin_unlock(&sbc_gxx_spin);
 	return ret;
 }
 
-static void sbc_gxx_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
+static void sbc_gxx_copy_from(struct map_info *map, void *to,
+			      unsigned long from, ssize_t len)
 {
-	while(len) {
+	while (len) {
 		unsigned long thislen = len;
 		if (len > (WINDOW_LENGTH - (from & WINDOW_MASK)))
-			thislen = WINDOW_LENGTH-(from & WINDOW_MASK);
-		
+			thislen = WINDOW_LENGTH - (from & WINDOW_MASK);
+
 		spin_lock(&sbc_gxx_spin);
-		sbc_gxx_page(map, from);
+		sbc_gxx_page(map, from, map->map_priv_2);
 		memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen);
 		spin_unlock(&sbc_gxx_spin);
 		to += thislen;
@@ -141,23 +143,24 @@
 	}
 }
 
-static void sbc_gxx_write8(struct map_info *map, map_word d, unsigned long adr)
+static void sbc_gxx_write(struct map_info *map, map_word d, unsigned long adr)
 {
 	spin_lock(&sbc_gxx_spin);
-	sbc_gxx_page(map, adr);
+	sbc_gxx_page(map, adr, map->map_priv_2);
 	writeb(d.x[0], iomapadr + (adr & WINDOW_MASK));
 	spin_unlock(&sbc_gxx_spin);
 }
 
-static void sbc_gxx_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
-{	
-	while(len) {
+static void sbc_gxx_copy_to(struct map_info *map, unsigned long to,
+			    const void *from, ssize_t len)
+{
+	while (len) {
 		unsigned long thislen = len;
 		if (len > (WINDOW_LENGTH - (to & WINDOW_MASK)))
-			thislen = WINDOW_LENGTH-(to & WINDOW_MASK);
-		
+			thislen = WINDOW_LENGTH - (to & WINDOW_MASK);
+
 		spin_lock(&sbc_gxx_spin);
-		sbc_gxx_page(map, to);
+		sbc_gxx_page(map, to, map->map_priv_2);
 		memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen);
 		spin_unlock(&sbc_gxx_spin);
 		to += thislen;
@@ -166,69 +169,120 @@
 	}
 }
 
-static struct map_info sbc_gxx_map = {
-	.name = "SBC-GXx flash",
-	.phys = NO_XIP,
-	.size = MAX_SIZE_KiB*1024, /* this must be set to a maximum possible amount
-			 of flash so the cfi probe routines find all
-			 the chips */
-	.bankwidth = 1,
-	.read = sbc_gxx_read8,
-	.copy_from = sbc_gxx_copy_from,
-	.write = sbc_gxx_write8,
-	.copy_to = sbc_gxx_copy_to
+static struct map_info flash_map = {
+	.name 		= "flash",
+	.phys		= NO_XIP,
+	.size		= 16 * 1024 * 1024,
+	.map_priv_2	= SBC_GXX_FLASH,
+	
+	.bankwidth	= 1,
+	.read		= sbc_gxx_read,
+	.copy_from	= sbc_gxx_copy_from,
+	.write		= sbc_gxx_write,
+	.copy_to	= sbc_gxx_copy_to,
 };
 
-/* MTD device for all of the flash. */
-static struct mtd_info *all_mtd;
-
-static void cleanup_sbc_gxx(void)
-{
-	if( all_mtd ) {
-		del_mtd_partitions( all_mtd );
-		map_destroy( all_mtd );
-	}
+static struct map_info sram_map = {
+	.name		= "sram",
+	.phys		= NO_XIP,
+	.size		= 128 * 1024,
+	.map_priv_2	= SBC_GXX_SRAM,
+
+	.bankwidth	= 1,
+	.read		= sbc_gxx_read,
+	.copy_from	= sbc_gxx_copy_from,
+	.write		= sbc_gxx_write,
+	.copy_to	= sbc_gxx_copy_to,
+};
 
-	iounmap((void *)iomapadr);
-	release_region(PAGE_IO,PAGE_IO_SIZE);
-}
+static struct mtd_info *flash_mtd;
+static struct mtd_info *sram_mtd;
 
 static int __init init_sbc_gxx(void)
 {
-  	iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH);
+	int ret = -EIO;
+
+	iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH);
 	if (!iomapadr) {
-		printk( KERN_ERR"%s: failed to ioremap memory region\n",
-			sbc_gxx_map.name );
-		return -EIO;
+		printk(KERN_ERR "sbc-gxx: failed to ioremap memory region\n");
+		goto out;
 	}
-	
-	if (!request_region( PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) {
-		printk( KERN_ERR"%s: IO ports 0x%x-0x%x in use\n",
-			sbc_gxx_map.name,
-			PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1 );
-		iounmap((void *)iomapadr);
-		return -EAGAIN;
+
+	if (!request_region(PAGE_IO, PAGE_IO_SIZE, "SBC-GXx flash")) {
+		printk(KERN_ERR "sbc-gxx: I/O ports 0x%x-0x%x in use\n",
+		       PAGE_IO, PAGE_IO + PAGE_IO_SIZE - 1);
+		goto out_unmap;
 	}
-		
-	
-	printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n",
-		sbc_gxx_map.name,
-		PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1,
-		WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 );
+
+	printk(KERN_INFO "sbc-gxx: Flash/SRAM driver IO:0x%x-0x%x MEM:0x%x-0x%x\n",
+	       PAGE_IO, PAGE_IO + PAGE_IO_SIZE - 1, WINDOW_START,
+	       WINDOW_START + WINDOW_LENGTH - 1);
 
 	/* Probe for chip. */
-	all_mtd = do_map_probe( "cfi_probe", &sbc_gxx_map );
-	if( !all_mtd ) {
-		cleanup_sbc_gxx();
-		return -ENXIO;
+	flash_mtd = do_map_probe("cfi_probe", &flash_map);
+	if (!flash_mtd) {
+		ret = -ENXIO;
+		goto out_unio;
 	}
-	
-	all_mtd->owner = THIS_MODULE;
+	flash_mtd->owner = THIS_MODULE;
 
-	/* Create MTD devices for each partition. */
-	add_mtd_partitions(all_mtd, partition_info, NUM_PARTITIONS );
+#ifdef CONFIG_MTD_PARTITIONS
+	mtd_parts_nb = parse_mtd_partitions(flash_mtd, part_probes, &mtd_parts, 0);
+	if (mtd_parts_nb > 0) {
+		add_mtd_partitions(flash_mtd, mtd_parts, mtd_parts_nb);
+	} else if (NUM_PARTITIONS != 0) {
+		printk(KERN_NOTICE "sbc-gxx: using static partition definition\n");
+		add_mtd_partitions(flash_mtd, partition_info, NUM_PARTITIONS);
+	} else
+#endif
+	{
+		add_mtd_device(flash_mtd);
+	}
+	
+	sram_mtd = do_map_probe("map_ram", &sram_map);
+	if (sram_mtd) {
+		sram_mtd->owner = THIS_MODULE;
+		add_mtd_device(sram_mtd);
+	} else {
+		/* Most SBC-GX1s have no SRAM fitted, so ignore them */
+		printk(KERN_INFO "sbc-gxx: No SRAM Found.\n");
+	}
 
 	return 0;
+
+ out_unio:
+	release_region(PAGE_IO, PAGE_IO_SIZE);
+ out_unmap:
+	iounmap(iomapadr);
+	iomapadr = NULL;
+ out:
+	return ret;
+}
+
+static void __exit cleanup_sbc_gxx(void)
+{
+#ifdef CONFIG_MTD_PARTITIONS
+	if (mtd_parts_nb) {
+		del_mtd_partitions(flash_mtd);
+		kfree(mtd_parts);
+	} else if (NUM_PARTITIONS != 0) {
+		del_mtd_partitions(flash_mtd);
+	} else
+#endif
+	{
+		del_mtd_device(flash_mtd);
+	}
+
+	if (sram_mtd) {
+		map_destroy(sram_mtd);
+		sram_mtd = NULL;
+	}
+
+	if (iomapadr)
+		iounmap(iomapadr);
+
+	iomapadr = NULL;
+	release_region(PAGE_IO, PAGE_IO_SIZE);
 }
 
 module_init(init_sbc_gxx);
@@ -236,4 +290,4 @@
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Arcom Control Systems Ltd.");
-MODULE_DESCRIPTION("MTD map driver for SBC-GXm and SBC-GX1 series boards");
+MODULE_DESCRIPTION("MTD map driver for SBC-GXx series boards");

-- 
Ian Campbell, Senior Design Engineer
                                        Web: http://www.arcom.com
Arcom, Clifton Road,                    Direct: +44 (0)1223 403 465
Cambridge CB1 7EA, United Kingdom       Phone:  +44 (0)1223 411 200

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] fix detection of redboot fis partition table
  2004-11-22 11:40   ` Ian Campbell
@ 2004-11-22 11:42     ` David Woodhouse
  0 siblings, 0 replies; 4+ messages in thread
From: David Woodhouse @ 2004-11-22 11:42 UTC (permalink / raw)
  To: Ian Campbell; +Cc: linux-mtd

On Mon, 2004-11-22 at 11:40 +0000, Ian Campbell wrote:
> On Mon, 2004-11-22 at 11:08 +0000, David Woodhouse wrote:
> > On Fri, 2004-10-29 at 14:50 +0100, Ian Campbell wrote:
> > > The patch (against BK) below sorts these out. Is it OK to commit to MTD
> > > CVS and then send to Linus?
> > 
> > Please commit them. I'll put them in the BK tree for pulling after
> > 2.6.10 is released.
> 
> Done. 
> 
> Would you object to my updating the sbc_gxx.c map driver as well? It has
> gotten rather out of sync with the code we are currently running. 
> 
> The patch is pretty huge but I've attached it anyway... It adds support
> for the SRAM device and updates the partitioning code, I think I also
> lindented it at some point in the last couple of years as well.

Go for it.

-- 
dwmw2

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-11-22 11:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-29 13:50 [PATCH 1/2] fix detection of redboot fis partition table Ian Campbell
2004-11-22 11:08 ` David Woodhouse
2004-11-22 11:40   ` Ian Campbell
2004-11-22 11:42     ` David Woodhouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox