From a24b24783cc1b889136b3ba26e2a1bf29029a0f7 Mon Sep 17 00:00:00 2001 From: juhosg Date: Sun, 28 Mar 2010 07:16:27 +0000 Subject: package/mtd: fix automatic partition size detection in fis_remap git-svn-id: svn://svn.openwrt.org/openwrt/trunk@20537 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/mtd/src/fis.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'package/mtd/src/fis.c') diff --git a/package/mtd/src/fis.c b/package/mtd/src/fis.c index 3108c5a9e..b285d24db 100644 --- a/package/mtd/src/fis.c +++ b/package/mtd/src/fis.c @@ -146,7 +146,7 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new) struct fis_image_desc *desc; struct fis_part *part; uint32_t offset = 0, size = 0; - char *end, *tmp; + char *start, *end, *tmp; int i; desc = fis_open(); @@ -156,6 +156,7 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new) if (!quiet) fprintf(stderr, "Updating FIS table... \n"); + start = (char *) desc; end = (char *) desc + fis_erasesize; while ((char *) desc < end) { if (!desc->hdr.name[0] || (desc->hdr.name[0] == 0xff)) @@ -167,9 +168,12 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new) if (!strcmp((char *) desc->hdr.name, "RedBoot")) redboot = desc; + /* update max offset */ + if (offset < desc->hdr.flash_base) + offset = desc->hdr.flash_base; + for (i = 0; i < n_old; i++) { if (!strncmp((char *) desc->hdr.name, (char *) old[i].name, sizeof(desc->hdr.name))) { - size += desc->hdr.size; last = desc; if (!first) first = desc; @@ -180,13 +184,21 @@ fis_remap(struct fis_part *old, int n_old, struct fis_part *new, int n_new) } desc--; - if (desc == last) { - desc = fisdir; + /* determine size of available space */ + desc = (struct fis_image_desc *) start; + while ((char *) desc < end) { + if (!desc->hdr.name[0] || (desc->hdr.name[0] == 0xff)) + break; + + if (desc->hdr.flash_base > last->hdr.flash_base && + desc->hdr.flash_base < offset) + offset = desc->hdr.flash_base; + + desc++; } + desc--; - /* size fixup */ - if (desc && (last->hdr.flash_base < desc->hdr.flash_base - last->hdr.size)) - size += (desc->hdr.flash_base - last->hdr.flash_base) - last->hdr.size; + size = offset - first->hdr.flash_base; #ifdef notyet desc = first - 1; -- cgit v1.2.3