Skip to content

Commit b25ae26

Browse files
committed
soc: esp32c6: enable PMP and define SoC regions
Enable RISC-V PMP for ESP32-C6 and configure appropriate defaults: - 16 PMP slots available on hardware - Unlocked global entries for XIP flash execution - MEM_ATTR subsystem for device tree memory regions Define SoC-specific PMP regions: - SoC ROM (0x40000000): libc functions, R+X - IRAM text: interrupt handlers and critical code, R+X Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
1 parent 1482e98 commit b25ae26

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

soc/espressif/common/Kconfig.flash

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,15 @@ endchoice
113113

114114
config BOOTLOADER_REGION_PROTECTION_ENABLE
115115
bool "Protect unmapped memory regions from unintended accesses"
116-
default y
116+
default y if !RISCV_PMP && !MCUBOOT
117117
help
118118
Protects the unmapped memory regions of the entire address space from unintended accesses.
119119
This will ensure that an exception will be triggered whenever the CPU performs a memory
120120
operation on unmapped regions of the address space.
121121

122+
Automatically disabled when RISCV_PMP is enabled since Zephyr manages PMP directly.
123+
Also disabled for MCUboot builds since the bootloader handles its own region protection.
124+
122125
config SPI_FLASH_HPM_ENABLE
123126
bool
124127
depends on SOC_SERIES_ESP32S3

soc/espressif/esp32c6/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ if(CONFIG_SOC_ESP32C6_HPCORE)
2121
zephyr_library_sources_ifdef(CONFIG_PM power.c)
2222
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
2323
zephyr_sources_ifdef(CONFIG_ULP_COPROC_ENABLED hpcore_init_ulp.c)
24+
zephyr_sources_ifdef(CONFIG_RISCV_PMP pmp_regions.c)
2425
endif()

soc/espressif/esp32c6/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
config SOC_SERIES_ESP32C6
55
select RISCV
66
select RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
7+
select RISCV_PMP if SOC_ESP32C6_HPCORE && !MCUBOOT
78
select DYNAMIC_INTERRUPTS if SOC_ESP32C6_HPCORE
89
select CLOCK_CONTROL if SOC_ESP32C6_HPCORE
910
select PINCTRL if SOC_ESP32C6_HPCORE

soc/espressif/esp32c6/Kconfig.defconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ if SOC_SERIES_ESP32C6
66
config NUM_IRQS
77
default 32
88

9+
config PMP_SLOTS
10+
default 16
11+
12+
# ESP32-C6 uses MMU to map flash to virtual addresses for code execution.
13+
# The PMP init code runs from IRAM while the main rom region is in flash.
14+
# Locked PMP entries would block IRAM execution before proper coverage is set.
15+
# Use unlocked entries with MPRV-based enforcement instead.
16+
config PMP_NO_LOCK_GLOBAL
17+
default y
18+
919
config FLASH_SIZE
1020
default $(dt_node_reg_size_int,/soc/flash-controller@60002000/flash@0,0)
1121

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/arch/riscv/csr.h>
9+
#include <zephyr/devicetree.h>
10+
#include <pmp.h>
11+
12+
/*
13+
* ESP32-C6 SoC ROM region.
14+
*
15+
* The ESP32-C6 has a ROM at 0x40000000 containing libc and other utility
16+
* functions. This region needs to be accessible (R+X) from both kernel
17+
* and user mode for proper operation.
18+
*/
19+
#define SOC_ROM_NODE DT_NODELABEL(soc_rom)
20+
21+
PMP_SOC_REGION_DEFINE(esp32c6_soc_rom,
22+
DT_REG_ADDR(SOC_ROM_NODE),
23+
DT_REG_ADDR(SOC_ROM_NODE) + DT_REG_SIZE(SOC_ROM_NODE),
24+
PMP_R | PMP_X);
25+
26+
/*
27+
* ESP32-C6 IRAM text region.
28+
*
29+
* On ESP32-C6, IRAM and DRAM share the same 512KB physical memory space
30+
* (0x40800000-0x40880000). The split between code (IRAM) and data (DRAM)
31+
* is determined at link time. Only the IRAM text portion should be
32+
* executable to maintain security - making the entire region executable
33+
* would allow code execution from the data area.
34+
*
35+
* The linker symbols _iram_text_start and _iram_text_end define the
36+
* actual IRAM text boundaries.
37+
*/
38+
extern char _iram_text_start[];
39+
extern char _iram_text_end[];
40+
41+
PMP_SOC_REGION_DEFINE(esp32c6_iram_text, _iram_text_start, _iram_text_end, PMP_R | PMP_X);

0 commit comments

Comments
 (0)