Skip to contentSkip to conversation

Fix OneNAND ipl to read 256KB

PATCH New Rohit Hagargundgi 5 participants 14 messages Feb 26, 2009 – Mar 9, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

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

---
  onenand_ipl/onenand_ipl.h  |    1 +
  onenand_ipl/onenand_read.c |   29 +++++++++++++++++++++--------
  2 files changed, 22 insertions(+), 8 deletions(-)
onenand_ipl/onenand_ipl.h +1 -0
index 3387998..f96e88a 100644
@@ -24,6 +24,7 @@
  #include <linux/mtd/onenand_regs.h>
 
  #define ONENAND_BLOCK_SIZE              2048
+#define ONENAND_BOOTLOADER_SIZE		0x40000
 
  #ifndef CONFIG_SYS_PRINTF
  #define printf(format, args...)
onenand_ipl/onenand_read.c +21 -8
index 6d04943..33c66ff 100644
@@ -72,6 +72,13 @@ 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) {
+		unsigned int mark = onenand_readw(THIS_ONENAND(ONENAND_SPARERAM));
+		if (mark != 0xffff)
+			return 1;
+	}
+
  #ifdef __HAVE_ARCH_MEMCPY32
  	/* 32 bytes boundary memory copy */
  	memcpy32(buf, base, pagesize);
@@ -94,21 +101,27 @@ 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, offset = 0;
  	int pagesize = ONENAND_PAGE_SIZE;
+	int nblocks = ONENAND_BOOTLOADER_SIZE / (ONENAND_PAGES_PER_BLOCK * ONENAND_PAGE_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 >>= 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 (page = ONENAND_START_PAGE; block < nblocks; page = 0, 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;
+		}
 
  	return 0;
  }
Signature · 1 line
1.6.0.6
#1 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

Quoted 16 lines · Rohit Hagargundgi

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

---
  onenand_ipl/onenand_ipl.h  |    1 +
  onenand_ipl/onenand_read.c |   29 +++++++++++++++++++++--------
  2 files changed, 22 insertions(+), 8 deletions(-)
onenand_ipl/onenand_ipl.h +0 -0
index 3387998..f96e88a 100644

onenand_ipl/onenand_ipl.h line 27

Quoted 4 lines
onenand_ipl/onenand_ipl.h +1 -0
@@ -24,6 +24,7 @@
  #include <linux/mtd/onenand_regs.h>
 
  #define ONENAND_BLOCK_SIZE              2048
+#define ONENAND_BOOTLOADER_SIZE		0x40000

why hardcoded value?

Quoted 8 lines
onenand_ipl/onenand_ipl.h +0 -0
  #ifndef CONFIG_SYS_PRINTF
  #define printf(format, args...)
onenand_ipl/onenand_read.c +0 -0
index 6d04943..33c66ff 100644

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

Quoted 6 lines
onenand_ipl/onenand_read.c +3 -0
@@ -72,6 +72,13 @@ 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) {
+		unsigned int mark = onenand_readw(THIS_ONENAND(ONENAND_SPARERAM));

please add a empty line

and why not do this

	if (page < 2 && (onenand_readw(THIS_ONENAND(ONENAND_SPARERAM)) != 0xffff))
		return 1;
Quoted 22 lines
onenand_ipl/onenand_read.c +9 -2
+		if (mark != 0xffff)
+			return 1;
+	}
+
  #ifdef __HAVE_ARCH_MEMCPY32
  	/* 32 bytes boundary memory copy */
  	memcpy32(buf, base, pagesize);
@@ -94,21 +101,27 @@ 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, offset = 0;
  	int pagesize = ONENAND_PAGE_SIZE;
+	int nblocks = ONENAND_BOOTLOADER_SIZE / (ONENAND_PAGES_PER_BLOCK * ONENAND_PAGE_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 >>= 1;
+	}

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

