Skip to contentSkip to conversation

ECC in Nand_write_page

DISCUSSION Steve Tsai 4 participants 6 messages Jul 11, 2002 – Jul 12, 2002 Memory technology devices (MTD)

lore
Share & tools
lore

Steve Tsai

author
#0 lore raw

The board I used will display the message, "nand_write_ecc: Failed ECC write", so I try to trace the function nand_write_ecc, I found it can not write the ECC code into OOB sometime because the ECC in OOB are not set as 0xff. There are two conditions to cause the problem, one condition is the erase does not success, another condition is that the page was written before. Nand_write_page could write partial page to the flash. Does it cause the ECC in OOB was written and ECC can not be written next time. For example, nand_write_page write 100 byte the first time and if it want to write 412 bytes to the same page next time, it will fail. Does anyone have this problem?

Steve Tsai

#1 lore raw
Quoted 10 lines · Steve Tsai

The board I used will display the message, "nand_write_ecc: Failed ECC write", so I try to trace the function nand_write_ecc, I found it can not write the ECC code into OOB sometime because the ECC in OOB are not set as 0xff. There are two conditions to cause the problem, one condition is the erase does not success, another condition is that the page was written before. Nand_write_page could write partial page to the flash. Does it cause the ECC in OOB was written and ECC can not be written next time. For example, nand_write_page write 100 byte the first time and if it want to write 412 bytes to the same page next time, it will fail. Does anyone have this problem?

I have read that some NAND memory devices can read partial pages but must write full pages. Could this be your problem? In such cases you might have to read the page, make a write to part of the page and then write out the modified full page.

+-----------------------------------------------------------+
|  Ken Offer        [email protected]         ARL:UT  |
|  Office: 512-835-3859                  Fax: 512-835-3259  |
+-----------------------------------------------------------+
author
#2 lore raw

I don't think nand_write_page can write partial page, if someone enable ECC. For example, when I write the partial page to the page 100, it will write ECC code into the page also, but when I write the other data to the empty area of the same page, I can write data into the empty area of the page, but I can not write the ECC code, because the area storing ECC code was written at the previous time.

Steve Tsai

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ken Offer
Sent: Thursday, July 11, 2002 9:25 PM
To: Steve Tsai
Cc: LinuxMTD
Subject: Re: ECC in Nand_write_page

Quoted 7 lines · Steve Tsai

The board I used will display the message, "nand_write_ecc: Failed ECC

write", so I try to trace the function nand_write_ecc, I found it can not write the ECC code into OOB sometime because the ECC in OOB are not set as 0xff. There are two conditions to cause the problem, one condition is the erase does not success, another condition is that the

Quoted 6 lines

page was written before. Nand_write_page could write partial page to the flash. Does it cause the ECC in OOB was written and ECC can not be

written next time. For example, nand_write_page write 100 byte the first time and if it want to write 412 bytes to the same page next time, it will fail. Does anyone have this problem?

I have read that some NAND memory devices can read partial pages but must write full pages. Could this be your problem? In such cases you might have to read the page, make a write to part of the page and then write out the modified full page.

+-----------------------------------------------------------+
|  Ken Offer        [email protected]         ARL:UT  |
|  Office: 512-835-3859                  Fax: 512-835-3259  |
+-----------------------------------------------------------+

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#4 lore raw
In reply to Steve Tsai
Quoted 10 lines · Steve Tsai

The board I used will display the message, "nand_write_ecc: Failed ECC write", so I try to trace the function nand_write_ecc, I found it can not write the ECC code into OOB sometime because the ECC in OOB are not set as 0xff. There are two conditions to cause the problem, one condition is the erase does not success, another condition is that the page was written before. Nand_write_page could write partial page to the flash. Does it cause the ECC in OOB was written and ECC can not be written next time. For example, nand_write_page write 100 byte the first time and if it want to write 412 bytes to the same page next time, it will fail. Does anyone have this problem?

Do you use latest CVS code ?
Which filesystem do you use ?
There's only JFFS2, which can handle the nand problem correct.

Read http://www.linux-mtd.infradead.org/tech/nand.html !

1. If an erase fails, the JFFS2 does not use this block.

2. JFFS2 writes only full pages

