Skip to content

mediatek: snfi: FM35Q1GA is x4-only and needs 12mA pin drive strength#7

Open
dangowrt wants to merge 52 commits intomtk-openwrt:mtksocfrom
dangowrt:fix-FM35Q1GA
Open

mediatek: snfi: FM35Q1GA is x4-only and needs 12mA pin drive strength#7
dangowrt wants to merge 52 commits intomtk-openwrt:mtksocfrom
dangowrt:fix-FM35Q1GA

Conversation

@dangowrt
Copy link

@dangowrt dangowrt commented Feb 29, 2024

Dont allow x2 read and cache read operations on FM35Q1GA as they seem to be unstable. Also the Linux drivers does not allow x2 ops:
https://github.com/openwrt/openwrt/blob/main/target/linux/mediatek/patches-6.1/340-mtd-spinand-Add-support-for-the-Fidelix-FM35X1GA.patch#L49

We may need a similar fix for the U-Boot driver, though problems have not been observed there. However, we sporadically see bl2 failing to load fip for no apparent reason (ie. after the device was powered-off and working fine before, or after a reboot). The error then persists.

F0: 102B 0000
F6: 0000 0000
V0: 0000 0000 [0001]
00: 0000 0000
BP: 0400 0041 [0000]
G0: 1190 0000
T0: 0000 02D4 [000F]
Jump to BL

NOTICE:  BL2: v2.9(release):OpenWrt v2023-07-24-00ac6db3-2 (mt7622-snand-1ddr)
NOTICE:  BL2: Built : 21:45:35, Oct  9 2023
NOTICE:  CPU: MT7622
NOTICE:  WDT: Cold boot
NOTICE:  WDT: disabled
NOTICE:  SPI-NAND: FM35Q1GA (128MB)
ERROR:   BL2: Failed to load image id 5 (-2)

Also using UBI apparently didn't help

F0: 102B 0000
F6: 0000 0000
V0: 0000 0000 [0001]
00: 0000 0000
BP: 0400 0041 [0000]
G0: 1190 0000
T0: 0000 02F1 [000F]
Jump to BL

