help calculate Micron NAND on die ECC - Page 1
Forum section: electronics / general

author: carver
author_rank: Contributor
timestamp: September 05, 2021, 01:00:04 pm
content: Hi. I can't google how to check ECC in a read NAND image.NAND chip from Micron, 29F2G16for READ ID (90h) command gives 2C CA 90 D5 86 00 00 00according to the PDF, the bits say that 4-bit ECC.512+4 (data) + 4 (spare/"not_used") + 8 (parity/ECC) bytesand Internal ECC enabledan old micron decoder with pudn/google calculatebch_encoder_0x201b.exe -m 13 -k 4128 -t 4 <noname.txt // -> 07ED34D14242Cbch_encoder_0x25af.exe -m 13 -k 4128 -t 4 <noname.txt // -> EDE66E50C82B7depending on the polynomial, but not A3BE308501E09E8A as in my dumpbelow is an example of a sector. maybe someone can help. thanks.Code:00000000 74 65 6d 20 66 6f 75 6e 64 20 61 74 20 62 6c 6f |tem found at blo|00000010 63 6b 20 25 64 0a 00 00 3c 35 3e 52 41 4d 44 49 |ck %d...<5>RAMDI|00000020 53 4b 3a 20 43 6f 75 6c 64 6e 27 74 20 66 69 6e |SK: Couldn't fin|00000030 64 20 76 61 6c 69 64 20 52 41 4d 20 64 69 73 6b |d valid RAM disk|00000040 20 69 6d 61 67 65 20 73 74 61 72 74 69 6e 67 20 | image starting |00000050 61 74 20 25 64 2e 0a 00 3c 33 3e 52 41 4d 44 49 |at %d...<3>RAMDI|00000060 53 4b 3a 20 43 6f 75 6c 64 6e 27 74 20 61 6c 6c |SK: Couldn't all|00000070 6f 63 61 74 65 20 67 7a 69 70 20 62 75 66 66 65 |ocate gzip buffe|00000080 72 0a 00 00 3c 33 3e 52 41 4d 44 49 53 4b 3a 20 |r...<3>RAMDISK: |00000090 43 6f 75 6c 64 6e 27 74 20 61 6c 6c 6f 63 61 74 |Couldn't allocat|000000a0 65 20 67 7a 69 70 20 77 69 6e 64 6f 77 0a 00 00 |e gzip window...|000000b0 62 61 64 20 67 7a 69 70 20 6d 61 67 69 63 20 6e |bad gzip magic n|000000c0 75 6d 62 65 72 73 00 00 69 6e 74 65 72 6e 61 6c |umbers..internal|000000d0 20 65 72 72 6f 72 2c 20 69 6e 76 61 6c 69 64 20 | error, invalid |000000e0 6d 65 74 68 6f 64 00 00 49 6e 70 75 74 20 69 73 |method..Input is|000000f0 20 65 6e 63 72 79 70 74 65 64 00 00 4d 75 6c 74 | encrypted..Mult|00000100 69 20 70 61 72 74 20 69 6e 70 75 74 00 00 00 00 |i part input....|00000110 49 6e 70 75 74 20 68 61 73 20 69 6e 76 61 6c 69 |Input has invali|00000120 64 20 66 6c 61 67 73 00 69 6e 76 61 6c 69 64 20 |d flags.invalid |00000130 63 6f 6d 70 72 65 73 73 65 64 20 66 6f 72 6d 61 |compressed forma|00000140 74 20 28 65 72 72 3d 31 29 00 00 00 69 6e 76 61 |t (err=1)...inva|00000150 6c 69 64 20 63 6f 6d 70 72 65 73 73 65 64 20 66 |lid compressed f|00000160 6f 72 6d 61 74 20 28 65 72 72 3d 32 29 00 00 00 |ormat (err=2)...|00000170 6f 75 74 20 6f 66 20 6d 65 6d 6f 72 79 00 00 00 |out of memory...|00000180 6f 75 74 20 6f 66 20 69 6e 70 75 74 20 64 61 74 |out of input dat|00000190 61 00 00 00 69 6e 76 61 6c 69 64 20 63 6f 6d 70 |a...invalid comp|000001a0 72 65 73 73 65 64 20 66 6f 72 6d 61 74 20 28 6f |ressed format (o|000001b0 74 68 65 72 29 00 00 00 63 72 63 20 65 72 72 6f |ther)...crc erro|000001c0 72 00 00 00 6c 65 6e 67 74 68 20 65 72 72 6f 72 |r...length error|000001d0 00 00 00 00 52 41 4d 44 49 53 4b 3a 20 69 6d 61 |....RAMDISK: ima|000001e0 67 65 20 74 6f 6f 20 62 69 67 21 20 28 25 64 4b |ge too big! (%dK|000001f0 69 42 2f 25 6c 64 4b 69 42 29 0a 00 2f 69 6e 69 |iB/%ldKiB)../ini|00000200 ff ff ff ff ff ff ff ff a3 be 30 85 01 e0 9e 8a |..........0.....|

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 05, 2021, 04:10:54 pm
content: You don't have any ECC algorithm in the nand itself, it only has extra spare space for storing it, and the host writes whatever on it:QuoteCommands don't have ECC.READ ID is a 5-byte command, so: 2C CA 90 D5 86Byte 0: Manufacturer ID 0x2C = MicronByte 1: Device ID 0xCA = MT29F2G16AAD...Only "Read Unique ID (EDh)" has a sort-of protection system:QuoteYou'll need to know the ECC used in the system where you took the nand from.Did you see this?https://github.com/SySS-Research/nand-dump-tools

