2019-04-06 15:08:09 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# kernel is a normal CMake library and not a zephyr_library because it
|
linker: Include libkernel.a in the whole-archive when llext is enabled
Differently from other libraries, which are included whole in the final
Zephyr ELF, libkernel.a itself isn't. Assuming this is intended to
enable optimisations (if it isn't, this patch will break things) - linker
can remove parts of the kernel that are not used by the application.
However, when considering Linkable Loadable Extensions (llext), this
optimisations can be counterproductive: for instance, syscalls that are
not used by the application won't be available for extensions. It won't
matter if someone "EXPORT_SYMBOL" for them, or even try to keep them
using LINKER_KEEP, they'll be gone.
To avoid that, this patches includes, when CONFIG_LLEXT=y, libkernel.a
inside the linker "whole-archive" block. This ends up making it consider
libkernel.a as a library whose all symbols should be kept. Note this
doesn't mean that all symbols will be there - things compiled out via
Kconfig will naturally still be out.
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2024-03-21 23:50:13 +01:00
|
|
|
# should usually not be --whole-archive'd
|
2020-08-27 14:37:10 +02:00
|
|
|
|
2023-03-11 00:06:16 +01:00
|
|
|
zephyr_syscall_header(
|
|
|
|
${ZEPHYR_BASE}/include/zephyr/device.h
|
|
|
|
${ZEPHYR_BASE}/include/zephyr/kernel.h
|
|
|
|
${ZEPHYR_BASE}/include/zephyr/sys/kobject.h
|
|
|
|
${ZEPHYR_BASE}/include/zephyr/sys/time_units.h
|
|
|
|
)
|
|
|
|
|
|
|
|
if(NOT CONFIG_ERRNO_IN_TLS AND NOT CONFIG_LIBC_ERRNO)
|
|
|
|
zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/sys/errno_private.h)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
zephyr_syscall_header_ifdef(
|
|
|
|
CONFIG_ATOMIC_OPERATIONS_C
|
|
|
|
${ZEPHYR_BASE}/include/zephyr/sys/atomic_c.h
|
|
|
|
)
|
|
|
|
|
|
|
|
zephyr_syscall_header_ifdef(
|
|
|
|
CONFIG_MMU
|
2023-11-14 00:12:45 +01:00
|
|
|
${ZEPHYR_BASE}/include/zephyr/kernel/mm.h
|
2023-03-11 00:06:16 +01:00
|
|
|
${ZEPHYR_BASE}/include/zephyr/sys/mem_manage.h
|
|
|
|
)
|
|
|
|
|
2023-11-14 02:59:14 +01:00
|
|
|
zephyr_syscall_header_ifdef(
|
|
|
|
CONFIG_DEMAND_PAGING
|
|
|
|
${ZEPHYR_BASE}/include/zephyr/kernel/mm/demand_paging.h
|
|
|
|
)
|
|
|
|
|
2021-08-05 20:11:23 +02:00
|
|
|
# If a pre-built static library containing kernel code exists in
|
|
|
|
# this directory, libkernel.a, link it with the application code
|
|
|
|
# instead of building from source.
|
|
|
|
zephyr_library_get_current_dir_lib_name(${ZEPHYR_BASE} libkernel_stem)
|
|
|
|
set(libkernel ${CMAKE_CURRENT_SOURCE_DIR}/lib${libkernel_stem}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
|
|
|
unset(libkernel_stem)
|
|
|
|
|
|
|
|
if(EXISTS ${libkernel})
|
|
|
|
|
|
|
|
add_library(kernel INTERFACE)
|
|
|
|
target_link_libraries(kernel INTERFACE ${libkernel})
|
|
|
|
|
|
|
|
else()
|
|
|
|
|
2023-08-11 22:40:05 +02:00
|
|
|
# FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally.
|
|
|
|
add_compile_options($<TARGET_PROPERTY:compiler,warning_shadow_variables>)
|
|
|
|
|
2020-08-27 14:37:10 +02:00
|
|
|
list(APPEND kernel_files
|
2021-05-31 14:59:23 +02:00
|
|
|
main_weak.c
|
2021-04-14 13:40:25 +02:00
|
|
|
banner.c
|
2023-07-01 04:22:35 +02:00
|
|
|
busy_wait.c
|
2017-10-27 15:43:34 +02:00
|
|
|
device.c
|
|
|
|
errno.c
|
2019-07-11 23:18:28 +02:00
|
|
|
fatal.c
|
2017-10-27 15:43:34 +02:00
|
|
|
init.c
|
2020-04-03 19:01:03 +02:00
|
|
|
kheap.c
|
2017-10-27 15:43:34 +02:00
|
|
|
mem_slab.c
|
2024-02-27 14:48:37 +01:00
|
|
|
float.c
|
2021-04-14 13:40:25 +02:00
|
|
|
version.c
|
|
|
|
)
|
|
|
|
|
2024-02-22 19:51:15 +01:00
|
|
|
if(CONFIG_SCHED_CPU_MASK)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
cpu_mask.c
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2021-04-14 13:40:25 +02:00
|
|
|
if(CONFIG_MULTITHREADING)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
idle.c
|
|
|
|
mailbox.c
|
2017-10-27 15:43:34 +02:00
|
|
|
msg_q.c
|
|
|
|
mutex.c
|
|
|
|
queue.c
|
|
|
|
sem.c
|
|
|
|
stack.c
|
|
|
|
system_work_q.c
|
2020-11-24 23:47:47 +01:00
|
|
|
work.c
|
2021-04-14 13:40:25 +02:00
|
|
|
condvar.c
|
2024-03-28 15:09:26 +01:00
|
|
|
priority_queues.c
|
|
|
|
thread.c
|
|
|
|
sched.c
|
2018-03-28 11:46:48 +02:00
|
|
|
)
|
2021-04-06 12:32:55 +02:00
|
|
|
if(CONFIG_SMP)
|
|
|
|
list(APPEND kernel_files
|
2024-03-08 13:51:01 +01:00
|
|
|
smp.c
|
|
|
|
ipi.c)
|
2021-04-06 12:32:55 +02:00
|
|
|
endif()
|
2024-03-28 15:09:26 +01:00
|
|
|
else() # CONFIG_MULTITHREADING
|
|
|
|
list(APPEND kernel_files
|
|
|
|
nothread.c
|
|
|
|
)
|
|
|
|
endif() # CONFIG_MULTITHREADING
|
2024-03-08 13:51:01 +01:00
|
|
|
|
|
|
|
if(CONFIG_TIMESLICING)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
timeslicing.c)
|
|
|
|
endif()
|
|
|
|
|
2024-02-23 03:56:37 +01:00
|
|
|
if(CONFIG_SPIN_VALIDATE)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
spinlock_validate.c)
|
|
|
|
endif()
|
|
|
|
|
2024-02-23 04:19:05 +01:00
|
|
|
if(CONFIG_IRQ_OFFLOAD)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
irq_offload.c
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2024-02-26 23:03:35 +01:00
|
|
|
|
|
|
|
if(CONFIG_THREAD_MONITOR)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
thread_monitor.c)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2020-08-27 14:37:10 +02:00
|
|
|
if(CONFIG_XIP)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
xip.c)
|
|
|
|
endif()
|
|
|
|
|
2021-03-26 20:03:42 +01:00
|
|
|
if(CONFIG_DEMAND_PAGING_STATS)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
paging/statistics.c)
|
|
|
|
endif()
|
|
|
|
|
2020-08-27 14:37:10 +02:00
|
|
|
add_library(kernel ${kernel_files})
|
|
|
|
|
2018-03-28 11:46:48 +02:00
|
|
|
# Kernel files has the macro __ZEPHYR_SUPERVISOR__ set so that it
|
|
|
|
# optimizes the code when userspace is enabled.
|
2020-11-21 13:58:58 +01:00
|
|
|
|
2018-03-28 11:46:48 +02:00
|
|
|
set_target_properties(
|
|
|
|
kernel
|
|
|
|
PROPERTIES
|
|
|
|
COMPILE_DEFINITIONS
|
|
|
|
__ZEPHYR_SUPERVISOR__
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
target_sources_ifdef(CONFIG_STACK_CANARIES kernel PRIVATE compiler_stack_protect.c)
|
2018-09-28 01:50:00 +02:00
|
|
|
target_sources_ifdef(CONFIG_SYS_CLOCK_EXISTS kernel PRIVATE timeout.c timer.c)
|
2017-10-27 15:43:34 +02:00
|
|
|
target_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_C kernel PRIVATE atomic_c.c)
|
2020-07-31 13:52:40 +02:00
|
|
|
target_sources_ifdef(CONFIG_MMU kernel PRIVATE mmu.c)
|
|
|
|
target_sources_ifdef(CONFIG_POLL kernel PRIVATE poll.c)
|
2021-09-20 20:14:32 +02:00
|
|
|
target_sources_ifdef(CONFIG_EVENTS kernel PRIVATE events.c)
|
2022-07-08 17:27:09 +02:00
|
|
|
target_sources_ifdef(CONFIG_PIPES kernel PRIVATE pipes.c)
|
|
|
|
target_sources_ifdef(CONFIG_SCHED_THREAD_USAGE kernel PRIVATE usage.c)
|
2023-05-09 17:01:33 +02:00
|
|
|
target_sources_ifdef(CONFIG_OBJ_CORE kernel PRIVATE obj_core.c)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2020-09-18 23:12:51 +02:00
|
|
|
if(${CONFIG_KERNEL_MEM_POOL})
|
|
|
|
target_sources(kernel PRIVATE mempool.c)
|
2020-04-04 00:39:25 +02:00
|
|
|
|
kernel: Introduce a way to specify minimum system heap size
There are several subsystems and boards which require a relatively large
system heap (used by k_malloc()) to function properly. This became even
more notable with the recent introduction of the ACPICA library, which
causes ACPI-using boards to require a system heap of up to several
megabytes in size.
Until now, subsystems and boards have tried to solve this by having
Kconfig overlays which modify the default value of HEAP_MEM_POOL_SIZE.
This works ok, except when applications start explicitly setting values
in their prj.conf files:
$ git grep CONFIG_HEAP_MEM_POOL_SIZE= tests samples|wc -l
157
The vast majority of values set by current sample or test applications
is much too small for subsystems like ACPI, which results in the
application not being able to run on such boards.
To solve this situation, we introduce support for subsystems to specify
their own custom system heap size requirement. Subsystems do
this by defining Kconfig options with the prefix HEAP_MEM_POOL_ADD_SIZE_.
The final value of the system heap is the sum of the custom
minimum requirements, or the value existing HEAP_MEM_POOL_SIZE option,
whichever is greater.
We also introduce a new HEAP_MEM_POOL_IGNORE_MIN Kconfig option which
applications can use to force a lower value than what subsystems have
specficied, however this behavior is disabled by default.
Whenever the minimum is greater than the requested value a CMake warning
will be issued in the build output.
This patch ends up modifying several places outside of kernel code,
since the presence of the system heap is no longer detected using a
non-zero CONFIG_HEAP_MEM_POOL_SIZE value, rather it's now detected using
a new K_HEAP_MEM_POOL_SIZE value that's evaluated at build.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2023-11-29 10:22:39 +01:00
|
|
|
if(CONFIG_HEAP_MEM_POOL_IGNORE_MIN)
|
|
|
|
set(final_heap_size ${CONFIG_HEAP_MEM_POOL_SIZE})
|
|
|
|
else()
|
|
|
|
# Import all custom HEAP_MEM_POOL size requirements
|
|
|
|
import_kconfig(CONFIG_HEAP_MEM_POOL_ADD_SIZE_ ${DOTCONFIG} add_size_keys)
|
|
|
|
|
|
|
|
# Calculate the sum of all "ADD_SIZE" requirements
|
|
|
|
set(add_size_sum 0)
|
|
|
|
foreach(add_size ${add_size_keys})
|
|
|
|
math(EXPR add_size_sum "${add_size_sum} + ${${add_size}}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(CONFIG_HEAP_MEM_POOL_SIZE LESS "${add_size_sum}")
|
|
|
|
# Only warn if default value 0 has been modified
|
|
|
|
if(NOT CONFIG_HEAP_MEM_POOL_SIZE EQUAL 0)
|
|
|
|
message(WARNING "
|
|
|
|
CONFIG_HEAP_MEM_POOL_SIZE is less than requested minimum:
|
|
|
|
${CONFIG_HEAP_MEM_POOL_SIZE} < ${add_size_sum}
|
|
|
|
Setting the system heap size to ${add_size_sum}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(final_heap_size ${add_size_sum})
|
|
|
|
else()
|
|
|
|
# CONFIG_HEAP_MEM_POOL_SIZE was greater than the sum of the requirements
|
|
|
|
set(final_heap_size ${CONFIG_HEAP_MEM_POOL_SIZE})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
zephyr_compile_definitions(K_HEAP_MEM_POOL_SIZE=${final_heap_size})
|
|
|
|
endif()
|
2021-09-20 20:14:32 +02:00
|
|
|
|
2017-12-14 10:07:00 +01:00
|
|
|
# The last 2 files inside the target_sources_ifdef should be
|
|
|
|
# userspace_handler.c and userspace.c. If not the linker would complain.
|
|
|
|
# This order has to be maintained. Any new file should be placed
|
|
|
|
# above these 2 files.
|
2017-10-27 15:43:34 +02:00
|
|
|
target_sources_ifdef(
|
|
|
|
CONFIG_USERSPACE
|
|
|
|
kernel PRIVATE
|
2019-06-20 17:51:27 +02:00
|
|
|
futex.c
|
2017-10-27 15:43:34 +02:00
|
|
|
mem_domain.c
|
2017-12-14 10:07:00 +01:00
|
|
|
userspace_handler.c
|
|
|
|
userspace.c
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
|
|
|
|
2023-07-18 14:33:41 +02:00
|
|
|
if(${CONFIG_DYNAMIC_THREAD})
|
|
|
|
target_sources(kernel PRIVATE dynamic.c)
|
|
|
|
else()
|
|
|
|
target_sources(kernel PRIVATE dynamic_disabled.c)
|
|
|
|
endif()
|
2022-06-28 05:43:32 +02:00
|
|
|
|
2019-10-24 17:08:21 +02:00
|
|
|
target_include_directories(kernel PRIVATE
|
|
|
|
${ZEPHYR_BASE}/kernel/include
|
2020-07-07 08:06:27 +02:00
|
|
|
${ARCH_DIR}/${ARCH}/include
|
2019-10-24 17:08:21 +02:00
|
|
|
)
|
2018-03-28 11:46:48 +02:00
|
|
|
|
2021-08-05 20:11:23 +02:00
|
|
|
target_link_libraries(kernel zephyr_interface)
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
2020-01-23 15:39:17 +01:00
|
|
|
add_dependencies(kernel zephyr_generated_headers)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2021-08-05 20:11:23 +02:00
|
|
|
unset(libkernel)
|