BPI-R3 v1.1 (MT7986A/Filogic) Insert new spi nand flash devices

BPI-R3 v1.1 (SOC MT7986A/Filogic) Insert new spi nand flash devices.

1 Spi flash device Infomation.

  • XT26G11D ( 1Gbit / 128MiByte )
    image
    Flash ID table:
    Comand byte0 byte1 byte1
    9Fh 00 0x0b(MID) 0x34(DID)



  • XT26G12D ( 2Gbit / 256GiByte )
    image
    Flash ID table:
    Comand byte0 byte1 byte1
    9Fh 00 0x0b(MID) 0x35(DID)



spec. or more infomation can mail to [email protected]


2 Add spi flash device drivers.

Uboot&atf source code from hackpascal’s Build, customize and use MediaTek open-source U-Boot and ATF

Kernal source code from R3 Wiki 2022-06-01udptae BPI-R3 OpenWRT 21.02

2.1 U-boot & ATF driver Add (for SPIM / flash on-die ECC / Flash hw ECC):

  • Add u-boot/drivers/mtd/nand/spi/xtxtech.c
    xtxtech.c (5.6 KB)
static const struct spinand_info xtxtech_spinand_table[] = {
    SPINAND_INFO("XT26G11D",
                 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x34),
                 NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
                 NAND_ECCREQ(8, 512),
                 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
                                          &write_cache_variants,
                                          &update_cache_variants),
                 SPINAND_HAS_QE_BIT,
                 SPINAND_ECCINFO(&xt26g1xdwsixx_ooblayout, 
					xt26g1xdwsixx_ecc_get_status)),
    SPINAND_INFO("XT26G12D",
                 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x35),
                 NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
                 NAND_ECCREQ(8, 512),
                 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
                                          &write_cache_variants,
                                          &update_cache_variants),
                 SPINAND_HAS_QE_BIT,
                 SPINAND_ECCINFO(&xt26g1xdwsixx_ooblayout, 
							xt26g1xdwsixx_ecc_get_status)),
};
  • Modify u-boot/drivers/mtd/nand/spi/Makefile
    Makefile (162 字节)
spinand-objs := core.o gigadevice.o macronix.o micron.o toshiba.o winbond.o xtxtech.o
  • Modify u-boot/drivers/mtd/nand/spi/core.c
    core.c (34.3 KB)
static const struct spinand_manufacturer *spinand_manufacturers[] = {
    ...
    &xtxtech_spinand_manufacturer,
};
  • Modify u-boot/include/linux/mtd/spinand.h
    spinand.h (17.0 KB)
/* SPI NAND manufacturers */
...
extern const struct spinand_manufacturer xtxtech_spinand_manufacturer;
  • Modify arm-trusted-firmware/drivers/mtd/nand/spi_nand.c
    spi_nand.c (15.5 KB)
