Skip to content

Commit 3163edf

Browse files
committed
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 <guennadi.liakhovetski@linux.intel.com>
1 parent d3d3592 commit 3163edf

File tree

6 files changed

+230
-4
lines changed

6 files changed

+230
-4
lines changed

scripts/calc_elf_addresses.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
file=$1
4+
text_addr=$2
5+
6+
# We need to take addresses of .text, .data, .rodata and .bss and calculate
7+
# offsets, because the linker will keep everything between .data and .rodata and
8+
# between .rodata and .bss in the final image too, when we specify section
9+
# addresses. So just taking sizes of .text, .data and .rodata isn't enough.
10+
# We use file offset from the objdump command output to avoid unused sections.
11+
12+
source <(
13+
objdump -h $file | awk '/ .text / {print "text="toupper($6)} / .rodata / {print "rodata="toupper($6)} / .data / {print "data="toupper($6)}'
14+
)
15+
16+
# round up to 4KiB
17+
upper=$((0x$rodata - 0x$text + 0x$text_addr + 0xFFF))
18+
rem=$(($upper % 0x1000))
19+
rodata_addr=$(($upper - $rem))
20+
# round up to 16 bytes
21+
upper=$((0x$data - 0x$rodata + $rodata_addr + 0xF))
22+
rem=$(($upper % 0x10))
23+
data_addr=$(($upper - $rem))
24+
25+
printf " -Wl,-Ttext=0x%x" 0x$text_addr
26+
printf " -Wl,--section-start=.rodata=0x%x" $rodata_addr
27+
printf " -Wl,-Tdata=0x%x\n" $data_addr

src/samples/audio/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
menu "Audio component samples"
44

