* [PATCH] parse_redboot_partitions not always works correctly
@ 2003-10-27 15:25 andrzej.mialkowski
2003-11-06 21:21 ` andrzej.mialkowski
0 siblings, 1 reply; 2+ messages in thread
From: andrzej.mialkowski @ 2003-10-27 15:25 UTC (permalink / raw)
To: linux-mtd
[-- 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_
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] parse_redboot_partitions not always works correctly
2003-10-27 15:25 [PATCH] parse_redboot_partitions not always works correctly andrzej.mialkowski
@ 2003-11-06 21:21 ` andrzej.mialkowski
0 siblings, 0 replies; 2+ messages in thread
From: andrzej.mialkowski @ 2003-11-06 21:21 UTC (permalink / raw)
To: andrzej.mialkowski; +Cc: linux-mtd
Single char autocorrection of address calculation in legacy mode (not used in
regular cases).
- flash_base = buf[i].flash_base & (master->size - 1);
+ flash_base = buf[i].flash_base & ~(master->size - 1);
Andrzej
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-11-06 21:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-27 15:25 [PATCH] parse_redboot_partitions not always works correctly andrzej.mialkowski
2003-11-06 21:21 ` andrzej.mialkowski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.