Skip to content

mt7987: make SPI controller configurable#17

Open
dangowrt wants to merge 67 commits intomtk-openwrt:mtksocfrom
dangowrt:mt7987-configure-spim
Open

mt7987: make SPI controller configurable#17
dangowrt wants to merge 67 commits intomtk-openwrt:mtksocfrom
dangowrt:mt7987-configure-spim

Conversation

@dangowrt
Copy link

@dangowrt dangowrt commented Oct 3, 2025

Allow selecting the SPI controller used for SPIM-NAND or SPI-NOR boot devices (either SPI0 or SPI2).
This is required for creating bl2 for the BananaPi BPi-R4 Lite which got SPI-NAND connected to SPI2 (unlike the reference board which uses SPI0 for SPI-NAND).

@frank-w @hackpascal

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>
Add offline sign support, not only offline sign trusted key certificate
using FIP key (ROT key), but take all keys used by FIP into account.

We disable the CREATE_KEYS option and specify all keys (public) may be
used by cert_create tool.

When using cert_create, it reads all keys public part to assemble
correct certificates body, but uses dummy key to sign the certificate.

After the certificate is generated we extract the sign body from
certificate and invoke sign_offline function to allow user to hook the
sign operation, user can invoke the correct sign process with the
sign body, algorithm, and corresponding key id information. When the
sign operation is done, the correct signature is put into the certificate.

Signed-off-by: Tim-cy Yang <Tim-cy.Yang@mediatek.com>
Ascript to generate salt for encryption

Signed-off-by: guan-gm.lin <guan-gm.lin@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>
Add support for key deriving for fw bl33/fw encryption

Signed-off-by: guan-gm.lin <guan-gm.lin@mediatek.com>
This patch defines a new ToC item for storing fip checksum data as
the platform-defined ToC entry will always be put after all common
ToC entries.

The new ToC item data consists of three fields:
1. data length for calculating the checksum/hash
2. crc32 (compatible with tf_crc32) checksum
3. sha256 hash

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 a write indication for prepare ops to acknowledge mmc driver
whether the next operation is a write operation. This is very useful
is the mmc driver require this indication to setup mmc controller.

Note: We'll only modify for MediaTek platform with this API change.

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>
According to JESD84-B51, CMD6 timeout depends on the value
of EXT_CSD[248]. With this patch, eMMC controller will read out
EXT_CSD first and decide the timeout value for CMD6.
After that, we can execute mmc_set_ios().

Signed-off-by: Sky Huang <skylake.huang@mediatek.com>
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>
Close backend_dev handle to ensure enc_dev can be reused.

Signed-off-by: guan-gm.lin <guan-gm.lin@mediatek.com>
The load_image() didn't call io_dev_close() on failure of io_open()
which rejects reloading of the same image as plat_get_image_source()
would fail due to device was already opened.

Add io_dev_close() can solve this issue.

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>
… empty

Avoid compile failure when PLAT_ARM_G0_IRQ_PROPS is empty

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>
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>
Upon decompression failure, this API will be used to restore the
saved original image_info for retry

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>
Add support for BL33 encryption

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>
hackpascal and others added 28 commits July 11, 2025 19:34
Add DDR initialization support for mt7629

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

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/BL31 support for mt7986.

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

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>
This patch adds anti-rollback v2 support for mt7986

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add support for decrypting BL33/image at runtime.

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/BL31 support for mt7981.

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

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>
This patch adds anti-rollback v2 support for mt7981

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/BL31 support for mt7988.

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

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>
This patch adds anti-rollback v2 support for mt7988

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add support for decrypting BL33/image at runtime.

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/BL31 support for mt7987.

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

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>
This patch adds anti-rollback v2 support for mt7987

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Add support for decrypting BL33/image at runtime.

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 Kconfiglib and related Config.in files to allow configure all
MediaTek-related features.

After configured, run make directly without and arguments to start build.
Any argument padded to make will override the configs in .config.

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Allow selecting the SPI controller used for SPIM-NAND or SPI-NOR boot
devices (either SPI0 or SPI2).

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

Hi @dangowrt, thanks for the PR.
Unfortunately the logic in your PR is not quiet correct.
The fact is that only mt7987 supports booting from spi-nand on spi2. All other platforms do not support this feature.
Also, mt7987 will only boot spi-nor on spi2. It will not try spi0.
For booting spi-nand, mt7987 will always try spi0 then spi2.

So I've updated mtk's version of this support in atf:
b182f4c#diff-4f6b65855918ddae2e6e5458cbcb89664b9aaf733d4a0f19bd983f1761f2291fR16
SPIM_NAND_PREFER_SPI2 is used to control atf to try spi2 or spi0 first. If that fails, another spi node will be used.
SPIM_NAND_NO_RETRY is used to forbid atf retrying another spi node.

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.

2 participants