140-redboot_partition_scan.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --- a/drivers/mtd/redboot.c
  2. +++ b/drivers/mtd/redboot.c
  3. @@ -62,31 +62,32 @@ static int parse_redboot_partitions(stru
  4. static char nullstring[] = "unallocated";
  5. #endif
  6. + buf = vmalloc(master->erasesize);
  7. + if (!buf)
  8. + return -ENOMEM;
  9. +
  10. + restart:
  11. if ( directory < 0 ) {
  12. offset = master->size + directory * master->erasesize;
  13. - while (master->block_isbad &&
  14. + while (master->block_isbad &&
  15. master->block_isbad(master, offset)) {
  16. if (!offset) {
  17. nogood:
  18. printk(KERN_NOTICE "Failed to find a non-bad block to check for RedBoot partition table\n");
  19. + vfree(buf);
  20. return -EIO;
  21. }
  22. offset -= master->erasesize;
  23. }
  24. } else {
  25. offset = directory * master->erasesize;
  26. - while (master->block_isbad &&
  27. + while (master->block_isbad &&
  28. master->block_isbad(master, offset)) {
  29. offset += master->erasesize;
  30. if (offset == master->size)
  31. goto nogood;
  32. }
  33. }
  34. - buf = vmalloc(master->erasesize);
  35. -
  36. - if (!buf)
  37. - return -ENOMEM;
  38. -
  39. printk(KERN_NOTICE "Searching for RedBoot partition table in %s at offset 0x%lx\n",
  40. master->name, offset);
  41. @@ -158,6 +159,11 @@ static int parse_redboot_partitions(stru
  42. }
  43. if (i == numslots) {
  44. /* Didn't find it */
  45. + if (offset + master->erasesize < master->size) {
  46. + /* not at the end of the flash yet, maybe next block :) */
  47. + directory++;
  48. + goto restart;
  49. + }
  50. printk(KERN_NOTICE "No RedBoot partition table detected in %s\n",
  51. master->name);
  52. ret = 0;