- onenand_read_page(0, page, buf + offset, pagesize);
- offset += pagesize;
+ erasesize = (1 << erase_shift);
+ nblocks = (CONFIG_SYS_MONITOR_LEN + erasesize - 1) >> erase_shift;
+
+ /* NOTE: you must read page from page 1 of block 0 */
+ /* read the block page by page */
+ for (block = 0; block < nblocks; block++) {
+ for (; page < ONENAND_PAGES_PER_BLOCK; page++) {
+ if (onenand_read_page(block, page, buf + offset,
+ pagesize)) {
+ /* This block is bad. Skip it
+ * and read next block */
+ offset -= page * pagesize;
+ nblocks++;
+ break;
+ }
+ offset += pagesize;
+ }
+ page = 0;