From 84148e467d72cc11997f31503b1215c04dedab33 Mon Sep 17 00:00:00 2001 From: nbd Date: Tue, 17 Jul 2012 11:35:29 -0400 Subject: [PATCH 093/123] 408-mtd-redboot_partition_scan Import of the above patch from openwrt trunk, as of this commit: ---------- commit c1d79f64eed0a7ac36b5b9bca52275b397bec424 Author: nbd Date: Mon Jul 16 16:26:51 2012 +0000 uboot-ar71xx: fix compile on recent mac os x versions git-svn-id: svn://svn.openwrt.org/openwrt/trunk@32750 3c298f89-4303-0410-b956-a3cf2f4a3e73 ---------- Path to patch in the repo is: target/linux/ar71xx/patches-3.3 Repo is: git://nbd.name/openwrt.git Signed-off-by: Paul Gortmaker --- drivers/mtd/redboot.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c index 68a289b..eebeb05 100644 --- a/drivers/mtd/redboot.c +++ b/drivers/mtd/redboot.c @@ -79,12 +79,18 @@ static int parse_redboot_partitions(struct mtd_info *master, static char nullstring[] = "unallocated"; #endif + buf = vmalloc(master->erasesize); + if (!buf) + return -ENOMEM; + + restart: if ( directory < 0 ) { offset = master->size + directory * master->erasesize; while (mtd_block_isbad(master, offset)) { if (!offset) { nogood: printk(KERN_NOTICE "Failed to find a non-bad block to check for RedBoot partition table\n"); + vfree(buf); return -EIO; } offset -= master->erasesize; @@ -97,10 +103,6 @@ static int parse_redboot_partitions(struct mtd_info *master, goto nogood; } } - buf = vmalloc(master->erasesize); - - if (!buf) - return -ENOMEM; printk(KERN_NOTICE "Searching for RedBoot partition table in %s at offset 0x%lx\n", master->name, offset); @@ -173,6 +175,11 @@ static int parse_redboot_partitions(struct mtd_info *master, } if (i == numslots) { /* Didn't find it */ + if (offset + master->erasesize < master->size) { + /* not at the end of the flash yet, maybe next block :) */ + directory++; + goto restart; + } printk(KERN_NOTICE "No RedBoot partition table detected in %s\n", master->name); ret = 0; -- 1.7.9.7