Page 1 of 1

at91sam9260ek, How to change the nand-flash.

Posted: Tue Jul 14, 2020 12:10 pm
by mmanzel
We have built a device upon the base of the at91sam9260ek. The original flash is discontinued now and
we need to change it.
A problem that arises here is the ecc-strength, which has grown over the years.
Nor the processor nor the tools support the necessary strength. But the nice thing is, that the nand has learned to do it internally.

As I got some help here in this forum I would like to draw my way to get it functioning. We use the following chip: Micron MT29F2G08ABAGAWP

There are four tools that write to the nand and need to be adopted: Sam-ba, Bootstrap, u-boot and linux.
The only way I found was to switch off ecc, to let it do the on-die hardware.

To get it a bit more clear I want to put my description into four posts, starting with Sam-ba:
- In EccNandFlash.c you need to switch off the ecc calculation and writing. The proposed chip has the
on-die ecc calculation switched on, so there is no need to switch it on.
- In main.c there are some changes to follow the complaints of the modern gcc.
- You have to compile the files using a none-eabi gcc! I used: gcc-arm-none-eabi-9-2020-q2-update

I would like to attach the changed files, but my quota seems to be below 17kB.
If you are interested I can send it to you.

Re: at91sam9260ek, How to change the nand-flash.

Posted: Tue Jul 14, 2020 1:01 pm
by mmanzel
2. The Bootstrap loader:

Here it it was not necessary to change source code. I configured:

Switched off:
- Memory selection ---> NAND flash configuration ---> Use NAND flash with small blocks
- Memory selection ---> NAND flash configuration ---> Using Software ECC

Switched on:
- Memory selection ---> NAND flash configuration ---> Support to use NAND flash On-Die ECC

Re: at91sam9260ek, How to change the nand-flash.

Posted: Tue Jul 14, 2020 1:28 pm
by mmanzel
3. u-boot:

I defined CONFIG_NAND_ECC_NONE in buildroot-2019.11/output/build/uboot-2016.09.0/include/configs/at91sam9260ek.h

Than I added in buildroot-2019.11/output/build/uboot-2016.09.01/drivers/mtd/nand/atmel_nand.c
the lines:
nand->ecc.mode = NAND_ECC_NONE;

to the functions board_nand_init() and atmel_nand_chip_init()
nand->ecc.mode = NAND_ECC_SOFT;

In nand_base.c there is already a case NAND_ECC_NONE, which does the initialization.

Re: at91sam9260ek, How to change the nand-flash.

Posted: Tue Jul 14, 2020 2:31 pm
by mmanzel
4. Linux

In the device tree I switched off ecc:
In buildroot-2019.11/output/build/linux-4.8.6/arch/arm/boot/dts/at91sam9260ek.dts:
nand-ecc-mode = "none"

In buildroot-2019.11/output/build/linux-4.8.6/drivers/mtd/nand/atmel_nand.c,
in atmel_nand_probe() I changed:
nand_chip->chip_delay = 80; /* 40 --> 80 */

Now it should work like with u-boot, but the function shrink_ecclayout() in
has and error, does not return and stops our linux if we call flasherase from user space.
So I added in mtdchar.c:

/* This ioctl is being deprecated - it truncates the ECC layout */
struct nand_ecclayout_user *usrlay;

if (!mtd->ooblayout)

/* added */
if (mtd->ecc_strength == 0)
/* added */

usrlay = kmalloc(sizeof(*usrlay), GFP_KERNEL);