NOTICE:  BL2: v2.9.0(release):OpenWrt v2023-10-13-0ea67d76-1 (mt7622-snand-ubi-1ddr)
NOTICE:  BL2: Built : 11:23:19, Feb 18 2024
NOTICE:  WDT: Cold boot
NOTICE:  CPU: MT7622
NOTICE:  WDT: disabled
NOTICE:  SPI-NAND: FM35Q1GA (128MB)
NOTICE:  UBI: scanning [0x80000 - 0x8000000] ...
NOTICE:  UBI: scanning is finished
NOTICE:  UBI: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
NOTICE:  UBI: VID header offset: 2048 (aligned 2048), data offset: 4096
NOTICE:  UBI: Volume fip (Id #0) size is 1019644 bytes
ERROR:   BL2: Failed to load image id 5 (-2)

@hackpascal @nbd168

hackpascal and others added 30 commits January 17, 2024 21:42
Add MediaTek-specific ignore entries

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Enable debug symbols for release build which will be convenient for
debugging over JTAG.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add support to use prebuilt libraries for BL2 and BL31

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
This utility is used for adding a BootROM readable header for BL2 image.
The BL2 image is directly loaded by the BootROM and supports RSA signing
for secure boot.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add tools to generate anti-rollback table with an example

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
There's a situation that ROT_KEY(private) does not exist in building
environment, and thus signing is impossible during build stage.

This tool is used to sign certificate without knowing ROT_KEY

Since ROT_KEY is used to sign trusted_key.cert, we only need to make sure
trusted_key.crt is signed correctly.

This tool does the first, and third actions within following flow:

1. Extract sign body from trusted_key.cert
2. Sign body using ROT_KEY [Done by user after build]
3. Use signature to assemble new trusted_key.cert
4. use fiptool to generate new FIP image

Usage:
Extract sign body from trusted_key.crt:
  signoffline -p [fip_public_key] -c [trusted_key.crt] \
              -m [message to be signed]

Use signature to assemble new trusted_key.crt:
  signoffline -p [fip_public_key] -c [trusted_key.crt] \
              -s [signature] -o [new trusted_key.crt]

Signed-off-by: Tim-cy Yang <Tim-cy.Yang@mediatek.com>
Add GPT editor for generate GPT table for SD/eMMC
Add single image (ROM dump image) making tool

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Some eMMC chips have wrong value of field spec_vers in CSD register.
spec_vers is not checked by both linux kernel and u-boot. So it better to
remove this check.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add support to poll card busy state for R1b command

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add oob_size field for nand framework

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Support more 4-byte address flashes

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add interface for gpio driver to change gpio mode

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
This patch adds UBI loading support for BL2.

The main UBI code comes from u-boot (drivers/mtd/ubispl.c) with
modifications. The original code permits BSD-3-Clause license.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add support for patching MBR with correct number of LBAs

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
The APSoC platform includes mt7622, mt7629, filogic chips and future chips.

These common files are shared between all chips list above.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
The pmuv3_init_el3() add recently causes mt7629 hang in booting in bl32.
Just disable it.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add NAND mapping block management (NMBM) common library.
This library acts as a translation layer to hide bad blocks of a raw NAND
device. It's very useful for factory production where data may shift due
to bad blocks.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add xz-embedded-20210201 from
https://tukaani.org/xz/embedded.html

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add support to compress images using xz

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
This patch adds a new bootloader stage named BL2PL (aka. BL2 preloader)
to support BL2 compression.

This stage only implements XZ decompression for BL2 payload, and the BL2
payload must be compressed by XZ with crc32 checksum support.

To make use of this stage, a BL2PL specific image header must be added to
the compressed BL2 payload to record its load address and size. Then this
payload with header should be directly appended to the end of BL2PL raw
binary without any padding.

-------------------------------
| BL2PL | Header | XZ payload |
-------------------------------

On startup, BL2PL will first relocate itself to On-Chip SRAM and setup
the C environment, and then decompress the real BL2 to its load address,
and finally jump to the real BL2.

---------------------------------------------------------------
| Stage | On-Chip SRAM |            L2 shared SRAM            |
---------------------------------------------------------------
|   1   |              | BL2PL | XZ payload                   |
---------------------------------------------------------------
|   2   | BL2PL        |                           XZ payload |
---------------------------------------------------------------
|   3   | BL2PL        | BL2                     | XZ payload |
---------------------------------------------------------------

Also, add a tool named bl2plimage to generate BL2PL image header for XZ
compressed BL2 payload.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
This patch adds a simple build option dependency checking mechanism, which
makes changes of build options to take effect immediately without a clean.

Currently we have many C macros defined in gcc command line by build
options passed from the make command line. However in ATF build framework,
the macros defined in gcc command line will not be treated as dependency,
which means changes in those macros will not take effect to C source files
using those macros.

This mechanism is done by adding a dependency rule explictly for a
specific source file, and the dependency rule is a new header file.

Everytime before building, the mechanism writes all registered build
options of a file to the dependency rule file. Once the build option is
changed, the content of the dependency rule file will also be changed,
which will trigger a rebuild of the source file.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
The Anti-Rollback mechanism of MediaTek uses NV-counter for the minimum
allowed version, and discard the original purpose of NV-counter.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
The FSEK is used to help decrypt rootfs data.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add initial BL2/BL31 support for mt7622.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add DDR initialization support for mt7622

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add eFuse prebuilt library and relative SIP services for BL31 to allow
BL33 to manipulate the eFuse features (SecureBoot, Anti-Rollback, ...)

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add basic anti-rollback framework for mt7622 (PATCH-v3)
- Add ar_table tool which support parsing customer's
  version control xml file to generate auto-config
  file, and embeded those information into atf code
- Modify platform.mk that allow us feed customer's
  version control xml file and build anti-rollback
  atf image in one step

Usage:
Add following parameters to make input:
ANTI_ROLLBACK=1 ANTI_ROLLBACK_CONF=./ar_table_example.xml

Add following make target to make input:
ar_table

For example:
make PLAT=mt7622 BOOT_DEVICE=snand BROM_SIGN_KEY=/path/to/key	\
BL33=/path/to/u-boot-binary MBEDTLS_DIR=/path/to/mbedtls	\
TRUSTED_BOARD_BOOT=1 GENERATE_COT=1 ROT_KEY=/path/to/key	\
ANTI_ROLLBACK=1 ANTI_ROLLBACK_CONF=path/to/version-xml		\
ar_table all fip

Change since v2:
- Fix multiple cert_tool --tfw-nvctr and --ntfw-nvctr parameters
exist in the CERT_ARGS variable
- Remove duplicate ar_table make target in platform.mk

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add build option dependency rules to make sure option changes take effect
on .o files immediately to avoid cleaning current build.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add initial BL2/BL32 support for mt7629.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add DDR initialization support for mt7629

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
It seems like we might need to adjust the pin driver strength to 12mA
for Fidelix SPI-NAND chip on MT7622 to avoid SPI data corruption on
some devices.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
In addition to FM35X1GA, also change the driver strength to 12mA for
all chips where this is done by the old/legacy U-Boot:
 * Winbond 512Mb
 * Winbond 1Gb
 * Winbond 2Gb
 * GD5F4GQ4UBYIG
 * GD5F4GQ4UAYIG
 * GD5F1GQ4UX
 * GD5F1GQ4UE
 * GD5F2GQ4UX
 * GD5F2GQ4UE

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@dangowrt
Copy link
Author

@hackpascal Does the change suggested here generally look acceptable to you? Handling this "properly" in pinctrl/gpio driver looks a bit more complicated...

@hackpascal
Copy link
Member

@hackpascal Does the change suggested here generally look acceptable to you? Handling this "properly" in pinctrl/gpio driver looks a bit more complicated...

Actually I want to add a simple pinctrl layer to make it "generic" :p

@hackpascal
Copy link
Member

@dangowrt I managed to buy a spi-nand flash DS35Q1GA. It seems to use exactly the same die that FM35Q1GA is using.
Not sure if this nand chip can reproduce the issue.
Datasheet: http://www.dosilicon.com/resources/new_Datasheet/DS35X1GAXXX_rev07.pdf

@pepe2k
Copy link

pepe2k commented Mar 21, 2024

@dangowrt @981213 @hackpascal if you are looking at driver strength on the SOC's I/O side, I would also look how it's configured on the SPI-NAND side (usually, by default it should be set to 100%).

@dangowrt
Copy link
Author

dangowrt commented Apr 3, 2024

...and another brick with full debug log here:
https://gist.github.com/taylorkline/64da33842b464b4e27bda7ec04113aec

@onlyfly34
Copy link

onlyfly34 commented Apr 8, 2024

Hi @dangowrt
I've heard this issue from @hackpascal
According to @hackpascal, if DS35Q1GA uses the same die as FM35Q1GA, here's something worth to note in Dosilicon's datasheet, page 28:

Prior to performing a PROGRAM LOAD RANDOM DATA operation, a WRITE ENABLE (06h) command must be
issued to change the contents of the memory array. Following a WRITE ENABLE (06) command, first a PROGRAM
LOAD (02h or 32h) command must be issued to reset the cache
, then issue a PROGRAM LOAD RANDOM DATA
(84h or 34h) command

Since we use 0x84/0x34 for x1/x4 program load random data in Linux(https://elixir.bootlin.com/linux/latest/source/include/linux/mtd/spinand.h#L138), issues occur with such combination: FM35Q1GA(DS35Q1GA)+Uboot/Linux spi-mem framework. We observed the same thing on Foresee's F35SQA001G.

I'm not 100% sure if the above issue has something to do with this ticket. But it indeed causes serious problems when we program NAND flash, and impacts further reading behavior.

Here's dirty fix you may try (apply both to Uboot & Linux):
In FM35Q1GA's patch, change update_cache_variants macro from:

+static SPINAND_OP_VARIANTS(update_cache_variants,
+		SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
+		SPINAND_PROG_LOAD(false, 0, NULL, 0));

to this:

+static SPINAND_OP_VARIANTS(update_cache_variants,
+		SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
+		SPINAND_PROG_LOAD(true, 0, NULL, 0));

This is pretty dirty because it makes SPI controller unable to send 0x84/0x34. This is a big problem for SPI controllers which can't send data of page size(2K or 4K bytes) in one transfer.

For example, if the SPI controller is capable to transfer only 512bytes with one command, it needs to issue 0x84/0x34 command four times to transfer 2K bytes data onto NAND flash's cache.

dangowrt added a commit to dangowrt/openwrt that referenced this pull request Apr 8, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
dangowrt added a commit to dangowrt/openwrt that referenced this pull request Apr 8, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@dangowrt
Copy link
Author

dangowrt commented Apr 8, 2024

Summarizing all discoveries I've opened a PR for openwrt.git to add all of that, in the hope that we can rescue users from OKD asap:

openwrt/openwrt#15112

@lynxthecat
Copy link

lynxthecat commented Apr 22, 2024

Summarizing all discoveries I've opened a PR for openwrt.git to add all of that, in the hope that we can rescue users from OKD asap:

openwrt/openwrt#15112

Will this potentially prevent OKD even for devices that haven’t been OKD’ed?

dangowrt added a commit to dangowrt/openwrt that referenced this pull request May 3, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
nasbdh9 pushed a commit to nasbdh9/openwrt that referenced this pull request May 10, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
dangowrt added a commit to dangowrt/openwrt that referenced this pull request Jun 5, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
dangowrt added a commit to dangowrt/openwrt that referenced this pull request Jun 5, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Vladdrako pushed a commit to Vladdrako/openwrt that referenced this pull request Jun 8, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
RolandoMagico pushed a commit to RolandoMagico/openwrt that referenced this pull request Aug 11, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
c-herz pushed a commit to c-herz/openwrt that referenced this pull request Sep 5, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
dzzinstant pushed a commit to dzzinstant/openwrt that referenced this pull request Sep 9, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
dzzinstant pushed a commit to dzzinstant/openwrt that referenced this pull request Sep 9, 2024
Import pending patches to set pinconf settings for SPI-NAND pins on
MT7622 identical to what the old proprietary preloader did.

Should further increase the reliability of some SNFI-attached SPI-NAND
flash chips.

Link: mtk-openwrt/arm-trusted-firmware#7
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@hackpascal hackpascal force-pushed the mtksoc branch 3 times, most recently from 7cc6b76 to e090770 Compare February 12, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants