--- zzzz-none-000/linux-3.10.107/drivers/mtd/redboot.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/mtd/redboot.c 2021-02-04 17:41:59.000000000 +0000 @@ -76,12 +76,18 @@ 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; @@ -94,10 +100,6 @@ 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); @@ -170,6 +172,11 @@ } 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; @@ -265,14 +272,21 @@ #endif names += strlen(names)+1; -#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED if(fl->next && fl->img->flash_base + fl->img->size + master->erasesize <= fl->next->img->flash_base) { - i++; - parts[i].offset = parts[i-1].size + parts[i-1].offset; - parts[i].size = fl->next->img->flash_base - parts[i].offset; - parts[i].name = nullname; - } + if (!strcmp(parts[i].name, "rootfs")) { + parts[i].size = fl->next->img->flash_base; + parts[i].size &= ~(master->erasesize - 1); + parts[i].size -= parts[i].offset; +#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED + nrparts--; + } else { + i++; + parts[i].offset = parts[i-1].size + parts[i-1].offset; + parts[i].size = fl->next->img->flash_base - parts[i].offset; + parts[i].name = nullname; #endif + } + } tmp_fl = fl; fl = fl->next; kfree(tmp_fl); @@ -300,7 +314,8 @@ static int __init redboot_parser_init(void) { - return register_mtd_parser(&redboot_parser); + register_mtd_parser(&redboot_parser); + return 0; } static void __exit redboot_parser_exit(void)