Skip to content

Build fixes for Yocto cross toolchains: FDT byte swaps without libgcc, prebuilt keytools, LDFLAGS_EXTRA - #921

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:yocto_build
Open

dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:yocto_build

Conversation

@dgarske

@dgarske dgarske commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Found building the PolarFire SoC M-mode target with a Yocto RISC-V Linux toolchain through meta-wolfssl. Three independent problems; none changes the output of a bare-metal toolchain build.

1. fdt.c pulled __bswapsi2 from libgcc

cpu_to_fdt32() used __builtin_bswap32. On rv64imac without Zbb, gcc expands that to a call into libgcc, and a Linux toolchain only ships libgcc for its own ABI (lp64d), which cannot be linked into the soft-float lp64 image. The byte swap is now open-coded; targets with a byte-swap instruction still get it from the compiler.

2. keytools_check rebuilt the in-tree keytools even when prebuilt tools were given

The keystore rule depends on keytools_check, which always built tools/keytools. A build that supplies native tools (Yocto's wolfboot-keytools-native) still rebuilt keygen with whatever CC was in effect, which under a cross compiler fails or produces a binary that cannot run on the host. When both KEYGEN_TOOL and SIGN_TOOL come from the command line the rule now checks that they resolve (command -v, so a bare name on PATH works) instead; with only one of them given the in-tree tools are still built, since the signing steps fall back to the in-tree sign.

3. LDFLAGS_EXTRA was documented but never consumed

arch.mk describes LDFLAGS_EXTRA as the way to add link flags, but nothing appended it, and Makefile resets LDFLAGS after .config is read, so a config cannot add link flags at all. options.mk now adds LDFLAGS_EXTRA next to CFLAGS_EXTRA, and the ARMclang paths that rebuild LDFLAGS from scratch (Makefile, test-app/Makefile) re-append it.

Hardware / test status

Built with both the bare-metal SoftConsole toolchain and the Yocto riscv64 Linux toolchain for polarfire_mpfs250_m.config; the Yocto build boots Linux from an SD FIT on the PolarFire SoC Video Kit. sim.config and the unit tests pass.

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.

Copilot review overview

🟡 Changes recommended

Prebuilt-tool validation rejects PATH-resolved executables, and ARMclang builds still discard extra linker flags.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Improves wolfBoot builds with Yocto cross toolchains, particularly for PolarFire SoC.

Changes:

  • Adds explicit FDT byte swaps for RISC-V without Zbb.
  • Skips rebuilding keytools when both prebuilt tools are supplied.
  • Appends LDFLAGS_EXTRA to linker flags.
File Description
src/​fdt.c Adds RISC-V byte-swap implementations.
options.mk Incorporates extra linker flags.
Makefile Validates prebuilt keytools instead of rebuilding them.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Makefile Outdated
Comment thread options.mk
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