Skip to content

Commit

Permalink
linker: add custom align size to reduce alignment memory wasting
Browse files Browse the repository at this point in the history
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: zephyrproject-rtos#17337.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
  • Loading branch information
wentongwu committed Sep 20, 2019
1 parent 8a5e66b commit 7937c4a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 19 additions & 0 deletions arch/arm/core/cortex_m/mpu/Kconfig
Expand Up @@ -44,4 +44,23 @@ config MPU_ALLOW_FLASH_WRITE
help
Enable this to allow MPU RWX access to flash memory

config CUSTOM_SECTION_ALIGN
bool "Custom Section Align"
depends on ARM_MPU
help
MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT(ARMv7-M) sometimes cause memory
wasting in linker scripts defined memory sections. Use this symbol
to guarantee user custom section align size to avoid more memory used
for respect alignment. But that needs carefully configure MPU region
and sub-regions(ARMv7-M) to cover this feature.

config CUSTOM_SECTION_MIN_ALIGN_SIZE
int "Custom Section Align Size"
default 32
help
Custom algin size of memory section in linker scripts. Usually
it should consume less alignment memory. Alougth this alignment
size is configured by users, it must also respect the power of
two regulation if hardware requires.

endif # CPU_HAS_MPU
6 changes: 5 additions & 1 deletion include/arch/arm/cortex_m/scripts/linker.ld
Expand Up @@ -73,6 +73,9 @@
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
#endif

#if defined(CONFIG_CUSTOM_SECTION_ALIGN)
_region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE;
#else
/* Set alignment to CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
* to make linker section alignment comply with MPU granularity.
*/
Expand All @@ -82,8 +85,9 @@ _region_min_align = CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE;
/* If building without MPU support, use default 4-byte alignment. */
_region_min_align = 4;
#endif
#endif

#if defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
#if !defined(CONFIG_CUSTOM_SECTION_ALIGN) && defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
#define MPU_ALIGN(region_size) \
. = ALIGN(_region_min_align); \
. = ALIGN( 1 << LOG2CEIL(region_size))
Expand Down

0 comments on commit 7937c4a

Please sign in to comment.