55
config SAMPLE_SMART_AMP
6-
bool "Smart amplifier test component"
6+
tristate "Smart amplifier test component"
77
default y
88
help
99
Select for test smart amplifier component
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (c) 2023 Intel Corporation.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(smart_amp_test)
7+
8+
SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
9+
10+
set(MODULE "smart_amp_test")
11+
cmake_path(SET SOF_BASE NORMALIZE ${PROJECT_SOURCE_DIR}/../../../..)
12+
13+
add_library(${MODULE} SHARED)
14+
15+
target_sources(${MODULE} PRIVATE
16+
${CMAKE_CURRENT_LIST_DIR}/../smart_amp_test_ipc4.c
17+
)
18+
19+
sof_append_relative_path_definitions(${MODULE})
20+
21+
target_include_directories(${MODULE} PRIVATE
22+
"${ZEPHYR_BASE}/include"
23+
"${ZEPHYR_BASE}/soc/xtensa/intel_adsp/common/include"
24+
"${ZEPHYR_BASE}/soc/xtensa/intel_adsp/ace/include/intel_ace15_mtpm"
25+
"${ZEPHYR_BASE}/../modules/hal/xtensa/include"
26+
"${ZEPHYR_BASE}/../modules/hal/xtensa/zephyr/soc/intel_ace15_mtpm"
27+
"${SOF_BASE}/src/include"
28+
"${SOF_BASE}/src/arch/xtensa/include"
29+
"${SOF_BASE}/src/platform/meteorlake/include"
30+
"${SOF_BASE}/src/platform/intel/ace/include"
31+
"${SOF_BASE}/src/include/sof/audio/module_adapter/iadk"
32+
"${SOF_BASE}/zephyr/include"
33+
"${SOF_BASE}/xtos/include"
34+
"${SOF_BASE}/tools/rimage/src/include"
35+
"${PROJECT_BINARY_DIR}/../include/generated"
36+
)
37+
38+
set(MODULE_PROPERTIES HPSRAM_ADDR "0xa06c1000")
39+
set_target_properties(${MODULE} PROPERTIES ${MODULE_PROPERTIES})
40+
41+
set(MODULE_COMPILE_DEF
42+
__ZEPHYR__=1
43+
__XTENSA__
44+
KERNEL
45+
MAJOR_IADSP_API_VERSION=5
46+
MIDDLE_IADSP_API_VERSION=0
47+
MINOR_IADSP_API_VERSION=0
48+
)
49+
target_compile_definitions(${MODULE} PRIVATE ${MODULE_COMPILE_DEF})
50+
51+
target_compile_options(${MODULE} PRIVATE
52+
-imacros${PROJECT_BINARY_DIR}/../include/generated/autoconf.h
53+
-save-temps -O2
54+
)
55+
56+
set(MODULE_LINKER_PARAMS -nostdlib -nodefaultlibs)
57+
target_link_options(${MODULE} PRIVATE
58+
${MODULE_LINKER_PARAMS}
59+
)
60+
61+
add_custom_target(${MODULE}_llext ${CMAKE_C_COMPILER}
62+
${MODULE_LINKER_PARAMS}
63+
"$$(${SOF_BASE}/scripts/calc_elf_addresses.sh" lib${MODULE}.so "A06CA000)"
64+
-shared -fPIC
65+
-o lib${MODULE}_llext.so $<TARGET_OBJECTS:${MODULE}>
66+
COMMAND ${CMAKE_STRIP} -R .xt.* -o lib${MODULE}_out.so lib${MODULE}_llext.so
67+
DEPENDS ${MODULE}
68+
COMMAND_EXPAND_LISTS
69+
)
70+
71+
add_dependencies(${MODULE} zephyr_interface)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
version = [3, 0]
2+
3+
[adsp]
4+
name = "mtl"
5+
image_size = "0x2C0000" # (22) bank * 128KB
6+
alias_mask = "0xE0000000"
7+
8+
[[adsp.mem_zone]]
9+
type = "ROM"
10+
base = "0x1FF80000"
11+
size = "0x400"
12+
[[adsp.mem_zone]]
13+
type = "IMR"
14+
base = "0xA104A000"
15+
size = "0x2000"
16+
[[adsp.mem_zone]]
17+
type = "SRAM"
18+
base = "0xa00f0000"
19+
size = "0x100000"
20+
21+
[[adsp.mem_alias]]
22+
type = "uncached"
23+
base = "0x40000000"
24+
[[adsp.mem_alias]]
25+
type = "cached"
26+
base = "0xA0000000"
27+
28+
[cse]
29+
partition_name = "ADSP"
30+
[[cse.entry]]
31+
name = "ADSP.man"
32+
offset = "0x5c"
33+
length = "0x464"
34+
[[cse.entry]]
35+
name = "ADSP.met"
36+
offset = "0x4c0"
37+
length = "0x70"
38+
[[cse.entry]]
39+
name = "ADSP"
40+
offset = "0x540"
41+
length = "0x0" # calculated by rimage
42+
43+
[css]
44+
45+
[signed_pkg]
46+
name = "ADSP"
47+
partition_usage = "0x23"
48+
[[signed_pkg.module]]
49+
name = "ADSP.met"
50+
51+
[adsp_file]
52+
[[adsp_file.comp]]
53+
base_offset = "0x2000"
54+
55+
[fw_desc.header]
56+
name = "ADSPFW"
57+
load_offset = "0x40000"
58+
59+
[module]
60+
count = 1
61+
62+
[[module.entry]]
63+
name = "SMATEST"
64+
uuid = "167A961E-8AE4-11EA-89F1-000C29CE1635"
65+
affinity_mask = "0x1"
66+
instance_count = "1"
67+
domain_types = "0"
68+
load_type = "0"
69+
init_config = "1"
70+
module_type = "0xD"
71+
auto_start = "0"
72+
sched_caps = [1, 0x00008000]
73+
74+
# pin = [dir, type, sample rate, size, container, channel-cfg]
75+
pin = [0, 0, 0xfeef, 0xf, 0xa, 0x45ff,
76+
0, 0, 0xfeef, 0xf, 0xa, 0x45ff,
77+
1, 0, 0xfeef, 0xf, 0xa, 0x45ff]
78+
79+
# mod_cfg [PAR_0 PAR_1 PAR_2 PAR_3 IS_BYTES CPS IBS OBS MOD_FLAGS CPC OBLS]
80+
mod_cfg = [0, 0, 0, 0, 4096, 1000000, 128, 128, 0, 0, 0]

