diff --git a/arch/arm/core/cortex_m/Kconfig b/arch/arm/core/cortex_m/Kconfig index 3537960c6e9..54e1a74580d 100644 --- a/arch/arm/core/cortex_m/Kconfig +++ b/arch/arm/core/cortex_m/Kconfig @@ -199,6 +199,17 @@ config FLASH_BASE_ADDRESS This option specifies the base address of the flash on the board. It is normally set by the board's defconfig file and the user should generally avoid modifying it via the menu configuration. + +config FLASH_LOAD_OFFSET + hex "Kernel load offset" + default 0 + help + This option specifies the byte offset from FLASH_BASE_ADDRESS that the + kernel should be loaded into. Changing this value from zero will affect + the Zephyr image's link, and will decrease the total amount of flash + available for use by application code. + + If unsure, leave at the default value 0. endmenu menu "ARM Cortex-M0/M0+/M3/M4/M7 options" diff --git a/arch/arm/core/cortex_m/prep_c.c b/arch/arm/core/cortex_m/prep_c.c index 19c31d5063d..ee910cfb358 100644 --- a/arch/arm/core/cortex_m/prep_c.c +++ b/arch/arm/core/cortex_m/prep_c.c @@ -27,7 +27,8 @@ static inline void relocate_vector_table(void) { /* do nothing */ } #elif defined(CONFIG_ARMV7_M) #ifdef CONFIG_XIP -#define VECTOR_ADDRESS (CONFIG_FLASH_BASE_ADDRESS + CONFIG_TEXT_SECTION_OFFSET) +#define VECTOR_ADDRESS ((uintptr_t)&_image_rom_start + \ + CONFIG_TEXT_SECTION_OFFSET) #else #define VECTOR_ADDRESS CONFIG_SRAM_BASE_ADDRESS #endif diff --git a/include/arch/arm/cortex_m/scripts/linker.ld b/include/arch/arm/cortex_m/scripts/linker.ld index 8bfc57adda8..ba35922aa2d 100644 --- a/include/arch/arm/cortex_m/scripts/linker.ld +++ b/include/arch/arm/cortex_m/scripts/linker.ld @@ -40,8 +40,8 @@ #define SKIP_TO_KINETIS_FLASH_CONFIG #endif -#define ROM_ADDR CONFIG_FLASH_BASE_ADDRESS -#define ROM_SIZE CONFIG_FLASH_SIZE*1K +#define ROM_ADDR (CONFIG_FLASH_BASE_ADDRESS + CONFIG_FLASH_LOAD_OFFSET) +#define ROM_SIZE (CONFIG_FLASH_SIZE*1K - CONFIG_FLASH_LOAD_OFFSET) #if defined(CONFIG_XIP) #if defined(CONFIG_IS_BOOTLOADER) @@ -72,7 +72,7 @@ SECTIONS { GROUP_START(ROMABLE_REGION) - _image_rom_start = CONFIG_FLASH_BASE_ADDRESS; + _image_rom_start = ROM_ADDR; SECTION_PROLOGUE(_TEXT_SECTION_NAME,,) {