3. ECC is definitely not written, if you write 100 bytes

	/* Calculate and write the ECC if we have enough data */
	if ((col < mtd->eccsize) && (last >= mtd->eccsize)) {
		nand_calculate_ecc (&this->data_buf[0], &(ecc_code[0]));
		for (i = 0; i < 3; i++)
			this->data_buf[(mtd->oobblock + oob_config.ecc_pos[i])] = ecc_code[i];
		if (oob_config.eccvalid_pos != -1)
			this->data_buf[mtd->oobblock + oob_config.eccvalid_pos] = 0xf0;
	}

	/* Calculate and write the second ECC if we have enough data */
	if ((mtd->oobblock == 512) && (last == mtd->oobblock)) {
		nand_calculate_ecc (&this->data_buf[256], &(ecc_code[3]));
		for (i = 3; i < 6; i++)
			this->data_buf[(mtd->oobblock + oob_config.ecc_pos[i])] = ecc_code[i];
		if (oob_config.eccvalid_pos != -1)
			this->data_buf[mtd->oobblock + oob_config.eccvalid_pos] &= 0x0f;
	}
Signature · 5 lines
Thomas
___________________________________________
linutronix - competence in embedded & realtime linux
http://www.linutronix.de
mail: [email protected]
author
#5 lore raw

Hi,
I am using 20020619 and JFFS2 file system. I did not set the following option. Will it cause the error? Thanks.

CONFIG_MTD_NAND_ECC_JFFS2=y
CONFIG_JFFS2_FS_NAND=y

Steve Tsai

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Thomas Gleixner
Sent: Friday, July 12, 2002 2:12 PM
To: Steve Tsai; Linux MTD mailing list
Subject: Re: ECC in Nand_write_page

Quoted 7 lines · Steve Tsai

The board I used will display the message, "nand_write_ecc: Failed ECC

write", so I try to trace the function nand_write_ecc, I found it can not write the ECC code into OOB sometime because the ECC in OOB are not set as 0xff. There are two conditions to cause the problem, one condition is the erase does not success, another condition is that the

Quoted 6 lines

page was written before. Nand_write_page could write partial page to the flash. Does it cause the ECC in OOB was written and ECC can not be

written next time. For example, nand_write_page write 100 byte the first time and if it want to write 412 bytes to the same page next time, it will fail. Does anyone have this problem?

Do you use latest CVS code ?
Which filesystem do you use ?
There's only JFFS2, which can handle the nand problem correct.

Read http://www.linux-mtd.infradead.org/tech/nand.html !

1. If an erase fails, the JFFS2 does not use this block.

2. JFFS2 writes only full pages

3. ECC is definitely not written, if you write 100 bytes

	/* Calculate and write the ECC if we have enough data */
	if ((col < mtd->eccsize) && (last >= mtd->eccsize)) {
		nand_calculate_ecc (&this->data_buf[0], &(ecc_code[0]));
		for (i = 0; i < 3; i++)
			this->data_buf[(mtd->oobblock +
oob_config.ecc_pos[i])] = ecc_code[i];
		if (oob_config.eccvalid_pos != -1)
			this->data_buf[mtd->oobblock +
oob_config.eccvalid_pos] = 0xf0;
	}

	/* Calculate and write the second ECC if we have enough data */
	if ((mtd->oobblock == 512) && (last == mtd->oobblock)) {
		nand_calculate_ecc (&this->data_buf[256],
&(ecc_code[3]));
		for (i = 3; i < 6; i++)
			this->data_buf[(mtd->oobblock +
oob_config.ecc_pos[i])] = ecc_code[i];
		if (oob_config.eccvalid_pos != -1)
			this->data_buf[mtd->oobblock +
oob_config.eccvalid_pos] &= 0x0f;
	}
Signature · 9 lines
Thomas
___________________________________________
linutronix - competence in embedded & realtime linux
http://www.linutronix.de
mail: [email protected]

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#3 lore raw
In reply to Steve Tsai
Quoted 6 lines · Steve Tsai

I don't think nand_write_page can write partial page, if someone enable ECC. For example, when I write the partial page to the page 100, it will write ECC code into the page also, but when I write the other data to the empty area of the same page, I can write data into the empty area of the page, but I can not write the ECC code, because the area storing ECC code was written at the previous time.

You are right. I've had a similar problem with ECC flash lately - NOR flash, but the principle is the same. The ECC checksum is written to the flash. By writing the same page twice, the checksum would have to toggle some bits from 0 to 1, which is impossible for flash. Thus you have a constraint to write any given page but once between two erase cycles.

Joern