...
#define XTXTECH_ID			0x0BU
...
static int spi_nand_quad_enable(uint8_t manufacturer_id)
{
	bool enable = false;

	if (manufacturer_id != MACRONIX_ID &&
	    manufacturer_id != GIGADEVICE_ID &&
	    manufacturer_id != ETRON_ID && 
		manufacturer_id != WINBOND_ID &&
		manufacturer_id != XTXTECH_ID) {
		return 0;
	}
...

2.2 U-boot & ATF driver Add (for NFI / on-host HW ECC / MTK soc ECC) (But mt7986 not support):

  • Modify u-boot/drivers/mtd/mtk-snand/mtk-snand-ids.c
    mtk-snand-ids.c (20.2 KB)
static const struct snand_flash_info snand_flash_ids[] = {
	SNAND_INFO("XT26G11D", SNAND_ID(SNAND_ID_DYMMY, 0x0b, 0x34),
		   SNAND_MEMORG_1G_2K_128,
		   &snand_cap_read_from_cache_quad_q2d,
		   &snand_cap_program_load_x4),
	SNAND_INFO("XT26G12D", SNAND_ID(SNAND_ID_DYMMY, 0x0b, 0x35),
		   SNAND_MEMORG_2G_2K_128,
		   &snand_cap_read_from_cache_quad_q2d,
		   &snand_cap_program_load_x4),

2.3 compile u-boot&atf by custumer script.

  • For u-boot make script file(on u-boot dir):
#!/bin/sh
make clean
make mt7986_spim_nand_rfb_defconfig
make CROSS_COMPILE="~/BPI-R3-OPENWRT-V21.02.3-main/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/bin/aarch64-openwrt-linux-"
cp -f u-boot.bin ~/mt7986av_dir_home/uboot_files/u-boot-spim-xtxtect-"$(date +'%Y%m%d')".bin

  • For atf make script file(on atf dir):
#!/bin/sh
make clean
make CROSS_COMPILE="~/BPI-R3-OPENWRT-V21.02.3-main/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/bin/aarch64-openwrt-linux-" -f Makefile PLAT="mt7986" BOOT_DEVICE="spim-nand" BL33="~/mt7986av_dir_home/uboot_files/u-boot-spim-xtxtect-"$(date +'%Y%m%d')".bin"  NAND_TYPE="spim:2k+128" NMBM="1" DRAM_USE_DDR4="1"  all fip
cp -f ~/mt7986av_dir_home/atf_files/arm-trusted-firmware/build/mt7986/release/bl2.img -f ~/mt7986av_dir_home/atf_files/bl2_spim_"$(date +'%Y%m%d')".img
cp -f ~/mt7986av_dir_home/atf_files/arm-trusted-firmware/build/mt7986/release/fip.bin -f ~/mt7986av_dir_home/atf_files/fip_spim_"$(date +'%Y%m%d')".bin

At the end, u can got “fip_spim_xxxxxxxx.bin” and “bl2_spim_xxxxxxxx.img” files;

2.4 Openwrt Kernel drivers add.

  • Add BPI-R3-OPENWRT-V21.02.3-main/build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7986/linux-5.4.188/drivers/mtd/nand/spi/xtxtech.c
    xtxtech.c (5.2 KB)
static const struct spinand_info xtxtech_spinand_table[] = {
    SPINAND_INFO("XT26G11D",
                 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x34),
                 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
                 NAND_ECCREQ(8, 512),
                 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
                                          &write_cache_variants,
                                          &update_cache_variants),
                 SPINAND_HAS_QE_BIT,
                 SPINAND_ECCINFO(&xt26g1xdwsixx_ooblayout, 
					xt26g1xdwsixx_ecc_get_status)),
    SPINAND_INFO("XT26G12D",
                 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x35),
                 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
                 NAND_ECCREQ(8, 512),
                 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
                                          &write_cache_variants,
                                          &update_cache_variants),
                 SPINAND_HAS_QE_BIT,
                 SPINAND_ECCINFO(&xt26g1xdwsixx_ooblayout, 
							xt26g1xdwsixx_ecc_get_status)),
};
  • Modify BPI-R3-OPENWRT-V21.02.3-main/build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7986/linux-5.4.188/drivers/mtd/nand/spi/core.c
    core.c (27.5 KB)
static const struct spinand_manufacturer *spinand_manufacturers[] = {
    ...
	&xtxtech_spinand_manufacturer,
};
  • Modify BPI-R3-OPENWRT-V21.02.3-main/build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7986/linux-5.4.188/drivers/mtd/nand/spi/Makefile
    Makefile (171 字节)
spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtxtech.o
  • Modify BPI-R3-OPENWRT-V21.02.3-main/build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7986/linux-5.4.188/include/linux/mtd/spinand.h
    spinand.h (14.8 KB)
/* SPI NAND manufacturers */
...
extern const struct spinand_manufacturer xtxtech_spinand_manufacturer;
...
  • Modify BPI-R3-OPENWRT-V21.02.3-main/build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7986/linux-5.4.188/drivers/mtd/mtk-snand/mtk-snand-ids.c
    mtk-snand-ids.c (20.2 KB)
