Skip to content

Phase 2 (part 1): add src/kernel and a sof_kernel library, move src/init - #11394

Merged
lgirdwood merged 2 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase2a
Nov 4, 2026
Merged

lgirdwood merged 2 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase2a

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Phase 2 of #11306 (kernel / user-space partition), first part: add src/kernel and a sof_kernel library for code that only runs in kernel mode, and move the firmware init code there. Further directories follow, one per PR.

Patches

  • src/init → src/kernel/init: a pure move. zephyr/CMakeLists.txt adds src/kernel instead of src/init. The README and a ztest comment get the new path. Only Zephyr builds this code; the host builds don't.
  • sof_kernel library: src/kernel is built into a new Zephyr library instead of modules_sof. It can then get kernel-only include directories later (Phase 4).
    • Where it's created: in zephyr/CMakeLists.txt, next to modules_sof, so it gets the same directory-level definitions (for example CC_OPTIMIZE_FLAGS, used by ext_manifest.c). It also links the same SOF interface library.
    • Current library: sof_kernel is created before modules_sof, so modules_sof stays the current library in zephyr/CMakeLists.txt. src/kernel/CMakeLists.txt makes sof_kernel the current library for its own directory tree, so the CMake files of directories moved there need no change.
    • Trace paths: the relative trace file paths are set for the new library as well.

Functional change

None. The compile flags of the moved files are unchanged apart from their RELATIVE_FILE path, and the generated objects are unchanged.

What changes is the link order: the init objects now come after the IPC code, from a library of their own. Zephyr links all its libraries as whole archives, so sof_init()'s SYS_INIT() entry is kept. In every firmware image the symbols (name, type and size) and the SYS_INIT() order are identical before and after. The only section differences are a few bytes of alignment padding in .text, .xt.prop and .xt.lit on MTL, TGL and TGL-H. The ASan fuzz builds also embed the longer source path. On the Cortex-M7 builds (imx8m_cm7, imx95), sof_init() changes size from commit to commit because it embeds the git hash (SOF_SRC_HASH), and Thumb-2 encodes some constants more compactly than others. Rebuilding init.c with each commit's hash value gives the same sizes, and the source path has no effect.

Testing

  • Per commit:
    • Builds: every commit was built on tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx95 and qemu_xtensa, and in the extra CI configurations:
      • native_sim IPC3/IPC4 stub builds;
      • imx93 64-bit;
      • PTL with each userspace overlay;
      • PTL with CONFIG_SOF_USERSPACE_PROXY=n;
      • PTL and MTL with os_linux_overlay.conf;llext_relocatable.conf.
    • Objects and LLEXT modules: same non-debug section sizes as the previous commit.
    • Firmware images: compared for symbols, SYS_INIT() order and section sizes, with the results above.
    • Cadence xt-clang (RI-2022.10): MTL, PTL and NVL compile.
    • Host: the host library and cmocka build and pass.
  • At the tip:
    • all cmocka configurations, the testbench and the tools pass;
    • the platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365) have unchanged error sets.
  • Hardware: TGL (UP Xtreme i11) with sof-hda-generic-cavs25-2ch.tplg, comparing main and this branch. Both boot, play 5 s on the HDA analog PCM, and play again after runtime suspend, with no DSP errors.

All of the above was run on 78b23ad (current main), except for the hardware test, which was run on the same two patches on d44cbf0.

🤖 Generated with Claude Code

lrgirdwo and others added 2 commits November 3, 2026 12:59
Phase 2 of the kernel / user-space partition (thesofproject#11306) moves the code
that only runs in kernel mode to src/kernel. The firmware init code is
the first: it brings up the SOF context and runs from SYS_INIT() in
supervisor mode.

Move it to src/kernel/init and add src/kernel/CMakeLists.txt, which
the Zephyr build now adds instead of src/init. Update the paths in the
README and in a ztest comment. Only Zephyr builds src/init, so the
host builds are not affected. No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add a sof_kernel Zephyr library for the code in src/kernel, so that
kernel-only code is built separately from modules_sof and can later be
given include directories of its own.

The library is created in zephyr/CMakeLists.txt, next to modules_sof,
so that it gets the same directory-level compile definitions, and it
links the same SOF interface library. It is created first so that
modules_sof stays the current Zephyr library there.
src/kernel/CMakeLists.txt makes sof_kernel the current library for its
own directory tree, so the CMake files of the directories moved there
need no change. The trace relative paths are set for it as well.

Like all Zephyr libraries it is linked as a whole archive, so the
SYS_INIT() entries it holds are kept and their order is unchanged.
The generated code is unchanged; only the link order, and with it the
alignment padding in some sections, changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>

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.

🟢 Approval recommended

No active review issues are recorded for the kernel source-tree and library reorganization.

No open issues 🎉

What changed in this PR

This PR begins Phase 2 of #11306 by establishing a kernel-only source tree and library for SOF’s kernel/userspace partition. It moves firmware initialization into that tree without intended functional changes.

Changes:

  • Move src/init to src/kernel/init, preserving initialization logic and firmware metadata.
  • Add the sof_kernel Zephyr library, shared SOF build settings, and relative trace-path definitions.
  • Update documentation and a test-support comment to reflect the new location.
File Description
zephyr/​CMakeLists.txt Creates and links sof_kernel, includes the kernel tree, and configures trace paths.
test/​ztest/​unit/​common/​sof_context.c Updates the initialization source path in a comment.
src/​kernel/​init/​README.md Updates directory references, the userspace documentation link, and the boot diagram.
src/​kernel/​init/​init.c Relocates firmware initialization code without logic changes.
src/​kernel/​init/​ext_manifest.c Relocates firmware metadata definitions without logic changes.
src/​kernel/​init/​CMakeLists.txt Preserves the relocated initialization source list.
src/​kernel/​CMakeLists.txt Selects sof_kernel for the directory tree and includes initialization sources.

Review effort: Balanced

@intel-sofci

Copy link
Copy Markdown

PR 11394: test results

Run date: 2026-11-03 21:02 UTC

Tested commit: 1c51b07250943bc6a21bcb6250590c7767d571f3

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@lgirdwood
lgirdwood merged commit d3f51d0 into thesofproject:main Nov 4, 2026
47 of 48 checks passed
@lgirdwood
lgirdwood deleted the kernel-user/phase2a branch November 4, 2026 11:24
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.

5 participants