+ if (page_is_4KiB) {
+ pagesize = 4096; /* OneNAND has 4KiB pagesize */
+ erase_shift = 18;
+ } else {
+ pagesize = 2048; /* OneNAND has 2KiB pagesize */
+ erase_shift = 17;
+ }
+
+ 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;