samples/llext/modules: build hello_world as built-in by default

This commit changes the default value of CONFIG_HELLO_WORLD_MODE to 'y'
so that the hello_world function is compiled as a built-in part of the
Zephyr image by default. This is the simplest possible configuration,
that works for all architectures.

To build hello_world as an llext module, the user must either follow the
commands in the documentation or set CONFIG_HELLO_WORLD_MODE=m in the
project file along with additional architecture-specific settings that
may be required for proper LLEXT support on the target.
Leave a note in the prj.conf and sample.yaml files to remind the user.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This commit is contained in:
Luca Burelli 2024-08-27 18:00:24 +02:00 committed by Anas Nashif
commit 030c1c8308
4 changed files with 31 additions and 10 deletions

View file

@ -7,7 +7,7 @@ source "Kconfig.zephyr"
config HELLO_WORLD_MODE
tristate "Include the hello_world function"
default m
default y
help
This enables building the hello_world function, implemented in
hello_world_ext.c, either as an llext module or as a built-in part of
@ -16,3 +16,7 @@ config HELLO_WORLD_MODE
If you select 'm', the hello_world function will be built as an llext
"module". If you select 'y', the hello_world function will be directly
linked in the Zephyr image.
Note that additional architecture-specific configuration may be
required if you select 'm'. Please review this sample's documentation
and sample.yaml for more information.

View file

@ -36,14 +36,13 @@ executed in QEMU emulation on the :ref:`qemu_xtensa <qemu_xtensa>` or
Building and running
********************
- The following commands build and run the sample so that the files are linked
together in the same binary:
- By default, the sample will compile the function along with the rest of
Zephyr in the same binary. This can be verified via the following commands:
.. zephyr-app-commands::
:zephyr-app: samples/subsys/llext/modules
:board: qemu_xtensa
:goals: build run
:west-args: -T sample.llext.modules.builtin_build
:compact:
- The following commands build and run the sample so that the extension code is
@ -56,8 +55,9 @@ Building and running
:west-args: -T sample.llext.modules.module_build
:compact:
Take a look at :zephyr_file:`samples/subsys/llext/modules/sample.yaml` for the
additional architecture-specific configurations required in this case.
.. important::
Take a look at :zephyr_file:`samples/subsys/llext/modules/sample.yaml` for
the additional architecture-specific configurations required in this case.
To build for a different board, replace ``qemu_xtensa`` in the commands above
with the desired board name.

View file

@ -1,6 +1,10 @@
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
# CONFIG_MODULES must be enabled to allow setting any options to "m" in the
# Kconfig files. For compatibility with Kconfiglib, the name must be kept
# as-is even if Zephyr has a completely different concept for "modules".
CONFIG_MODULES=y
# LLEXT is only required when loading the extension at runtime. Since in this
@ -11,9 +15,21 @@ CONFIG_MODULES=y
CONFIG_LLEXT=y
CONFIG_LLEXT_LOG_LEVEL_DBG=y
CONFIG_LLEXT_HEAP_SIZE=64
CONFIG_LLEXT_TYPE_ELF_RELOCATABLE=y
CONFIG_LLEXT_TYPE_ELF_RELOCATABLE=y # supported by all targets
# This test consumes large amounts of stack when loading the LLEXT.
# Increase the available size to avoid overflowing (see issue #74536).
CONFIG_MAIN_STACK_SIZE=2048
# NOTE
#
# This project file explicitly does NOT include the configuration for
# CONFIG_HELLO_WORLD_MODE, so a clean compile will include the function as
# built-in by default.
#
# To build it as an llext, please follow the instructions in the documentation
# of this sample; there are architecture-specific settings that must be set in
# addition to CONFIG_HELLO_WORLD_MODE=m. For example, most ARM targets need to
# either enable CONFIG_USERSPACE (if they support it) or disable MPU/MMU
# features for LLEXT to work correctly.

View file

@ -33,16 +33,17 @@ tests:
sample.llext.modules.module_build:
filter: not CONFIG_MPU and not CONFIG_MMU and not CONFIG_SOC_SERIES_S32ZE
extra_configs:
- CONFIG_HELLO_WORLD_MODE=m
# Disabling MPU is the most compatible option. If the target supports
# CONFIG_USERSPACE, that should be preferred as it has many additional
# security benefits.
- arch:arm:CONFIG_ARM_MPU=n
- arch:arm:CONFIG_ARM_AARCH32_MMU=n
- CONFIG_HELLO_WORLD_MODE=m
harness_config:
type: one_line
regex:
- "Hello, world, from an llext!"
sample.llext.modules.builtin_build:
extra_configs:
- CONFIG_HELLO_WORLD_MODE=y
harness_config:
type: one_line
regex: