linker: add bits for boot regions

This adds the necessary bits for linker scripts and source code
to specify which symbols are needed for boot process so they
can be grouped together.

One use of this is to group boot related code and data so these
won't interval with other kernel and application for better
caching.

This is a must for demand paging as some functions and data
must be available during the boot process and before the memory
manager is initialized. During this time, paging cannot be used
so symbols linked in virtual memory space are unavailable.

This is up to the arch/SoC/board to define the sections in
their linker scripts as section may need special alignment
which cannot be done in common script snippets.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2021-02-24 10:18:34 -08:00 committed by Kumar Gala
parent af49ec0277
commit d812728ec4
6 changed files with 103 additions and 0 deletions

View file

@ -180,6 +180,20 @@ config SRAM_OFFSET
If unsure, leave at the default value 0.
menu "Linker Sections"
config LINKER_USE_BOOT_SECTION
bool "Enable Usage of Boot Linker Section"
help
If enabled, the symbols which are needed for the boot process
will be put into another linker section reserved for these
symbols.
Requires that boot sections exist in the architecture, SoC,
board or custom linker script.
endmenu # "Linker Sections"
endmenu
menu "Compiler Options"

View file

@ -317,6 +317,30 @@ extern char __tls_end[];
extern char __tls_size[];
#endif /* CONFIG_THREAD_LOCAL_STORAGE */
#ifdef CONFIG_LINKER_USE_BOOT_SECTION
/* lnkr_boot_start[] and lnkr_boot_end[]
* must encapsulate all the boot sections.
*/
extern char lnkr_boot_start[];
extern char lnkr_boot_end[];
extern char lnkr_boot_text_start[];
extern char lnkr_boot_text_end[];
extern char lnkr_boot_text_size[];
extern char lnkr_boot_data_start[];
extern char lnkr_boot_data_end[];
extern char lnkr_boot_data_size[];
extern char lnkr_boot_rodata_start[];
extern char lnkr_boot_rodata_end[];
extern char lnkr_boot_rodata_size[];
extern char lnkr_boot_bss_start[];
extern char lnkr_boot_bss_end[];
extern char lnkr_boot_bss_size[];
extern char lnkr_boot_noinit_start[];
extern char lnkr_boot_noinit_end[];
extern char lnkr_boot_noinit_size[];
#endif /* CONFIG_LINKER_USE_BOOT_SECTION */
#endif /* ! _ASMLANGUAGE */
#endif /* ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_ */

View file

@ -52,6 +52,20 @@
#define __kstackmem __noinit
#endif /* CONFIG_KERNEL_COHERENCE */
#if defined(CONFIG_LINKER_USE_BOOT_SECTION)
#define __boot_func Z_GENERIC_DOT_SECTION(BOOT_TEXT_SECTION_NAME)
#define __boot_data Z_GENERIC_DOT_SECTION(BOOT_DATA_SECTION_NAME)
#define __boot_rodata Z_GENERIC_DOT_SECTION(BOOT_RODATA_SECTION_NAME)
#define __boot_bss Z_GENERIC_DOT_SECTION(BOOT_BSS_SECTION_NAME)
#define __boot_noinit Z_GENERIC_DOT_SECTION(BOOT_NOINIT_SECTION_NAME)
#else
#define __boot_func
#define __boot_data
#define __boot_rodata
#define __boot_bss
#define __boot_noinit __noinit
#endif /* CONFIG_LINKER_USE_BOOT_SECTION */
#endif /* !_ASMLANGUAGE */
#endif /* ZEPHYR_INCLUDE_LINKER_SECTION_TAGS_H_ */

View file

@ -67,6 +67,14 @@
#define _NOCACHE_SECTION_NAME nocache
#endif
#if defined(CONFIG_LINKER_USE_BOOT_SECTION)
#define BOOT_TEXT_SECTION_NAME boot_text
#define BOOT_BSS_SECTION_NAME boot_bss
#define BOOT_RODATA_SECTION_NAME boot_rodata
#define BOOT_DATA_SECTION_NAME boot_data
#define BOOT_NOINIT_SECTION_NAME boot_noinit
#endif
/* Short section references for use in ASM files */
#if defined(_ASMLANGUAGE)
/* Various text section names */
@ -77,6 +85,21 @@
#define RODATA rodata
#define DATA data
#define NOINIT noinit
#if defined(CONFIG_LINKER_USE_BOOT_SECTION)
#define BOOT_TEXT BOOT_TEXT_SECTION_NAME
#define BOOT_BSS BOOT_BSS_SECTION_NAME
#define BOOT_RODATA BOOT_RODATA_SECTION_NAME
#define BOOT_DATA BOOT_DATA_SECTION_NAME
#define BOOT_NOINIT BOOT_NOINIT_SECTION_NAME
#else
#define BOOT_TEXT TEXT
#define BOOT_BSS BSS
#define BOOT_RODATA RODATA
#define BOOT_DATA DATA
#define BOOT_NOINIT NOINIT
#endif /* CONFIG_LINKER_USE_BOOT_SECTION */
#endif /* _ASMLANGUAGE */
#include <linker/section_tags.h>

View file

@ -35,6 +35,16 @@ static inline void z_data_copy(void)
/* Do nothing */
}
#endif
#ifdef CONFIG_LINKER_USE_BOOT_SECTION
void z_bss_zero_boot(void);
#else
static inline void z_bss_zero_boot(void)
{
/* Do nothing */
}
#endif
FUNC_NORETURN void z_cstart(void);
void z_device_state_init(void);

View file

@ -109,6 +109,24 @@ void z_bss_zero(void)
#endif
}
#ifdef CONFIG_LINKER_USE_BOOT_SECTION
/**
* @brief Clear BSS within the bot region
*
* This routine clears the BSS within the boot region.
* This is separate from z_bss_zero() as boot region may
* contain symbols required for the boot process before
* paging is initialized.
*/
__boot_func
void z_bss_zero_boot(void)
{
(void)memset(&lnkr_boot_bss_start, 0,
(uintptr_t)&lnkr_boot_bss_end
- (uintptr_t)&lnkr_boot_bss_start);
}
#endif /* CONFIG_LINKER_USE_BOOT_SECTION */
#ifdef CONFIG_STACK_CANARIES
extern volatile uintptr_t __stack_chk_guard;
#endif /* CONFIG_STACK_CANARIES */