Skip to content

Commit 828c08d

Browse files
committed
cmake: linker generator: MPU_ALIGN for CONFIG_CMAKE_LINKER_GENERATOR
Make gen_app_partitions.py pass size argument to SMEM_PARTIOTION_ALIGN Implement MPU_ALIGN for CONFIG_CMAKE_LINKER_GENERATOR for cortex-m, and setup SMEM_PARTITION_ALIGN to use MPU_ALIGN. Following the pattern of how it is setup in the non-generator scrips. This is an example of how the recursive @@ variables can be used to implement MPU_ALIGN(region_size) Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
1 parent 55438a9 commit 828c08d

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

cmake/linker_script/arm/linker.cmake

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ if((NOT DEFINED CONFIG_CUSTOM_SECTION_ALIGN) AND DEFINED CONFIG_MPU_REQUIRES_PO
2222
# . = ALIGN( 1 << LOG2CEIL(region_size))
2323
# Handling this requires us to handle log2ceil() in iar linker since the size
2424
# isn't known until then.
25-
set(MPU_ALIGN_BYTES ${region_min_align})
25+
zephyr_linker_include_var(VAR MPU_ALIGN VALUE "MAX(${region_min_align} , 1 << LOG2CEIL(@region_size@) )")
2626
#message(WARNING "We can not handle . = ALIGN( 1 << LOG2CEIL(region_size)) ")
2727
else()
28-
set(MPU_ALIGN_BYTES ${region_min_align})
28+
zephyr_linker_include_var(VAR MPU_ALIGN VALUE "${region_min_align}")
2929
endif()
30-
# The APP_SHARED_ALIGN and SMEM_PARTITION_ALIGN macros are defined as
31-
# ". = ALIGN(...)" things.
32-
# the cmake generator stuff needs an align-size in bytes so:
33-
zephyr_linker_include_var(VAR APP_SHARED_ALIGN_BYTES VALUE ${region_min_align})
34-
zephyr_linker_include_var(VAR SMEM_PARTITION_ALIGN_BYTES VALUE ${MPU_ALIGN_BYTES})
30+
31+
zephyr_linker_include_var(VAR APP_SHARED_ALIGN VALUE ${region_min_align})
32+
# Note that MPU_ALIGN (may) require an argument (region_size
33+
zephyr_linker_include_var(VAR SMEM_PARTITION_ALIGN VALUE "@MPU_ALIGN@")
3534

3635
# Note, the `+ 0` in formulas below avoids errors in cases where a Kconfig
3736
# variable is undefined and thus expands to nothing.

scripts/build/gen_app_partitions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ def zephyr_linker_symbol(symbol, expr) :
279279

280280
class CmakeTemplate:
281281
section_name = "@_APP_SMEM{SECTION}_SECTION_NAME@"
282+
smem_partition_align = "@SMEM_PARTITION_ALIGN,region_size=z_data_smem_{partition}_bss_end - z_data_smem_{partition}_part_start@"
282283
data_template = (
283-
zephyr_linker_section_configure(section=section_name, align="@SMEM_PARTITION_ALIGN_BYTES@")+
284+
zephyr_linker_section_configure(section=section_name, align=smem_partition_align)+
284285
zephyr_linker_section_configure(section=section_name, input="data_smem_{partition}_data*", symbols="z_data_smem_{partition}_part_start", keep=True)
285286
)
286287

@@ -294,20 +295,20 @@ class CmakeTemplate:
294295

295296
footer_template = (
296297
zephyr_linker_section_configure(section=section_name, symbols="z_data_smem_{partition}_bss_end", keep=True) +
297-
zephyr_linker_section_configure(section=section_name, align="@SMEM_PARTITION_ALIGN_BYTES@") +
298+
zephyr_linker_section_configure(section=section_name, align=smem_partition_align) +
298299
zephyr_linker_section_configure(section=section_name, symbols="z_data_smem_{partition}_part_end", keep=True)
299300
)
300301

301302
linker_start_seq = (
302303
zephyr_linker_section(name=section_name, group="APP_SMEM_GROUP", noinput=True, align_with_input=True) +
303-
zephyr_linker_section_configure(section=section_name, align="@APP_SHARED_ALIGN_BYTES@", symbols="_app_smem{section}_start"))
304+
zephyr_linker_section_configure(section=section_name, align="@APP_SHARED_ALIGN@", symbols="_app_smem{section}_start"))
304305

305306
linker_end_seq = (
306-
zephyr_linker_section_configure(section=section_name, align="@APP_SHARED_ALIGN_BYTES@") +
307+
zephyr_linker_section_configure(section=section_name, align="@APP_SHARED_ALIGN@") +
307308
zephyr_linker_section_configure(section=section_name, symbols="_app_smem{section}_end") )
308309

309310
empty_app_smem = (
310-
zephyr_linker_section(name=section_name, group="APP_SMEM_GROUP", align="@APP_SHARED_ALIGN_BYTES@", noinput=True, align_with_input=True) +
311+
zephyr_linker_section(name=section_name, group="APP_SMEM_GROUP", align="@APP_SHARED_ALIGN@", noinput=True, align_with_input=True) +
311312
zephyr_linker_section_configure(section = section_name, symbols="_app_smem{section}_start") +
312313
zephyr_linker_section_configure(section = section_name, symbols="_app_smem{section}_end") )
313314

0 commit comments

Comments
 (0)