From d2c101d466f5260e68054e6fd37c16fd19291833 Mon Sep 17 00:00:00 2001 From: Alexander Razinkov Date: Fri, 27 Oct 2023 18:33:15 +0300 Subject: [PATCH] kernel: init: conditional .bss section zeroing Some platforms already have .bss section zeroed-out externally before the Zephyr initialization and there is no sence to zero it out the second time from the SW. Such boot-time optimization could be critical e.g. for RTL Simulation. Signed-off-by: Alexander Razinkov --- arch/Kconfig | 2 ++ kernel/Kconfig | 10 ++++++++++ kernel/init.c | 7 +------ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 65b73557f7b..0a108702ad9 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -139,6 +139,8 @@ config ARCH_POSIX select NATIVE_BUILD select HAS_COVERAGE_SUPPORT select BARRIER_OPERATIONS_BUILTIN + # native_posix gets its memory cleared on entry by the host OS + select SKIP_BSS_CLEAR help POSIX (native) architecture diff --git a/kernel/Kconfig b/kernel/Kconfig index 4cdd6209264..6280e80a400 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -382,6 +382,16 @@ config INIT_STACKS water mark can be easily determined. This applies to the stack areas for threads, as well as to the interrupt stack. +config SKIP_BSS_CLEAR + bool + help + This option disables software .bss section zeroing during Zephyr + initialization. Such boot-time optimization could be used for + platforms where .bss section is zeroed-out externally. + Please pay attention that when this option is enabled + the responsibility for .bss zeroing in all possible scenarios + (mind e.g. SW reset) is delegated to the external SW or HW. + config BOOT_BANNER bool "Boot banner" default y diff --git a/kernel/init.c b/kernel/init.c index c2109499a07..e4637d3aff1 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -165,12 +165,7 @@ void __weak z_early_memcpy(void *dst, const void *src, size_t n) __boot_func void z_bss_zero(void) { - if (IS_ENABLED(CONFIG_ARCH_POSIX)) { - /* native_posix gets its memory cleared on entry by - * the host OS, and in any case the host clang/lld - * doesn't emit the __bss_end symbol this code expects - * to see - */ + if (IS_ENABLED(CONFIG_SKIP_BSS_CLEAR)) { return; }