From 382de4a7e9278cdd086897ef94b02d35cbd8aa5e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 26 Jun 2019 13:51:46 +0900 Subject: [PATCH] arm64: add an option to switch visibility of CONFIG_SYS_INIT_SP_BSS_OFFSET By default, CONFIG_SYS_INIT_SP_BSS_OFFSET was made invisible by not giving a prompt to it. The only way to define it is to hard-code an extra entry in SoC/board Kconfig, like arch/arm/mach-tegra/tegra{186,210}/Kconfig. Add a prompt to it in order to allow defconfig files to specify the value of CONFIG_SYS_INIT_SP_BSS_OFFSET. With this, CONFIG_SYS_INIT_SP_BSS_OFFSET would become always visible. So, we need a new bool option to turn it off by default. I move the 'default 524288' to the common place. This value is not too big, but is big enough to avoid the overwrap of DT in most platforms. If 512KB is not a suitable choice for your platform, you can change it from your defconfig or menuconfig etc. Signed-off-by: Masahiro Yamada Acked-by: Stephen Warren --- Makefile | 4 ++-- arch/arm/Kconfig | 20 ++++++++++++++----- .../armv8/linux-kernel-image-header-vars.h | 2 +- arch/arm/lib/crt0_64.S | 2 +- arch/arm/mach-tegra/Kconfig | 1 + arch/arm/mach-tegra/tegra186/Kconfig | 3 --- arch/arm/mach-tegra/tegra210/Kconfig | 3 --- 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 516260f46d..73fdf70cdd 100644 --- a/Makefile +++ b/Makefile @@ -874,7 +874,7 @@ ifneq ($(CONFIG_BUILD_TARGET),) ALL-y += $(CONFIG_BUILD_TARGET:"%"=%) endif -ifneq ($(CONFIG_SYS_INIT_SP_BSS_OFFSET),) +ifdef CONFIG_INIT_SP_RELATIVE ALL-y += init_sp_bss_offset_check endif @@ -1155,7 +1155,7 @@ binary_size_check: u-boot-nodtb.bin FORCE fi \ fi -ifneq ($(CONFIG_SYS_INIT_SP_BSS_OFFSET),) +ifdef CONFIG_INIT_SP_RELATIVE ifneq ($(CONFIG_SYS_MALLOC_F_LEN),) subtract_sys_malloc_f_len = space=$$(($${space} - $(CONFIG_SYS_MALLOC_F_LEN))) else diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index f5a7630e4f..8754197725 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -20,15 +20,25 @@ config POSITION_INDEPENDENT information that is embedded into the binary to support U-Boot relocating itself to the top-of-RAM later during execution. -config SYS_INIT_SP_BSS_OFFSET - int +config INIT_SP_RELATIVE + bool "Specify the early stack pointer relative to the .bss section" help U-Boot typically uses a hard-coded value for the stack pointer - before relocation. Define this option to instead calculate the + before relocation. Enable this option to instead calculate the initial SP at run-time. This is useful to avoid hard-coding addresses into U-Boot, so that can be loaded and executed at arbitrary - addresses and thus avoid using arbitrary addresses at runtime. This - option's value is the offset added to &_bss_start in order to + addresses and thus avoid using arbitrary addresses at runtime. + + If this option is enabled, the early stack pointer is set to + &_bss_start with a offset value added. The offset is specified by + SYS_INIT_SP_BSS_OFFSET. + +config SYS_INIT_SP_BSS_OFFSET + int "Early stack offset from the .bss base address" + depends on INIT_SP_RELATIVE + default 524288 + help + This option's value is the offset added to &_bss_start in order to calculate the stack pointer. This offset should be large enough so that the early malloc region, global data (gd), and early stack usage do not overlap any appended DTB. diff --git a/arch/arm/cpu/armv8/linux-kernel-image-header-vars.h b/arch/arm/cpu/armv8/linux-kernel-image-header-vars.h index fa6e86d1c2..b4220e4936 100644 --- a/arch/arm/cpu/armv8/linux-kernel-image-header-vars.h +++ b/arch/arm/cpu/armv8/linux-kernel-image-header-vars.h @@ -48,7 +48,7 @@ #define __MAX(a, b) (((a) > (b)) ? (a) : (b)) #define __CODE_DATA_SIZE (__bss_start - _start) #define __BSS_SIZE (__bss_end - __bss_start) -#ifdef CONFIG_SYS_INIT_SP_BSS_OFFSET +#ifdef CONFIG_INIT_SP_RELATIVE #define __MAX_EXTRA_RAM_USAGE __MAX(__BSS_SIZE, CONFIG_SYS_INIT_SP_BSS_OFFSET) #else #define __MAX_EXTRA_RAM_USAGE __BSS_SIZE diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S index d6b632aa87..e76b25a03e 100644 --- a/arch/arm/lib/crt0_64.S +++ b/arch/arm/lib/crt0_64.S @@ -72,7 +72,7 @@ ENTRY(_main) ldr x0, =(CONFIG_TPL_STACK) #elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK) ldr x0, =(CONFIG_SPL_STACK) -#elif defined(CONFIG_SYS_INIT_SP_BSS_OFFSET) +#elif defined(CONFIG_INIT_SP_RELATIVE) adr x0, __bss_start add x0, x0, #CONFIG_SYS_INIT_SP_BSS_OFFSET #else diff --git a/arch/arm/mach-tegra/Kconfig b/arch/arm/mach-tegra/Kconfig index 97e22ead59..ff9f29f2d5 100644 --- a/arch/arm/mach-tegra/Kconfig +++ b/arch/arm/mach-tegra/Kconfig @@ -86,6 +86,7 @@ config TEGRA_ARMV7_COMMON config TEGRA_ARMV8_COMMON bool "Tegra 64-bit common options" select ARM64 + select INIT_SP_RELATIVE select LINUX_KERNEL_IMAGE_HEADER select POSITION_INDEPENDENT select TEGRA_COMMON diff --git a/arch/arm/mach-tegra/tegra186/Kconfig b/arch/arm/mach-tegra/tegra186/Kconfig index 479c0955ee..b2e53b58ca 100644 --- a/arch/arm/mach-tegra/tegra186/Kconfig +++ b/arch/arm/mach-tegra/tegra186/Kconfig @@ -21,9 +21,6 @@ endchoice config SYS_SOC default "tegra186" -config SYS_INIT_SP_BSS_OFFSET - default 524288 - source "board/nvidia/p2771-0000/Kconfig" endif diff --git a/arch/arm/mach-tegra/tegra210/Kconfig b/arch/arm/mach-tegra/tegra210/Kconfig index 250738aed3..3637473051 100644 --- a/arch/arm/mach-tegra/tegra210/Kconfig +++ b/arch/arm/mach-tegra/tegra210/Kconfig @@ -40,9 +40,6 @@ endchoice config SYS_SOC default "tegra210" -config SYS_INIT_SP_BSS_OFFSET - default 524288 - source "board/nvidia/e2220-1170/Kconfig" source "board/nvidia/p2371-0000/Kconfig" source "board/nvidia/p2371-2180/Kconfig" -- 2.25.1