From ece9cad8580ce85533dcf967718509c684afbc74 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Sat, 20 Feb 2021 11:02:17 -0800 Subject: [PATCH] kernel: add CONFIG_SRAM_OFFSET This adds a new kconfig CONFIG_SRAM_OFFSET to specify the offset from beginning of SRAM where the kernel begins. On x86 and PC compatible platforms, the first 1MB of RAM is reserved and Zephyr should not link anything there. However, this 1MB still needs to be mapped by the MMU to access various platform related information. CONFIG_SRAM_OFFSET serves similar function as CONFIG_KERNEL_VM_OFFSET and is needed for proper phys/virt address translations. Signed-off-by: Daniel Leung --- Kconfig.zephyr | 16 ++++++++++++++++ arch/Kconfig | 2 +- arch/x86/include/x86_mmu.h | 2 +- kernel/include/mmu.h | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 68864a1bf9b..190d05528fd 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -167,6 +167,22 @@ config LINKER_SORT_BY_ALIGNMENT in decreasing size of symbols. This helps to minimize padding between symbols. +config HAS_SRAM_OFFSET + bool + help + This option is selected by targets that require SRAM_OFFSET. + +config SRAM_OFFSET + hex "Kernel SRAM offset" if HAS_SRAM_OFFSET + default 0 + help + This option specifies the byte offset from the beginning of SRAM + where the kernel begins. Changing this value from zero will affect + the Zephyr image's link, and will decrease the total amount of + SRAM available for use by application code. + + If unsure, leave at the default value 0. + endmenu menu "Compiler Options" diff --git a/arch/Kconfig b/arch/Kconfig index 194eb3591c7..93818d650c7 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -608,7 +608,7 @@ config KERNEL_VM_OFFSET in page tables, the equation: virt = phys + ((KERNEL_VM_BASE + KERNEL_VM_OFFSET) - - SRAM_BASE_ADDRESS) + (SRAM_BASE_ADDRESS + SRAM_OFFSET)) Will be used to convert between physical and virtual addresses for memory that is mapped at boot. diff --git a/arch/x86/include/x86_mmu.h b/arch/x86/include/x86_mmu.h index 02835aa6949..450208d6937 100644 --- a/arch/x86/include/x86_mmu.h +++ b/arch/x86/include/x86_mmu.h @@ -82,7 +82,7 @@ */ #ifdef CONFIG_MMU #define Z_X86_VIRT_OFFSET ((CONFIG_KERNEL_VM_BASE + CONFIG_KERNEL_VM_OFFSET) - \ - CONFIG_SRAM_BASE_ADDRESS) + (CONFIG_SRAM_BASE_ADDRESS + CONFIG_SRAM_OFFSET)) #else #define Z_X86_VIRT_OFFSET 0 #endif diff --git a/kernel/include/mmu.h b/kernel/include/mmu.h index 34b77fb9fa7..f568ec4d04d 100644 --- a/kernel/include/mmu.h +++ b/kernel/include/mmu.h @@ -41,7 +41,7 @@ #define Z_KERNEL_VIRT_SIZE (Z_KERNEL_VIRT_END - Z_KERNEL_VIRT_START) #define Z_VM_OFFSET ((CONFIG_KERNEL_VM_BASE + CONFIG_KERNEL_VM_OFFSET) - \ - CONFIG_SRAM_BASE_ADDRESS) + (CONFIG_SRAM_BASE_ADDRESS + CONFIG_SRAM_OFFSET)) /* Only applies to boot RAM mappings within the Zephyr image that have never * been remapped or paged out. Never use this unless you know exactly what you