Skip to content

Commit da31c81

Browse files
wentongwunashif
authored andcommitted
linker: add custom align size to reduce alignment memory wasting
when enable CONFIG_CUSTOM_SECTION_ALIGN, it need less alignment memory for image rom region. But that needs carefully configure MPU region and sub-regions(ARMv7-M) to cover this feature. Fixes: #17337. Signed-off-by: Wentong Wu <[email protected]>
1 parent f987029 commit da31c81

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

arch/arm/core/cortex_m/mpu/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ config MPU_ALLOW_FLASH_WRITE
6161
help
6262
Enable this to allow MPU RWX access to flash memory
6363

64+
config CUSTOM_SECTION_ALIGN
65+
bool "Custom Section Align"
66+
depends on ARM_MPU
67+
help
68+
MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT(ARMv7-M) sometimes cause memory
69+
wasting in linker scripts defined memory sections. Use this symbol
70+
to guarantee user custom section align size to avoid more memory used
71+
for respect alignment. But that needs carefully configure MPU region
72+
and sub-regions(ARMv7-M) to cover this feature.
73+
74+
config CUSTOM_SECTION_MIN_ALIGN_SIZE
75+
int "Custom Section Align Size"
76+
default 32
77+
help
78+
Custom algin size of memory section in linker scripts. Usually
79+
it should consume less alignment memory. Alougth this alignment
80+
size is configured by users, it must also respect the power of
81+
two regulation if hardware requires.
82+
6483
endif # ARM_MPU
6584

6685
endif # CPU_HAS_MPU

include/arch/arm/cortex_m/scripts/linker.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
7070
#endif
7171

72+
#if defined(CONFIG_CUSTOM_SECTION_ALIGN)
73+
_region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE;
74+
#else
7275
/* Set alignment to CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
7376
* to make linker section alignment comply with MPU granularity.
7477
*/
@@ -78,8 +81,9 @@ _region_min_align = CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE;
7881
/* If building without MPU support, use default 4-byte alignment. */
7982
_region_min_align = 4;
8083
#endif
84+
#endif
8185

82-
#if defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
86+
#if !defined(CONFIG_CUSTOM_SECTION_ALIGN) && defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
8387
#define MPU_ALIGN(region_size) \
8488
. = ALIGN(_region_min_align); \
8589
. = ALIGN( 1 << LOG2CEIL(region_size))

0 commit comments

Comments
 (0)