public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: andrzej.mialkowski@inetia.pl
To: "linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>
Subject: [PATCH] parse_redboot_partitions not always works correctly
Date: Mon, 27 Oct 2003 16:25:57 +0100	[thread overview]
Message-ID: <1067268357.3f9d3905c3fc9@imail.internetia.pl> (raw)

[-- Attachment #1: Type: text/plain, Size: 1514 bytes --]

Hi,
 I just found that redboot_parse_partitions on my system (IXDP2801) builds 
incorrect list of partitions, base addresses of some partitions are wrong. I 
located a problem in following line in redboot.c:
		buf[i].flash_base &= master->size-1;
This line tries to relocate partition base address to be 0 based, by cutting 
off some high order bits. This expression works correctly if two assumptions 
are true:
 1) master->size should be power of 2
 2) base address must be aligned to map size
Unfortunately on my board both are false: I have 10 flash chips, and base 
address is not aligned to size even after number of chips align to 16 (because 
of banking).

On different platforms I sow different use of flash base address. Some platforms
are using 0 based addresses in redboot some other physical address of flash 
chip (my case). As far as I know base address used for building partition 
entries is not stored.

The most portable method that I found is use "FIS directory" entry for guessing 
value of flash base used during building partitions. Assumption here is simple:
FIS directory is located in known place at MTD level, in last erase block of 
map. Subtracting flash base address stored in this entry with actual location 
at map driver offset level should give base address used during creating 
partition table.
Of course all partition entries must be created with the same flash base 
address.
Did anybody have better idea? Patch attached.
Thanks in advance for comments.

	Andrzej Mialkowski


[-- Attachment #2: mtd-redboot-parse.patch --]
[-- Type: text/plain, Size: 1701 bytes --]

diff -Nru prev/drivers/mtd/redboot.c linux/drivers/mtd/redboot.c
--- prev/drivers/mtd/redboot.c	Fri Mar 14 16:30:08 2003
+++ linux/drivers/mtd/redboot.c	Mon Oct 27 14:53:17 2003
@@ -44,6 +44,7 @@
 	size_t retlen;
 	char *names;
 	int namelen = 0;
+	unsigned flash_base = 0;
 
 	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
 
@@ -64,8 +65,12 @@
 
 	/* RedBoot image could appear in any of the first three slots */
 	for (i = 0; i < 3; i++) {
-		if (!memcmp(buf[i].name, "RedBoot", 8))
+		if (!memcmp(buf[i].name, "RedBoot", 8)) {
+			/* Legacy way of detecting flash base */
+			/* Use RedBoot to be sure that we are using valid entry */ 
+			flash_base = buf[i].flash_base & (master->size - 1);
 			break;
+		}
 	}
 	if (i == 3) {
 		/* Didn't find it */
@@ -75,6 +80,22 @@
 		goto out;
 	}
 
+	/* 
+	 * Legacy way of detecting flash base does not work in two cases:
+	 * 1) When map size (number of chips) is not equal power of 2
+	 * 2) When flash base is not aligned to map size
+	 */
+	/* Look for FIS directory in entire read area */	
+	for (i = 0; i < PAGE_SIZE / sizeof(struct fis_image_desc); i++) {
+		if (!memcmp(buf[i].name, "FIS directory", sizeof("FIS directory"))) {
+			flash_base = buf[i].flash_base - (master->size - master->erasesize);
+			break;
+		}
+	}
+	printk(KERN_DEBUG "RedBoot partition base 0x%08X\n",
+		       flash_base);
+
+
 	for (i = 0; i < PAGE_SIZE / sizeof(struct fis_image_desc); i++) {
 		struct fis_list *new_fl, **prev;
 
@@ -90,7 +111,7 @@
 			goto out;
 		}
 		new_fl->img = &buf[i];
-		buf[i].flash_base &= master->size-1;
+		buf[i].flash_base -= flash_base;
 
 		/* I'm sure the JFFS2 code has done me permanent damage.
 		 * I now think the following is _normal_

             reply	other threads:[~2003-10-27 15:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-27 15:25 andrzej.mialkowski [this message]
2003-11-06 21:21 ` [PATCH] parse_redboot_partitions not always works correctly andrzej.mialkowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1067268357.3f9d3905c3fc9@imail.internetia.pl \
    --to=andrzej.mialkowski@inetia.pl \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox