Skip to content

Add wolfBoot target for NXP S32G2 (S32G274A GoldBox) - #984

Open
dgarske wants to merge 8 commits into
wolfSSL:masterfrom
dgarske:s32g2_goldbox
Open

dgarske wants to merge 8 commits into
wolfSSL:masterfrom
dgarske:s32g2_goldbox

Conversation

@dgarske

@dgarske dgarske commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Description

Adds TARGET=s32g2 for the NXP S32G274A on the S32G-VNP-GLDBOX (RDB2). wolfBoot is the Boot ROM's application image: it runs from SRAM at EL3 in place of U-Boot, brings the SoC up, verifies a signed FIT and enters Linux at EL2.

What it adds

  • hal/s32g2.c, hal/s32g2.h, hal/s32g2.ld - HAL: LINFlexD console, VR5510 watchdog over I2C, clock tree, Ncore, EL3 identity MMU, GICv3, secondary cores on a spin table, QuadSPI NOR driver behind the ext_flash API, device tree fixups
  • hal/s32g2_ddr.c - LPDDR4 controller and PHY bring-up. The board's register tables and the Synopsys PHY training firmware are not in the tree: tools/scripts/s32g2/s32g2-ddr-blob.py packs them from an NXP BSP U-Boot checkout into a blob the build links in
  • config/examples/s32g2-goldbox.config - boot from SD or eMMC with two FIT file slots and boot confirmation; s32g2-goldbox-qspi.config - boot from QuadSPI NOR with BOOT/UPDATE partitions in the NOR and the partition state kept as a journal (NVM_FLASH_JOURNAL), because the flash allows each 16-byte ECC unit to be programmed once per erase
  • tools/scripts/s32g2/ - Boot ROM image writer (IVT, DCD, QuadSPI parameter block) and FIT build script
  • docs/Targets.md, CI build jobs for each variant

Touches shared code

  • src/boot_aarch64_start.S, src/boot_aarch64.c - S32G2 blocks only: SRAM ECC initialisation before the first store, EL3 fault vectors, secondary core entry, EL3 to EL2 handoff; invalidate_dcache_range moves next to flush_dcache_range so it is built for every AArch64 target
  • hal/imx_usdhc_sdhci.c, include/aarch64_arch.h - the shared uSDHC shim now also serves S32G2, and its SDMA cache maintenance is available to any target that defines WOLFBOOT_AARCH64_DCACHE_RANGE
  • src/update_disk.c - ALLOW_DOWNGRADE=1 no longer fails to build on an unused variable
  • src/update_disk.c, src/disk_fs.c, src/fat32.c, src/ext4.c - DISK_BOOT_CONFIRM now also covers FAT32 and ext4 file slots: the state trailer is the last 8 bytes of the image file, located through the read path (fs_map()) and rewritten in place, with no filesystem structure changed. The booted file is published as /chosen/wolfboot,boot-file
  • hal/imx8qm.c - the device tree fixup now publishes /chosen/wolfboot,boot-part, which its hal_dts_fixup() override had dropped
  • src/fdt.c - fit_ramdisk_loaded() reports whether the FIT ramdisk loader wrote the initrd range, so a device tree fixup can clear a range the tree already carried
  • arch.mk - -U_FORTIFY_SOURCE for AArch64, so distribution aarch64-linux-gnu- compilers do not emit __memcpy_chk into a bare-metal image

Testing

Validated on a GoldBox (S32G274A rev 2.1, RDB2 rev D): Boot ROM boot from SD and from QuadSPI NOR (plain SPI and octal DTR parameter blocks), the signed FIT read from SD (both file slots), eMMC and the NOR BOOT partition, Linux 5.4 (BSP29) to a login prompt with four cores. Boot confirmation on file slots was run on the SD card (FAT32): a staged slot boots on probation, is skipped when not confirmed, and stays selected once Linux confirms it. A NOR update was run with the programmer build: a newer FIT staged in UPDATE with the update marker is selected, recorded as testing and booted, and keeps booting across cold boots. Also run on the board from SD: a build without the wolfBoot console (DEBUG_UART=0), a FIT_RAMDISK=1 build with a FIT that carries no ramdisk, the ALLOW_DOWNGRADE=1 fallback to the older slot when the newer one fails to verify, and the NOR programmer refusing an oversized file and an out-of-range offset. ext4 file slots are covered by host unit tests only. The i.MX 8QuadMax and _FORTIFY_SOURCE changes are build-tested only.

@dgarske dgarske self-assigned this Nov 11, 2026
Copilot AI balanced review requested due to automatic review settings November 12, 2026 17:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical flash-programming and build-reuse defects can erase unrelated NOR partitions or overwrite the bootloader, while programming can proceed despite failed QuadSPI initialization.

9 open issues
What changed in this PR

Adds TARGET=s32g2 for the NXP S32G274A GoldBox, allowing wolfBoot to replace U-Boot as the Boot ROM application, verify a signed FIT, and enter Linux at EL2.

Changes:

  • Adds SoC and DDR initialization, storage drivers, device-tree fixups, and multicore startup.
  • Provides SD/eMMC and QuadSPI configurations, image-generation tools, documentation, and CI build coverage.
  • Extends shared AArch64 cache maintenance and uSDHC support, and fixes the ALLOW_DOWNGRADE unused-variable warning.
File Description
tools/​scripts/​s32g2/​s32g2-mkfit.sh Builds and signs kernel-plus-DTB FIT images.
tools/​scripts/​s32g2/​s32g2-ddr-blob.py Packages external DDR tables and training firmware.
tools/​scripts/​s32g2/​s32g2_mkimage.py Creates SD/eMMC and QuadSPI Boot ROM images.
src/​update_disk.c Suppresses an unused-variable warning with downgrade support.
src/​boot_aarch64.c Adds the S32G2 EL3-to-EL2 handoff.
src/​boot_aarch64_start.S Adds SRAM initialization, fault vectors, and secondary-core startup.
Makefile Selects wolfboot.bin as the target output.
include/​aarch64_arch.h Exposes cache-range maintenance independently of EL2 mapping.
hal/​s32g2.ld Defines SRAM placement, alignment, and stack space.
hal/​s32g2.its Defines the kernel and device-tree FIT layout.
hal/​s32g2.h Defines platform registers, memory layout, and interfaces.
hal/​s32g2.c Implements SoC initialization, storage, and Linux preparation.
hal/​s32g2_ddr.c Implements LPDDR4 training and controller setup.
hal/​imx_usdhc_sdhci.c Extends shared uSDHC and DMA cache support to S32G2.
docs/​Targets.md Documents building, programming, hardware setup, and limitations.
config/​examples/​s32g2-goldbox.config Configures SD/eMMC boot with two FIT file slots.
config/​examples/​s32g2-goldbox-qspi.config Configures NOR boot and image partitions.
arch.mk Adds architecture flags, objects, and platform options.
.gitignore Ignores generated platform artifacts.
.github/​workflows/​test-configs.yml Adds SD, eMMC, NOR, and programmer build jobs.

Review effort: Balanced

Comment thread arch.mk Resolved
Comment thread docs/Targets.md Resolved
Comment thread hal/s32g2.c Resolved
Comment thread hal/s32g2.c Resolved
Comment thread arch.mk Resolved
Comment thread hal/s32g2.c Resolved
Comment thread hal/s32g2.c Resolved
Comment thread tools/scripts/s32g2/s32g2-mkfit.sh Resolved
Comment thread tools/scripts/s32g2/s32g2-mkfit.sh Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #984

Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): .github/workflows/test-configs.yml, .gitignore, Makefile, arch.mk, config/examples/s32g2-goldbox-qspi.config, config/examples/s32g2-goldbox.config, docs/Targets.md, hal/s32g2.h, hal/s32g2.its, hal/s32g2.ld, src/boot_aarch64_start.S, tools/scripts/s32g2/s32g2-ddr-blob.py, tools/scripts/s32g2/s32g2-mkfit.sh, tools/scripts/s32g2/s32g2_mkimage.py
Coverage: 6 of 6 in-scope changed file(s) opened by the reviewer

Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Max

Comment thread hal/s32g2.c Resolved
Comment thread hal/s32g2.c Resolved
Comment thread hal/s32g2.c Resolved
@dgarske
dgarske force-pushed the s32g2_goldbox branch 2 times, most recently from 12b75e0 to 7a6bece Compare November 12, 2026 22:48
@dgarske
dgarske requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 12, 2026 22:56

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #984

Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): .github/workflows/test-configs.yml, .gitignore, Makefile, arch.mk, config/examples/s32g2-goldbox-qspi.config, config/examples/s32g2-goldbox.config, docs/Targets.md, docs/compile.md, hal/s32g2.h, hal/s32g2.its, hal/s32g2.ld, src/boot_aarch64_start.S, tools/config.mk, tools/scripts/s32g2/s32g2-ddr-blob.py, tools/scripts/s32g2/s32g2-mkfit.sh, tools/scripts/s32g2/s32g2_mkimage.py, tools/unit-tests/Makefile
Coverage: 7 of 13 in-scope changed file(s) opened by the reviewer; not opened: hal/library_fs.c, hal/s32g2.c, include/disk_fs.h, include/ext4.h, include/fat32.h, tools/unit-tests/unit-fat32.c

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread hal/s32g2.c Resolved
Comment thread hal/s32g2.c Resolved
Comment thread src/ext4.c Resolved
Comment thread hal/s32g2.c Resolved
Comment thread hal/s32g2.c Resolved
Comment thread src/update_disk.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #984

Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): .github/workflows/test-configs.yml, .gitignore, Makefile, arch.mk, config/examples/s32g2-goldbox-qspi.config, config/examples/s32g2-goldbox.config, docs/Targets.md, docs/compile.md, hal/s32g2.h, hal/s32g2.its, hal/s32g2.ld, src/boot_aarch64_start.S, tools/config.mk, tools/scripts/s32g2/s32g2-ddr-blob.py, tools/scripts/s32g2/s32g2-mkfit.sh, tools/scripts/s32g2/s32g2_mkimage.py, tools/unit-tests/Makefile
Coverage: 3 of 7 in-scope changed file(s) opened by the reviewer; not opened: hal/s32g2.c, include/ext4.h, include/fdt.h, tools/unit-tests/unit-update-disk-fs.c

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed stale reviews from themself November 13, 2026 16:17

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread hal/s32g2.c Resolved
Comment thread src/boot_aarch64_start.S Resolved
Comment thread hal/s32g2.c Resolved
Comment thread hal/s32g2.c Resolved
Comment thread src/ext4.c Resolved
Comment thread src/update_disk.c Resolved
@dgarske
dgarske force-pushed the s32g2_goldbox branch 2 times, most recently from b57e274 to 0ec99c0 Compare November 13, 2026 20:19
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.

3 participants