Quoted 10 lines
onenand_ipl/onenand_read.c +1 -6
 
  	/* 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 (page = ONENAND_START_PAGE; block < nblocks; page = 0, block++)

please add the {} and move the page = 0 to the second 'for' it will be easier to read and understand

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

Quoted 8 lines
onenand_ipl/onenand_read.c +8 -0
+		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;
+		}

Best Regards,
J.

#2 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

Hi,

Quoted 3 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 2 lines

#define ONENAND_BLOCK_SIZE 2048
+#define ONENAND_BOOTLOADER_SIZE 0x40000

why hardcoded value?

Is it possible to get image size instead of hard value. Then we can read exactly u-boot image size on boot up.

Quoted 8 lines

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

Quoted 3 lines
onenand_ipl/onenand_read.c +3 -0
+	/* Check for invalid block mark*/
+	if (page < 2) {
+		unsigned int mark = onenand_readw(THIS_ONENAND(ONENAND_SPARERAM));

please add a empty line

and why not do this

	if (page < 2 && (onenand_readw(THIS_ONENAND(ONENAND_SPARERAM)) != 0xffff))
		return 1;

okay.

Quoted 9 lines

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

Quoted 7 lines
onenand_ipl/onenand_read.c +1 -6
-	for (page = ONENAND_START_PAGE;
-	    page < ONENAND_PAGES_PER_BLOCK; page++) {
-
-		onenand_read_page(0, page, buf + offset, pagesize);
-		offset += pagesize;
-	}
+	for (page = ONENAND_START_PAGE; block < nblocks; page = 0, block++)

please add the {} and move the page = 0 to the second 'for' it will be easier to read and understand

okay.

Thanks,
Rohit

#3 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

Quoted 9 lines · Rohit Hagargundgi

Hi,

Quoted 3 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 2 lines

#define ONENAND_BLOCK_SIZE 2048
+#define ONENAND_BOOTLOADER_SIZE 0x40000

why hardcoded value?

Is it possible to get image size instead of hard value. Then we can read exactly u-boot image size on boot up.

as point out Wolfgang you can use the MONITOR_LEN.

If you really need the u-boot.bin size you will need to built it first and then on the host calculate it and genereate a .h with its size.

But IMHO the MONITOR_LEN will give enough information evenif it's not the real size to copy u-boot in memory

Best Regards,
J.

#4 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

In reply to Rohit Hagargundgi

Dear Rohit Hagargundgi,

Quoted 8 lines · In message <[email protected]> you wrote:
Quoted 3 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 2 lines

#define ONENAND_BLOCK_SIZE 2048
+#define ONENAND_BOOTLOADER_SIZE 0x40000

why hardcoded value?

Is it possible to get image size instead of hard value. Then we can read exactly u-boot image size on boot up.

Use CONFIG_SYS_MONITOR_LEN as I suggested in my previous message.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The philosophy exam was a piece of cake  -  which  was  a  bit  of  a
surprise, actually, because I was expecting some questions on a sheet
of paper.
#5 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

In reply to Rohit Hagargundgi

Dear Rohit Hagargundgi,

Quoted 4 lines · In message <[email protected]> you wrote:

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

What if there is a board that enables additional features and the size grows above 256 kB?

Quoted 4 lines
  #include <linux/mtd/onenand_regs.h>

#define ONENAND_BLOCK_SIZE 2048
+#define ONENAND_BOOTLOADER_SIZE 0x40000

Why do we need a new #define here. CONFIG_SYS_MONITOR_LEN already contains the U-Boot image size, and is configurable for each board.

Please drop this #define here and substitute ONENAND_BOOTLOADER_SIZE by CONFIG_SYS_MONITOR_LEN in the rest of the patch.

Thanks.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It's not an optical illusion, it just looks like one.   -- Phil White
#6 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

Hi,

In the previous mail, I also solve this issue. multi-block read for IPL

http://www.mail-archive.com/u-boot at lists.denx.de/msg04641.html

Of course, it's not consider the Flex-OneNAND, please apply this one first and then fix it for Flex-OneNAND.

How do you think?

Thank you,
Kyungmin Park

Quoted 38 lines · Wolfgang Denk

Dear Rohit Hagargundgi,

Quoted 4 lines · In message <[email protected]> you wrote:

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

What if there is a board that enables additional features and the size grows above 256 kB?

Quoted 4 lines

? #include <linux/mtd/onenand_regs.h>

? #define ONENAND_BLOCK_SIZE ? ? ? ? ? ? ?2048 +#define ONENAND_BOOTLOADER_SIZE ? ? ? ? ? ? ?0x40000

Why do we need a new #define here. CONFIG_SYS_MONITOR_LEN already contains the U-Boot image size, and is configurable for each board.

Please drop this #define here and substitute ONENAND_BOOTLOADER_SIZE by CONFIG_SYS_MONITOR_LEN in the rest of the patch.

Thanks.

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de It's not an optical illusion, it just looks like one. ? -- Phil White
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#7 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

Hi,

Quoted 5 lines · Kyungmin Park

Hi,

In the previous mail, I also solve this issue. multi-block read for IPL

http://www.mail-archive.com/u-boot at lists.denx.de/msg04641.html

oh, okay. So this merge first.

To Scott, Wolfgang - can you please apply this patch.

Also environment block is affected by larger ipl size. I will repost as per comments.

Thanks and regards,
Rohit

#8 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

Hi,

Here is the updated patch.

Thanks,
Rohit

---
  include/configs/apollon.h  |    1 +
  onenand_ipl/onenand_read.c |   27 ++++++++++++++++++++-------
  2 files changed, 21 insertions(+), 7 deletions(-)
include/configs/apollon.h +1 -0
index dff47fc..2e8198f 100644
@@ -254,6 +254,7 @@
 
  /* OneNAND boot, OneNAND has CS0, NOR boot ONeNAND has CS2 */
  #define	CONFIG_SYS_ONENAND_BASE	0x00000000
+#define CONFIG_SYS_MONITOR_LEN		SZ_256K	/* U-Boot image size */
  #define	CONFIG_ENV_IS_IN_ONENAND	1
  #define CONFIG_ENV_ADDR		0x00020000
 
onenand_ipl/onenand_read.c +20 -7
index 6d04943..6782eac 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);
@@ -94,20 +98,29 @@ 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, offset = 0;
  	int pagesize = ONENAND_PAGE_SIZE;
