SAMA5D2 nandflash problems with linux

Discussion around products based on ARM Cortex-A5 core.

Moderator: nferre

deejay
Posts: 4
Joined: Thu Aug 04, 2016 7:08 am

SAMA5D2 nandflash problems with linux

Thu Oct 27, 2016 2:08 am

Hi all,

I'm having difficulty configuring the nand flash driver for a sama5d2 based device. The nandflash device (S34MS04G1) is a 512M NAND flash with an ONFI 1.0 compliant interface.

PMECC bootrom configuration value 0xc0082405 written with SAM-BA utility (see https://github.com/atmelcorp/atmel-soft ... e/issues/8 for more details)

Kernel source: https://github.com/linux4sam/linux-at91 ... dbaceaed21

Device tree

Code: Select all

#include "sama5d2.dtsi"
...
        ahb {
                nand0: nand@80000000 {
                        nand-bus-width = <8>;
                        nand-ecc-mode = "hw";
                        pinctrl-names = "default";
                        pinctrl-0 = <&pinctrl_nand_default>;
                        status = "okay";

                        bootstrap@0 {
                                label = "bootstrap";
                                reg = <0x0 0x000c0000>;
                        };

                        boot@c0000 {
                                label = "boot";
                                reg = <0x000c0000 0x07d00000>;
                        };

                        data@7dc0000 {
                                label = "data";
                                reg = <0x07dc0000 0x08740000>;
                        };

                        cache@10500000 {
                                label = "cache";
                                reg = <0x10500000 0x07d00000>;
                        };

                        recover@18200000 {
                                label = "recover";
                                reg = <0x18200000 0x07d00000>;
                        };

                        mfg@1ff00000 {
                                label = "mfg";
                                reg = <0x1ff00000 0x00100000>;
                        };
                };
...
        };
...
                                pinctrl_nand_default: nand_default {
                                        pinmux = <PIN_PA8__NWE_NANDWE>,
                                                 <PIN_PA9__NCS3>,
                                                 <PIN_PA10__A21_NANDALE>,
                                                 <PIN_PA11__A22_NANDCLE>,
                                                 <PIN_PA12__NRD_NANDOE>,
                                                 <PIN_PA0__D0>,
                                                 <PIN_PA1__D1>,
                                                 <PIN_PA2__D2>,
                                                 <PIN_PA3__D3>,
                                                 <PIN_PA4__D4>,
                                                 <PIN_PA5__D5>,
                                                 <PIN_PA6__D6>,
                                                 <PIN_PA7__D7>,
                                                 <PIN_PC8__NANDRDY>;
                                        bias-disable;
                                };

Linux reports all the erase blocks on nandflash chip as bad as seen in the kernel log below

Code: Select all

atmel_nand 80000000.nand: Using dma0chan0 for DMA transfers.
atmel_nand 80000000.nand: Time out to wait for interrupt: 0x01000000
nand: device found, Manufacturer ID: 0x01, Chip ID: 0xac
nand: AMD/Spansion S34MS04G1
nand: 512 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
atmel_nand 80000000.nand: minimum ECC: 1 bits in 512 bytes
atmel_nand 80000000.nand: Initialize PMECC params, cap: 2, sector: 512
atmel_nand 80000000.nand: Using NFC Sram read and write
Scanning device for bad blocks
Bad eraseblock 0 at 0x000000000000
Bad eraseblock 1 at 0x000000020000
Bad eraseblock 2 at 0x000000040000
Bad eraseblock 3 at 0x000000060000
...
Bad eraseblock 4095 at 0x00001ffe0000
6 ofpart partitions found on MTD device atmel_nand
Creating 6 MTD partitions on "atmel_nand":
0x000000000000-0x0000000c0000 : "bootstrap"
0x0000000c0000-0x000007dc0000 : "boot"
0x000007dc0000-0x000010500000 : "data"
0x000010500000-0x000018200000 : "cache"
0x000018200000-0x00001ff00000 : "recover"
0x00001ff00000-0x000020000000 : "mfg"
Is anybody able to provide some clues as to what I'm missing here?

Thanks.
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 nandflash problems with linux

Fri Oct 28, 2016 1:28 am

Your Device Tree is sparse in regards to the (optional) PMECC properties, so the atmel_nand.c driver will use default/minimum values.
For example, you previously specified a 4- bit ECC in the header value (eccBitReq =1), but your boot log clearly shows that the Linux configuration is for only 2 bits.
atmel_nand 80000000.nand: minimum ECC: 1 bits in 512 bytes
atmel_nand 80000000.nand: Initialize PMECC params, cap: 2, sector: 512
Refer to Documentation/devicetree/bindings/mtd/atmel-nand.txt in the kernel source tree for the list of optional properties.

Regards
deejay
Posts: 4
Joined: Thu Aug 04, 2016 7:08 am

Re: SAMA5D2 nandflash problems with linux

Fri Oct 28, 2016 5:59 am

Hi blue_z,

Thanks for the response.

You're right. The ECC value should have been set to 4. However it didn't solve the issue (this is one of the experiments I did while trying to ascertain the cause of the problem). I've now added the following line to the device tree.

Code: Select all

atmel,pmecc-cap = <4>;


However, I have made further progress. I was speaking to one of the devs and he pointed out that the ecc offset needs to be set to 36 to match the default value assigned in linux. This changes the flash header value to 0xc0902405

Code: Select all

         /*
			0xc0902405
				1100		key = 0xc0
				0			Reserved
				000100100	eccOffset = 36
				00			sectorSize = 0
				001			eccBitReq = 1			4 bit ecc
				001000000	spareSize = 0x40 (64)
				010			nbSectorsPerPage = 2
				1			usPmecc = 1
			*/
			nandHeader: 0xc0902405
This doesn't fix the issue though :-(
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAMA5D2 nandflash problems with linux

Sat Oct 29, 2016 12:56 am

deejay wrote:I've now added the following line to the device tree.

Code: Select all

atmel,pmecc-cap = <4>;
You should also consider adding

Code: Select all

                        atmel,pmecc-sector-size = <512>;
                        nand-on-flash-bbt;
which are typically used with other boards.
deejay wrote:I was speaking to one of the devs and he pointed out that the ecc offset needs to be set to 36 to match the default value assigned in linux.
I cannot find anything that confirms that default value in the driver.
As far as I can tell, the offset is a function of the OOB size, the page size, and the number of ECC bytes.
The routine atmel_pmecc_nand_init_params() has the salient code to calculate this offset:

Code: Select all

                nand_chip->ecc.strength = cap;
                nand_chip->ecc.bytes = pmecc_get_ecc_bytes(cap, sector_size);
                nand_chip->ecc.steps = mtd->writesize / sector_size;
                nand_chip->ecc.total = nand_chip->ecc.bytes *
                        nand_chip->ecc.steps;
                ...
                pmecc_config_ecc_layout(&atmel_pmecc_oobinfo,
                                        mtd->oobsize,
                                        nand_chip->ecc.total);
         ...
        atmel_pmecc_core_init(mtd);
When you retest, have you verified that the header and Device Tree match the configuration used to last write the flash?
Do you have another tool to r/w the flash, such as U-Boot?

Regards

Return to “SAMA5D Cortex-A5 MPU”

Who is online

Users browsing this forum: No registered users and 1 guest