diff --git a/components/esp_hw_support/cpu.c b/components/esp_hw_support/cpu.c index fb67935002..ee4c722cd2 100644 --- a/components/esp_hw_support/cpu.c +++ b/components/esp_hw_support/cpu.c @@ -395,11 +395,13 @@ extern int _data_start; #define CONDITIONAL_NONE 0x0 #define CONDITIONAL_RX PMP_R | PMP_X #define CONDITIONAL_RW PMP_R | PMP_W +#define CONDITIONAL_RWX PMP_R | PMP_W | PMP_X #else // With L bit set #define CONDITIONAL_NONE NONE #define CONDITIONAL_RX RX #define CONDITIONAL_RW RW +#define CONDITIONAL_RWX RWX #endif void esp_cpu_configure_region_protection(void) @@ -466,7 +468,12 @@ void esp_cpu_configure_region_protection(void) } else { // 1. IRAM PMP_ENTRY_SET(0, SOC_DIRAM_IRAM_LOW, CONDITIONAL_NONE); + +#if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT PMP_ENTRY_SET(1, IRAM_END, PMP_TOR | CONDITIONAL_RX); +#else + PMP_ENTRY_SET(1, IRAM_END, PMP_TOR | CONDITIONAL_RWX); +#endif // 2. DRAM PMP_ENTRY_SET(2, DRAM_START, CONDITIONAL_NONE); diff --git a/components/heap/test/test_diram.c b/components/heap/test/test_diram.c index f31aecb673..c3db5e7c81 100644 --- a/components/heap/test/test_diram.c +++ b/components/heap/test/test_diram.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* Tests for D/IRAM support in heap capability allocator */ @@ -10,8 +15,7 @@ #define ALLOC_SZ 1024 -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5167 +#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE static void *malloc_block_diram(uint32_t caps) { void *attempts[256] = { 0 }; // Allocate up to 256 ALLOC_SZ blocks to exhaust all non-D/IRAM memory temporarily @@ -74,4 +78,4 @@ TEST_CASE("Allocate D/IRAM as IRAM", "[heap]") free(iram); } -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) +#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE diff --git a/components/heap/test/test_malloc_caps.c b/components/heap/test/test_malloc_caps.c index 0010327441..e87662ae24 100644 --- a/components/heap/test/test_malloc_caps.c +++ b/components/heap/test/test_malloc_caps.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* Tests for the capabilities-based memory allocator. */ @@ -13,9 +18,6 @@ #include #include - -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5167 #ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE TEST_CASE("Capabilities allocator test", "[heap]") { @@ -106,8 +108,7 @@ TEST_CASE("Capabilities allocator test", "[heap]") free(m1); printf("Done.\n"); } -#endif -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) +#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE #ifdef CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY TEST_CASE("IRAM_8BIT capability test", "[heap]") @@ -170,11 +171,10 @@ TEST_CASE("heap_caps metadata test", "[heap]") TEST_ASSERT(after.minimum_free_bytes < original.total_free_bytes); } -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5167 /* Small function runs from IRAM to check that malloc/free/realloc all work OK when cache is disabled... */ +#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE static IRAM_ATTR __attribute__((noinline)) bool iram_malloc_test(void) { spi_flash_guard_get()->start(); // Disables flash cache @@ -196,7 +196,7 @@ TEST_CASE("heap_caps_xxx functions work with flash cache disabled", "[heap]") { TEST_ASSERT( iram_malloc_test() ); } -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) +#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE #ifdef CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS TEST_CASE("When enabled, allocation operation failure generates an abort", "[heap][reset=abort,SW_CPU_RESET]") diff --git a/components/heap/test/test_realloc.c b/components/heap/test/test_realloc.c index c106c57f19..9a25d4fbfa 100644 --- a/components/heap/test/test_realloc.c +++ b/components/heap/test/test_realloc.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* Generic test for realloc */ @@ -23,8 +28,6 @@ TEST_CASE("realloc shrink buffer in place", "[heap]") #endif -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5167 #ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE TEST_CASE("realloc shrink buffer with EXEC CAPS", "[heap]") { @@ -64,5 +67,4 @@ TEST_CASE("realloc move data to a new heap type", "[heap]") free(c); } -#endif -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) +#endif // CONFIG_ESP_SYSTEM_MEMPROT_FEATURE diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index c55f336cdb..6db0ab75d0 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -787,12 +787,9 @@ components/heap/include/esp_heap_trace.h components/heap/include/heap_memory_layout.h components/heap/test/test_aligned_alloc_caps.c components/heap/test/test_allocator_timings.c -components/heap/test/test_diram.c components/heap/test/test_heap_trace.c components/heap/test/test_leak.c components/heap/test/test_malloc.c -components/heap/test/test_malloc_caps.c -components/heap/test/test_realloc.c components/heap/test/test_runtime_heap_reg.c components/heap/test_multi_heap_host/main.cpp components/heap/test_multi_heap_host/test_multi_heap.cpp diff --git a/tools/unit-test-app/configs/default_3_c2 b/tools/unit-test-app/configs/default_3_c2 index af8e5fbf11..b978fc45ac 100644 --- a/tools/unit-test-app/configs/default_3_c2 +++ b/tools/unit-test-app/configs/default_3_c2 @@ -1,3 +1,4 @@ # This config is split between targets since different component needs to be included CONFIG_IDF_TARGET="esp32c2" TEST_EXCLUDE_COMPONENTS=app_trace bootloader_support console efuse esp_common esp_eth esp_event esp_hid esp_http_client esp_http_server esp_netif esp_phy esp_ringbuf esp_rom esp_wifi espcoredump hal lwip mbedtls mdns mqtt newlib nvs_flash partition_table protocomm sdmmc spiffs freertos esp_hw_support esp_ipc esp_system esp_timer driver heap pthread soc spi_flash vfs +CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT=n # for c2 this config must be disabled for certain tests diff --git a/tools/unit-test-app/configs/default_c2 b/tools/unit-test-app/configs/default_c2 index d99387e17e..5bdd529e6a 100644 --- a/tools/unit-test-app/configs/default_c2 +++ b/tools/unit-test-app/configs/default_c2 @@ -1,3 +1,4 @@ # This config is split between targets since different component needs to be included CONFIG_IDF_TARGET="esp32c2" TEST_COMPONENTS=freertos esp_hw_support esp_ipc esp_system esp_timer driver heap pthread soc spi_flash vfs +CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT=n # for c2 this config must be disabled for certain tests diff --git a/tools/unit-test-app/configs/heap_light_poison_c2 b/tools/unit-test-app/configs/heap_light_poison_c2 index 1c165b4765..4b95d36384 100644 --- a/tools/unit-test-app/configs/heap_light_poison_c2 +++ b/tools/unit-test-app/configs/heap_light_poison_c2 @@ -2,3 +2,4 @@ CONFIG_IDF_TARGET="esp32c2" TEST_COMPONENTS=heap CONFIG_HEAP_POISONING_COMPREHENSIVE=n CONFIG_HEAP_POISONING_LIGHT=y +CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT=n # for c2 this config must be disabled for certain tests diff --git a/tools/unit-test-app/configs/release_c2 b/tools/unit-test-app/configs/release_c2 index 820ad4f26e..5348110bb5 100644 --- a/tools/unit-test-app/configs/release_c2 +++ b/tools/unit-test-app/configs/release_c2 @@ -3,3 +3,4 @@ TEST_COMPONENTS=freertos esp_hw_support esp_system esp_ipc esp_timer driver heap CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT=n # for c2 this config must be disabled for certain tests