+	int nblocks = CONFIG_SYS_MONITOR_LEN / (ONENAND_PAGES_PER_BLOCK * ONENAND_PAGE_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;
+	page = ONENAND_START_PAGE;
+	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;
Signature · 1 line
1.6.0.6
#9 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

Quoted 30 lines · Rohit Hagargundgi

Hi,

Here is the updated patch.

Thanks,
Rohit

---
?include/configs/apollon.h ?| ? ?1 + ?onenand_ipl/onenand_read.c | ? 27 ++++++++++++++++++++------- ?2 files changed, 21 insertions(+), 7 deletions(-)

include/configs/apollon.h +0 -0
index dff47fc..2e8198f 100644
@@ -254,6 +254,7 @@
 

?/* OneNAND boot, OneNAND has CS0, NOR boot ONeNAND has CS2 */ ?#define ? ? ? CONFIG_SYS_ONENAND_BASE 0x00000000
+#define CONFIG_SYS_MONITOR_LEN ? ? ? ? SZ_256K /* U-Boot image size */ ?#define ? ? ? CONFIG_ENV_IS_IN_ONENAND ? ? ? ?1
?#define CONFIG_ENV_ADDR ? ? ? ? ? ? ? 0x00020000

onenand_ipl/onenand_read.c +0 -0
index 6d04943..6782eac 100644

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

Quoted 7 lines
onenand_ipl/onenand_read.c +4 -0
@@ -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;
+

No need to check invalid block. Note that block 0 is always good block. no exception.
Now you assume block 1 can be invalid block. If true just skip it. when update bootloader at u-boot or kernel.
there's bad block at block 1. it will skip write. it means bootloader are located at block 0 and block 2.

Quoted 39 lines

?#ifdef __HAVE_ARCH_MEMCPY32
? ? ? ?/* 32 bytes boundary memory copy */
? ? ? ?memcpy32(buf, base, pagesize);

onenand_ipl/onenand_read.c +0 -0
@@ -94,20 +98,29 @@ 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, offset = 0;
? ? ? ?int pagesize = ONENAND_PAGE_SIZE;
+ ? ? ? int nblocks = CONFIG_SYS_MONITOR_LEN / (ONENAND_PAGES_PER_BLOCK * ONENAND_PAGE_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;
+ ? ? ? page = ONENAND_START_PAGE;
+ ? ? ? 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;
? ? ? ?}

Quoted 1 line

? ? ? ?return 0;

NAK, please use previous one as I sent.
In Flex-OneNAND block 0 has 256KiB. need to handle at here how many blocks are needed.
I also want to use CONFIG_ONENAND_END_BLOCK since we don't know which OneNAND or Flex-OneNAND are attached to apollon board.

Thank you,
Kyungmin Park

#10 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

Hi,

Quoted 8 lines · Kyungmin Park

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

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

No need to check invalid block. Note that block 0 is always good block. no exception.

Correct. block 0 is guaranteed to be good.

Quoted 4 lines

Now you assume block 1 can be invalid block. If true just skip it. when update bootloader at u-boot or kernel.
there's bad block at block 1. it will skip write. it means bootloader are located at block 0 and block 2.

yes, block 1 is invalid so block 0 and block 2 store bootloader. so in ipl, we need to check invalid mark. block 1 is detected bad. block 1 is skipped and block 2 is read for bootloader.

Quoted 8 lines

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

Quoted 8 lines
onenand_ipl/onenand_read.c +4 -1
+       int nblocks = CONFIG_SYS_MONITOR_LEN / (ONENAND_PAGES_PER_BLOCK * ONENAND_PAGE_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;
+       }

assuming page size of 2KB, nblocks is initialised to 2. for 4KB paged devices (like Flex-OneNAND), nblocks gets halved ie 1.

Quoted 21 lines
Quoted 21 lines
       /* NOTE: you must read page from page 1 of block 0 */
       /* read the block page by page*/
onenand_ipl/onenand_read.c +11 -5
-       for (page = ONENAND_START_PAGE;
-           page < ONENAND_PAGES_PER_BLOCK; page++) {
-
-               onenand_read_page(0, page, buf + offset, pagesize);
-               offset += pagesize;
+       page = ONENAND_START_PAGE;
+       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;
       }
Quoted 5 lines
Quoted 1 line
       return 0;

NAK, please use previous one as I sent.
In Flex-OneNAND block 0 has 256KiB. need to handle at here how many blocks are needed.

this is taken care above.

Quoted 2 lines

I also want to use CONFIG_ONENAND_END_BLOCK since we don't know which OneNAND or Flex-OneNAND are attached to apollon board.

okay. but why not use a variable instead.

Thanks,
Rohit

#11 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

In reply to Rohit Hagargundgi

Dear Rohit Hagargundgi,

Quoted 6 lines · In message <[email protected]> you wrote:

Hi,

Here is the updated patch.

Thanks,
Rohit

This is not an acceptable commit message.

Please include a reasonable commit message that explains what you are doinbg and why.

Quoted 2 lines

---

Comments must go below this "---" line, not above.

Quoted 9 lines
  include/configs/apollon.h  |    1 +
  onenand_ipl/onenand_read.c |   27 ++++++++++++++++++++-------
  2 files changed, 21 insertions(+), 7 deletions(-)
include/configs/apollon.h +0 -0
index dff47fc..2e8198f 100644

include/configs/apollon.h line 259

Quoted 6 lines
include/configs/apollon.h +1 -0
@@ -254,6 +254,7 @@
 
  /* OneNAND boot, OneNAND has CS0, NOR boot ONeNAND has CS2 */
  #define	CONFIG_SYS_ONENAND_BASE	0x00000000
+#define CONFIG_SYS_MONITOR_LEN		SZ_256K	/* U-Boot image size */
  #define	CONFIG_ENV_IS_IN_ONENAND	1
  #define CONFIG_ENV_ADDR		0x00020000

Your patch is white-space corrupted. Please fix your mailer settings.

include/configs/apollon.h

Quoted 4 lines
include/configs/apollon.h +0 -0
  int onenand_read_block0(unsigned char *buf)
  {
include/configs/apollon.h +1 -1
-	int page, offset = 0;
+	int block = 0, page, offset = 0;

Please don;t mix uninitialized and initialized variables on one line.

include/configs/apollon.h

Quoted 2 lines
  	int pagesize = ONENAND_PAGE_SIZE;
include/configs/apollon.h +1 -0
+	int nblocks = CONFIG_SYS_MONITOR_LEN / (ONENAND_PAGES_PER_BLOCK * ONENAND_PAGE_SIZE);

Line too long.

include/configs/apollon.h

Quoted 2 lines
include/configs/apollon.h +2 -0
+	page = ONENAND_START_PAGE;
+	for (; block < nblocks; block++) {

-----------------------^^^^^^^^

include/configs/apollon.h

Quoted 4 lines
include/configs/apollon.h +4 -0
+		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++;

--------------------------------^^^^^^^^^^

include/configs/apollon.h

Quoted 5 lines
include/configs/apollon.h +5 -0
+				break;
+			}
+			offset += pagesize;
+		}
+		page = 0;

I always consider it a design problem when the loop limits get changed within the loop. While legal C, it always gives me the creeps.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Politics:  A  strife  of  interests  masquerading  as  a  contest  of
principles. The conduct of public affairs for private advantage.
- Ambrose Bierce
#12 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

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

---
 include/configs/apollon.h  |    1 +
 onenand_ipl/onenand_read.c |   27 ++++++++++++++++++++-------
 2 files changed, 21 insertions(+), 7 deletions(-)
include/configs/apollon.h +1 -0
index dff47fc..2e8198f 100644
@@ -254,6 +254,7 @@
 
 /* OneNAND boot, OneNAND has CS0, NOR boot ONeNAND has CS2 */
 #define	CONFIG_SYS_ONENAND_BASE	0x00000000
+#define CONFIG_SYS_MONITOR_LEN		SZ_256K	/* U-Boot image size */
 #define	CONFIG_ENV_IS_IN_ONENAND	1
 #define CONFIG_ENV_ADDR		0x00020000
 
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;
#13 lore raw

PATCH 1/1 Fix OneNAND ipl to read 256KB

Dear Rohit Hagargundgi,

Quoted 4 lines · In message <[email protected]> you wrote:

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

NAK.

The description is wrong:

The code was not changed to read 256 KB (fixed), but to read whetever there is defined by the CONFIG_SYS_MONITOR_LEN definition.

Please change the commit messages accordingly.

Also, please split this into two separate patches: the first to implement the feature (changes to onenand_ipl/onenand_read.c), and a second one to fix the apollon board (changes to include/configs/apollon.h).

Thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
All a hacker needs is a tight PUSHJ, a loose pair of UUOs, and a warm
place to shift.