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

[SKIP SOF_TEST][WiP][DNM] IMR: illustrate running in IMR #9522

Draft
wants to merge 3 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
36 changes: 29 additions & 7 deletions scripts/llext_link_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ def main():

command = [args.command]

executable = []
writable = []
readonly = []

text_found = False

elf = ELFFile(open(args.file, 'rb'))

# Create an object file with sections grouped by their properties,
Expand All @@ -102,13 +105,14 @@ def main():
# In general additional executable sections are possible, e.g.
# .init. In the future support for arbitrary such sections can be
# added, similar to writable and read-only data below.
if s_name != '.text':
print(f"Warning! Non-standard executable section {s_name}")

text_addr = max_alignment(text_addr, 0x1000, s_alignment)
text_size = s_size

command.append(f'-Wl,-Ttext=0x{text_addr:x}')
if s_name == '.text':
text_found = True
text_addr = max_alignment(text_addr, 0x1000, s_alignment)
text_size = s_size
command.append(f'-Wl,-Ttext=0x{text_addr:x}')
else:
# Any additional executable sections are intended for IMR
executable.append(section)

continue

Expand All @@ -122,6 +126,24 @@ def main():
# .rodata or other read-only sections
readonly.append(section)

if not text_found:
raise RuntimeError('No .text section found in the object file')

# IMR sections don't need to be linked with SRAM addresses
imr_addr = 0

for section in executable:
s_alignment = section.header['sh_addralign']
s_name = section.name

imr_addr = align_up(imr_addr, s_alignment)

command.append(f'-Wl,--section-start={s_name}=0x{imr_addr:x}')

imr_addr += section.header['sh_size']

# So far there doesn't seem to be any reason to align additional
# executable sections after .text
start_addr = align_up(text_addr + text_size, 0x1000)

for section in readonly:
Expand Down
31 changes: 30 additions & 1 deletion src/audio/drc/drc.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,27 @@ static void drc_params(struct processing_module *mod)
}
#endif /* CONFIG_IPC_MAJOR_4 */

void *my_addr(void);

void *drc_who_called(void)
{
return my_addr();
//return __builtin_return_address(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of interest, why wont the builtin work ? Its not relying on linker script to set address is it ?

}
void sof_addr_assign(const void *src, const void **tgt);

__attribute__((section(".text.imr")))
int drc_test_imr(struct processing_module *mod, void **addr, void **addr2)
{
void *(*fn)(void) = my_addr;

*addr = drc_who_called();
*addr2 = fn();
comp_info(mod->dev, "%p", *addr);

return mod->period_bytes;
}

static int drc_prepare(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
Expand All @@ -322,7 +343,15 @@ static int drc_prepare(struct processing_module *mod,
int rate;
int ret;

comp_info(dev, "drc_prepare()");
const int (*fptr)(struct processing_module *mod, void **addr, void **addr2);
const void *pfptr;
void *addr = drc_test_imr, *addr2 = NULL;

sof_addr_assign(drc_test_imr, &pfptr);
fptr = pfptr;
comp_info(dev, "IMR test %p %p", (void *)addr, (void *)fptr);
ret = fptr(mod, &addr, &addr2);
comp_info(dev, "IMR test %p: %d, %p %p", fptr, ret, addr, addr2);

#if CONFIG_IPC_MAJOR_4
drc_params(mod);
Expand Down
26 changes: 26 additions & 0 deletions src/library_manager/llext_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <rtos/sof.h>
#include <rtos/spinlock.h>
#include <rtos/symbol.h>
#include <sof/lib/cpu-clk-manager.h>
#include <sof/lib_manager.h>
#include <sof/llext_manager.h>
Expand Down Expand Up @@ -219,6 +220,13 @@ static int llext_manager_unload_module(uint32_t module_id, const struct sof_man_
return err;
}

#define LLEXT_SECTION_MIN_ADDR 0x10000

static bool llext_manager_section_detached(const elf_shdr_t *shdr)
{
return shdr->sh_addr < LLEXT_SECTION_MIN_ADDR;
}

static int llext_manager_link(struct sof_man_fw_desc *desc, struct sof_man_module *mod,
uint32_t module_id, struct module_data *md, const void **buildinfo,
const struct sof_man_module_manifest **mod_manifest)
Expand All @@ -232,6 +240,7 @@ static int llext_manager_link(struct sof_man_fw_desc *desc, struct sof_man_modul
struct llext_load_param ldr_parm = {
.relocate_local = !ctx->segment[LIB_MANAGER_TEXT].size,
.pre_located = true,
.section_detached = llext_manager_section_detached,
};
int ret = llext_load(&ebl.loader, mod->name, &md->llext, &ldr_parm);

Expand Down Expand Up @@ -373,3 +382,20 @@ bool comp_is_llext(struct comp_dev *comp)

return mod && module_is_llext(mod);
}

void *my_addr(void)
{
uintptr_t reta;

__asm__ __volatile__("mov %0, a0" : "=r"(reta));
tr_info(&lib_manager_tr, "caller %#lx", reta);

return __builtin_return_address(0);
}
EXPORT_SYMBOL(my_addr);

void sof_addr_assign(const void *src, const void **tgt)
{
*tgt = src;
}
EXPORT_SYMBOL(sof_addr_assign);
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ manifest:

- name: zephyr
repo-path: zephyr
revision: 99e6280d7e22552de9a94992b626acdcbde00fee
revision: pull/79012/head
remote: zephyrproject

# Import some projects listed in zephyr/west.yml@revision
Expand Down
Loading