NAND on DM355: Add 4-bit ECC support for large page NAND chips
Subsystems (5)
PATCH 2/2 NAND on DM355: Add 4-bit ECC support for large page NAND chips
From: Sneha Narnakaje <[email protected]>
This patch adds 4-bit ECC support for large page NAND chips using the new ECC mode NAND_ECC_HW_OOB_FIRST. The platform data from board-dm355-evm has been adjusted to use this mode.
The patches have been verified on DM355 device with 2K Micron devices using mtd-tests and JFFS2. Error correction upto 4-bits has also been verified using nandwrite/nanddump utilities.
Note: This patch is dependent on '[patch 2.6.30-rc1] NAND: minor davinci nand cleanup' and '[patch 2.6.30-rc1] NAND: davinci nand, 4-bit ECC for smallpage' from David Brownell:
http://lists.infradead.org/pipermail/linux-mtd/2009-April/025206.html
http://lists.infradead.org/pipermail/linux-mtd/2009-April/025207.html
--- arch/arm/mach-davinci/board-dm355-evm.c | 3 ++- drivers/mtd/nand/davinci_nand.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletions(-)
arch/arm/mach-davinci/board-dm355-evm.c +2 -1
@@ -85,8 +85,9 @@ static struct davinci_nand_pdata davinci_nand_data = { .mask_chipsel = BIT(14), .parts = davinci_nand_partitions, .nr_parts = ARRAY_SIZE(davinci_nand_partitions), - .ecc_mode = NAND_ECC_HW_SYNDROME, + .ecc_mode = NAND_ECC_HW, .options = NAND_USE_FLASH_BBT, + .ecc_bits = 4, };static struct resource davinci_nand_resources[] = {
drivers/mtd/nand/davinci_nand.c +22 -0
@@ -500,6 +500,21 @@ static struct nand_ecclayout hwecc4_small __initconst = { }, }; +/* An ECC layout for using 4-bit ECC with large-page (2048bytes) flash, +* storing ten ECC bytes plus the manufacturer's bad block marker byte, +* and not overlapping the default BBT markers. +*/ +static struct nand_ecclayout hwecc4_2048__initconst = { + .eccbytes =10 , + .eccpos = {0 ,1 ,2 ,3 ,4 ,6 ,7 ,8 ,9 ,10 , +11 ,12 ,13 ,14 ,15 ,24 ,25 ,26 ,27 ,28 , +29 ,30 ,31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 , +39 ,40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 ,48 , }, + .oobfree = { + {.offset =16 , .length =8 , }, + {.offset =49 , }, + }, +};static int __init nand_davinci_probe (struct platform_device *pdev) {
@@ -690,6 +705,13 @@ static int __init nand_davinci_probe(struct platform_device *pdev) info->mtd.oobsize -16 ; goto syndrome_done; } +if (chunks ==4 ) { + info->ecclayout = hwecc4_2048; + info->ecclayout.oobfree[1 ].length = + info->mtd.oobsize -49 ; + info->chip.ecc.mode =NAND_ECC_HW_OOB_FIRST ; + goto syndrome_done; + }/* For large page chips we'll be wanting to use a * not-yet-implemented mode that reads OOB data
Signature · 1 line
1.6.0.4
I'm glad to see this patch is so small ... basically, just adding a special case for 2K pages, and keeping the core of this NAND driver the same. Not needing to change the 4-bit ECC support from the patch I sent earlier seems a good sign.
Two comments though: (a) the board-dm355-evm.c file isn't yet in mainline, so the MTD folk can't take this patch as-is;
(b) as noted elsewhere, there are still issues with 4K pages and the NAND core infrastructure.
This patch is sufficient to support development boards for the dm355, dm357, and dm365 ... right? They all have 2 GByte NAND chips, ISTR with 2K pages, and haven't yet had to switch to more current parts with 4K pages.
drivers/mtd/nand/davinci_nand.c static struct nand_ecclayout hwecc4_small __initconst = { · line 508
Quoted 12 lines · On Wednesday 06 May 2009, [email protected] wrote:
drivers/mtd/nand/davinci_nand.c +0
-0@@ -500,6 +500,21 @@ static struct nand_ecclayout hwecc4_small __initconst = { }, };drivers/mtd/nand/davinci_nand.c +6
-0+/* An ECC layout for using 4-bit ECC with large-page (2048bytes) flash, +* storing ten ECC bytes plus the manufacturer's bad block marker byte, +* and not overlapping the default BBT markers. +*/ +static struct nand_ecclayout hwecc4_2048__initconst = { + .eccbytes = 10,
Not ".eccbytes = 40"? This is 4 chunks, 10 ecc bytes each...
Quoted 7 lines
+ .eccpos = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, }, + .oobfree = {
+ {.offset = 16, .length = 8, },
+ {.offset = 49, },
Comments would be good, highlighting (a) byte 5 is reserved, it's the manufacturer bad block marker, (b) 8 bytes @16 are expected by JFFS2. Not everyone will "just know" those.
Quoted 17 lines
+ },
+};
static int__initnand_davinci_probe(struct platform_device *pdev){drivers/mtd/nand/davinci_nand.c +7
-0@@ -690,6 +705,13 @@ static int __init nand_davinci_probe(struct platform_device *pdev) info->mtd.oobsize - 16; goto syndrome_done; } + if (chunks == 4) { + info->ecclayout = hwecc4_2048; + info->ecclayout.oobfree[1].length = + info->mtd.oobsize - 49; + info->chip.ecc.mode = NAND_ECC_HW_OOB_FIRST; + goto syndrome_done; + }
Quoted 3 lines
/* For large page chips we'll be wanting to use a
* not-yet-implemented mode that reads OOB data
You should update that comment ... that not-yet-implemented mode is now called "NAND_ECC_HW_OOB_FIRST", from patch 1/2 ... ;)
Dave,
Quoted 10 lines
-----Original Message-----
From: David Brownell [mailto:[email protected]]
Sent: Thursday, May 07, 2009 3:17 AM
To: Narnakaje, Snehaprabha
Cc: [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/2] NAND on DM355: Add 4-bit ECC support for large page NAND chips
Quoted 4 lines
I'm glad to see this patch is so small ... basically, just adding a special case for 2K pages, and keeping the core of this NAND driver the same. Not needing to change the 4-bit ECC support from the patch I sent earlier seems a good sign.
Yes, I had to use the .calculate in the new read_page handler to stop the ECC though.
Quoted 3 lines
Two comments though: (a) the
board-dm355-evm.cfile isn't yet in mainline, so the MTD folk can't take this patch as-is;
Sorry, I didn't realize this. I will separate the board-dm355-evm.c from this patch and submit the patch #3 for board-dm355-evm.c to go to davinci-linux-open-source.
Quoted 2 lines
(b) as noted elsewhere, there are still issues with 4K pages and the NAND core infrastructure.
Yes, this is still an issue, if we make the read_page handler use .eccpos[] for positioning the ECC bytes in the OOB area. If we had fixed prepad+ecc nand_ecclayout we would avoid using eccpos[] (This is what my initial set of 4-bit ECC patches did to support 4K). But this is not a generic solution.
The main problem is with nand_ooblayout structure that is not extendable for large pages 4K or more, without breaking the userspace IOCTLs that is dependent on the size of this structure.
Question to linux-mtd list: Are there plans in the linux-mtd to address this generic issue, now that NAND manufacturers are coming up NAND chips > 4K page size?
Quoted 15 lines
This patch is sufficient to support development boards for the dm355, dm357, and dm365 ... right? They all have 2 GByte NAND chips, ISTR with 2K pages, and haven't yet had to switch to more current parts with 4K pages.
drivers/mtd/nand/davinci_nand.c static struct nand_ecclayout hwecc4_small
Quoted 3 lines · On Wednesday 06 May 2009, [email protected] wrote:
drivers/mtd/nand/davinci_nand.c +0
-0@@ -500,6 +500,21 @@ static struct nand_ecclayout hwecc4_small
__initconstQuoted 3 lines
drivers/mtd/nand/davinci_nand.c +0
-0= { }, };
Quoted 8 lines
drivers/mtd/nand/davinci_nand.c static struct nand_ecclayout hwecc4_small __initconst = { · line 508
Quoted 6 lines
drivers/mtd/nand/davinci_nand.c +6
-0+/* An ECC layout for using 4-bit ECC with large-page (2048bytes) flash, +* storing ten ECC bytes plus the manufacturer's bad block marker byte, +* and not overlapping the default BBT markers. +*/ +static struct nand_ecclayout hwecc4_2048__initconst = { + .eccbytes = 10,Not ".eccbytes = 40"? This is 4 chunks, 10 ecc bytes each...
No, .eccbytes is for each chips->ecc.steps. And all nand read/write APIs, we handle ecc.steps (for loop). There is chips->ecc.total that is initialized as (chips->ecc.steps * chips->ecc.bytes).
It is strange that .eccbytes is for each chunk, while eccpos[] and .oobfree[] have to handle/cover all chunks.
Quoted 10 lines
drivers/mtd/nand/davinci_nand.c static struct nand_ecclayout hwecc4_small __initconst = { · line 515
Quoted 9 lines
drivers/mtd/nand/davinci_nand.c +7
-0+ .eccpos = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, }, + .oobfree = { + {.offset = 16, .length = 8, }, + {.offset = 49, },
Quoted 3 lines
Comments would be good, highlighting (a) byte 5 is reserved, it's the manufacturer bad block marker, (b) 8 bytes @16 are expected by JFFS2. Not everyone will "just know" those.
OK, will add in the next patch.
Quoted 21 lines
drivers/mtd/nand/davinci_nand.c static int __init nand_davinci_probe(struct
Quoted 9 lines
drivers/mtd/nand/davinci_nand.c +2
-0+ }, +}; static int __init nand_davinci_probe(struct platform_device *pdev) {@@ -690,6 +705,13 @@ static int __init nand_davinci_probe(struct
platform_device*pdev)Quoted 11 lines
drivers/mtd/nand/davinci_nand.c +7
-0info->mtd.oobsize - 16; goto syndrome_done; } + if (chunks == 4) { + info->ecclayout = hwecc4_2048; + info->ecclayout.oobfree[1].length = + info->mtd.oobsize - 49; + info->chip.ecc.mode = NAND_ECC_HW_OOB_FIRST; + goto syndrome_done; + }
Quoted 5 lines
drivers/mtd/nand/davinci_nand.c static int __init nand_davinci_probe(struct platform_device *pdev) · line 717
Quoted 2 lines
drivers/mtd/nand/davinci_nand.c +0
-0/* For large page chips we'll be wanting to use a* not-yet-implemented mode that reads OOB data You should update that comment ... that not-yet-implemented mode is now called "
NAND_ECC_HW_OOB_FIRST", from patch 1/2 ... ;)
Yes, but will have a comment about 4K though.
Thanks
Sneha
Quoted 1 line
Quoted 7 lines · Snehaprabha
Quoted 4 lines
I'm glad to see this patch is so small ... basically, just adding a special case for 2K pages, and keeping the core of this NAND driver the same. Not needing to change the 4-bit ECC support from the patch I sent earlier seems a good sign.
Yes, I had to use the .calculate in the new
read_pagehandler to stop the ECC though.
Oh, now I see what you were talking about off-list. That doesn't seem quite right. I'll take a look.
Quoted 6 lines
Quoted 2 lines
Two comments though: (a) the
board-dm355-evm.cfile isn't yet in mainline, so the MTD folk can't take this patch as-is;Sorry, I didn't realize this. I will separate the
board-dm355-evm.cfrom this patch and submit the patch #3 forboard-dm355-evm.cto go to davinci-linux-open-source.
Let's wait until we see the previous davinci_nand.c patches get queued up somewhere "official" though ... in fact, I don't see why they shouldn't merge for 2.6.30-soon.
Quoted 9 lines
Quoted 2 lines
(b) as noted elsewhere, there are still issues with 4K pages and the NAND core infrastructure.
Yes, this is still an issue, if we make the
read_pagehandler use .eccpos[] for positioning the ECC bytes in the OOB area. If we had fixed prepad+eccnand_ecclayoutwe would avoid using eccpos[] (This is what my initial set of 4-bit ECC patches did to support 4K). But this is not a generic solution.
Quoted 7 lines
The main problem is with
nand_ooblayoutstructure that is not extendable for large pages 4K or more, without breaking the userspace IOCTLs that is dependent on the size of this structure.Question to linux-mtd list: Are there plans in the linux-mtd to address this generic issue, now that NAND manufacturers are coming up NAND chips > 4K page size?
They've been doing it for a while now, actually. :)
And it wouldn't be an issue here ... *IF* this 4-bit ECC didn't need to use 80 bytes (8 chunks of 512 bytes, 10 bytes ECC per chunk) from a 64 byte field. Doesn't fit.
Maybe the ecclayout stuff should migrate to sysfs, and just drop the old ioctl stuff for parts that can't use it ... as is being done to support chips that are 4 GByte and bigger.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
+static struct
nand_ecclayouthwecc4_2048__initconst= { + .eccbytes = 10,Not ".eccbytes = 40"? This is 4 chunks, 10 ecc bytes each...
No, .eccbytes is for each
chips->ecc.steps.
So it's the same as ecc.bytes, which is not exported to userspace.
Quoted 6 lines
And all nand read/write
APIs, we handle ecc.steps (for loop). There ischips->ecc.totalthat is initialized as (chips->ecc.steps*chips->ecc.bytes).It is strange that .eccbytes is for each chunk, while eccpos[] and .oobfree[] have to handle/cover all chunks.
Also strange: when ECC_HW_SYNDROME is in use, nothing even looks at the nand_ecclayout to make sure it matches the actual layout being used ... which derives entirely from the prepad, postpad, and bytes fields of "ecc". (Except that some of the OOB bytes not used for ECC may be hidden, e.g. manufacturer bad block markers are usually not listed.)
- Dave
Quoted 19 lines
-----Original Message-----
From: David Brownell [mailto:[email protected]]
Sent: Thursday, May 07, 2009 1:11 PM
To: Narnakaje, Snehaprabha
Cc: [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/2] NAND on DM355: Add 4-bit ECC support for large page NAND chipsQuoted 5 lines · Snehaprabha
Quoted 4 lines
I'm glad to see this patch is so small ... basically, just adding a special case for 2K pages, and keeping the core of this NAND driver the same. Not needing to change the 4-bit ECC support from the patch I sent earlier seems a good sign.
Quoted 5 lines
Quoted 2 lines
Yes, I had to use the .calculate in the new
read_pagehandler to stop the ECC though.Oh, now I see what you were talking about off-list. That doesn't seem quite right. I'll take a look.
Looks like you had to implement is_readmode option in the .calculate function, to use the NAND_ECC_HW mode for small pages. The read_page handler for NAND_ECC_HW calls the .calculate function, and in our case we shouldn't be doing anything here for read. We use the .calculate function from write_page.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Two comments though: (a) the
board-dm355-evm.cfile isn't yet in mainline, so the MTD folk can't take this patch as-is;
Quoted 7 lines
Quoted 3 lines
Sorry, I didn't realize this. I will separate the
board-dm355-evm.cfrom this patch and submit the patch #3 forboard-dm355-evm.cto go to davinci-linux-open-source.Let's wait until we see the previous
davinci_nand.cpatches get queued up somewhere "official" though ... in fact, I don't see why they shouldn't merge for 2.6.30-soon.
I was hoping my patch (dependent on your patch set) would at least trigger the review/acceptance :-)
Quoted 21 lines
Quoted 11 lines
Quoted 4 lines
(b) as noted elsewhere, there are still issues with 4K pages and the NAND core infrastructure.
Yes, this is still an issue, if we make the
read_pagehandler use .eccpos[] for positioning the ECC bytes in the OOB area. If we had fixed prepad+eccnand_ecclayoutwe would avoid using eccpos[] (This is what my initial set of 4-bit ECC patches did to support 4K). But this is not a generic solution.Quoted 7 lines
The main problem is with
nand_ooblayoutstructure that is not extendable for large pages 4K or more, without breaking the userspace IOCTLs that is dependent on the size of this structure.Question to linux-mtd list: Are there plans in the linux-mtd to address this generic issue, now that NAND manufacturers are coming up NAND chips > 4K page size?
They've been doing it for a while now, actually. :)
Quoted 7 lines
And it wouldn't be an issue here ... *IF* this 4-bit ECC didn't need to use 80 bytes (8 chunks of 512 bytes, 10 bytes ECC per chunk) from a 64 byte field. Doesn't fit.
Maybe the ecclayout stuff should migrate to sysfs, and just drop the old ioctl stuff for parts that can't use it ... as is being done to support chips that are 4 GByte and bigger.
I will explore more on this option.
Quoted 19 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
+static struct
nand_ecclayouthwecc4_2048__initconst= { + .eccbytes = 10,Not ".eccbytes = 40"? This is 4 chunks, 10 ecc bytes each...
No, .eccbytes is for each
chips->ecc.steps.So it's the same as ecc.bytes, which is not exported to userspace.
Quoted 6 lines
And all nand read/write
APIs, we handle ecc.steps (for loop). There ischips->ecc.totalthat is initialized as (chips->ecc.steps*chips->ecc.bytes).It is strange that .eccbytes is for each chunk, while eccpos[] and .oobfree[] have to handle/cover all chunks.
Quoted 6 lines
Also strange: when
ECC_HW_SYNDROMEis in use, nothing even looks at thenand_ecclayoutto make sure it matches the actual layout being used ... which derives entirely from the prepad, postpad, and bytes fields of "ecc". (Except that some of the OOB bytes not used for ECC may be hidden, e.g. manufacturer bad block markers are usually not listed.)
If you leave enough prepad to cover manufacturer's BB and JFFS2 markers, this mechanism was OK, I guess.
Thanks
Sneha
Quoted 5 lines
- Dave
Quoted 14 lines
Quoted 4 lines
Quoted 3 lines
drivers/mtd/nand/davinci_nand.c static struct nand_ecclayout hwecc4_small __initconst = { · line 508
Quoted 2 lines
drivers/mtd/nand/davinci_nand.c +2
-0+static struct nand_ecclayout hwecc4_2048__initconst = { + .eccbytes =10 ,Not ".eccbytes = 40"? This is 4 chunks, 10 ecc bytes each...
No, .eccbytes is for each
chips->ecc.steps.So it's the same as ecc.bytes, which is not exported to userspace.
Quoted 6 lines
And all nand read/write
APIs, we handle ecc.steps (for loop). There ischips->ecc.totalthat is initialized as (chips->ecc.steps*chips->ecc.bytes).It is strange that .eccbytes is for each chunk, while eccpos[] and .oobfree[] have to handle/cover all chunks.
No, eccbytes should equal ecc.total
i.e. from nand_base.c
static struct nand_ecclayout nand_oob_64 = {
.eccbytes = 24,
.eccpos = {
40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63},
.oobfree = {
{.offset = 2,
.length = 38}}
};Troy
Quoted 20 lines
-----Original Message-----
From: Troy Kisky [mailto:[email protected]]
Sent: Thursday, May 07, 2009 6:37 PM
To: David Brownell
Cc: Narnakaje, Snehaprabha; [email protected]; davinci-linux-open- [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/2] NAND on DM355: Add 4-bit ECC support for large page NAND chipsQuoted 8 lines
Quoted 4 lines
Quoted 3 lines
drivers/mtd/nand/davinci_nand.c static struct nand_ecclayout hwecc4_small __initconst = { · line 508
Quoted 2 lines
drivers/mtd/nand/davinci_nand.c +2
-0+static struct nand_ecclayout hwecc4_2048__initconst = { + .eccbytes =10 ,Not ".eccbytes = 40"? This is 4 chunks, 10 ecc bytes each...
No, .eccbytes is for each
chips->ecc.steps.So it's the same as ecc.bytes, which is not exported to userspace.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
And all nand read/write
APIs, we handle ecc.steps (for loop). There ischips->ecc.totalthat is initialized as (chips->ecc.steps*chips->ecc.bytes).It is strange that .eccbytes is for each chunk, while eccpos[] and .oobfree[] have to handle/cover all chunks.
No, eccbytes should equal ecc.total
Thanks Troy and Dave.
Yes, it should indeed be 40 --> total size. eccbytes in the nand_ecclayout is different from chip->ecc.bytes. We do set the chip->ecc.bytes to 10 which is for each trunk.
I will change this and test it.
Quoted 17 lines
i.e. from
nand_base.cstatic struct nand_ecclayout nand_oob_64 = { .eccbytes = 24, .eccpos = { 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}, .oobfree = { {.offset = 2, .length = 38}} };Troy