From 64e7d85ef670a4731ee086f864c3d7668c7ea853 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Tue, 9 Apr 2024 09:53:58 +0200 Subject: [PATCH] llext: define target binary type Add a new Kconfig option to select the binary object type for the llext subsystem. This will allow to fully decouple the architecture type from the kind of binary object that is expected by the loader. The defaults have been chosen to match the current behavior of the ARM and Xtensa architectures, but developers can now more easily experiment with other object types. Signed-off-by: Luca Burelli --- cmake/modules/extensions.cmake | 16 ++++++---------- subsys/llext/Kconfig | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index 4c989e808ae..c0eeb18acbf 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -5309,17 +5309,15 @@ function(add_llext_target target_name) ) # Compile the source file using current Zephyr settings but a different - # set of flags. - # This is currently arch-specific since the ARM loader for .llext files - # expects object file format, while the Xtensa one uses shared libraries. + # set of flags to obtain the desired llext object type. set(llext_lib_target ${target_name}_llext_lib) - if(CONFIG_ARM) + if(CONFIG_LLEXT_TYPE_ELF_OBJECT) # Create an object library to compile the source file add_library(${llext_lib_target} OBJECT ${source_file}) set(llext_lib_output $) - elseif(CONFIG_XTENSA) + elseif(CONFIG_LLEXT_TYPE_ELF_SHAREDLIB) # Create a shared library add_library(${llext_lib_target} SHARED ${source_file}) @@ -5371,8 +5369,8 @@ function(add_llext_target target_name) COMMAND_EXPAND_LISTS ) - # Arch-specific packaging of the built binary file into an .llext file - if(CONFIG_ARM) + # Type-specific packaging of the built binary file into an .llext file + if(CONFIG_LLEXT_TYPE_ELF_OBJECT) # No packaging required, simply copy the object file add_custom_command( @@ -5381,7 +5379,7 @@ function(add_llext_target target_name) DEPENDS ${llext_proc_target} ${llext_pkg_input} ) - elseif(CONFIG_XTENSA) + elseif(CONFIG_LLEXT_TYPE_ELF_SHAREDLIB) # Need to strip the shared library of some sections add_custom_command( @@ -5395,8 +5393,6 @@ function(add_llext_target target_name) DEPENDS ${llext_proc_target} ${llext_pkg_input} ) - else() - message(FATAL_ERROR "add_llext_target: unsupported architecture") endif() # Add user-visible target and dependency, and fill in properties diff --git a/subsys/llext/Kconfig b/subsys/llext/Kconfig index 59a4129a1ad..4bc5e5b6136 100644 --- a/subsys/llext/Kconfig +++ b/subsys/llext/Kconfig @@ -9,6 +9,29 @@ menuconfig LLEXT if LLEXT +choice LLEXT_BINARY_TYPE + prompt "Binary object type for llext" + default LLEXT_TYPE_ELF_OBJECT if ARM + default LLEXT_TYPE_ELF_SHAREDLIB if XTENSA + help + Object type for llext + +config LLEXT_TYPE_ELF_OBJECT + bool "Single object ELF file" + help + Build and expect object files as binary object type for the + llext subsystem. A single compiler invocation is used to + generate the object file. + +config LLEXT_TYPE_ELF_SHAREDLIB + bool "Shared library ELF file" + help + Build and expect shared libraries as binary object type for + the llext subsystem. The usual linking process is used to + generate the shared library from multiple object files. + +endchoice + config LLEXT_HEAP_SIZE int "llext heap memory size in kilobytes" default 8