Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLEXT: build libraries #9702

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 67 additions & 35 deletions scripts/xtensa-build-zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,11 @@ def install_lib(sof_lib_dir, abs_build_dir, platform_wconfig):

global signing_key

libs = dict()
lib_uuids = dict()
rimage_cmd = shlex.split(platform_wconfig.get('rimage.path'))[0]
_ws_args = platform_wconfig.get("rimage.extra-args")

with os.scandir(str(abs_build_dir)) as iter:
if args.key_type_subdir != "none":
sof_lib_dir = sof_lib_dir / args.key_type_subdir
Expand All @@ -955,45 +960,72 @@ def install_lib(sof_lib_dir, abs_build_dir, platform_wconfig):
# eq_iir_llext/eq_iir.llext
llext_base = entry.name[:-6]
llext_file = llext_base + '.llext'

dst = sof_lib_dir / llext_file

rimage_cfg = entry_path / 'rimage_config.toml'
llext_input = entry_path / (llext_base + '.llext')
llext_output = entry_path / (llext_file + '.ri')

# See why the shlex() parsing step is required at
# https://docs.zephyrproject.org/latest/develop/west/sign.html#rimage
# and in Zephyr commit 030b740bd1ec
rimage_cmd = shlex.split(platform_wconfig.get('rimage.path'))[0]
sign_cmd = [rimage_cmd, "-o", str(llext_output),
"-e", "-c", str(rimage_cfg),
"-k", str(signing_key), "-l", "-r"]
_ws_args = platform_wconfig.get("rimage.extra-args")
if _ws_args is not None:
sign_cmd.extend(shlex.split(_ws_args))
sign_cmd.append(str(llext_input))
execute_command(sign_cmd, cwd=west_top)

# An intuitive way to make this multiline would be
# with (open(dst, 'wb') as fdst, open(llext_output, 'rb') as fllext,
# open(llext_output.with_suffix('.llext.xman'), 'rb') as fman):
# but a Python version, used on Windows errored out on this.
# 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('.ri.xman'), 'rb') as fman:
# Concatenate the manifest and the llext
shutil.copyfileobj(fman, fdst)
shutil.copyfileobj(fllext, fdst)
lib_name = ''

lib_fname = entry_path / 'lib_name.txt'
if os.path.exists(lib_fname):
with open(lib_fname, 'r') as libs_f:
lib_name = libs_f.read()
if lib_name not in libs.keys():
libs[lib_name] = []
libs[lib_name].append(str(entry_path / llext_file))
else:
dst = sof_lib_dir / llext_file

rimage_cfg = entry_path / 'rimage_config.toml'
llext_input = entry_path / (llext_base + '.llext')
llext_output = entry_path / (llext_file + '.ri')

# See why the shlex() parsing step is required at
# https://docs.zephyrproject.org/latest/develop/west/sign.html#rimage
# and in Zephyr commit 030b740bd1ec
sign_cmd = [rimage_cmd, "-o", str(llext_output),
"-e", "-c", str(rimage_cfg),
"-k", str(signing_key), "-l", "-r"]
if _ws_args is not None:
sign_cmd.extend(shlex.split(_ws_args))
sign_cmd.append(str(llext_input))
execute_command(sign_cmd, cwd=west_top)

# An intuitive way to make this multiline would be
# with (open(dst, 'wb') as fdst, open(llext_output, 'rb') as fllext,
# open(llext_output.with_suffix('.llext.xman'), 'rb') as fman):
# but a Python version, used on Windows errored out on this.
# 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('.ri.xman'), 'rb') as fman:
# Concatenate the manifest and the llext
shutil.copyfileobj(fman, fdst)
shutil.copyfileobj(fllext, fdst)

# Create symbolic links for all UUIDs
with open(uuids, 'r') as uuids_f:
for uuid in uuids_f:
linkname = uuid.strip() + '.bin'
symlink_or_copy(sof_lib_dir, llext_file,
sof_lib_dir, linkname)

if os.path.exists(lib_fname):
if lib_name not in lib_uuids.keys():
lib_uuids[lib_name] = []
lib_uuids[lib_name].append(uuid.strip())
else:
linkname = uuid.strip() + '.bin'
symlink_or_copy(sof_lib_dir, llext_file,
sof_lib_dir, linkname)

