Skip to content
Merged
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
23 changes: 23 additions & 0 deletions scripts/llext_link_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def parse_args():
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("-c", "--copy", required=True, type=str,
help='Objcopy command')
parser.add_argument("-o", "--output", required=True, type=str,
help='Output file name')
parser.add_argument("-t", "--text-addr", required=True, type=str,
help='.text section address')
parser.add_argument("-s", "--size-file", required=True, type=str,
Expand Down Expand Up @@ -148,11 +152,16 @@ def main():
# we accept only the .coldrodata name for now.

dram_addr = 0
first_dram_text = None
first_dram_rodata = None

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

if not first_dram_text:
first_dram_text = s_name

dram_addr = align_up(dram_addr, s_alignment)

command.append(f'-Wl,--section-start={s_name}=0x{dram_addr:x}')
Expand All @@ -163,6 +172,9 @@ def main():
s_alignment = section.header['sh_addralign']
s_name = section.name

if not first_dram_rodata:
first_dram_rodata = s_name

dram_addr = align_up(dram_addr, s_alignment)

command.append(f'-Wl,--section-start={s_name}=0x{dram_addr:x}')
Expand Down Expand Up @@ -196,9 +208,20 @@ def main():

start_addr += section.header['sh_size']

command.extend(['-o', f'{args.file}.tmp'])
command.extend(args.params)

subprocess.run(command)

copy_command = [args.copy]

if first_dram_text:
copy_command.extend(['--set-section-alignment', f'{first_dram_text}=4096'])
if first_dram_rodata:
copy_command.extend(['--set-section-alignment', f'{first_dram_rodata}=4096'])

copy_command.extend([f'{args.file}.tmp', f'{args.output}'])
subprocess.run(copy_command)

if __name__ == "__main__":
main()
6 changes: 3 additions & 3 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ function(sof_llext_build module)
POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${SOF_BASE}scripts/llext_link_helper.py -s ${size_file}
--text-addr=${CONFIG_LIBRARY_BASE_ADDRESS}
-f ${proc_in_file} ${CMAKE_C_COMPILER} --
-o ${proc_out_file} ${EXTRA_LINKER_PARAMS}
$<TARGET_OBJECTS:${module}_llext_lib>
-c $<TARGET_PROPERTY:bintools,elfconvert_command>
-f ${proc_in_file} -o ${proc_out_file} ${CMAKE_C_COMPILER} --
${EXTRA_LINKER_PARAMS} $<TARGET_OBJECTS:${module}_llext_lib>
)

add_llext_command(TARGET ${module}
Expand Down
Loading