From d8bdddd52f4ced694f5dcb418f7bda9fcd7a7032 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 28 Jul 2023 19:47:45 +0000 Subject: [PATCH] arch: arm: aarch32: introduce CONFIG_BUILD_ALIGN_LMA Introduce CONFIG_BUILD_ALIGN_LMA. When enabled, this symbol will add a padding section after the final read only data section in the image. This padding section will ensure that the LMA of the data sections follows the same alignment restrictions as the VMA does. This LMA alignment is needed for objcopy to adjust the LMA address of the output ELF file. Signed-off-by: Daniel DeGrasse --- Kconfig.zephyr | 9 +++++++++ .../arch/arm/aarch32/cortex_m/scripts/linker.ld | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index a1b8a57db52..9f9132eb753 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -674,6 +674,15 @@ config BUILD_OUTPUT_INFO_HEADER - VMA address of each segment - Size of each segment +config BUILD_ALIGN_LMA + bool "Align LMA in output image" + default y if BUILD_OUTPUT_ADJUST_LMA!="" + help + Ensure that the LMA for each section in the output image respects + the alignment requirements of that section. This is required for + some tooling, such as objcopy, to be able to adjust the LMA of the + ELF file. + config APPLICATION_DEFINED_SYSCALL bool "Scan application folder for any syscall definition" help diff --git a/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld b/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld index b170b514a9c..92b6f02d029 100644 --- a/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld +++ b/include/zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld @@ -206,8 +206,21 @@ SECTIONS #include +#if defined(CONFIG_BUILD_ALIGN_LMA) + /* + * Include a padding section here to make sure that the LMA address + * of the sections in the RAMABLE_REGION are aligned with those + * section's VMA alignment requirements. + */ + SECTION_PROLOGUE(padding_section,,) + { __rodata_region_end = .; MPU_ALIGN(__rodata_region_end - ADDR(rom_start)); + } GROUP_LINK_IN(ROMABLE_REGION) +#else + __rodata_region_end = .; + MPU_ALIGN(__rodata_region_end - ADDR(rom_start)); +#endif __rom_region_end = __rom_region_start + . - ADDR(rom_start); GROUP_END(ROMABLE_REGION)