[Tutorial] Reworking BPI-R3 nand Flash

[Description]

This tutorial shows how to replace SPI NAND flash with a larger/smaller one on BPI R3, including how to build corresponding atf(TF-A), openwrt based on MediaTek SDK.

[Steps]

1. Setup ATF, U-boot, Openwrt environment

Please refer the following references

  • For atf, U-boot :

[Tutorial] Build, customize and use MediaTek open-source U-Boot and ATF to set up uboot and atf code base.

  • For openwrt :

https://github.com/BPI-SINOVOIP/BPI-R3-OPENWRT-V21.02.3

https://wiki.banana-pi.org/Banana_Pi_BPI-R3#MediaTek_MT7986.28Filogic_830.29

2. Choose a SPI NAND flash you want to replace with

Here, we take Macronix MX35LF4GE4AD nand flash and banana pi r3 (mt7986) as an example.

3. Rework nand flash on banana pi board

4. Build U-boot

  • Note that the deconfig must be selected with SPI NAND related.

5. Build ATF

  • First, please find out the page size of nand flash in its corresponding flash datasheet. image
  • Second, determine the NAND_TYPE with the following table. In this case, the page size of Macronix MX35LF4GE4AD nand flash is 4k+128 which can be found in Macronix MX35LF4GE4AD datasheet. Hence, we can select spim:4k+256 for NAND_TYPE.
Value Boot device Platform Description Compatibel device setting
spim:2k+64 spim-nand mt7981/mt7986 Page size: 2K, Spare size: 64 (default) 2k+32, 2k+256
spim:2k+128 spim-nand mt7981/mt7986 Page size: 2K, Spare size: 128 2k+32, 2k+256
spim:4k+256 spim-nand mt7981/mt7986 Page size: 4K, Spare size: 256 4k+128

[Note.]

(i) Some special cases such as 4k+128, 2k+32, 2k+256 which aren’t available above will be set in “Compatible device setting”. You can use the corresponding NAND_TYPE value to build with.

$make -f Makefile PLAT=<plat> BOOT_DEVICE=spim-nand nand_type=4k+256 BL33=<path-to-u-boot.bin> all fip
// Ex. $make -f Makefile PLAT=mt7986 BOOT_DEVICE=spim-nand NAND_TYPE=spim:4k+256 BL33=../U-boot/u-boot/u-boot.bin DRAM_USE_DDR4=1 all fip

6. Build Openwrt SDK (Optional by case)

  • It’s necessary to rebuild openwrt if you have changed to use a different page/block size nand flash. For example, if you replace a 1G nand flash with a new 4G nand flash which has a larger page/block size, then you have to follow this part.

  • Set the proper page size and block size for nand device in mt7986.mk (depends on which Soc you used).

$vim {Openwrt_Root_Path}/target/linux/mediatek/image/mt7986.mk
// 1. Set BLOCKSIZE to 256k
// 2. Set PAGESIZE  to 4096
// save and exit

image image

  • After setting the proper page size and block size, rebuild the Openwrt image.

7. Update bl2.img & fip.bin & Openwrt image to banana pi

Please refer to [Tutorial] Build, customize and use MediaTek open-source U-Boot and ATF to study the methods about how to upgrade bl2.img, fip.bin and openwrt.

8. Done!

Finally, boot the banana pi and you will see that nand flash can be found successfully. image

[Attachment]

  • Macronix MX35LF4GE4AD nand flash datasheet :

https://www.mxic.com.tw/en-us/products/NAND-Flash/Serial-NAND-Flash/Pages/spec.aspx?p=MX35LF4GE4AD&m=Serial%20NAND&n=PM2794

4 Likes

how to burn kernel and filesystem?

You can refer to [Tutorial] Build, customize and use MediaTek open-source U-Boot and ATF.

# 6. Upgrade the new U-Boot and ATF
The final files are  bl2.img  and  fip.bin. You can upgrade them from anywhere, e.g. from u-boot bootmenu or from linux shell of OpenWrt.