From e8acdd028a335336cbe15fa1fc5f2ceea53c77f5 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Mon, 2 Nov 2026 21:36:40 +0000 Subject: [PATCH 1/2] init: move src/init to src/kernel/init Phase 2 of the kernel / user-space partition (#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 Signed-off-by: Liam Girdwood --- src/kernel/CMakeLists.txt | 5 +++++ src/{ => kernel}/init/CMakeLists.txt | 0 src/{ => kernel}/init/README.md | 8 ++++---- src/{ => kernel}/init/ext_manifest.c | 0 src/{ => kernel}/init/init.c | 0 test/ztest/unit/common/sof_context.c | 6 +++--- zephyr/CMakeLists.txt | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 src/kernel/CMakeLists.txt rename src/{ => kernel}/init/CMakeLists.txt (100%) rename src/{ => kernel}/init/README.md (93%) rename src/{ => kernel}/init/ext_manifest.c (100%) rename src/{ => kernel}/init/init.c (100%) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt new file mode 100644 index 000000000000..4cb00996f9ef --- /dev/null +++ b/src/kernel/CMakeLists.txt @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: BSD-3-Clause + +# Code that only runs in kernel mode, see scripts/kernel_user_partition.txt. + +add_subdirectory(init) diff --git a/src/init/CMakeLists.txt b/src/kernel/init/CMakeLists.txt similarity index 100% rename from src/init/CMakeLists.txt rename to src/kernel/init/CMakeLists.txt diff --git a/src/init/README.md b/src/kernel/init/README.md similarity index 93% rename from src/init/README.md rename to src/kernel/init/README.md index 58528af0a4d8..b20d490550f2 100644 --- a/src/init/README.md +++ b/src/kernel/init/README.md @@ -1,10 +1,10 @@ -# DSP Initialization (`src/init`) +# DSP Initialization (`src/kernel/init`) > **Runs in:** Kernel-only — boot and bring-up code runs in supervisor context; no path here > executes directly in a user thread. See -> [User/kernel split](../include/sof/userspace/README.md). +> [User/kernel split](../../include/sof/userspace/README.md). -The `src/init` directory contains the generic digital signal processor (DSP) initialization code and firmware metadata structures for Sound Open Firmware (SOF). It acts as the bridge between the underlying RTOS (Zephyr) boot phase and the SOF-specific task scheduling and processing pipelines. +The `src/kernel/init` directory contains the generic digital signal processor (DSP) initialization code and firmware metadata structures for Sound Open Firmware (SOF). It acts as the bridge between the underlying RTOS (Zephyr) boot phase and the SOF-specific task scheduling and processing pipelines. ## Architecture and Boot Flow @@ -19,7 +19,7 @@ The primary entry point for SOF system initialization is `sof_init()`, registere ```mermaid sequenceDiagram participant Zephyr as Zephyr RTOS - participant sof_init as sof_init (src/init.c) + participant sof_init as sof_init (src/kernel/init/init.c) participant primary_core as primary_core_init participant trace as trace_init participant notify as init_system_notify diff --git a/src/init/ext_manifest.c b/src/kernel/init/ext_manifest.c similarity index 100% rename from src/init/ext_manifest.c rename to src/kernel/init/ext_manifest.c diff --git a/src/init/init.c b/src/kernel/init/init.c similarity index 100% rename from src/init/init.c rename to src/kernel/init/init.c diff --git a/test/ztest/unit/common/sof_context.c b/test/ztest/unit/common/sof_context.c index 91d20c644572..87aa6832f299 100644 --- a/test/ztest/unit/common/sof_context.c +++ b/test/ztest/unit/common/sof_context.c @@ -7,9 +7,9 @@ // // Minimal SOF context for standalone ztest applications that link SOF code // calling sof_get(), for example src/audio/component.c, but do not link -// src/init/init.c. The context is created on first use and only its component -// driver list is initialised, which is what buffer_new() and the component -// infrastructure need. +// src/kernel/init/init.c. The context is created on first use and only its +// component driver list is initialised, which is what buffer_new() and the +// component infrastructure need. #include #include diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 0e5e9749b26b..42b00a15fcad 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -231,8 +231,8 @@ add_subdirectory(../src/math/ math_unused_install/) add_subdirectory(../src/audio/ audio_unused_install/) add_subdirectory(../src/debug/ debug_unused_install/) add_subdirectory(../src/idc/ idc_unused_install/) -add_subdirectory(../src/init/ init_unused_install/) add_subdirectory(../src/ipc/ ipc_unused_install/) +add_subdirectory(../src/kernel/ kernel_unused_install/) add_subdirectory(../src/lib/ lib_unused_install/) add_subdirectory(../src/library_manager/ library_manager_unused_install/) add_subdirectory(../src/logging/ logging_unused_install/) From 1c51b07250943bc6a21bcb6250590c7767d571f3 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Mon, 2 Nov 2026 22:03:54 +0000 Subject: [PATCH 2/2] zephyr: build src/kernel into a sof_kernel library 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 Signed-off-by: Liam Girdwood --- src/kernel/CMakeLists.txt | 8 ++++++++ zephyr/CMakeLists.txt | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 4cb00996f9ef..0b6846d11494 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -2,4 +2,12 @@ # Code that only runs in kernel mode, see scripts/kernel_user_partition.txt. +is_zephyr(zephyr) +if(zephyr) + # Build everything below into the sof_kernel library created in + # zephyr/CMakeLists.txt instead of modules_sof. This only sets the + # variable for this directory and its subdirectories. + set(ZEPHYR_CURRENT_LIBRARY sof_kernel) +endif() + add_subdirectory(init) diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 42b00a15fcad..47dcaca6cf4c 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -174,6 +174,13 @@ target_include_directories(SOF INTERFACE ${SOF_SRC_PATH}/arch/${ARCH}/include) target_include_directories(SOF INTERFACE ${sof_top_dir}/third_party/include) target_include_directories(SOF INTERFACE ${sof_top_dir}/zephyr/include) +# Code that only runs in kernel mode, from src/kernel. It is built as a +# library of its own so that it can later be given kernel-only include +# directories. Created before modules_sof so that modules_sof stays the +# current library here; src/kernel/CMakeLists.txt switches to this one. +zephyr_library_named(sof_kernel) +zephyr_library_link_libraries(SOF) + # SOF module init zephyr_library_named(modules_sof) @@ -665,5 +672,6 @@ include(../scripts/cmake/uuid-registry.cmake) # Create Trace realtive file paths sof_append_relative_path_definitions(modules_sof) +sof_append_relative_path_definitions(sof_kernel) endif() # CONFIG_SOF_FULL_ZEPHYR_APPLICATION