author: carver
author_rank: Contributor
timestamp: September 11, 2021, 08:19:41 pm
content: sorry for the silence, I forgot to subscribe to the topic.thanks for the link, I will try to search for the algorithm there.but I wrote everything right, in my case, it is the internal ECC in the NAND Micron.it does not depend on the OS in any way (I use JTAG and, and simple loader (code from MPC8321 manual) to work with NAND.I erase flash, read all 0xFF, write 0x800, and read 0x800 data + 0x40 ECC back.so I wrote above, the bits indicate hardware ECC in NAND, and CPU like MPC8321 - haven't ECC.on the Internet - there was an ECC Micron algorithm, but it gives me different values ((Micron is a well-known manufacturer, Linux/Uboot mentions "on die ECC",so I was hoping that someone might have already solved this ECC or would point out my mistake.p,s, yea, 2048+64 = 512+512+512+512+4+4+4+4+4+4+4+4+8+8+8+8,so I post only one 528 block, where 516 bytes - data, 4 bytes - "not used", 8 bytes - ECC...oh, need fix my first post. 512->512+4(for data).

author: DavidAlfa
author_rank: Super Contributor
timestamp: September 15, 2021, 08:30:03 pm
content: It's strange. I got at least 3 different datasheets with different data.I guess due the AAD/ABD/AABWP/BABWP/etc variations.The last datasheet shows what you say.ECC is done by on-die hardware, so after enabling the ECC bit, it should be managed automatically when writing/reading data?So, unless the data is damaged beyond what ECC can repair, you should be getting correct data?I suspect you should only read or write to the first 2048 Bytes, leaving the rest for the ECC.So writing 2048 bytes to a page should "refresh" the ECC data?

author: carver
author_rank: Contributor
timestamp: September 15, 2021, 11:28:10 pm
content: yea. at my pdf 2C CA 90 D5 86 = Micron MT29F2G16ABAEA.before I save forum and gogle space, and post only 512+16 bytes, here full 2112 bytes (2048 + 64 bytes)Code:00000000 65 72 72 75 70 74 73 00 64 69 73 61 62 6c 65 64 |errupts.disabled|00000010 20 68 61 72 64 20 69 6e 74 65 72 72 75 70 74 73 | hard interrupts|00000020 00 00 00 00 3c 34 3e 69 6e 69 74 63 61 6c 6c 20 |....<4>initcall |00000030 61 74 20 30 78 25 70 00 3a 20 72 65 74 75 72 6e |at 0x%p.: return|00000040 65 64 20 77 69 74 68 20 25 73 0a 00 69 6e 69 74 |ed with %s..init|00000050 2f 6d 61 69 6e 2e 63 00 2f 64 65 76 2f 63 6f 6e |/main.c./dev/con|00000060 73 6f 6c 65 00 00 00 00 3c 34 3e 57 61 72 6e 69 |sole....<4>Warni|00000070 6e 67 3a 20 75 6e 61 62 6c 65 20 74 6f 20 6f 70 |ng: unable to op|00000080 65 6e 20 61 6e 20 69 6e 69 74 69 61 6c 20 63 6f |en an initial co|00000090 6e 73 6f 6c 65 2e 0a 00 3c 34 3e 46 61 69 6c 65 |nsole...<4>Faile|000000a0 64 20 74 6f 20 65 78 65 63 75 74 65 20 25 73 0a |d to execute %s.|000000b0 00 00 00 00 3c 34 3e 46 61 69 6c 65 64 20 74 6f |....<4>Failed to|000000c0 20 65 78 65 63 75 74 65 20 25 73 2e 20 20 41 74 | execute %s. At|000000d0 74 65 6d 70 74 69 6e 67 20 64 65 66 61 75 6c 74 |tempting default|000000e0 73 2e 2e 2e 0a 00 00 00 2f 73 62 69 6e 2f 69 6e |s......./sbin/in|000000f0 69 74 00 00 2f 65 74 63 2f 69 6e 69 74 00 00 00 |it../etc/init...|00000100 2f 62 69 6e 2f 69 6e 69 74 00 00 00 2f 62 69 6e |/bin/init.../bin|00000110 2f 73 68 00 4e 6f 20 69 6e 69 74 20 66 6f 75 6e |/sh.No init foun|00000120 64 2e 20 20 54 72 79 20 70 61 73 73 69 6e 67 20 |d. Try passing |00000130 69 6e 69 74 3d 20 6f 70 74 69 6f 6e 20 74 6f 20 |init= option to |00000140 6b 65 72 6e 65 6c 2e 00 3c 34 3e 50 61 72 61 6d |kernel..<4>Param|00000150 65 74 65 72 20 25 73 20 69 73 20 6f 62 73 6f 6c |eter %s is obsol|00000160 65 74 65 2c 20 69 67 6e 6f 72 65 64 0a 00 00 00 |ete, ignored....|00000170 3c 33 3e 55 6e 6b 6e 6f 77 6e 20 62 6f 6f 74 20 |<3>Unknown boot |00000180 6f 70 74 69 6f 6e 20 60 25 73 27 3a 20 69 67 6e |option `%s': ign|00000190 6f 72 69 6e 67 0a 00 00 54 6f 6f 20 6d 61 6e 79 |oring...Too many|000001a0 20 62 6f 6f 74 20 65 6e 76 20 76 61 72 73 20 61 | boot env vars a|000001b0 74 20 60 25 73 27 00 00 54 6f 6f 20 6d 61 6e 79 |t `%s'..Too many|000001c0 20 62 6f 6f 74 20 69 6e 69 74 20 76 61 72 73 20 | boot init vars |000001d0 61 74 20 60 25 73 27 00 65 61 72 6c 79 20 6f 70 |at `%s'.early op|000001e0 74 69 6f 6e 73 00 00 00 3c 34 3e 4d 61 6c 66 6f |tions...<4>Malfo|000001f0 72 6d 65 64 20 65 61 72 6c 79 20 6f 70 74 69 6f |rmed early optio|00000200 6e 20 27 25 73 27 0a 00 3c 35 3e 00 3c 35 3e 4b |n '%s'..<5>.<5>K|00000210 65 72 6e 65 6c 20 63 6f 6d 6d 61 6e 64 20 6c 69 |ernel command li|00000220 6e 65 3a 20 25 73 0a 00 42 6f 6f 74 69 6e 67 20 |ne: %s..Booting |00000230 6b 65 72 6e 65 6c 00 00 73 74 61 72 74 5f 6b 65 |kernel..start_ke|00000240 72 6e 65 6c 28 29 3a 20 62 75 67 3a 20 69 6e 74 |rnel(): bug: int|00000250 65 72 72 75 70 74 73 20 77 65 72 65 20 65 6e 61 |errupts were ena|00000260 62 6c 65 64 20 65 61 72 6c 79 0a 00 3c 32 3e 69 |bled early..<2>i|00000270 6e 69 74 72 64 20 6f 76 65 72 77 72 69 74 74 65 |nitrd overwritte|00000280 6e 20 28 30 78 25 30 38 6c 78 20 3c 20 30 78 25 |n (0x%08lx < 0x%|00000290 30 38 6c 78 29 20 2d 20 64 69 73 61 62 6c 69 6e |08lx) - disablin|000002a0 67 20 69 74 2e 0a 00 00 48 4f 4d 45 3d 2f 00 00 |g it....HOME=/..|000002b0 54 45 52 4d 3d 6c 69 6e 75 78 00 00 69 6e 69 74 |TERM=linux..init|000002c0 00 00 00 00 2f 64 65 76 2f 72 6f 6f 74 00 00 00 |..../dev/root...|000002d0 3c 35 3e 56 46 53 3a 20 49 6e 73 65 72 74 20 25 |<5>VFS: Insert %|000002e0 73 20 61 6e 64 20 70 72 65 73 73 20 45 4e 54 45 |s and press ENTE|000002f0 52 0a 00 00 20 72 65 61 64 6f 6e 6c 79 00 00 00 |R... readonly...|00000300 56 46 53 3a 20 4d 6f 75 6e 74 65 64 20 72 6f 6f |VFS: Mounted roo|00000310 74 20 28 25 73 20 66 69 6c 65 73 79 73 74 65 6d |t (%s filesystem|00000320 29 25 73 2e 0a 00 00 00 56 46 53 3a 20 43 61 6e |)%s.....VFS: Can|00000330 6e 6f 74 20 6f 70 65 6e 20 72 6f 6f 74 20 64 65 |not open root de|00000340 76 69 63 65 20 22 25 73 22 20 6f 72 20 25 73 0a |vice "%s" or %s.|00000350 00 00 00 00 50 6c 65 61 73 65 20 61 70 70 65 6e |....Please appen|00000360 64 20 61 20 63 6f 72 72 65 63 74 20 22 72 6f 6f |d a correct "roo|00000370 74 3d 22 20 62 6f 6f 74 20 6f 70 74 69 6f 6e 0a |t=" boot option.|00000380 00 00 00 00 56 46 53 3a 20 55 6e 61 62 6c 65 20 |....VFS: Unable |00000390 74 6f 20 6d 6f 75 6e 74 20 72 6f 6f 74 20 66 73 |to mount root fs|000003a0 20 6f 6e 20 25 73 00 00 4e 6f 20 66 69 6c 65 73 | on %s..No files|000003b0 79 73 74 65 6d 20 63 6f 75 6c 64 20 6d 6f 75 6e |ystem could moun|000003c0 74 20 72 6f 6f 74 2c 20 74 72 69 65 64 3a 20 00 |t root, tried: .|000003d0 2f 73 79 73 2f 62 6c 6f 63 6b 2f 25 73 2f 64 65 |/sys/block/%s/de|000003e0 76 00 00 00 25 75 3a 25 75 00 00 00 2f 73 79 73 |v...%u:%u.../sys|000003f0 2f 62 6c 6f 63 6b 2f 25 73 2f 72 61 6e 67 65 00 |/block/%s/range.|00000400 2f 73 79 73 00 00 00 00 73 79 73 66 73 00 00 00 |/sys....sysfs...|00000410 2f 64 65 76 2f 00 00 00 6e 66 73 00 3c 36 3e 57 |/dev/...nfs.<6>W|00000420 61 69 74 69 6e 67 20 25 64 73 65 63 20 62 65 66 |aiting %dsec bef|00000430 6f 72 65 20 6d 6f 75 6e 74 69 6e 67 20 72 6f 6f |ore mounting roo|00000440 74 20 64 65 76 69 63 65 2e 2e 2e 0a 00 00 00 00 |t device........|00000450 6d 74 64 00 3c 33 3e 25 73 0a 00 00 52 41 4d 44 |mtd.<3>%s...RAMD|00000460 49 53 4b 3a 20 72 61 6e 20 6f 75 74 20 6f 66 20 |ISK: ran out of |00000470 63 6f 6d 70 72 65 73 73 65 64 20 64 61 74 61 00 |compressed data.|00000480 3c 33 3e 52 41 4d 44 49 53 4b 3a 20 69 6e 63 6f |<3>RAMDISK: inco|00000490 6d 70 6c 65 74 65 20 77 72 69 74 65 20 28 25 64 |mplete write (%d|000004a0 20 21 3d 20 25 64 29 20 25 6c 64 0a 00 00 00 00 | != %d) %ld.....|000004b0 69 6e 63 6f 6d 70 6c 65 74 65 20 6c 69 74 65 72 |incomplete liter|000004c0 61 6c 20 74 72 65 65 00 69 6e 63 6f 6d 70 6c 65 |al tree.incomple|000004d0 74 65 20 64 69 73 74 61 6e 63 65 20 74 72 65 65 |te distance tree|000004e0 00 00 00 00 2f 64 65 76 2f 72 61 6d 00 00 00 00 |..../dev/ram....|000004f0 3c 35 3e 52 41 4d 44 49 53 4b 3a 20 43 6f 6d 70 |<5>RAMDISK: Comp|00000500 72 65 73 73 65 64 20 69 6d 61 67 65 20 66 6f 75 |ressed image fou|00000510 6e 64 20 61 74 20 62 6c 6f 63 6b 20 25 64 0a 00 |nd at block %d..|00000520 3c 35 3e 52 41 4d 44 49 53 4b 3a 20 72 6f 6d 66 |<5>RAMDISK: romf|00000530 73 20 66 69 6c 65 73 79 73 74 65 6d 20 66 6f 75 |s filesystem fou|00000540 6e 64 20 61 74 20 62 6c 6f 63 6b 20 25 64 0a 00 |nd at block %d..|00000550 3c 35 3e 52 41 4d 44 49 53 4b 3a 20 63 72 61 6d |<5>RAMDISK: cram|00000560 66 73 20 66 69 6c 65 73 79 73 74 65 6d 20 66 6f |fs filesystem fo|00000570 75 6e 64 20 61 74 20 62 6c 6f 63 6b 20 25 64 0a |und at block %d.|00000580 00 00 00 00 3c 35 3e 52 41 4d 44 49 53 4b 3a 20 |....<5>RAMDISK: |00000590 73 71 75 61 73 68 66 73 20 66 69 6c 65 73 79 73 |squashfs filesys|000005a0 74 65 6d 20 66 6f 75 6e 64 20 61 74 20 62 6c 6f |tem found at blo|000005b0 63 6b 20 25 64 0a 00 00 3c 35 3e 52 41 4d 44 49 |ck %d...<5>RAMDI|000005c0 53 4b 3a 20 4d 69 6e 69 78 20 66 69 6c 65 73 79 |SK: Minix filesy|000005d0 73 74 65 6d 20 66 6f 75 6e 64 20 61 74 20 62 6c |stem found at bl|000005e0 6f 63 6b 20 25 64 0a 00 3c 35 3e 52 41 4d 44 49 |ock %d..<5>RAMDI|000005f0 53 4b 3a 20 65 78 74 32 20 66 69 6c 65 73 79 73 |SK: ext2 filesys|00000600 74 65 6d 20 66 6f 75 6e 64 20 61 74 20 62 6c 6f |tem found at blo|00000610 63 6b 20 25 64 0a 00 00 3c 35 3e 52 41 4d 44 49 |ck %d...<5>RAMDI|00000620 53 4b 3a 20 43 6f 75 6c 64 6e 27 74 20 66 69 6e |SK: Couldn't fin|00000630 64 20 76 61 6c 69 64 20 52 41 4d 20 64 69 73 6b |d valid RAM disk|00000640 20 69 6d 61 67 65 20 73 74 61 72 74 69 6e 67 20 | image starting |00000650 61 74 20 25 64 2e 0a 00 3c 33 3e 52 41 4d 44 49 |at %d...<3>RAMDI|00000660 53 4b 3a 20 43 6f 75 6c 64 6e 27 74 20 61 6c 6c |SK: Couldn't all|00000670 6f 63 61 74 65 20 67 7a 69 70 20 62 75 66 66 65 |ocate gzip buffe|00000680 72 0a 00 00 3c 33 3e 52 41 4d 44 49 53 4b 3a 20 |r...<3>RAMDISK: |00000690 43 6f 75 6c 64 6e 27 74 20 61 6c 6c 6f 63 61 74 |Couldn't allocat|000006a0 65 20 67 7a 69 70 20 77 69 6e 64 6f 77 0a 00 00 |e gzip window...|000006b0 62 61 64 20 67 7a 69 70 20 6d 61 67 69 63 20 6e |bad gzip magic n|000006c0 75 6d 62 65 72 73 00 00 69 6e 74 65 72 6e 61 6c |umbers..internal|000006d0 20 65 72 72 6f 72 2c 20 69 6e 76 61 6c 69 64 20 | error, invalid |000006e0 6d 65 74 68 6f 64 00 00 49 6e 70 75 74 20 69 73 |method..Input is|000006f0 20 65 6e 63 72 79 70 74 65 64 00 00 4d 75 6c 74 | encrypted..Mult|00000700 69 20 70 61 72 74 20 69 6e 70 75 74 00 00 00 00 |i part input....|00000710 49 6e 70 75 74 20 68 61 73 20 69 6e 76 61 6c 69 |Input has invali|00000720 64 20 66 6c 61 67 73 00 69 6e 76 61 6c 69 64 20 |d flags.invalid |00000730 63 6f 6d 70 72 65 73 73 65 64 20 66 6f 72 6d 61 |compressed forma|00000740 74 20 28 65 72 72 3d 31 29 00 00 00 69 6e 76 61 |t (err=1)...inva|00000750 6c 69 64 20 63 6f 6d 70 72 65 73 73 65 64 20 66 |lid compressed f|00000760 6f 72 6d 61 74 20 28 65 72 72 3d 32 29 00 00 00 |ormat (err=2)...|00000770 6f 75 74 20 6f 66 20 6d 65 6d 6f 72 79 00 00 00 |out of memory...|00000780 6f 75 74 20 6f 66 20 69 6e 70 75 74 20 64 61 74 |out of input dat|00000790 61 00 00 00 69 6e 76 61 6c 69 64 20 63 6f 6d 70 |a...invalid comp|000007a0 72 65 73 73 65 64 20 66 6f 72 6d 61 74 20 28 6f |ressed format (o|000007b0 74 68 65 72 29 00 00 00 63 72 63 20 65 72 72 6f |ther)...crc erro|000007c0 72 00 00 00 6c 65 6e 67 74 68 20 65 72 72 6f 72 |r...length error|000007d0 00 00 00 00 52 41 4d 44 49 53 4b 3a 20 69 6d 61 |....RAMDISK: ima|000007e0 67 65 20 74 6f 6f 20 62 69 67 21 20 28 25 64 4b |ge too big! (%dK|000007f0 69 42 2f 25 6c 64 4b 69 42 29 0a 00 2f 69 6e 69 |iB/%ldKiB)../ini|00000800 ff ff ff ff ff ff ff ff 1b 47 01 e3 00 00 39 1e |.........G....9.|00000810 ff ff ff ff ff ff ff ff fa 08 11 e9 00 30 23 06 |.............0#.|00000820 ff ff ff ff ff ff ff ff 8f 6d ce 82 01 20 64 74 |.........m... dt|00000830 ff ff ff ff ff ff ff ff a3 be 30 85 01 e0 9e 8a |..........0.....|according pdf - internal ECC - its 8 bytes from 516 bytes (512 of data and 4 spare(in my case always 0xFFFFFFFF))Earlier, on other devices, I came across the fact that after reading data and writing it to another device,this new device didn't work. them due to uncorrected ECC data.so, when I need write 0x800 to new flash, I need read 0x840 from old flash, and check ECC.that's why I'm always check ECC in the read data. but i can't do this here ((