llext: update to use add_llext_target()

Zephyr now provides a convenient cmake API for LLEXT modules, update
SOF to use it by defining common cmake functions.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
This commit is contained in:
Guennadi Liakhovetski 2024-05-03 16:43:55 +02:00 committed by Liam Girdwood
parent 30386bae13
commit 05e69e1bb9
4 changed files with 69 additions and 103 deletions

View File

@ -931,8 +931,8 @@ def install_lib(sof_lib_dir, abs_build_dir, platform_wconfig):
dst = sof_lib_dir / llext_file
rimage_cfg = entry_path / 'rimage_config.toml'
llext_input = entry_path / (llext_base + '.so')
llext_output = entry_path / llext_file
llext_input = entry_path / (llext_base + '.llext')
llext_output = entry_path / (llext_file + '.ri')
sign_cmd = [str(platform_wconfig.get("rimage.path")), "-o", str(llext_output),
"-e", "-c", str(rimage_cfg),
@ -947,7 +947,7 @@ def install_lib(sof_lib_dir, abs_build_dir, platform_wconfig):
# Thus we're left with a choice between a 150-character
# long line and an illogical split like this
with open(dst, 'wb') as fdst, open(llext_output, 'rb') as fllext, open(
llext_output.with_suffix('.llext.xman'), 'rb') as fman:
llext_output.with_suffix('.ri.xman'), 'rb') as fman:
# Concatenate the manifest and the llext
shutil.copyfileobj(fman, fdst)
shutil.copyfileobj(fllext, fdst)

View File

@ -404,7 +404,7 @@ SOF_MODULE_INIT(smart_amp_test, sys_comp_module_smart_amp_test_interface_init);
#endif
#ifdef MAJOR_IADSP_API_VERSION
#if defined(MAJOR_IADSP_API_VERSION) || defined(CONFIG_SAMPLE_SMART_AMP_MODULE)
/* modular: system-services or dynamic link */
#include <module/module/llext.h>

View File

@ -1,102 +1,8 @@
# Copyright (c) 2023 Intel Corporation.
# SPDX-License-Identifier: Apache-2.0
# FIXME: This *WILL* be converted to add_llext_target() as long as that's
# reasonably possible, and if it isn't, a *significant* effort will be made to
# make that possible
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(smart_amp_test)
SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
set(MODULE "smart_amp_test")
cmake_path(SET SOF_BASE NORMALIZE ${PROJECT_SOURCE_DIR}/../../../..)
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/../${MODULE}.toml uuids REGEX "^[ \t]*uuid *=")
file(WRITE ${PROJECT_BINARY_DIR}/llext.uuid "")
foreach(line IN LISTS uuids)
# extract UUID value - drop the 'uuid = ' part of the assignment line
string(REGEX REPLACE "^[ \t]*uuid *= \"([0-9A-F\-]*)\"" "\\1" uuid ${line})
file(APPEND ${PROJECT_BINARY_DIR}/llext.uuid "${uuid}\n")
endforeach()
add_library(${MODULE} SHARED)
target_sources(${MODULE} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/../smart_amp_test_ipc4.c
# Hard-coded .text address to be moved to a common place
sof_llext_build("smart_amp_test"
SOURCES ../smart_amp_test_ipc4.c
TEXT_ADDR 0xa06ca000
)
sof_append_relative_path_definitions(${MODULE})
target_include_directories(${MODULE} PRIVATE
"${ZEPHYR_BASE}/include"
"${ZEPHYR_BASE}/soc/intel/intel_adsp/common/include"
"${ZEPHYR_BASE}/soc/intel/intel_adsp/ace/include/ace15_mtpm"
"${ZEPHYR_BASE}/../modules/hal/xtensa/include"
"${ZEPHYR_BASE}/../modules/hal/xtensa/zephyr/soc/intel_ace15_mtpm"
"${SOF_BASE}/src/include"
"${SOF_BASE}/src/arch/xtensa/include"
"${SOF_BASE}/src/platform/meteorlake/include"
"${SOF_BASE}/src/platform/intel/ace/include"
"${SOF_BASE}/src/include/sof/audio/module_adapter/iadk"
"${SOF_BASE}/zephyr/include"
"${SOF_BASE}/xtos/include"
"${SOF_BASE}/tools/rimage/src/include"
"${PROJECT_BINARY_DIR}/../include/generated"
)
set(MODULE_PROPERTIES HPSRAM_ADDR "0xa06c1000")
set_target_properties(${MODULE} PROPERTIES ${MODULE_PROPERTIES})
set(MODULE_COMPILE_DEF
__ZEPHYR__=1
__XTENSA__
KERNEL
MAJOR_IADSP_API_VERSION=5
MIDDLE_IADSP_API_VERSION=0
MINOR_IADSP_API_VERSION=0
)
target_compile_definitions(${MODULE} PRIVATE ${MODULE_COMPILE_DEF})
target_compile_options(${MODULE} PRIVATE
-imacros${PROJECT_BINARY_DIR}/../include/generated/autoconf.h
-save-temps -O2
)
if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "zephyr")
set(MODULE_LINKER_PARAMS -nostdlib -nodefaultlibs)
set(EXTRA_LINKER_PARAMS -shared)
set(COPY_CMD ${CMAKE_STRIP} -R .xt.* -o ${MODULE}.so ${MODULE}_pre.so)
else()
set(MODULE_LINKER_PARAMS -nostdlib -nodefaultlibs -r)
set(EXTRA_LINKER_PARAMS)
set(COPY_CMD ${CMAKE_OBJCOPY} -R .xt.* ${MODULE}_pre.so ${MODULE}.so)
endif()
target_link_options(${MODULE} PRIVATE
${MODULE_LINKER_PARAMS}
)
add_custom_command(OUTPUT lib${MODULE}_out.so
DEPENDS ${MODULE}
COMMAND ${CMAKE_C_COMPILER} -E ${CMAKE_CURRENT_LIST_DIR}/llext.toml.h -P -DREM=
-I${SOF_BASE} -I${SOF_BASE}src
-imacros ../include/generated/autoconf.h
-o rimage_config.toml
COMMAND ${SOF_BASE}scripts/llext_link_helper.py
-f lib${MODULE}.so -t "0xa06ca000" ${CMAKE_C_COMPILER} --
${MODULE_LINKER_PARAMS} ${EXTRA_LINKER_PARAMS} -fPIC
-o ${MODULE}_pre.so $<TARGET_OBJECTS:${MODULE}>
COMMAND ${COPY_CMD}
COMMAND_EXPAND_LISTS
)
add_custom_target(${MODULE}_llext ALL
DEPENDS lib${MODULE}_out.so
)
add_dependencies(${MODULE} zephyr_interface)

