This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

am335x nand write issue

Hi All,

I am using am335x and able to boot using mmc, but when flashing was done in u-boot space from usb using nand write command, I came across timeout error all the time as mentioned below.

Nand Flash: 512MB

I'm booting from mmc and going to u-boot space. Below are the logs.

U-Boot SPL 2013.10-00189-g78d8ebd-dirty (Oct 12 2015 - 12:12:29)
Enabling NAND pin mux Successful
s_init Success
before gpmc_init
after gpmc_init

DRA 618 MPU freq set to 720Mhz
DRA 618 Core freq set to 720Mhz
reading u-boot.img
reading u-boot.img

U-Boot 2013.10-00189-g78d8ebd-dirty (Oct 12 2015 - 12:12:29)

I2C:   ready
DRAM:  256 MiB
8-12-2014 before gpmc_init8-12-2014 after gpmc_initNAND:  512 MiB
MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Using default environment

Hit any key to stop autoboot:  0
U-Boot#
U-Boot#
U-Boot#
U-Boot# nand erase.chip

NAND erase.chip: device 0 whole chip
Erasing at 0x1ffe0000 -- 100% complete.
OK
U-Boot# usb reset
(Re)start USB...
USB0:   scanning bus 0 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
U-Boot# fatls usb 0  
   312124   u-boot.img
            svs1/ 
 182972416   ngt_ubifs.img
            lost.dir/    
 220200960   system_image.bin
         
  3 file(s), 0 dir(s)

U-Boot# fatload usb 0 0x81000000 system_image.bin
reading system_image.bin
220200960 bytes read in 134815 ms (1.6 MiB/s)
U-Boot# nand write 0x81000000 0x0 0xD200000

NAND write: device 0 offset 0x0, size 0xd200000
Timeout!NAND write to offset 0 failed -5
 0 bytes written: ERROR
