Skip to content

Commit f696a5c

Browse files
author
Nikolay Agishev
committed
boards: qemu_arc: fix of MPU regions setup for !XIP config
Add some changes to ARC linker script. They make correct alignment for ROMable region. Now regions borders are aligned with respect to MPU settings. Signed-off-by: Nikolay Agishev <[email protected]>
1 parent 888bc68 commit f696a5c

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

boards/arc/qemu_arc/arc_mpu_regions.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <zephyr/devicetree.h>
88
#include <zephyr/arch/arc/v2/mpu/arc_mpu.h>
9+
#include <zephyr/arch/arc/arch.h>
910
#include <zephyr/linker/linker-defs.h>
1011

1112
/*
@@ -23,12 +24,31 @@ static struct arc_mpu_region mpu_regions[] = {
2324
#endif /* CONFIG_COVERAGE_GCOV && CONFIG_USERSPACE */
2425

2526
#if DT_REG_SIZE(DT_CHOSEN(zephyr_sram)) > 0
27+
28+
#ifdef CONFIG_XIP
2629
/* Region RAM */
2730
MPU_REGION_ENTRY("RAM",
2831
DT_REG_ADDR(DT_CHOSEN(zephyr_sram)),
2932
DT_REG_SIZE(DT_CHOSEN(zephyr_sram)),
3033
REGION_KERNEL_RAM_ATTR | REGION_DYNAMIC),
31-
#endif
34+
#else
35+
/* Region RAM */
36+
/*
37+
* In case if Zephyr is configured with CONFIG_XIP=n it linked into
38+
* SRAM. So RAM region should have EXECUTE permission.
39+
*/
40+
MPU_REGION_ENTRY("RAM_RX",
41+
(uintptr_t)__rom_region_start,
42+
(uintptr_t)__rom_region_size,
43+
REGION_ROM_ATTR),
44+
45+
MPU_REGION_ENTRY("RAM_RW",
46+
(uintptr_t)_image_ram_start,
47+
(uintptr_t)__arc_rw_sram_size,
48+
REGION_KERNEL_RAM_ATTR | REGION_DYNAMIC),
49+
#endif /* CONFIG_XIP */
50+
51+
#endif /* zephyr_sram > 0 */
3252

3353
#if DT_REG_SIZE(DT_CHOSEN(zephyr_flash)) > 0
3454
/* Region DCCM */

include/zephyr/arch/arc/arch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ static ALWAYS_INLINE void arch_nop(void)
344344
__builtin_arc_nop();
345345
}
346346

347+
#ifndef CONFIG_XIP
348+
extern char __arc_rw_sram_size[];
349+
#endif /* CONFIG_XIP */
350+
347351
#endif /* _ASMLANGUAGE */
348352

349353
#ifdef __cplusplus

include/zephyr/arch/arc/v2/linker.ld

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ SECTIONS {
9393

9494
#include <zephyr/linker/common-rom.ld>
9595
#include <zephyr/linker/thread-local-storage.ld>
96+
#ifdef __MWDT_LINKER_CMD__
97+
/* TODO: add mwdt specific ROM C++ sections */
98+
#else
99+
#include <zephyr/linker/cplusplus-rom.ld>
100+
#endif /* __MWDT_LINKER_CMD__ */
96101

97102
SECTION_PROLOGUE(_RODATA_SECTION_NAME,,) {
98103
*(".rodata")
@@ -103,7 +108,6 @@ SECTIONS {
103108
* zephyr_linker_sources() Cmake function.
104109
*/
105110
#include <snippets-rodata.ld>
106-
107111
#include <zephyr/linker/kobject-rom.ld>
108112

109113
#if defined(CONFIG_CPLUSPLUS) && !defined(CONFIG_CPP_STATIC_INIT_GNU) && defined(__MWDT_LINKER_CMD__)
@@ -112,15 +116,12 @@ SECTIONS {
112116
KEEP(*(.ctors*))
113117
_ectors = .;
114118
#endif /* CONFIG_CPLUSPLUS && !CONFIG_CPP_STATIC_INIT_GNU && __MWDT_LINKER_CMD__ */
115-
} GROUP_LINK_IN(ROMABLE_REGION)
116119

117-
#ifdef __MWDT_LINKER_CMD__
118-
/* TODO: add mwdt specific ROM C++ sections */
119-
#else
120-
#include <zephyr/linker/cplusplus-rom.ld>
121-
#endif /* __MWDT_LINKER_CMD__ */
120+
MPU_ALIGN(ABSOLUTE(.) - __rom_region_start);
121+
} GROUP_LINK_IN(ROMABLE_REGION)
122122

123123
__rodata_region_end = .;
124+
124125
MPU_ALIGN(__rodata_region_end - __rom_region_start);
125126
__rom_region_end = .;
126127
__rom_region_size = __rom_region_end - __rom_region_start;
@@ -129,6 +130,10 @@ SECTIONS {
129130

130131
GROUP_START(RAMABLE_REGION)
131132

133+
MPU_MIN_SIZE_ALIGN
134+
135+
_image_ram_start = .;
136+
132137
#include <app_data_alignment.ld>
133138

134139
/* Located in generated directory. This file is populated by the
@@ -141,8 +146,6 @@ SECTIONS {
141146
#define SMEM_PARTITION_ALIGN MPU_ALIGN
142147

143148
#include <app_smem.ld>
144-
145-
_image_ram_start = _app_smem_start;
146149
_app_smem_size = _app_smem_end - _app_smem_start;
147150
_app_smem_rom_start = LOADADDR(_APP_SMEM_SECTION_NAME);
148151
#endif /* CONFIG_USERSPACE */
@@ -155,7 +158,6 @@ SECTIONS {
155158
*/
156159
. = ALIGN(4);
157160
__bss_start = .;
158-
_image_ram_start = .;
159161
__kernel_ram_start = .;
160162
*(".bss")
161163
*(".bss.*")
@@ -244,6 +246,16 @@ SECTIONS {
244246
KEEP(*(.gnu.attributes))
245247
}
246248

249+
#if !defined(CONFIG_XIP)
250+
/*
251+
* Zephyr uses _estack as a start of heap allocation area.
252+
* Region [_estack .. sram_end] should be defined in MPU.
253+
* Including _image_ram region which is [_image_ram_start .. _image_ram_end]
254+
* we get [_image_ram_start .. sram_end] region to be defined in MPU.
255+
*/
256+
__arc_rw_sram_size = SRAM_START + SRAM_SIZE - _image_ram_start;
257+
#endif
258+
247259
/DISCARD/ : {
248260
#if defined(CONFIG_CPLUSPLUS) && !defined(CONFIG_CPP_STATIC_INIT_GNU) && defined(__MWDT_LINKER_CMD__)
249261
*(.dtors*)

0 commit comments

Comments
 (0)