forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
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. Signed-off-by: Guennadi Liakhovetski <[email protected]>
- Loading branch information
Showing
6 changed files
with
178 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,43 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import argparse | ||
from elftools.elf.elffile import ELFFile | ||
|
||
args = None | ||
def parse_args(): | ||
global args | ||
|
||
parser = argparse.ArgumentParser(description='Helper utility to generate a linker command' | ||
' line with calculated ELF section addresses') | ||
|
||
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.replace("0x", ""), 16) | ||
|
||
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 + int(args.text_addr, 16) + 0xfff | ||
rodata_addr = upper - (upper % 0x1000) | ||
|
||
upper = data_offset - rodata_offset + rodata_addr + 0xf | ||
data_addr = upper - (upper % 0x10) | ||
|
||
print(f'-Wl,-Ttext=0x{text_addr:x} ' | ||
f'-Wl,--section-start=.rodata=0x{rodata_addr:x} ' | ||
f'-Wl,-Tdata=0x{data_addr:x}') | ||
|
||
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,71 @@ | ||
# 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_target(${MODULE}_llext ${CMAKE_C_COMPILER} | ||
${MODULE_LINKER_PARAMS} | ||
"$$(${SOF_BASE}scripts/calc_elf_addresses.py" -f lib${MODULE}.so -t "A06CA000)" | ||
-shared -fPIC | ||
-o lib${MODULE}_llext.so $<TARGET_OBJECTS:${MODULE}> | ||
COMMAND ${CMAKE_STRIP} -R .xt.* -o lib${MODULE}_out.so lib${MODULE}_llext.so | ||
DEPENDS ${MODULE} | ||
COMMAND_EXPAND_LISTS | ||
) | ||
|
||
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