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.

NAND page size

Expert 1005 points

I have a board that we build for some times now and recently we build a new batch.

The new batch can not write/read from NAND.

We checked and NAND is the same part number and everything else is the same. We used a NAND from old batch and placed it on new board and the new board worked, we placed the NAND from a non working board into a working board and the working board stops working. So we belive it is the NAND that makes the problem.

After some investigation, we found that on a working board, we are getting this message in uboot :

nand info

Device 0: NAND 512MiB 3,3V 16-bit, sector size 128 KiB

and on a non working board we are getting this:

Device 0: NAND 512MiB 3,3V 16-bit, sector size 256 KiB

apparently the sector size is changed.

The device is: MT29F4G16ABAEAH4

How important is sector size? and how can I change the kernel and uboot to work with this new sector size?

  • Mans,

    mans said:
    Device 0: NAND 512MiB 3,3V 16-bit, sector size 128 KiB

    mans said:
    Device 0: NAND 512MiB 3,3V 16-bit, sector size 256 KiB

    Can you try modify the below file:

    ti-ezsdk_dm814x-evm_5_05_02_00/board-support/u-boot-2010.06-psp04.04.00.01/arch/arm/cpu/arm_cortexa8/omap3/mem.c

    #if defined(CONFIG_ENV_IS_IN_NAND)
        f_off = SMNAND_ENV_OFFSET;
       - f_sec = (128 << 10);    /* 128 KiB */
       +f_sec = (256 << 10);    /* 256 KiB */
        /* env setup */
        boot_flash_base = base;
        boot_flash_off = f_off;
        boot_flash_sec = f_sec;
        boot_flash_env_addr = f_off;

    See also the below e2e discussions:

    http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/100/t/311521.aspx

    http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/716/t/244831.aspx

    http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/717/t/231420.aspx

    Regards,
    Pavel

  • Thanks.

      After this change, should I change the boot.scr or the old boot.scr should work ?

  • Mans,

    mans said:
    After this change, should I change the boot.scr or the old boot.scr should work ?

    No, old boot.src should work.

    You need to compile and flash new u-boot.min.nand and new u-boot.bin.

    Note that the file you should modify is:

    ti-ezsdk_dm814x-evm_5_05_02_00/board-support/u-boot-2010.06-psp04.04.00.01/arch/arm/cpu/arm_cortexa8/ti81xx/mem.c

    #if defined(CONFIG_ENV_IS_IN_NAND)
        f_off = MNAND_ENV_OFFSET;
        //f_sec = (128 << 10);    /* 128 KiB */
        f_sec = (256 << 10);    /* 256 KiB */
        /* env setup */
        boot_flash_base = base;
        boot_flash_off = f_off;
        boot_flash_sec = f_sec;
        boot_flash_env_addr = f_off;

    Regards,
    Pavel

  • Thanks,

    Should I compile and use new MLO for SD card boot? I am using SD card to bot and then write uboot.min.nand and uboot.bin into nand.

  • Mans,

    mans said:
    Should I compile and use new MLO for SD card boot?

    No, you do not need new MLO and u-boot.bin for SD card boot.

    Best regards,
    Pavel

  • Thanks. I compiled the new nboot.min.nand and uboot.bin and wrote them to nand using this command from second stage of uboot.

    setenv success 1
    setenv loadaddr 0x81000000
    # Two notes:
    # 1. FAT file-systems handle letter case strangely---we should use
    #    lower-case only
    # 2. x-load should be copied first to the microSD card otherwise U-Boot
    #    doesn't see it.

        
      echo "Erasing nand..."
      nandecc hw 2
      nand erase

      echo "Flashing uimage..."
      mw.b ${loadaddr} 0xFF 0x2A0000
      if fatload mmc 0:1 ${loadaddr} uimage; then
         nand write ${loadaddr} 0x00280000 0x2A0000
      else
        echo "ERROR: couldn\'t find uimage..."
        setenv success 0
      fi

      echo "Flashing u-boot.bin..."
      mw.b ${loadaddr} 0xFF 0x240000
      if fatload mmc 0:1 ${loadaddr} u-boot.bin; then
        nand write.i ${loadaddr} 0x20000 0x240000
      else
       echo "ERROR: couldn\'t find u-boot.bin..."
        setenv success 0
      fi

      echo "Flashing u-boot.min.nand..."
      mw.b ${loadaddr} 0xFF 0x240000
      if fatload mmc 0:1 ${loadaddr} u-boot.min.nand; then
        nand write.i ${loadaddr} 0x00000000 0x00020000
      else
        echo "ERROR: couldn\'t find u-boot.min.nand..."
        setenv success 0
      fi

    # display error condition
    if test $success -eq 1; then
      echo "COMPLETED SUCCESSFULLY"
    else
      echo "COMPLETED WITH ERRORS"
    fi


    #echo "Flashing boot.env..."
    setenv bootcmd 'mmc rescan 0;if run loadbootscript; then run bootscript; else run nandboot; fi'
    setenv bootfile 'uImage'
    setenv loadaddr '0x81000000'
    setenv console 'ttyO0,115200n8'
    setenv nandargs 'setenv bootargs console=${console} rw ubi.mtd=4,2048 root=${rootfs_partition} rootfstype=ubifs init=/init earlyprintk ethaddr=9c:e1:0e:00:00:04 ip=10.0.0.51:10.0.0.45:10.0.0.254:255.0.0.0:istar:eth0:off ti814xfb.vram=0:8M,1:8M notifyk.vpssm3_sva=0xA0000000 vram=16M mem=384M mem=39M@0x9BD00000 mem=7M@0x9F900000 mem=275M@0xA2000000'
    setenv loadbootscript 'fatload mmc 0:1 ${loadaddr} boot.scr'
    setenv bootscript 'echo Running bootscript from mmc ...; source ${loadaddr}'
    setenv nandboot 'echo Booting from nand ...; run nandargs; nand read ${loadaddr} ${kernel_partition} 2A0000; bootm ${loadaddr}'
    setenv kernel_partition '280000'
    setenv rootfs_partition 'ubi0:rootfs'
    setenv bootdelay '1'
    setenv stdin 'serial'
    setenv stdout 'serial'
    setenv stderr 'serial'
    saveenv

    The output during flashing board is:


    U-Boot 2010.06-dirty (Mar 28 2013 - 11:12:27)

    TI8148-GP rev 2.1

    ARM clk: 600MHz
    DDR clk: 400MHz

    DRAM:  2 GiB
    MMC:   OMAP SD/MMC: 0
    Using default environment

    Hit any key to stop autoboot:  0
    reading u-boot.bin

    182868 bytes read
    ## Starting application at 0x80800000 ...


    U-Boot 2010.06-dirty (Mar 18 2013 - 09:49:00)

    TI8148-GP rev 2.1

    ARM clk: 600MHz
    DDR clk: 400MHz

    I2C:   ready
    DRAM:  2 GiB
    NAND:  HW ECC BCH8 Selected
    512 MiB
    MMC:   OMAP SD/MMC: 0
    *** Warning - bad CRC or NAND, using default environment

    Net:   <ethaddr> not set. Reading from E-fuse
    Detected MACID:84:7e:40:2a:e7:ae
    cpsw
    Hit any key to stop autoboot:  0
    reading boot.scr

    2732 bytes read
    Running bootscript from MMC/SD to set the ENV...
    ## Executing script at 80900000
    Erasing nand...
    HW ECC BCH8 Selected

    NAND erase: device 0 whole chip
    Erasing at 0x1ffc0000 -- 100% complete.
    OK
    Flashing uimage...
    reading uimage

    2421504 bytes read

    NAND write: device 0 offset 0x280000, size 0x2a0000
     2752512 bytes written: OK
    Flashing u-boot.bin...
    reading u-boot.bin

    182868 bytes read

    NAND write: device 0 offset 0x20000, size 0x240000
     2359296 bytes written: OK
    Flashing u-boot.min.nand...
    reading u-boot.min.nand

    93428 bytes read

    NAND write: device 0 offset 0x0, size 0x20000
     131072 bytes written: OK
    COMPLETED SUCCESSFULLY
    Saving Environment to NAND...
    Erasing Nand...
    Warning: Erase size 0x00002000 smaller than one erase block 0x00040000
             Erasing 0x00040000 instead

    NAND 512MiB 3,3V 16-bit: MTD Erase failure: -22

    I can see that the MTDs are not aligned to page block, but how can I change them as I think I need to change them in code so they for example uboot min knows where to find boot.bin and uboot.bin knows where to read its environment.

    How can I change the nand memory map?

  • Mans,

    mans said:
    How can I change the nand memory map?

    The NAND memory map in u-boot is as below:

    http://processors.wiki.ti.com/index.php/TI81XX_PSP_UBOOT_User_Guide#NAND_Layout

    Which part of the NAND memory map you need to change? Note that the 1st stage start address can not be changed as the DM814x ROM Code is expecting to find the 1st stage bootloader at this address.

    I will also recommend you to flash first the u-boot.min.nand, then u-boot.bin, then env settings, then uImage, then root fs.

    For ENV start addr and settings, see the below file:

    ti-ezsdk_dm814x-evm_5_05_02_00/board-support/u-boot-2010.06-psp04.04.00.01/include/configs/ti8148_evm.h

    /* NAND support */
    #ifdef CONFIG_NAND
    #define CONFIG_CMD_NAND
    #define CONFIG_NAND_TI81XX
    #define GPMC_NAND_ECC_LP_x16_LAYOUT     1
    #define NAND_BASE            (0x08000000)
    #define CONFIG_SYS_NAND_ADDR        NAND_BASE    /* physical address */
                                /* to access nand */
    #define CONFIG_SYS_NAND_BASE        NAND_BASE    /* physical address */
                                /* to access nand at */
                                /* CS0 */
    #define CONFIG_SYS_MAX_NAND_DEVICE    1        /* Max number of NAND */
    #endif                            /* devices */

    /* ENV in NAND */
    #if defined(CONFIG_NAND_ENV)
    # undef CONFIG_ENV_IS_NOWHERE
    # define CONFIG_ENV_IS_IN_NAND        1
    # ifdef CONFIG_ENV_IS_IN_NAND
    #  define CONFIG_SYS_MAX_FLASH_SECT    520        /* max number of sectors in a chip */
    #  define CONFIG_SYS_MAX_FLASH_BANKS    2        /* max number of flash banks */
    #  define CONFIG_SYS_MONITOR_LEN    (256 << 10)    /* Reserve 2 sectors */
    #  define CONFIG_SYS_FLASH_BASE        boot_flash_base
    #  define CONFIG_SYS_MONITOR_BASE    CONFIG_SYS_FLASH_BASE
    #  define MNAND_ENV_OFFSET        0x260000    /* environment starts here */
    #  define CONFIG_SYS_ENV_SECT_SIZE    boot_flash_sec
    #  define CONFIG_ENV_OFFSET        boot_flash_off
    #  define CONFIG_ENV_ADDR        MNAND_ENV_OFFSET
    # endif

    # ifndef __ASSEMBLY__
    extern unsigned int boot_flash_base;
    extern volatile unsigned int boot_flash_env_addr;
    extern unsigned int boot_flash_off;
    extern unsigned int boot_flash_sec;
    extern unsigned int boot_flash_type;
    # endif
    #endif /* NAND support */

    Regards,
    Pavel

  • mans said:
    Warning: Erase size 0x00002000 smaller than one erase block 0x00040000
             Erasing 0x00040000 instead

    The below links might be in help:

    http://processors.wiki.ti.com/index.php/TI81XX_PSP_FAQ#Uboot_Warning:_Erase_size_0x00002000_smaller_than_one_erase_block_0x00020000_Erasing_0x00020000_instead

    http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/717/t/149445.aspx

    http://e2e.ti.com/support/arm/sitara_arm/f/791/t/242186.aspx

    http://e2e.ti.com/support/arm/sitara_arm/f/791/t/246979.aspx

    Regards,
    Pavel

  • Thanks,

    If I manage to compile the uboot with the changes that you suggested, does it works on old boards too?  Since the erase block for new boards is exactly 2 time of the erase block of old board, I think it should work, but I like to make sure that there is not any else that I need to know.

    I am not sure that the new memory map is working properly when page size/erase block  of nand changed? Should it works?

  • Mans,

    Consider also the below u-boot patch:

    http://arago-project.org/git/projects/u-boot-omap3.git?p=projects/u-boot-omap3.git;a=commit;h=6edf92d4089aada02b6b19b912ac63763ae00483

    Regards,
    Pavel