for key in libs.keys():
lib_path = abs_build_dir / ('lib' + key + '.ri')
sign_cmd = [rimage_cmd, "-o", str(lib_path), "-e",
"-c", str(abs_build_dir / 'misc' / 'generated' / 'rimage_config_full.toml'),
"-k", str(signing_key), "-l", "-r"]
if _ws_args is not None:
sign_cmd.extend(shlex.split(_ws_args))
sign_cmd.extend(libs[key])
execute_command(sign_cmd, cwd=west_top)
dst = abs_build_dir / ('lib' + key + '.bin')
with open(dst, 'wb') as fdst, open(lib_path, 'rb') as fllext, open(
lib_path.with_suffix('.ri.xman'), 'rb') as fman:
# Concatenate the manifest and the llext
shutil.copyfileobj(fman, fdst)
shutil.copyfileobj(fllext, fdst)

def install_platform(platform, sof_output_dir, platf_build_environ, platform_wconfig):

Expand Down
1 change: 1 addition & 0 deletions src/audio/mixin_mixout/llext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ sof_llext_build("mixin_mixout"
../mixin_mixout_hifi3.c
../mixin_mixout_hifi5.c
../mixin_mixout_generic.c
LIB audio
)
18 changes: 13 additions & 5 deletions src/audio/mux/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ static const struct module_interface demux_interface = {
DECLARE_MODULE_ADAPTER(demux_interface, demux_uuid, demux_tr);
SOF_MODULE_INIT(demux, sys_comp_module_demux_interface_init);

#if CONFIG_COMP_VOLUME_MODULE
#if CONFIG_COMP_MUX_MODULE
/* modular: llext dynamic link */

#include <module/module/api_ver.h>
Expand All @@ -486,13 +486,21 @@ SOF_MODULE_INIT(demux, sys_comp_module_demux_interface_init);
0xE2, 0xA2, 0xF4, 0x2E, 0x30, 0x69
SOF_LLEXT_MOD_ENTRY(mux, &mux_interface);

#define UUID_DEMUX 0x68, 0x68, 0xB2, 0xC4, 0x30, 0x14, 0x0E, 0x47, 0x89, 0xA0, \
0x15, 0xD1, 0xC7, 0x7F, 0x85, 0x1A
SOF_LLEXT_MOD_ENTRY(demux, &demux_interface);
/*
* The demux entry is removed because mtl.toml doesn't have an entry
* for it. Once that is fixed, the manifest line below can be
* re-activated:
* #define UUID_DEMUX 0x68, 0x68, 0xB2, 0xC4, 0x30, 0x14, 0x0E, 0x47, 0x89, 0xA0, \
* 0x15, 0xD1, 0xC7, 0x7F, 0x85, 0x1A
* SOF_LLEXT_MOD_ENTRY(demux, &demux_interface);
*/

static const struct sof_man_module_manifest mod_manifest[] __section(".module") __used = {
SOF_LLEXT_MODULE_MANIFEST("MUX", mux_llext_entry, 1, UUID_MUX, 15),
SOF_LLEXT_MODULE_MANIFEST("DEMUX", demux_llext_entry, 1, UUID_DEMUX, 15),
/*
* See comment above for a demux deactivation reason
* SOF_LLEXT_MODULE_MANIFEST("DEMUX", demux_llext_entry, 1, UUID_DEMUX, 15),
*/
};

SOF_LLEXT_BUILDINFO;
Expand Down
2 changes: 2 additions & 0 deletions src/audio/src/llext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sof_llext_build("src"
../src_common.c
../src_ipc4.c
../src_lite.c
LIB audio
)
else()
sof_llext_build("src"
Expand All @@ -21,5 +22,6 @@ sof_llext_build("src"
../src.c
../src_common.c
../src_ipc4.c
LIB audio
)
endif()
1 change: 1 addition & 0 deletions src/audio/volume/llext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ sof_llext_build("volume"
../volume_hifi4_with_peakvol.c
../volume.c
../volume_ipc4.c
LIB misc
)
12 changes: 8 additions & 4 deletions src/include/sof/lib_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,26 @@ enum {
LIB_MANAGER_TEXT,
LIB_MANAGER_DATA,
LIB_MANAGER_RODATA,
LIB_MANAGER_BSS,
LIB_MANAGER_N_SEGMENTS,
};

struct lib_manager_segment_desc {
uintptr_t addr;
size_t size;
size_t file_offset;
};

struct lib_manager_mod_ctx {
void *base_addr;
struct lib_manager_module {
unsigned int start_idx;
const struct sof_man_module_manifest *mod_manifest;
struct lib_manager_segment_desc segment[LIB_MANAGER_N_SEGMENTS];
};

struct lib_manager_mod_ctx {
void *base_addr;
unsigned int n_mod;
struct lib_manager_module *mod;
};

struct ext_library {
struct k_spinlock lock; /* last locking CPU record */
struct lib_manager_mod_ctx *desc[LIB_MANAGER_MAX_LIBS];
Expand Down
Loading
Loading