All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] Fix OneNAND ipl to read CONFIG_SYS_MONITOR_LEN
@ 2009-03-23  9:02 apgmoorthy
  2009-03-23 21:25 ` Scott Wood
  0 siblings, 1 reply; 20+ messages in thread
From: apgmoorthy @ 2009-03-23  9:02 UTC (permalink / raw)
  To: u-boot

Hi Scott, 

>> +	if (page < 2 && (onenand_readw(THIS_ONENAND(ONENAND_SPARERAM)) != 0xffff))

 >Line length.

     - Corrected.
      
>>  	int pagesize = ONENAND_PAGE_SIZE;
>> +	int nblocks = CONFIG_SYS_MONITOR_LEN / ONENAND_BLOCK_SIZE;

 >Shouldn't nblocks be rounded up?

>>  		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;

       - Right , But the above line dosent give the nblocks ,
         used erasesize and erase_shift.


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

        - Removed it.

>> +	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?

       - Correct , have reverted back.

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

       - Corrected , Now onenand_readw/onenand_writew conatins THIS_ONENAND.

Please do find the updated patch below.

With Regards
  Moorthy


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.

Signed-off-by: Gangheyamoorthy   <moorthy.apg@samsung.com>
Signed-off-by: Rohit Hagargundgi <h.rohit@samsung.com>
---
 
diff --git a/onenand_ipl/onenand_boot.c b/onenand_ipl/onenand_boot.c
index 86428cc..63995ce 100644
--- a/onenand_ipl/onenand_boot.c
+++ b/onenand_ipl/onenand_boot.c
@@ -36,7 +36,7 @@ void start_oneboot(void)
 
 	buf = (uchar *) CONFIG_SYS_LOAD_ADDR;
 
-	onenand_read_block0(buf);
+	onenand_read_block(buf);
 
 	((init_fnc_t *)CONFIG_SYS_LOAD_ADDR)();
 
diff --git a/onenand_ipl/onenand_ipl.h b/onenand_ipl/onenand_ipl.h
index c5a722d..412572a 100644
--- a/onenand_ipl/onenand_ipl.h
+++ b/onenand_ipl/onenand_ipl.h
@@ -31,5 +31,5 @@
 #define READ_INTERRUPT()                                                \
 	onenand_readw(THIS_ONENAND(ONENAND_REG_INTERRUPT))
 
-extern int onenand_read_block0(unsigned char *buf);
+extern int onenand_read_block(unsigned char *buf);
 #endif
diff --git a/onenand_ipl/onenand_read.c b/onenand_ipl/onenand_read.c
index 6d04943..7415c7f 100644
--- a/onenand_ipl/onenand_read.c
+++ b/onenand_ipl/onenand_read.c
@@ -49,20 +49,20 @@ static inline int onenand_read_page(ulong block, ulong page,
 #endif
 
 	onenand_writew(onenand_block_address(block),
-		THIS_ONENAND(ONENAND_REG_START_ADDRESS1));
+			ONENAND_REG_START_ADDRESS1);
 
 	onenand_writew(onenand_bufferram_address(block),
-		THIS_ONENAND(ONENAND_REG_START_ADDRESS2));
+			ONENAND_REG_START_ADDRESS2);
 
 	onenand_writew(onenand_sector_address(page),
-		THIS_ONENAND(ONENAND_REG_START_ADDRESS8));
+			ONENAND_REG_START_ADDRESS8);
 
 	onenand_writew(onenand_buffer_address(),
-		THIS_ONENAND(ONENAND_REG_START_BUFFER));
+			ONENAND_REG_START_BUFFER);
 
-	onenand_writew(ONENAND_INT_CLEAR, THIS_ONENAND(ONENAND_REG_INTERRUPT));
+	onenand_writew(ONENAND_INT_CLEAR, ONENAND_REG_INTERRUPT);
 
-	onenand_writew(ONENAND_CMD_READ, THIS_ONENAND(ONENAND_REG_COMMAND));
+	onenand_writew(ONENAND_CMD_READ, ONENAND_REG_COMMAND);
 
 #ifndef __HAVE_ARCH_MEMCPY32
 	p = (unsigned long *) buf;
@@ -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(ONENAND_SPARERAM) != 0xffff))
+		return 1;
+
 #ifdef __HAVE_ARCH_MEMCPY32
 	/* 32 bytes boundary memory copy */
 	memcpy32(buf, base, pagesize);
@@ -89,25 +93,39 @@ static inline int onenand_read_page(ulong block, ulong page,
 #define ONENAND_PAGES_PER_BLOCK		64
 
 /**
- * onenand_read_block - Read a block data to buf
+ * onenand_read_block - Read First 'n' consecutive Good blocks holding 
+ *                      data to buf
  * @return 0 on success
  */
-int onenand_read_block0(unsigned char *buf)
+int onenand_read_block(unsigned char *buf)
 {
-	int page, offset = 0;
-	int pagesize = ONENAND_PAGE_SIZE;
-
-	/* MLC OneNAND has 4KiB page size */
-	if (onenand_readw(THIS_ONENAND(ONENAND_REG_TECHNOLOGY)))
-		pagesize <<= 1;
+	int block = 0, page = ONENAND_START_PAGE, offset = 0;
+	int pagesize = 0, erase_shift =0;
+	int erasesize = 0, nblocks = 0;
+
+	if(onenand_readw(ONENAND_REG_TECHNOLOGY)) {
+		pagesize = 4096; /* MLC OneNAND has 4KiB pagesize */
+		erase_shift = 18;
+	} else {
+		pagesize = 2048;
+		erase_shift = 17;
+	}
+	erasesize = ONENAND_PAGES_PER_BLOCK * pagesize;
+	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 (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 */
+	 			offset -= page * pagesize;
+				nblocks++;
+				break;
+			}
+			offset += pagesize;
+		}
+		page = 0;
 	}
 
 	return 0;

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2009-04-28 23:11 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-23  9:02 [U-Boot] [PATCH 1/2] Fix OneNAND ipl to read CONFIG_SYS_MONITOR_LEN apgmoorthy
2009-03-23 21:25 ` Scott Wood
2009-03-23 22:09   ` Wolfgang Denk
2009-03-23 22:22     ` Scott Wood
2009-03-23 22:46       ` Wolfgang Denk
2009-03-25  4:13         ` Amit Kumar Sharma
2009-03-25 15:49   ` apgmoorthy
2009-03-27  9:15   ` apgmoorthy
2009-03-30 22:33     ` Scott Wood
2009-03-31  4:12       ` Amit Kumar Sharma
2009-04-12  7:55       ` apgmoorthy
2009-04-23 22:39         ` Scott Wood
2009-04-24  5:05           ` Amit Kumar Sharma
2009-04-13 13:04       ` [U-Boot] [PATCH] Bad Block Capable environment for OneNAND apgmoorthy
2009-04-28 23:11         ` Scott Wood
2009-03-31 16:08     ` [U-Boot] [PATCH 1/2] Fix OneNAND ipl to read CONFIG_SYS_MONITOR_LEN Alessandro Rubini
2009-03-31 16:13       ` Scott Wood
2009-04-01  4:10         ` Amit Kumar Sharma
2009-04-01 21:55           ` Scott Wood
2009-04-06  6:05   ` [U-Boot] OneNand support broken for apollon apgmoorthy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.