static const struct snand_flash_info snand_flash_ids[] = {
	SNAND_INFO("XT26G11D", SNAND_ID(SNAND_ID_DYMMY, 0x0b, 0x34),
		   SNAND_MEMORG_1G_2K_128,
		   &snand_cap_read_from_cache_quad_q2d,
		   &snand_cap_program_load_x4),
	SNAND_INFO("XT26G12D", SNAND_ID(SNAND_ID_DYMMY, 0x0b, 0x35),
		   SNAND_MEMORG_2G_2K_128,
		   &snand_cap_read_from_cache_quad_q2d,
		   &snand_cap_program_load_x4),

2.5 Openwrt Kernel enable MTK soc ecc config (But mt7986 not support).

use:

make kernel_menuconfig

MTK SPI NAND controller driver be selected:(Device Drivers/ Memory Technology Device(MTD) support/)
image

than make :

make -j5 V=sc

2.6 flash burned

use mtkautoboot tools by tftp:

  *** U-Boot Boot Menu ***

      1. Startup system (Default)
      2. Upgrade firmware
      3. Upgrade ATF BL2       (use bl2_spim_xxxxxxxx.img)
      4. Upgrade ATF FIP       (use fip_spim_xxxxxxxx.bin)
      5. Upgrade single image
      6. Load image            (use openwrt-mediatek-mt7986-BPI-R3-NAND-WAN1-RJ45-initramfs-kernel.bin)
      0. U-Boot console

Also u can used single image file for programmer burn: on arm-trusted-firmware/tools/dev/single_img_wrapper/ dir:(ATF source code)

./mk_image.sh -p mt7986a -d spim-nand -b bl2_spim_"$(date +'%Y%m%d')".img -f fip_spim_"$(date +'%Y%m%d')".bin -k openwrt-mediatek-mt7986-BPI-R3-NAND-WAN1-RJ45-squashfs-factory.bin -o mt7986_spim_single_file_for_programer_"$(date +'%Y%m%d')"_mk.bin

the eng, u can got “mt7986_spim_single_file_for_programer_xxxxxxxx_mk.bin” for programmer.

All startup log can see next chapter.

3 SPI NAND Test (By MTD TEST TOOLS)

MTD test tools be selected(only use module):

Fast compile(module built):

make -j5 V=s

finally got “mtd_nandbiterrs.ko”,“mtd_stresstest.ko”,"mtd_speedtest.ko"files.(on BPI-R3-OPENWRT-V21.02.3-main/build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7986/linux-5.4.188/drivers/mtd/tests dir)

  • NAND Biterror Test step:

choose the test partition ( mtd3: Factory ) for test:

root@OpenWrt:/mnt# cat /proc/mtd
mod mtd_nandbdev:    size   erasesize  name
mtd0: 08000000 00020000 "spi0.1"
mtd1: 00100000 00020000 "BL2"
mtd2: 00080000 00020000 "u-boot-env"
mtd3: 00200000 00020000 "Factory"
mtd4: 00200000 00020000 "FIP"
mtd5: 04000000 00020000 "ubi"

Run test by module:

cat /proc/mtd
rmmod mtd_nandbiterrs.ko
insmod mtd_nandbiterrs.ko dev=3 page_offset=0 seed=1 mode=0
...
[2023/7/11 17:38:23] [  126.138306] mtd_nandbiterrs: Read reported 8 corrected bit errors
[2023/7/11 17:38:23] [  126.144385] mtd_nandbiterrs: verify_page
[2023/7/11 17:38:23] [  126.148329] mtd_nandbiterrs: Successfully corrected 8 bit errors per subpage
[2023/7/11 17:38:23] [  126.155362] mtd_nandbiterrs: Inserted biterror @ 2/7
[2023/7/11 17:38:23] [  126.160310] mtd_nandbiterrs: rewrite page
[2023/7/11 17:38:23] [  126.164860] mtd_nandbiterrs: read_page
[2023/7/11 17:38:23] [  126.169771] mtd_nandbiterrs: error: read failed at 0x0
[2023/7/11 17:38:23] [  126.174899] mtd_nandbiterrs: After 9 biterrors per subpage, read reported error -74
[2023/7/11 17:38:23] [  126.185307] mtd_nandbiterrs: finished successfully.
[2023/7/11 17:38:23] [  126.190170] ==================================================

cat /proc/mtd
rmmod mtd_nandbiterrs.ko
insmod mtd_nandbiterrs.ko dev=3 page_offset=1 seed=1 mode=1
...
[2023/7/11 17:38:46] [  148.505016] mtd_nandbiterrs: Page reads with   6 corrected bit errors: 53
[2023/7/11 17:38:46] [  148.511786] mtd_nandbiterrs: Page reads with   7 corrected bit errors: 53
[2023/7/11 17:38:46] [  148.521321] mtd_nandbiterrs: finished successfully.
[2023/7/11 17:38:46] [  148.526185] ==================================================



cat /sys/class/mtd/mtd3/ecc_strength
[2023/7/11 17:38:13] root@OpenWrt:/mnt# cat /sys/class/mtd/mtd3/ecc_strength
[2023/7/11 17:38:13] 
[2023/7/11 17:38:13] 8

  • Stress Test(on 85°C/20°C/-40°C more than 8hours):

choose the test partition ( mtd3: Factory ) for test:

root@OpenWrt:/mnt# cat /proc/mtd
mod mtd_nandbdev:    size   erasesize  name
mtd0: 08000000 00020000 "spi0.1"
mtd1: 00100000 00020000 "BL2"
mtd2: 00080000 00020000 "u-boot-env"
mtd3: 00200000 00020000 "Factory"
mtd4: 00200000 00020000 "FIP"
mtd5: 04000000 00020000 "ubi"
cat /proc/mtd
rmmod mtd_stresstest.ko
insmod mtd_stresstest.ko dev=3 count=800000

[2023/7/11 23:09:23] [19964.974012] mtd_stresstest: 796672 operations done
[2023/7/11 23:09:48] [19989.992301] mtd_stresstest: 797696 operations done
[2023/7/11 23:10:13] [20015.026233] mtd_stresstest: 798720 operations done
[2023/7/11 23:10:39] [20040.838243] mtd_stresstest: 799744 operations done
[2023/7/11 23:10:45] [20047.128456] mtd_stresstest: finished, 800000 operations done
[2023/7/11 23:10:45] [20047.134214] =================================================
  • Speed Test:
root@OpenWrt:/mnt# insmod mtd_speedtest.ko dev=3 count=0
=================================================
mtd_speedtest: MTD device: 3
mtd_speedtest: MTD device size 2097152, eraseblock size 131072, page size 2048, count of eraseblocks 16, pages per eraseblock 64, OOB size 128
mtd_test: scanning for bad eraseblocks
mtd_test: scanned 16 eraseblocks, 0 are bad
mtd_speedtest: testing eraseblock write speed
mtd_speedtest: eraseblock write speed is 3145 KiB/s
mtd_speedtest: testing eraseblock read speed
mtd_speedtest: eraseblock read speed is 7236 KiB/s
mtd_speedtest: testing page write speed
mtd_speedtest: page write speed is 3150 KiB/s
mtd_speedtest: testing page read speed
mtd_speedtest: page read speed is 7211 KiB/s
mtd_speedtest: testing 2 page write speed
mtd_speedtest: 2 page write speed is 3150 KiB/s
mtd_speedtest: testing 2 page read speed
mtd_speedtest: 2 page read speed is 7236 KiB/s
mtd_speedtest: Testing erase speed
mtd_speedtest: erase speed is 27675 KiB/s
mtd_speedtest: Testing 2x multi-block erase speed
mtd_speedtest: 2x multi-block erase speed is 33032 KiB/s
mtd_speedtest: Testing 4x multi-block erase speed
mtd_speedtest: 4x multi-block erase speed is 128000 KiB/s
mtd_speedtest: Testing 8x multi-block erase speed
mtd_speedtest: 8x multi-block erase speed is 170666 KiB/s
mtd_speedtest: Testing 16x multi-block erase speed
mtd_speedtest: 16x multi-block erase speed is 170666 KiB/s
mtd_speedtest: Testing 32x multi-block erase speed
mtd_speedtest: 32x multi-block erase speed is 170666 KiB/s
mtd_speedtest: Testing 64x multi-block erase speed
mtd_speedtest: 64x multi-block erase speed is 170666 KiB/s
mtd_speedtest: finished
=================================================

XT26G11D SPIM(flash on-die ECC) Test log:
XT26G11D_MTK7986A_Startup_and_test_log.log (236.4 KB)

XT26G12D SPIM(flash on-die ECC) config Test log:
XT26G12D_MTK7986A_Startup_and_test_log.log (241.8 KB)

2 Likes