Skip to contentSkip to conversation

Fix OneNAND ipl to read CONFIG_SYS_MONITOR_LEN

PATCH New Rohit Hagargundgi 2 participants 2 messages Mar 9, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Fix OneNAND ipl to read CONFIG_SYS_MONITOR_LEN

Currently OneNAND initial program loader (ipl) reads only block 0 ie 128KB. However, u-boot image for apollon board is 195KB making the board unbootable with OneNAND.

Fix ipl to read CONFIG_SYS_MONITOR_LEN. CONFIG_SYS_MONITOR_LEN macro holds the U-Boot image size.

---
 onenand_ipl/onenand_read.c |   27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
onenand_ipl/onenand_read.c +20 -7
index 6d04943..c3b63ed 100644
@@ -72,6 +72,10 @@ static inline int onenand_read_page(ulong block, ulong page,
 	while (!(READ_INTERRUPT() & ONENAND_INT_READ))
 		continue;
 
+	/* Check for invalid block mark*/
+	if (page < 2 && (onenand_readw(THIS_ONENAND(ONENAND_SPARERAM)) != 0xffff))
+		return 1;
+
 #ifdef __HAVE_ARCH_MEMCPY32
 	/* 32 bytes boundary memory copy */
 	memcpy32(buf, base, pagesize);
@@ -87,6 +91,7 @@ static inline int onenand_read_page(ulong block, ulong page,
 
 #define ONENAND_START_PAGE		1
 #define ONENAND_PAGES_PER_BLOCK		64
+#define ONENAND_BLOCK_SIZE	(ONENAND_PAGES_PER_BLOCK * ONENAND_PAGE_SIZE)
 
 /**
  * onenand_read_block - Read a block data to buf
@@ -94,20 +99,28 @@ static inline int onenand_read_page(ulong block, ulong page,
  */
 int onenand_read_block0(unsigned char *buf)
 {
-	int page, offset = 0;
+	int block = 0, page = ONENAND_START_PAGE, offset = 0;
 	int pagesize = ONENAND_PAGE_SIZE;
+	int nblocks = CONFIG_SYS_MONITOR_LEN / ONENAND_BLOCK_SIZE;
 
 	/* MLC OneNAND has 4KiB page size */
-	if (onenand_readw(THIS_ONENAND(ONENAND_REG_TECHNOLOGY)))
+	if (onenand_readw(THIS_ONENAND(ONENAND_REG_TECHNOLOGY))) {
 		pagesize <<= 1;
+		nblocks = (nblocks + 1) >> 1;
+	}
 
 	/* NOTE: you must read page from page 1 of block 0 */
 	/* read the block page by page*/
-	for (page = ONENAND_START_PAGE;
-	    page < ONENAND_PAGES_PER_BLOCK; page++) {
-
-		onenand_read_page(0, page, buf + offset, pagesize);
-		offset += pagesize;
+	for (; 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 */
+				nblocks++;
+				break;
+			}
+			offset += pagesize;
+		}
+		page = 0;
 	}
 
 	return 0;
#1 lore raw

PATCH 1/2 Fix OneNAND ipl to read CONFIG_SYS_MONITOR_LEN

onenand_ipl/onenand_read.c static inline int onenand_read_page(ulong block, ulong page, · line 77

Quoted 3 lines · Rohit Hagargundgi
onenand_ipl/onenand_read.c +3 -0
+	/* Check for invalid block mark*/
+	if (page < 2 && (onenand_readw(THIS_ONENAND(ONENAND_SPARERAM)) != 0xffff))
+		return 1;

Line length.

onenand_ipl/onenand_read.c static inline int onenand_read_page(ulong block, ulong page, · line 104

Quoted 4 lines
onenand_ipl/onenand_read.c +2 -1
-	int page, offset = 0;
+	int block = 0, page = ONENAND_START_PAGE, offset = 0;
 	int pagesize = ONENAND_PAGE_SIZE;
+	int nblocks = CONFIG_SYS_MONITOR_LEN / ONENAND_BLOCK_SIZE;

Shouldn't nblocks be rounded up?

onenand_ipl/onenand_read.c static inline int onenand_read_page(ulong block, ulong page, · line 110

Quoted 6 lines
onenand_ipl/onenand_read.c +3 -1
 	/* MLC OneNAND has 4KiB page size */
-	if (onenand_readw(THIS_ONENAND(ONENAND_REG_TECHNOLOGY)))
+	if (onenand_readw(THIS_ONENAND(ONENAND_REG_TECHNOLOGY))) {
 		pagesize <<= 1;
+		nblocks = (nblocks + 1) >> 1;
+	}

Hmm, might be clearer to just do this:

if (onenand_readw(THIS_ONENAND(ONENAND_REG_TECHNOLOGY))) {
	pagesize = 4096;
	pageshift = 12;
} else {
	pagesize = 2048;
	pageshift = 11;
}

nblocks = (CONFIG_SYS_MONITOR_LEN + pagesize - 1) >> pageshift;

ONENAND_PAGE_SIZE as a constant should go away since it's not always true.

Quoted 5 lines
onenand_ipl/onenand_read.c +0 -3
 	/* NOTE: you must read page from page 1 of block 0 */
 	/* read the block page by page*/
-	for (page = ONENAND_START_PAGE;
-	    page < ONENAND_PAGES_PER_BLOCK; page++) {
-

onenand_ipl/onenand_read.c static inline int onenand_read_page(ulong block, ulong page, · line 121

Quoted 10 lines
onenand_ipl/onenand_read.c +8 -2
-		onenand_read_page(0, page, buf + offset, pagesize);
-		offset += pagesize;
+	for (; 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 */
+				nblocks++;
+				break;
+			}
+			offset += pagesize;

If you find a bad block marker in the second page of a block, shouldn't you rewind offset to the beginning of the block?

BTW, if we're going to have "onenand_readw" and "onenand_writew" wrappers, can we make them useful by combining them with THIS_ONENAND?

-Scott