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.

AM625: AM62x SPI NAND Flash Bad Block Management

Part Number: AM625


Hi,

We tested two winbond SPI-Nand Flash, W25N02 (QSPI) and W35N02 (OSPI), on customer boards, and both encountered bad block problems.There was no problem with reading and writing at the beginning, but after a few days of testing, many bad blocks appeared.The read and write commands are as follows

mtd erase ospi_nand.tiboot3
ext4load mmc 0:2 ${loadaddr} /home/root/tiboot3.bin
mtd write ospi_nand.tiboot3 ${loadaddr} 0 $filesize
mtd read ospi_nand.tiboot3 ${cmpaddr} 0 $filesize


W25N02, some blocks have become bad blocks.

=> mtd list
List of MTD devices:
* spi-nand0
  - device: flash@0
  - parent: spi@fc40000
  - driver: spi_nand
  - path: /bus@f0000/bus@fc00000/spi@fc40000/flash@0
  - type: NAND flash
  - block size: 0x20000 bytes
  - min I/O: 0x800 bytes
  - OOB size: 64 bytes
  - OOB available: 24 bytes
  - 0x000000000000-0x000010000000 : "spi-nand0"
          - 0x000000000000-0x000000100000 : "ospi_nand.tiboot3"
          - 0x000000100000-0x000000300000 : "ospi_nand.tispl"
          - 0x000000300000-0x000000700000 : "ospi_nand.u-boot"
          - 0x000000700000-0x000000740000 : "ospi_nand.env"
......
          - 0x00000ffc0000-0x000010000000 : "ospi_nand.phypattern"
=> mtd erase ospi_nand.tiboot3
Erasing 0x00000000 ... 0x000fffff (8 eraseblock(s))
Skipping bad block at 0x00020000
Skipping bad block at 0x00040000
=> mtd erase ospi_nand.tispl
Erasing 0x00000000 ... 0x001fffff (16 eraseblock(s))
Skipping bad block at 0x00180000
Skipping bad block at 0x001a0000
Skipping bad block at 0x001c0000
Skipping bad block at 0x001e0000
=> mtd erase ospi_nand.u-boot
Erasing 0x00000000 ... 0x003fffff (32 eraseblock(s))
Skipping bad block at 0x00000000
Skipping bad block at 0x00020000
Skipping bad block at 0x00040000
Skipping bad block at 0x00060000
Skipping bad block at 0x00080000
=>

In W35N02, all blocks have become bad blocks.

=> mtd list
List of MTD devices:
* spi-nand0
  - device: flash@0
  - parent: spi@fc40000
  - driver: spi_nand
  - path: /bus@f0000/bus@fc00000/spi@fc40000/flash@0
  - type: NAND flash
  - block size: 0x40000 bytes
  - min I/O: 0x1000 bytes
  - OOB size: 128 bytes
  - OOB available: 80 bytes
  - 0x000000000000-0x000010000000 : "spi-nand0"
          - 0x000000000000-0x000000080000 : "ospi_nand.tiboot3"
          - 0x000000080000-0x000000280000 : "ospi_nand.tispl"
          - 0x000000280000-0x000000680000 : "ospi_nand.u-boot"
          - 0x000000680000-0x0000006c0000 : "ospi_nand.env"
......
          - 0x00000ffc0000-0x000010000000 : "ospi_nand.phypattern"
=> mtd erase ospi_nand.tiboot3
Erasing 0x00000000 ... 0x0007ffff (2 eraseblock(s))
Skipping bad block at 0x00000000
Skipping bad block at 0x00040000
=> mtd erase ospi_nand.tispl
Erasing 0x00000000 ... 0x001fffff (8 eraseblock(s))
Skipping bad block at 0x00000000
Skipping bad block at 0x00040000
Skipping bad block at 0x00080000
Skipping bad block at 0x000c0000
Skipping bad block at 0x00100000
Skipping bad block at 0x00140000
Skipping bad block at 0x00180000
Skipping bad block at 0x001c0000
=> mtd erase ospi_nand.u-boot
Erasing 0x00000000 ... 0x003fffff (16 eraseblock(s))
Skipping bad block at 0x00000000
Skipping bad block at 0x00040000
Skipping bad block at 0x00080000
Skipping bad block at 0x000c0000
Skipping bad block at 0x00100000
Skipping bad block at 0x00140000
Skipping bad block at 0x00180000
Skipping bad block at 0x001c0000
Skipping bad block at 0x00200000
Skipping bad block at 0x00240000
Skipping bad block at 0x00280000
Skipping bad block at 0x002c0000
Skipping bad block at 0x00300000
Skipping bad block at 0x00340000
Skipping bad block at 0x00380000
Skipping bad block at 0x003c0000
=>