U-Boot#
Does anyone is having similar kind of issue? Please let me know as soon as possible.
Thanks You.
Deshvir
  • Hi Deshvir,

    Even I am facing the same error. I didn't find any solution yet.

    Can anyone from TI please explain us the issue and provide any help.

    NAND write: device 0 offset 0x0, size 0xd200000
    Timeout!NAND write to offset 0 failed -5
     0 bytes written: ERROR


    Thanks

    Deep Ter

     

  • Hi,

    You're trying to flash ubifs to your nand, right?
    Can you try the following guide:
    processors.wiki.ti.com/.../AM335x_U-Boot_User's_Guide

    Best Regards,
    Yordan
  • Hi Yordan,

    We have followed the same guide. We were previously working on 1GB NAND. After changing the NAND size to 512 MB we are facing this issue.
    The ECC is now changed from 1 bit to 4 bit.Also the spare area was increased to 128 bytes per page.We had to change the BCH ECC scheme to OMAP_ECC_BCH16_CODE_HW using processors.wiki.ti.com/.../Linux_Core_NAND_User's_Guide
    We are able to flash till the u-boot.img.Due to this change it started booting.
    We are creating nand ubifs file system. Using the same method we created it for 1GB NAND and it was working. For 512 MB NAND we have taken care of the changes to be for creating ubifs i.e changes in the Volume size .

    But we are getting the timeout error .

    U-Boot # nand erase.chip
    U-Boot # fatload mmc 0 0x82000000 MLO
    U-Boot # nand write 0x82000000 NAND.SPL
    U-Boot # nand write 0x82000000 NAND.SPL.backup1
    U-Boot # nand write 0x82000000 NAND.SPL.backup2
    U-Boot # nand write 0x82000000 NAND.SPL.backup3
    U-Boot # fatload mmc 0 0x82000000 u-boot.img
    U-Boot # nand write 0x82000000 NAND.u-boot
    U-Boot # fatload mmc 0 0x82000000 zImage
    U-Boot # nand write 0x82000000 NAND.kernel
    U-Boot # run findfdt
    U-Boot # load mmc 0 0x82000000 $fdtfile
    U-Boot # nand write 0x82000000 NAND.u-boot-spl-os
    U-Boot # fatload mmc 0 0x82000000 ubi.img
    U-Boot # nand write 0x82000000 NAND.file-system
    U-Boot # saveenv


    NAND write: device 0 offset 0x0, size 0xd200000
    Timeout!NAND write to offset 0 failed -5
    0 bytes written: ERROR

    Thanks
  • Hi All,

    I am still stuck on this. Not able to find out what could be the issue.

    Can anyone from TI help?

  • Hi,

    We had to change the BCH ECC scheme to OMAP_ECC_BCH16_CODE_HW


    You modified the #define CONFIG_NAND_OMAP_ECCSCHEME in am335x_evm.h, right? What happens if you use the default
    #define CONFIG_NAND_OMAP_ECCSCHEME OMAP_ECC_BCH8_CODE_HW ?

    Best Regards,
    Yordan
  • The board was not able to boot itself with OMAP_ECC_BCH8_CODE. Look at this thread. Biser suggested me to add it. Then only it started booting
  • OK, thanks for the feedback.

    Can you share the am335x_evm.h, ti_am335x_common.h & ti_armv7_common.h files? Maybe there is something missing from the u-boot configuration.
  • Hi Yordan,

    Thanks for your support

    I have attached the 3 files.Also I wanted to ask you that as the OOBSIZE has been changed to 128,we have made the necessary changes in u-boot.But we need to confirm what changes we need to make in dts regarding oobsize. Where we need to add the oobsize in kernel. We have done the following changes in kernel to support the 128 bytes spare area

     ti,nand-ecc-opt ="bch16"
     ti,elm-id="<&elm>
    KConfigs
    CONFIG_MTD_NAND_OMAP_BCH=y

    ti_armv7_common.hti_am335x_common.h

    4578.am335x_evm.h
    Thanks for your support

  • Hi Yordan and Biser

    Any update on this issue?

    Thanks
  • Hi,

    Your u-boot stops in nand_base.c, nand_wait() :
    while (1) {
          if (get_timer(time_start) > timeo) {
                 printf("Timeout!");
                 return 0x01;
          }

    And then stops the programming of your nand, see nand_util.c: nand_write_skip_bad():
    if (!need_skip && !(flags & WITH_DROP_FFS)) {
              rval = nand_write(nand, offset, length, buffer);
              if (rval == 0)
                      return 0;

              *length = 0;
              printf("NAND write to offset %llx failed %d\n",
                       offset, rval);
    ......................
    ......................

    if (rval != 0) {
               printf("NAND write to offset %llx failed %d\n",
                        offset, rval);
               *length -= left_to_write;
                return rval;
    }

    Is it possible that your nand is somehow damaged? Can you boot your board through sd card & use mtd utils to test your nand?

    Best Regards,
    Yordan

  • Hi Yordan,

    Thanks for your reply.

    We have been booting from NAND upto filesystem.

    This Timeout issue is random. After 4-5 timeouts we are able to write image on the NAND. Kindly see the logs :


    U-Boot SPL 2013.10 (Aug 24 2016 - 21:55:20)
    s_init Success
    DRA 618 MPU freq set to 720Mhz
    DRA 618 Core freq set to 720Mhz
    reading u-boot.img
    reading u-boot.img


    U-Boot 2013.10 (Aug 24 2016 - 21:55:20)

    I2C: ready
    DRAM: 256 MiB
    dcache_enable
    NAND: 512 MiB
    MMC: OMAP SD/MMC: 0, OMAP SD/MMC: 1
    Using default environment

    Press NGT Keycode to stop autoboot in 1 second
    U-Boot#
    U-Boot#
    U-Boot# nand erase.chip

    NAND erase.chip: device 0 whole chip
    Erasing at 0x1ffe0000 -- 100% complete.
    OK
    U-Boot#
    U-Boot#
    U-Boot# usb reset
    (Re)start USB...
    USB0: scanning bus 0 for devices... 1 USB Device(s) found
    scanning usb for storage devices... 1 Storage Device(s) found
    U-Boot# fatls usb 0

    36515 am335x-boneblack.dtb
    18964 mlo
    189399040 ngt_ubifs.ubifs
    312124 u-boot.img
    189 uenv.txt
    2997091 zimage_with_dtb
    220200960 system_image.bin


    37 file(s), 21 dir(s)

    U-Boot# fatload usb 0 0x81000000 mlo
    reading mlo
    18964 bytes read in 35 ms (528.3 KiB/s)
    U-Boot# nand write 0x81000000 0x0 0x4a14

    NAND write: device 0 offset 0x0, size 0x4a14
    18964 bytes written: OK
    U-Boot# nand write 0x81000000 0x20000 0x4a14

    NAND write: device 0 offset 0x20000, size 0x4a14
    18964 bytes written: OK
    U-Boot# nand write 0x81000000 0x40000 0x4a14

    NAND write: device 0 offset 0x40000, size 0x4a14
    18964 bytes written: OK
    U-Boot# nand write 0x81000000 0x60000 0x4a14

    NAND write: device 0 offset 0x60000, size 0x4a14
    18964 bytes written: OK
    U-Boot# fatload usb 0 0x81000000 zimage_with_dtb
    reading zimage_with_dtb
    2997091 bytes read in 2427 ms (1.2 MiB/s)
    U-Boot# fatload usb 0 0x81000000 am335x-boneblack.dtb
    reading am335x-boneblack.dtb
    36515 bytes read in 50 ms (712.9 KiB/s)
    U-Boot# nand write 0x81000000 0x80000 0x8ea3

    NAND write: device 0 offset 0x80000, size 0x8ea3
    36515 bytes written: OK
    U-Boot# fatload usb 0 0x81000000 u-boot.img
    reading u-boot.img
    312124 bytes read in 227 ms (1.3 MiB/s)
    U-Boot# nand write 0x81000000 0xc0000 0x4c33c

    NAND write: device 0 offset 0xc0000, size 0x4c33c
    312124 bytes written: OK
    U-Boot# fatload usb 0 0x81000000 uenv.txt
    reading uenv.txt
    189 bytes read in 17 ms (10.7 KiB/s)
    U-Boot# nand write 0x81000000 0x140000 0xbd

    NAND write: device 0 offset 0x140000, size 0xbd
    189 bytes written: OK
    U-Boot# nand write 0x81000000 0x160000 0xbd

    NAND write: device 0 offset 0x160000, size 0xbd
    189 bytes written: OK
    U-Boot# fatload usb 0 0x81000000 zimage_with_dtb
    reading zimage_with_dtb
    2997091 bytes read in 1968 ms (1.5 MiB/s)
    U-Boot# nand write 0x81000000 0x700000 0x2dbb63

    NAND write: device 0 offset 0x700000, size 0x2dbb63
    2997091 bytes written: OK
    U-Boot# fatload usb 0 0x81000000 ngt_ubifs.ubifs
    reading ngt_ubifs.ubifs
    189399040 bytes read in 122910 ms (1.5 MiB/s)
    U-Boot# nand write 0x81000000 0xa00000 0xb4a0000

    NAND write: device 0 offset 0xa00000, size 0xb4a0000
    Timeout!NAND write to offset a00000 failed -5
    0 bytes written: ERROR
    U-Boot# nand write 0x81000000 0xa00000 0xb4a0000

    NAND write: device 0 offset 0xa00000, size 0xb4a0000
    Timeout!NAND write to offset a00000 failed -5
    0 bytes written: ERROR
    U-Boot# nand write 0x81000000 0xa00000 0xb4a0000

    NAND write: device 0 offset 0xa00000, size 0xb4a0000
    189399040 bytes written: OK




    As you can see from the logs it is writing after 4-5 attempts. Not able to understand the issue

    Thanks
    Deep
  • We will also try to test using mtd-utils in kernel after booting from sd card.
    Thanks for your support till now
  • Hi

    I booted using SD card and tried MTD-utils on all the partitions. You can check the logs for the following:

    root@ngt:~#
    root@ngt:~#
    root@ngt:~#
    root@ngt:~# nandtest -k -o 0x0 -l 0x20000 /dev/mtd0
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    00000000: checking...
    Finished pass 1 successfully
    root@ngt:~# nandtest -k -o 0x20000 -l 0x20000 /dev/mtd1
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    00000000: checking...
    Finished pass 1 successfully
    root@ngt:~# nandtest -k -o 0x40000 -l 0x20000 /dev/mtd2
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    00000000: checking...
    Finished pass 1 successfully
    root@ngt:~# nandtest -k -o 0x60000 -l 0x20000 /dev/mtd3
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    00000000: checking...
    Finished pass 1 successfully
    root@ngt:~# nandtest -k -o 0x80000 -l 0x40000 /dev/mtd4
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    00020000: checking...
    Finished pass 1 successfully
    root@ngt:~# nandtest -k -o 0xc0000 -l 0x80000 /dev/mtd5
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    00060000: checking...
    Finished pass 1 successfully
    root@ngt:~# nandtest -k -o 0x140000 -l 0x20000 /dev/mtd6
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    00000000: checking...
    Finished pass 1 successfully
    root@ngt:~# nandtest -k -o 0x160000 -l 0x5a0000 /dev/mtd7
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    00580000: checking...
    Finished pass 1 successfully
    root@ngt:~# nandtest -k -o 0x700000 -l 0x300000 /dev/mtd8
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    002e0000: checking...
    Finished pass 1 successfully
    root@ngt:~# nandtest -k -o 0xa00000 -l 0xf600000 /dev/mtd9
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    0c9c0000: reading...
     44 bit(s) ECC corrected at 0c9c0000
    0c9c0000: reading...
     32 bit(s) ECC corrected at 0c9c0000
    0f5e0000: checking...
    Finished pass 1 successfully
    root@ngt:~#
    root@ngt:~# nandtest -k -o 0x10000000 -l 0x10000000 /dev/mtd10
    ECC corrections: 0
    ECC failures   : 0
    Bad blocks     : 0
    BBT blocks     : 0
    04760000: reading...
     18 bit(s) ECC corrected at 04760000
    04760000: reading...
     32 bit(s) ECC corrected at 04760000
    0ffe0000: checking...
    Finished pass 1 successfully

    -------------------------------------------------

    I didn't found any issues with the nandtest. Still timeouts are coming when I am writing large size image on NAND. It is written only after 4-5 timeouts.

     

    Thanks

     

  • Hi Biser and Yordan,

    There is a configuration in nand_base.c file

    CONFIG_SYS_NAND_RESET_CNT . Right now it is set to 200000. Can I increase that value to prevent timeout. Also what other impacts will it give?

    Thanks
    Deep Ter
  • Hi,

    You could increase this counter, but you need to meet the requirement that CONFIG_SYS_NAND_RESET_CNT should not exceed max NAND reset time / NAND status read time. So the maximum allowed nand rst cnt will depend on the nand chip timings.

    Best Regards.
    Yordan
  • Hi

    I checked from the NAND datasheet. Max NAND reset time is 500 micro sec and max Read status time is 25ns. So we cannot change this value. Any other suggestion to prevent timeout?

    Thanks
    Deep Ter
  • Hi Yordan,

    We are still stuck on that. Do you have any suggestions?

    Thanks
    Deep Ter
  • Hi,

    Have a look at a newer u-boot, i.e. u-boot2015.07 from SDK02.00.02.11. There are some additional helper functions added in, such as panic_nand_get_device() & panic_nand_wait() ([GENERIC] wait until the command is done):

    /**
    * panic_nand_get_device - [GENERIC] Get chip for selected access
    * @chip: the nand chip descriptor
    * @mtd: MTD device structure
    * @new_state: the state which is requested
    *
    * Used when in panic, no locks are taken.
    */
    ====================================
    /**
    * panic_nand_wait - [GENERIC] wait until the command is done
    * @mtd: MTD device structure
    * @chip: NAND chip structure
    * @timeo: timeout
    *
    * Wait for command done. This is a helper function for nand_wait used when
    * we are in interrupt context. May happen when in panic and trying to write
    * an oops through mtdoops.
    */

    Also the read & write functions are updated.

    Can you try booting your board with that u-boot (u-boot-2015.07+gitAUTOINC+46c915c963)? It shouldn't be a problem for fully booting your OS, if you change just the u-boot & leave the older kernel & filesystem.

    Best Regards,
    Yordan
  • Hi Yordan,

    Thanks a lot for your suggestion.

    Just now I tried with adding a 500ns delay inside nand_wait() function. I added the delay after it is trying to send NAND_CMD_STATUS . It worked for me. So, the issue may be that NAND wanted some more time to get ready.
    Meanwhile we will also try with u-boot-2015.07+gitAUTOINC+46c915c963.

    Thanks for helping me throughout the issue

    Thanks
    Deep ter
  • Hi Deepika and Yordan,

    Thanks a lot. Even my nand flash issue is resolved after providing delay.

    Best Regards

    Deshvir Malik