-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
smart-amp-test: make a loadable module
Convert the smart-amp-test in its IPC4 version to a loadable LLEXT module. Use an overlay configuration to select between monolithic and modular builds. Signed-off-by: Guennadi Liakhovetski <[email protected]>
- Loading branch information
Showing
7 changed files
with
198 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_SAMPLE_SMART_AMP=m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
# We need to calculate ELF section addresses of an LLEXT module and use them to | ||
# run the linker. We could just use Python to calculate addresses and pass them | ||
# back to cmake to have it call the linker. However, there doesn't seem to be a | ||
# portable way to do that. Therefore we pass the linker path and all the command | ||
# line parameters to this script and call the linker directly. | ||
|
||
import argparse | ||
import subprocess | ||
from elftools.elf.elffile import ELFFile | ||
|
||
args = None | ||
def parse_args(): | ||
global args | ||
|
||
parser = argparse.ArgumentParser(description='Helper utility to run a linker command ' | ||
'with calculated ELF section addresses') | ||
|
||
parser.add_argument('command', type=str, help='Linker command to execute') | ||
parser.add_argument('params', nargs='+', help='Additional linker parameters') | ||
parser.add_argument("-f", "--file", required=True, type=str, | ||
help='Object file name') | ||
parser.add_argument("-t", "--text-addr", required=True, type=str, | ||
help='.text section address') | ||
|
||
args = parser.parse_args() | ||
|
||
def main(): | ||
parse_args() | ||
|
||
elf = ELFFile(open(args.file, 'rb')) | ||
|
||
text_addr = int(args.text_addr, 0) | ||
|
||
text_offset = elf.get_section_by_name('.text').header.sh_offset | ||
rodata_offset = elf.get_section_by_name('.rodata').header.sh_offset | ||
data_offset = elf.get_section_by_name('.data').header.sh_offset | ||
|
||
upper = rodata_offset - text_offset + text_addr + 0xfff | ||
rodata_addr = upper - (upper % 0x1000) | ||
|
||
upper = data_offset - rodata_offset + rodata_addr + 0xf | ||
data_addr = upper - (upper % 0x10) | ||
|
||
command = [args.command, | ||
f'-Wl,-Ttext=0x{text_addr:x}', | ||
f'-Wl,--section-start=.rodata=0x{rodata_addr:x}', | ||
f'-Wl,-Tdata=0x{data_addr:x}'] | ||
command.extend(args.params) | ||
|
||
subprocess.run(command) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright (c) 2023 Intel Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
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}/../../../..) | ||
|
||
add_library(${MODULE} SHARED) | ||
|
||
target_sources(${MODULE} PRIVATE | ||
${CMAKE_CURRENT_LIST_DIR}/../smart_amp_test_ipc4.c | ||
) | ||
|
||
sof_append_relative_path_definitions(${MODULE}) | ||
|
||
target_include_directories(${MODULE} PRIVATE | ||
"${ZEPHYR_BASE}/include" | ||
"${ZEPHYR_BASE}/soc/xtensa/intel_adsp/common/include" | ||
"${ZEPHYR_BASE}/soc/xtensa/intel_adsp/ace/include/intel_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 | ||
) | ||
|
||
set(MODULE_LINKER_PARAMS -nostdlib -nodefaultlibs) | ||
target_link_options(${MODULE} PRIVATE | ||
${MODULE_LINKER_PARAMS} | ||
) | ||
|
||
add_custom_command(OUTPUT lib${MODULE}_out.so | ||
DEPENDS ${MODULE} | ||
COMMAND ${SOF_BASE}scripts/llext_link_helper.py | ||
-f lib${MODULE}.so -t "0xa06ca000" ${CMAKE_C_COMPILER} -- | ||
${MODULE_LINKER_PARAMS} -shared -fPIC | ||
-o lib${MODULE}_llext.so $<TARGET_OBJECTS:${MODULE}> | ||
COMMAND ${CMAKE_STRIP} -R .xt.* -o lib${MODULE}_out.so lib${MODULE}_llext.so | ||
COMMAND_EXPAND_LISTS | ||
) | ||
|
||
add_custom_target(${MODULE}_llext ALL | ||
DEPENDS lib${MODULE}_out.so | ||
) | ||
|
||
add_dependencies(${MODULE} zephyr_interface) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <tools/rimage/config/platform.toml> | ||
#include "../smart_amp_test.toml" | ||
[module] | ||
count = __COUNTER__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters