Skip to content

Commit f2dc4a0

Browse files
57300carlescufi
authored andcommitted
cmake: Adjust LMA for user-specified sections
Fixes #64149 Add support for a new Kconfig symbol: BUILD_OUTPUT_ADJUST_LMA_SECTIONS. This is supplemental to the existing BUILD_OUTPUT_ADJUST_LMA setting, which normally adjusts all output sections' LMA by the provided offset. Defining the new symbol will narrow down the set of applicable sections to a user-specified CMake list of name patterns. Example usage: DT_CHOSEN_Z_FLASH = zephyr,flash DT_CHOSEN_Z_SRAM = zephyr,sram config BUILD_OUTPUT_ADJUST_LMA default "$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH)) - \ $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_SRAM))" config BUILD_OUTPUT_ADJUST_LMA_SECTIONS default "*;!bss;!noinit" Supported values for BUILD_OUTPUT_ADJUST_LMA_SECTIONS are aligned with objcopy, since this feature has only been supported with GNU binutils thus far. Signed-off-by: Grzegorz Swiderski <[email protected]>
1 parent 7502304 commit f2dc4a0

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,11 +1613,14 @@ endif()
16131613

16141614
if(CONFIG_BUILD_OUTPUT_ADJUST_LMA)
16151615
math(EXPR adjustment "${CONFIG_BUILD_OUTPUT_ADJUST_LMA}" OUTPUT_FORMAT DECIMAL)
1616+
set(args_adjustment ${CONFIG_BUILD_OUTPUT_ADJUST_LMA_SECTIONS})
1617+
list(TRANSFORM args_adjustment PREPEND $<TARGET_PROPERTY:bintools,elfconvert_flag_lma_adjust>)
1618+
list(TRANSFORM args_adjustment APPEND +${adjustment})
16161619
list(APPEND
16171620
post_build_commands
16181621
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
16191622
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
1620-
$<TARGET_PROPERTY:bintools,elfconvert_flag_lma_adjust>${adjustment}
1623+
${args_adjustment}
16211624
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>${KERNEL_ELF_NAME}
16221625
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>${KERNEL_ELF_NAME}
16231626
)

Kconfig.zephyr

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,23 @@ config BUILD_OUTPUT_ADJUST_LMA
822822
default "$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_IMAGE_M4))-\
823823
$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH))"
824824

825+
config BUILD_OUTPUT_ADJUST_LMA_SECTIONS
826+
def_string "*"
827+
depends on BUILD_OUTPUT_ADJUST_LMA!=""
828+
help
829+
This determines the output sections to which the above LMA adjustment
830+
will be applied.
831+
The value can be the name of a section in the final ELF, like "text".
832+
It can also be a pattern with wildcards, such as "*bss", which could
833+
match more than one section name. Multiple such patterns can be given
834+
as a ";"-separated list. It's possible to supply a 'negative' pattern
835+
starting with "!", to exclude sections matched by a preceding pattern.
836+
837+
By default, all sections will have their LMA adjusted. The following
838+
example excludes one section produced by the code relocation feature:
839+
config BUILD_OUTPUT_ADJUST_LMA_SECTIONS
840+
default "*;!.extflash_text_reloc"
841+
825842
config BUILD_OUTPUT_INFO_HEADER
826843
bool "Create a image information header"
827844
help

cmake/bintools/gnu/target_bintools.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ set_property(TARGET bintools PROPERTY elfconvert_flag_section_remove "--remove-s
4444
set_property(TARGET bintools PROPERTY elfconvert_flag_section_only "--only-section=")
4545
set_property(TARGET bintools PROPERTY elfconvert_flag_section_rename "--rename-section;")
4646

47-
set_property(TARGET bintools PROPERTY elfconvert_flag_lma_adjust "--change-section-lma;*+")
47+
set_property(TARGET bintools PROPERTY elfconvert_flag_lma_adjust "--change-section-lma;")
4848

4949
# Note, placing a ';' at the end results in the following param to be a list,
5050
# and hence space separated.

0 commit comments

Comments
 (0)