Skip to content

Commit 0161e50

Browse files
committed
soc: renode: cortex_r8_virtual: overhaul MPU regions
Apply the same modifications made to the ZynqMP's memory regions to the cortex_r8_virtual SoC which was mainlined while the fixes for the ZynqMP were being developed (minus the OCM mapping, as there's no indication that this type of memory was considered). The cortex_r8_virtual appears to be a stripped down copy of the old qemu_cortex_r5 codebase, therefore, the duplicated MPU regions have the same flaws as qemu_cortex_r5 or any actual ZynqMP-based target for that matter. Signed-off-by: Immo Birnbaum <[email protected]>
1 parent 162398b commit 0161e50

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

soc/renode/cortex_r8_virtual/arm_mpu_regions.c

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,67 @@
22
*
33
* Copyright (c) 2021 Lexmark International, Inc.
44
* Copyright (c) 2024 Antmicro <www.antmicro.com>
5+
* Copyright (c) 2024 Immo Birnbaum
56
*/
67

78
#include <zephyr/kernel.h>
8-
#include <zephyr/arch/arm/mpu/arm_mpu.h>
9+
#include <zephyr/arch/arm/cortex_m/arm_mpu_mem_cfg.h>
910

10-
#define MPUTYPE_READ_ONLY \
11-
{ \
12-
.rasr = (P_RO_U_RO_Msk \
13-
| (7 << MPU_RASR_TEX_Pos) \
14-
| MPU_RASR_C_Msk \
15-
| MPU_RASR_B_Msk \
16-
| MPU_RASR_XN_Msk) \
17-
}
11+
extern const uint32_t __rom_region_start;
12+
extern const uint32_t __rom_region_mpu_size_bits;
1813

19-
#define MPUTYPE_READ_ONLY_PRIV \
20-
{ \
21-
.rasr = (P_RO_U_RO_Msk \
22-
| (5 << MPU_RASR_TEX_Pos) \
23-
| MPU_RASR_B_Msk) \
24-
}
25-
26-
#define MPUTYPE_PRIV_WBWACACHE_XN \
27-
{ \
28-
.rasr = (P_RW_U_NA_Msk \
29-
| (5 << MPU_RASR_TEX_Pos) \
30-
| MPU_RASR_B_Msk \
31-
| MPU_RASR_XN_Msk) \
32-
}
33-
34-
#define MPUTYPE_PRIV_DEVICE \
35-
{ \
36-
.rasr = (P_RW_U_NA_Msk \
37-
| (2 << MPU_RASR_TEX_Pos)) \
38-
}
39-
40-
extern uint32_t _image_rom_end_order;
4114
static const struct arm_mpu_region mpu_regions[] = {
42-
MPU_REGION_ENTRY("FLASH0",
43-
0xc0000000,
44-
REGION_32M,
45-
MPUTYPE_READ_ONLY),
46-
47-
MPU_REGION_ENTRY("SRAM_PRIV",
48-
0x00000000,
49-
REGION_2G,
50-
MPUTYPE_PRIV_WBWACACHE_XN),
51-
52-
MPU_REGION_ENTRY("SRAM",
53-
0x00000000,
54-
((uint32_t)&_image_rom_end_order),
55-
MPUTYPE_READ_ONLY_PRIV),
56-
57-
MPU_REGION_ENTRY("REGISTERS",
58-
0xf8000000,
59-
REGION_128M,
60-
MPUTYPE_PRIV_DEVICE),
15+
/*
16+
* The address of the vectors is determined by arch/arm/core/cortex_a_r/prep_c.c
17+
* -> for v8-R, there's no other option than 0x0, HIVECS always gets cleared
18+
*/
19+
MPU_REGION_ENTRY(
20+
"vectors",
21+
0x00000000,
22+
REGION_64B,
23+
{.rasr = P_RO_U_NA_Msk |
24+
NORMAL_OUTER_INNER_NON_CACHEABLE_NON_SHAREABLE}),
25+
/* Basic SRAM mapping is all data, R/W + XN */
26+
MPU_REGION_ENTRY(
27+
"sram",
28+
CONFIG_SRAM_BASE_ADDRESS,
29+
REGION_SRAM_SIZE,
30+
{.rasr = P_RW_U_NA_Msk |
31+
NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NON_SHAREABLE |
32+
NOT_EXEC}),
33+
#if defined(CONFIG_XIP)
34+
/* .text and .rodata (=rom_region) are in flash, must be RO + executable */
35+
MPU_REGION_ENTRY(
36+
"rom_region",
37+
CONFIG_FLASH_BASE_ADDRESS,
38+
REGION_FLASH_SIZE,
39+
{.rasr = P_RO_U_RO_Msk |
40+
NORMAL_OUTER_INNER_WRITE_BACK_NON_SHAREABLE}),
41+
/* RAM contains R/W data, non-executable */
42+
#else /* !CONFIG_XIP */
43+
/* .text and .rodata are in RAM, flash is data only -> RO + XN */
44+
MPU_REGION_ENTRY(
45+
"flash",
46+
CONFIG_FLASH_BASE_ADDRESS,
47+
REGION_FLASH_SIZE,
48+
{.rasr = P_RO_U_RO_Msk |
49+
NORMAL_OUTER_INNER_WRITE_BACK_NON_SHAREABLE |
50+
NOT_EXEC}),
51+
/* add rom_region mapping for SRAM which is RO + executable */
52+
MPU_REGION_ENTRY(
53+
"rom_region",
54+
(uint32_t)(&__rom_region_start),
55+
(uint32_t)(&__rom_region_mpu_size_bits),
56+
{.rasr = P_RO_U_RO_Msk |
57+
NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NON_SHAREABLE}),
58+
#endif /* CONFIG_XIP */
59+
MPU_REGION_ENTRY(
60+
"peripherals",
61+
0xf8000000,
62+
REGION_128M,
63+
{.rasr = P_RW_U_NA_Msk |
64+
DEVICE_SHAREABLE |
65+
NOT_EXEC}),
6166
};
6267

6368
const struct arm_mpu_config mpu_config = {

0 commit comments

Comments
 (0)