1# Copyright (c) 2023 Intel Corporation
2# SPDX-License-Identifier: Apache-2.0
3
4menuconfig LLEXT
5	bool "Linkable loadable extensions"
6	select CACHE_MANAGEMENT if DCACHE
7	select KERNEL_WHOLE_ARCHIVE
8	help
9	  Enable the linkable loadable extension subsystem
10
11if LLEXT
12
13choice LLEXT_BINARY_TYPE
14	prompt "Binary object type for llext"
15	default LLEXT_TYPE_ELF_OBJECT if ARM || ARM64
16	default LLEXT_TYPE_ELF_SHAREDLIB if XTENSA
17	default LLEXT_TYPE_ELF_RELOCATABLE if RISCV
18	help
19	  Object type for llext
20
21config LLEXT_TYPE_ELF_OBJECT
22	bool "Single object ELF file"
23	depends on !RISCV
24	help
25	  Build and expect object files as binary object type for the
26	  llext subsystem. A single compiler invocation is used to
27	  generate the object file. Currently not supported on RISC-V.
28
29config LLEXT_TYPE_ELF_RELOCATABLE
30	bool "Relocatable ELF file"
31	help
32	  Build and expect relocatable (partially linked) files as the
33	  binary object type for the llext subsystem. These object files
34	  are generated by the linker by combining multiple object files
35	  into a single one.
36
37config LLEXT_TYPE_ELF_SHAREDLIB
38	bool "Shared library ELF file"
39	help
40	  Build and expect shared libraries as binary object type for
41	  the llext subsystem. The usual linking process is used to
42	  generate the shared library from multiple object files.
43
44endchoice
45
46config LLEXT_HEAP_DYNAMIC
47	bool "Do not allocate static LLEXT heap"
48	help
49	  Some applications require loading extensions into the memory which does not
50	  exist during the boot time and cannot be allocated statically. Make the application
51	  responsible for LLEXT heap allocation. Do not allocate LLEXT heap statically.
52
53	  Application must call llext_heap_init() in order to assign a buffer to be used
54	  as the LLEXT heap, otherwise LLEXT modules will not load. When the application
55	  does not need LLEXT functionality any more, it should call llext_heap_uninit(),
56	  which releases control of the buffer back to the application.
57
58config LLEXT_HEAP_SIZE
59	int "llext heap memory size in kilobytes"
60	depends on !LLEXT_HEAP_DYNAMIC && !HARVARD
61	default 8
62	help
63	  Heap size in kilobytes available to llext for dynamic allocation
64
65config LLEXT_INSTR_HEAP_SIZE
66	int "llext ICCM heap memory size in kilobytes"
67	depends on !LLEXT_HEAP_DYNAMIC && HARVARD
68	default 4
69	help
70	  ICCM heap size in kilobytes available to llext for dynamic allocation.
71	  Only executable sections will be placed in this heap.
72
73config LLEXT_DATA_HEAP_SIZE
74	int "llext DCCM heap memory size in kilobytes"
75	depends on !LLEXT_HEAP_DYNAMIC && HARVARD
76	default 8
77	help
78	  DCCM heap size in kilobytes available to llext for dynamic allocation.
79	  Extension data and metadata will be placed in this heap.
80
81config LLEXT_BUILD_PIC
82	bool "Use -fPIC when building LLEXT"
83	depends on XTENSA
84	default y if LLEXT_TYPE_ELF_SHAREDLIB
85	help
86	  By default LLEXT compilation is performed with -fno-pic -fno-pie compiler
87	  flags. Some platforms can benefit from using -fPIC instead, in which case
88	  most internal linking is performed by the linker at build time. Select "y"
89	  to make use of that advantage.
90
91config LLEXT_SHELL
92	bool "llext shell commands"
93	depends on SHELL
94	help
95	  Manage llext with shell commands for loading, unloading, and introspection
96
97config LLEXT_SHELL_MAX_SIZE
98	int "Maximum size of llext in bytes"
99	depends on LLEXT_SHELL
100	default 8192
101	help
102	  When loading llext with shell it is stored in a temporary buffer of this size
103
104config LLEXT_STORAGE_WRITABLE
105	bool "llext storage is writable"
106	default y if XTENSA
107	help
108	  Select if LLEXT storage is writable, i.e. if extensions are stored in
109	  RAM and can be modified in place
110
111config LLEXT_EXPORT_DEVICES
112	bool "Export all DT devices to llexts"
113	help
114	  When enabled, all Zephyr devices defined in the device tree are
115	  made available to llexts via the standard DT_ / DEVICE_* macros.
116
117config LLEXT_EXPORT_DEV_IDS_BY_HASH
118	bool "Use hash of device path in device name"
119	depends on LLEXT_EXPORT_DEVICES
120	help
121	  When enabled, exported device names are generated from a hash of the
122	  node path instead of an ordinal number. Identifiers generated this
123	  way are stable across rebuilds.
124
125config LLEXT_EXPORT_BUILTINS_BY_SLID
126	bool "Export built-in symbols to llexts via SLIDs"
127	help
128	  When enabled, symbols exported from the Zephyr kernel
129	  or application (via EXPORT_SYMBOL) are linked to LLEXTs
130	  via Symbol Link Identifiers (SLIDs) instead of name.
131
132	  Enabling this option provides a huge size reduction,
133	  makes the linking process faster and provides more
134	  confidentiality, as exported symbol names are dropped
135	  from the binary. However, it can make LLEXT debugging
136	  harder and prevents usage of 'llext_find_sym' to look
137	  up symbols from the built-in table by name. It also
138	  requires the LLEXTs to be post-processed after build.
139
140config LLEXT_IMPORT_ALL_GLOBALS
141	bool "Import all global symbols from extensions"
142	help
143	  When loading an extension, by default only symbols that are mentioned
144	  in the '.exported_sym' section (possibly via EXPORT_SYMBOL) are made
145	  available to the Zephyr core.
146
147	  This option instead allows all global symbols from extensions to be
148	  used by the main application. This is useful to load basic extensions
149	  that have been compiled without the full Zephyr EDK.
150
151config LLEXT_EXPERIMENTAL
152	bool "LLEXT experimental functionality"
153	help
154	  Include support for LLEXT experimental and unstable functionality that
155	  has a very high likelihood to change in the future.
156
157module = LLEXT
158module-str = llext
159source "subsys/logging/Kconfig.template.log_config"
160
161endif
162
163menuconfig LLEXT_EDK
164	bool "Linkable loadable Extension Development Kit (EDK)"
165	default y if LLEXT
166	help
167	  Enable the generation of an Extension Development Kit (EDK) for the
168	  Linkable Loadable Extension subsystem. The EDK is an archive that
169	  contains the necessary files and build settings to build extensions
170	  for Zephyr without the need to have the full Zephyr source tree.
171
172if LLEXT_EDK
173
174config LLEXT_EDK_NAME
175	string "Name for llext EDK (Extension Development Kit)"
176	default "llext-edk"
177	help
178	  <name> will be used when generating the EDK file; the appropriate
179	  extension will be appended depending on the chosen output format.
180	  It will also be used, normalized, as the prefix for the variable
181	  stating EDK location, used on generated Makefile.cflags. For
182	  instance, the default name, "llext-edk", becomes LLEXT_EDK_INSTALL_DIR.
183
184choice LLEXT_EDK_FORMAT
185prompt "EDK compression and output format"
186default LLEXT_EDK_FORMAT_TAR_XZ
187
188config LLEXT_EDK_FORMAT_TAR_XZ
189	bool ".tar.xz"
190	help
191	  Use GNU tar with XZ compression for the EDK file. Highest compression
192	  ratio, slower choice.
193
194config LLEXT_EDK_FORMAT_TAR_ZSTD
195	bool ".tar.Z"
196	help
197	  Use GNU tar with Zstd compression for the EDK file. Way faster than
198	  XZ, but still with a high compression ratio.
199
200config LLEXT_EDK_FORMAT_ZIP
201	bool ".zip"
202	help
203	  Use Zip format and compression for the EDK file. This is the most
204	  portable option, but it may not compress as well as XZ or Zstd.
205
206endchoice
207
208config LLEXT_EDK_USERSPACE_ONLY
209	bool "Only generate the Userspace codepath on syscall stubs for the EDK"
210	help
211	  Syscall stubs can contain code that verifies if running code is at user
212	  or kernel space and route the call accordingly. If the EDK is expected
213	  to be used by userspace only extensions, this option will make EDK stubs
214	  not contain the routing code, and only generate the userspace one.
215
216endif
217