Under normal circumstances, there should not be so many bad blocks in the flash during the past few days of testing. 
1. Whether to use mtd read/write command to operate flash under uboot? Are there any other instructions I can use?
2. There are so many bad blocks, especially on W35N02, the partition has all become bad blocks. It is suspected that it has been marked by mistake. Is there any way to clear the bad block marks?
3. Are there any suggested tools that can be used to debug Flash? Both uboot and Linux are available

Regards,
Stephen

  • We tested two winbond SPI-Nand Flash, W25N02 (QSPI) and W35N02 (OSPI), on customer boards, and both encountered bad block problems.There was no problem with reading and writing at the beginning, but after a few days of testing, many bad blocks appeared.The read and write commands are as follows

    Are you saying you executed those raw commands in an endless loop??? How often?

    Usually raw flash like OSPI/QSPI NAND/NOR  is used with some kind of wear-leveling driver (like the UBI subsystem, used by UBIFS), rather than "beating on it" in a raw fashion, which may lead to premature wear.

    Regards, Andreas

  • Hi Andreas,
    The test is not in a loop. The purpose of our operation is to test the Flash boot mode, write uboot image and ubifs to the Flash and then test the startup function. If there is a problem with startup after writing, we will reconfigure uboot or ubifs and then write it again. The number of writes is not very large, not exceed 10 times/day.

    Regards,
    Stephen

  • The number of writes is not very large, not exceed 10 times/day.

    Ok good, you should be able to do such raw flash operations 100s of times without issues. You just can't do that continuously. The Flash datasheet would have the details on min. erase/write cycles for a given block, but this is likely not your issue.

    Perhaps there's some other SW problem at play here, accidentally marking the blocks as bad. You can reset the bad block information in U-Boot by executing the `nand scrub` command to see if this fixes things. You will need to turn on CONFIG_CMD_NAND in U-Boot to get access to that command.

    https://git.ti.com/cgit/ti-u-boot/ti-u-boot/tree/doc/README.nand?h=ti-u-boot-2023.04#n215

    "scrub [offset length]"
    like "erase" but don't skip bad block. Instead erase them.
    DANGEROUS!!! Factory set bad blocks will be lost. Use only
    to remove artificial bad blocks created with the "markbad" command.

    If this fixes things we still need to figure out what is going wrong in the first place.

    Regards, Andreas

  • You will need to turn on CONFIG_CMD_NAND in U-Boot to get access to that command.

    Does CMD_NAND only can be used for parallel NAND flash, but not SPI NAND Flash?

    I tried enable nand cmd in uboot before but cannot operate the device.

    enabled CONFIG_CMD_NAND and CONFIG_MTD_RAW_NAND, and the error encountered during linking is as follows.

      CC      drivers/mtd/nand/raw/nand.o
      CC      drivers/mtd/nand/raw/nand_bbt.o
      CC      drivers/mtd/nand/raw/nand_ids.o
      CC      drivers/mtd/nand/raw/nand_util.o
      CC      drivers/mtd/nand/raw/nand_ecc.o
      CC      drivers/mtd/nand/raw/nand_base.o
      CC      drivers/mtd/nand/raw/nand_amd.o
      CC      drivers/mtd/nand/raw/nand_hynix.o
      CC      drivers/mtd/nand/raw/nand_macronix.o
      CC      drivers/mtd/nand/raw/nand_micron.o
      CC      drivers/mtd/nand/raw/nand_samsung.o
      CC      drivers/mtd/nand/raw/nand_toshiba.o
      CC      drivers/mtd/nand/raw/nand_timings.o
      AR      drivers/mtd/nand/raw/built-in.o
      CC      drivers/mtd/nand/spi/core.o
      CC      drivers/mtd/nand/spi/gigadevice.o
      CC      drivers/mtd/nand/spi/macronix.o
      CC      drivers/mtd/nand/spi/micron.o
      CC      drivers/mtd/nand/spi/toshiba.o
      CC      drivers/mtd/nand/spi/winbond.o
      AR      drivers/mtd/nand/spi/spinand.o
      AR      drivers/mtd/nand/spi/built-in.o
      CC      drivers/mtd/nand/core.o
      CC      drivers/mtd/nand/bbt.o
      AR      drivers/mtd/nand/nandcore.o
      AR      drivers/mtd/nand/built-in.o
      AR      drivers/mtd/onenand/built-in.o
      CC      drivers/mtd/spi/sf-uclass.o
      CC      drivers/mtd/spi/sf_probe.o
      CC      drivers/mtd/spi/spi-nor-ids.o
      CC      drivers/mtd/spi/spi-nor-core.o
      AR      drivers/mtd/spi/spi-nor.o
      AR      drivers/mtd/spi/built-in.o
      LDS     u-boot.lds
      LD      u-boot
    aarch64-none-linux-gnu-ld.bfd: drivers/mtd/nand/raw/nand.o: in function `nand_init_chip':
    /home/z98999/am62x/ti-u-boot/drivers/mtd/nand/raw/nand.c:92: undefined reference to `board_nand_init'
    /bin/sh: line 1: 23223 Segmentation fault      (core dumped) aarch64-none-linux-gnu-ld.bfd -z noexecstack -pie --gc-sections -Bstatic --no-dynamic-linker -z notext --build-id=none -Ttext 0x80800000 -o u-boot -T u-boot.lds arch/arm/cpu/armv8/start.o --whole-archive arch/arm/cpu/built-in.o arch/arm/cpu/armv8/built-in.o arch/arm/lib/built-in.o arch/arm/mach-k3/built-in.o board/ti/am62x/built-in.o board/ti/common/built-in.o boot/built-in.o cmd/built-in.o common/built-in.o disk/built-in.o drivers/built-in.o drivers/usb/cdns3/built-in.o drivers/usb/common/built-in.o drivers/usb/dwc3/built-in.o drivers/usb/emul/built-in.o drivers/usb/eth/built-in.o drivers/usb/gadget/built-in.o drivers/usb/gadget/udc/built-in.o drivers/usb/host/built-in.o drivers/usb/isp1760/built-in.o drivers/usb/mtu3/built-in.o drivers/usb/musb-new/built-in.o drivers/usb/musb/built-in.o drivers/usb/phy/built-in.o drivers/usb/ulpi/built-in.o env/built-in.o fs/built-in.o lib/built-in.o net/built-in.o --no-whole-archive -L /home/z98999/cross_compile/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1 -lgcc -Map u-boot.map
    /home/z98999/am62x/ti-u-boot/Makefile:1754: recipe for target 'u-boot' failed
    make[1]: *** [u-boot] Error 139
    make[1]: *** Deleting file 'u-boot'
    make[1]: Leaving directory '/home/z98999/am62x/ti-u-boot/out/a53'
    Makefile:177: recipe for target 'sub-make' failed
    make: *** [sub-make] Error 2
    

    It seems that the Raw Nand driver should be enabled. There is no Winbond driver in Raw NAND Device Support, so I enabled CONFIG_NAND_OMAP_GPMC and some related configurations, the compilation passed, but the device could not be found when using the nand command. 

    => nand info
    
    => nand bad
    
    no devices available
    => nand scrub
    
    no devices available

    I am using SDK9.0, uboot version 2023.04.

    Regards,
    Stephen

  • Is there a way to clear bad blocks in Linux? I didn't find a command similar to scrub. mtd-utils can read and write flash, but it can't erase bad blocks.

  • Hi Stephen,

    I would need to research this some more, please allow a couple of days for a response. Thanks for your patience.

    Regards, Andreas

  • Hi, Andreas:

        Is there any progress so far?

  • Unfortunately I have not been able to look at this yet due to other priorities.