src/samples/audio/smart_amp_test_ipc4.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ struct smart_amp_data {
3939
uint32_t out_channels;
4040
};
4141

42+
/* When building as a loadable module, we need .bss to avoid rimage errors */
43+
static int keep_bss __attribute__((used));
44+
4245
static int smart_amp_init(struct processing_module *mod)
4346
{
4447
struct smart_amp_data *sad;
@@ -49,7 +52,13 @@ static int smart_amp_init(struct processing_module *mod)
4952
int ret;
5053
const struct ipc4_base_module_extended_cfg *base_cfg = mod_data->cfg.init_data;
5154

55+
if (!base_cfg) {
56+
comp_err(dev, "smart_amp_init(): no module configuration");
57+
return -EINVAL;
58+
}
59+
5260
comp_dbg(dev, "smart_amp_init()");
61+
5362
sad = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*sad));
5463
if (!sad)
5564
return -ENOMEM;
@@ -393,3 +402,36 @@ DECLARE_MODULE_ADAPTER(smart_amp_test_interface, smart_amp_test_comp_uuid, smart
393402
* "sys_comp_module_<smart_amp_test_interface>_init()" (and a lot more)
394403
*/
395404
SOF_MODULE_INIT(smart_amp_test, sys_comp_module_smart_amp_test_interface_init);
405+
406+
#ifdef MAJOR_IADSP_API_VERSION
407+
408+
#include <rimage/sof/user/manifest.h>
409+
#include <module/module/api_ver.h>
410+
411+
static const void *loadable_module_main(void *mod_cfg, void *parent_ppl, void **mod_ptr)
412+
{
413+
return &smart_amp_test_interface;
414+
}
415+
416+
static const struct sof_man_module_manifest main_manifest __section(".module") __attribute__((used)) = {
417+
.module = {
418+
.name = "SMATEST",
419+
.uuid = {0x1E, 0x96, 0x7A, 0x16, 0xE4, 0x8A, 0xEA, 0x11,
420+
0x89, 0xF1, 0x00, 0x0C, 0x29, 0xCE, 0x16, 0x35},
421+
.entry_point = (uint32_t)loadable_module_main,
422+
.type = {
423+
.load_type = SOF_MAN_MOD_TYPE_LLEXT,
424+
.domain_ll = 1,
425+
},
426+
.affinity_mask = 1,
427+
}
428+
};
429+
430+
static const struct sof_module_api_build_info buildinfo __section(".mod_buildinfo") __attribute__((used)) = {
431+
.format = SOF_MODULE_API_BUILD_INFO_FORMAT,
432+
.api_version_number = {
433+
.fields.major = SOF_MODULE_API_MAJOR_VERSION,
434+
},
435+
};
436+
437+
#endif

zephyr/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,15 @@ if(CONFIG_IPC_MAJOR_3)
772772
${SOF_AUDIO_PATH}/tdfb/tdfb_ipc3.c
773773
)
774774
elseif(CONFIG_IPC_MAJOR_4)
775-
zephyr_library_sources_ifdef(CONFIG_SAMPLE_SMART_AMP
776-
${SOF_SAMPLES_PATH}/audio/smart_amp_test_ipc4.c
777-
)
775+
if(CONFIG_SAMPLE_SMART_AMP STREQUAL "m")
776+
add_subdirectory(${SOF_SAMPLES_PATH}/audio/smart_amp_llext
777+
${PROJECT_BINARY_DIR}/smart_amp_llext)
778+
add_dependencies(app smart_amp_test_llext)
779+
elseif(CONFIG_SAMPLE_SMART_AMP)
780+
zephyr_library_sources(
781+
${SOF_SAMPLES_PATH}/audio/smart_amp_test_ipc4.c
782+
)
783+
endif()
778784

779785
zephyr_library_sources_ifdef(CONFIG_COMP_TDFB
780786
${SOF_AUDIO_PATH}/tdfb/tdfb_ipc4.c

0 commit comments

Comments
 (0)