View File

@ -35,6 +35,66 @@ function(sof_append_relative_path_definitions target)
endforeach()
endfunction()
# Used by LLEXT modules to create a file with module UUIDs
function(sof_llext_write_uuids module)
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/../${module}.toml uuids REGEX "^[ \t]*uuid *=")
foreach(line IN LISTS uuids)
# extract UUID value - drop the 'uuid = ' part of the assignment line
string(REGEX REPLACE "^[ \t]*uuid *= \"([0-9A-F\-]*)\"" "\\1" uuid ${line})
file(APPEND ${ZEPHYR_BINARY_DIR}/${module}_llext/llext.uuid "${uuid}\n")
endforeach()
endfunction()
# Build an LLEXT module. Provice a module name, a list of sources and an address
# of the .text section as arguments.
function(sof_llext_build module)
set(single_args TEXT_ADDR)
set(multi_args SOURCES)
cmake_parse_arguments(PARSE_ARGV 1 SOF_LLEXT "${options}" "${single_args}" "${multi_args}")
cmake_path(SET SOF_BASE NORMALIZE ${APPLICATION_SOURCE_DIR}/..)
sof_llext_write_uuids(${module})
add_llext_target(${module}
OUTPUT ${PROJECT_BINARY_DIR}/${module}_llext/${module}.llext
SOURCES ${SOF_LLEXT_SOURCES}
)
target_include_directories(${module}_llext_lib PRIVATE
"${SOF_BASE}/xtos/include"
"${SOF_BASE}/src/include"
"${SOF_BASE}/tools/rimage/src/include"
)
sof_append_relative_path_definitions(${module}_llext_lib)
add_llext_command(TARGET ${module}
PRE_BUILD
COMMAND ${CMAKE_C_COMPILER} -E ${CMAKE_CURRENT_LIST_DIR}/llext.toml.h -P -DREM=
-I${SOF_BASE} -I${SOF_BASE}src
-imacros ../include/generated/autoconf.h
-o rimage_config.toml
)
if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "zephyr")
set(EXTRA_LINKER_PARAMS -nostdlib -nodefaultlibs -shared)
else()
set(EXTRA_LINKER_PARAMS -nostdlib -nodefaultlibs -r)
endif()
get_target_property(proc_in_file ${module} lib_output)
get_target_property(proc_out_file ${module} pkg_input)
add_llext_command(TARGET ${module}
POST_BUILD
COMMAND ${SOF_BASE}scripts/llext_link_helper.py
--text-addr="${SOF_LLEXT_TEXT_ADDR}" -f ${proc_in_file} ${CMAKE_C_COMPILER} --
-o ${proc_out_file} ${EXTRA_LINKER_PARAMS}
$<TARGET_OBJECTS:${module}_llext_lib>
)
endfunction()
# Initial SOF module will contain
#
# 1. Application logic - pipeline, audio components, IPC processing, topology
@ -802,7 +862,7 @@ elseif(CONFIG_IPC_MAJOR_4)
if(CONFIG_SAMPLE_SMART_AMP STREQUAL "m")
add_subdirectory(${SOF_SAMPLES_PATH}/audio/smart_amp_test_llext
${PROJECT_BINARY_DIR}/smart_amp_test_llext)
add_dependencies(app smart_amp_test_llext)
add_dependencies(app smart_amp_test)
elseif(CONFIG_SAMPLE_SMART_AMP)
zephyr_library_sources(
${SOF_SAMPLES_PATH}/audio/smart_amp_test_ipc4.c