2021-06-02 10:34:38 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2020-03-10 11:46:10 -04:00
|
|
|
|
|
|
|
/* INTERNAL API
|
|
|
|
* implementation of generic interface to MMU memory protection features
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "soc/sensitive_reg.h"
|
|
|
|
#include "soc/periph_defs.h"
|
|
|
|
#include "esp_intr_alloc.h"
|
|
|
|
#include "hal/memprot_ll.h"
|
2020-10-07 23:19:23 -04:00
|
|
|
#include "hal/memprot_peri_ll.h"
|
2021-08-18 07:31:35 -04:00
|
|
|
#include "esp32s2/memprot.h"
|
2020-03-10 11:46:10 -04:00
|
|
|
#include "esp_fault.h"
|
2021-12-13 23:38:15 -05:00
|
|
|
#include "esp_cpu.h"
|
2022-01-17 04:44:25 -05:00
|
|
|
#include "esp_rom_sys.h"
|
2020-03-10 11:46:10 -04:00
|
|
|
|
|
|
|
extern int _iram_text_end;
|
|
|
|
extern int _data_start;
|
2020-10-07 23:19:23 -04:00
|
|
|
extern int _rtc_text_end;
|
|
|
|
extern int _rtc_dummy_end;
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2022-07-05 15:01:45 -04:00
|
|
|
static inline esp_err_t esp_memprot_ll_err_to_esp_err(memprot_hal_err_t err)
|
2021-08-18 07:31:35 -04:00
|
|
|
{
|
|
|
|
switch (err) {
|
2022-07-05 15:01:45 -04:00
|
|
|
case MEMP_HAL_OK: return ESP_OK;
|
|
|
|
case MEMP_HAL_FAIL: return ESP_FAIL;
|
|
|
|
case MEMP_HAL_ERR_SPLIT_ADDR_INVALID: return ESP_ERR_INVALID_STATE;
|
|
|
|
case MEMP_HAL_ERR_SPLIT_ADDR_UNALIGNED: return ESP_ERR_INVALID_SIZE;
|
|
|
|
case MEMP_HAL_ERR_UNI_BLOCK_INVALID: return ESP_ERR_NOT_FOUND;
|
2021-08-18 07:31:35 -04:00
|
|
|
default:
|
|
|
|
return ESP_FAIL;
|
|
|
|
}
|
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
uint32_t *esp_memprot_iram0_sram_get_min_split_addr(void)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
|
|
|
return (uint32_t *)&_iram_text_end;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
uint32_t *esp_memprot_iram0_rtcfast_get_min_split_addr(void)
|
|
|
|
{
|
|
|
|
return (uint32_t *)&_rtc_text_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *esp_memprot_dram0_sram_get_min_split_addr(void)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
|
|
|
return (uint32_t *)&_data_start;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
uint32_t *esp_memprot_dram0_rtcfast_get_min_split_addr(void)
|
|
|
|
{
|
|
|
|
return (uint32_t *)&_rtc_dummy_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *esp_memprot_peri1_rtcslow_get_min_split_addr(void)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
return (uint32_t *)PERI1_RTCSLOW_ADDRESS_BASE;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *esp_memprot_peri2_rtcslow_0_get_min_split_addr(void)
|
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
return (uint32_t *)PERI2_RTCSLOW_0_ADDRESS_BASE;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *esp_memprot_peri2_rtcslow_1_get_min_split_addr(void)
|
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
return (uint32_t *)PERI2_RTCSLOW_1_ADDRESS_BASE;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
uint32_t *esp_memprot_get_split_addr(mem_type_prot_t mem_type)
|
|
|
|
{
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
return esp_memprot_iram0_sram_get_min_split_addr();
|
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
return esp_memprot_dram0_sram_get_min_split_addr();
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
|
|
|
return esp_memprot_iram0_rtcfast_get_min_split_addr();
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
|
|
|
return esp_memprot_dram0_rtcfast_get_min_split_addr();
|
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
|
|
|
return esp_memprot_peri1_rtcslow_get_min_split_addr();
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
return esp_memprot_peri2_rtcslow_0_get_min_split_addr();
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
|
|
|
return esp_memprot_peri2_rtcslow_1_get_min_split_addr();
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return (uint32_t *)MEMPROT_INVALID_ADDRESS;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *esp_memprot_type_to_str(mem_type_prot_t mem_type)
|
|
|
|
{
|
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
return "IRAM0_SRAM";
|
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
return "DRAM0_SRAM";
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
|
|
|
return "IRAM0_RTCFAST";
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
|
|
|
return "DRAM0_RTCFAST";
|
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
|
|
|
return "PERI1_RTCSLOW";
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
return "PERI2_RTCSLOW_0";
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
|
|
|
return "PERI2_RTCSLOW_1";
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return "INVALID_MEM_TYPE";
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_intr_init(mem_type_prot_t mem_type)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
|
|
|
ESP_INTR_DISABLE(ETS_MEMACCESS_ERR_INUM);
|
|
|
|
|
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2022-01-17 04:44:25 -05:00
|
|
|
esp_rom_route_intr_matrix(PRO_CPU_NUM, memprot_ll_iram0_get_intr_source_num(), ETS_MEMACCESS_ERR_INUM);
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2022-01-17 04:44:25 -05:00
|
|
|
esp_rom_route_intr_matrix(PRO_CPU_NUM, memprot_ll_dram0_get_intr_source_num(), ETS_MEMACCESS_ERR_INUM);
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2022-01-17 04:44:25 -05:00
|
|
|
esp_rom_route_intr_matrix(PRO_CPU_NUM, memprot_ll_peri1_get_intr_source_num(), ETS_MEMACCESS_ERR_INUM);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2022-01-17 04:44:25 -05:00
|
|
|
esp_rom_route_intr_matrix(PRO_CPU_NUM, memprot_ll_peri2_get_intr_source_num(), ETS_MEMACCESS_ERR_INUM);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ESP_INTR_ENABLE(ETS_MEMACCESS_ERR_INUM);
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_intr_ena(mem_type_prot_t mem_type, bool enable)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_intr_ena(enable);
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_intr_ena(enable);
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri1_intr_ena(enable);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_intr_ena(enable);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
mem_type_prot_t esp_memprot_get_active_intr_memtype()
|
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (memprot_ll_iram0_sram_is_intr_mine()) {
|
2020-10-07 23:19:23 -04:00
|
|
|
return MEMPROT_IRAM0_SRAM;
|
2021-08-18 07:31:35 -04:00
|
|
|
} else if (memprot_ll_iram0_rtcfast_is_intr_mine()) {
|
2020-10-07 23:19:23 -04:00
|
|
|
return MEMPROT_IRAM0_RTCFAST;
|
2021-08-18 07:31:35 -04:00
|
|
|
} else if (memprot_ll_dram0_sram_is_intr_mine()) {
|
2020-10-07 23:19:23 -04:00
|
|
|
return MEMPROT_DRAM0_SRAM;
|
2021-08-18 07:31:35 -04:00
|
|
|
} else if (memprot_ll_dram0_rtcfast_is_intr_mine()) {
|
2020-10-07 23:19:23 -04:00
|
|
|
return MEMPROT_DRAM0_RTCFAST;
|
2021-08-18 07:31:35 -04:00
|
|
|
} else if (memprot_ll_peri1_rtcslow_is_intr_mine()) {
|
2020-10-07 23:19:23 -04:00
|
|
|
return MEMPROT_PERI1_RTCSLOW;
|
2021-08-18 07:31:35 -04:00
|
|
|
} else if (memprot_ll_peri2_rtcslow_0_is_intr_mine()) {
|
2020-10-07 23:19:23 -04:00
|
|
|
return MEMPROT_PERI2_RTCSLOW_0;
|
2021-08-18 07:31:35 -04:00
|
|
|
} else if (memprot_ll_peri2_rtcslow_1_is_intr_mine()) {
|
2020-10-07 23:19:23 -04:00
|
|
|
return MEMPROT_PERI2_RTCSLOW_1;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
return MEMPROT_NONE;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_clear_intr(mem_type_prot_t mem_type)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_clear_intr();
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_clear_intr();
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri1_clear_intr();
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_clear_intr();
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_lock(mem_type_prot_t mem_type)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_set_lock();
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_set_lock();
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri1_set_lock();
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_set_lock();
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_lock(mem_type_prot_t mem_type, bool *locked)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (locked == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*locked = memprot_ll_iram0_get_lock_bit() > 0;
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*locked = memprot_ll_dram0_get_lock_bit() > 0;
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
*locked = memprot_ll_peri1_get_lock_bit() > 0;
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
*locked = memprot_ll_peri2_get_lock_bit() > 0;
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool esp_memprot_is_locked_any()
|
|
|
|
{
|
2020-10-07 23:19:23 -04:00
|
|
|
return
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_get_lock_bit() > 0 ||
|
|
|
|
memprot_ll_dram0_get_lock_bit() > 0 ||
|
|
|
|
memprot_ll_peri1_get_lock_bit() > 0 ||
|
|
|
|
memprot_ll_peri2_get_lock_bit() > 0;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_conf_reg(mem_type_prot_t mem_type, uint32_t *conf_reg_val)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (conf_reg_val == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*conf_reg_val = memprot_ll_iram0_get_conf_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*conf_reg_val = memprot_ll_dram0_get_conf_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
*conf_reg_val = memprot_ll_peri1_rtcslow_get_conf_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
2021-08-18 07:31:35 -04:00
|
|
|
*conf_reg_val = memprot_ll_peri2_rtcslow_0_get_conf_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
*conf_reg_val = memprot_ll_peri2_rtcslow_1_get_conf_reg();
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_fault_reg(mem_type_prot_t mem_type, uint32_t *fault_reg_val)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (fault_reg_val == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*fault_reg_val = memprot_ll_iram0_get_fault_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*fault_reg_val = memprot_ll_dram0_get_fault_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
*fault_reg_val = memprot_ll_peri1_get_fault_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
*fault_reg_val = memprot_ll_peri2_get_fault_reg();
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_fault_status(mem_type_prot_t mem_type, uint32_t **faulting_address, uint32_t *op_type, uint32_t *op_subtype)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (*faulting_address == NULL || op_type == NULL || op_subtype == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
*faulting_address = (uint32_t *)memprot_ll_iram0_sram_get_fault_address();
|
|
|
|
memprot_ll_iram0_get_fault_op_type(op_type, op_subtype);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*faulting_address = (uint32_t *)memprot_ll_iram0_rtcfast_get_fault_address();
|
|
|
|
memprot_ll_iram0_get_fault_op_type(op_type, op_subtype);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
*faulting_address = (uint32_t *)memprot_ll_dram0_sram_get_fault_address();
|
|
|
|
memprot_ll_dram0_get_fault_op_type(op_type, op_subtype);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*faulting_address = (uint32_t *)memprot_ll_dram0_rtcfast_get_fault_address();
|
|
|
|
memprot_ll_dram0_get_fault_op_type(op_type, op_subtype);
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
*faulting_address = (uint32_t *)memprot_ll_peri1_rtcslow_get_fault_address();
|
|
|
|
memprot_ll_peri1_get_fault_op_type(op_type, op_subtype);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
*faulting_address = (uint32_t *)memprot_ll_peri2_rtcslow_get_fault_address();
|
|
|
|
memprot_ll_peri2_get_fault_op_type(op_type, op_subtype);
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2020-10-07 23:19:23 -04:00
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool esp_memprot_is_intr_ena_any()
|
|
|
|
{
|
2020-10-07 23:19:23 -04:00
|
|
|
return
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_get_intr_ena_bit() > 0 ||
|
|
|
|
memprot_ll_dram0_get_intr_ena_bit() > 0 ||
|
|
|
|
memprot_ll_peri1_get_intr_ena_bit() > 0 ||
|
|
|
|
memprot_ll_peri2_get_intr_ena_bit() > 0;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_intr_ena_bit(mem_type_prot_t mem_type, uint32_t *enable_bit)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (enable_bit == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*enable_bit = memprot_ll_iram0_get_intr_ena_bit();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*enable_bit = memprot_ll_dram0_get_intr_ena_bit();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
*enable_bit = memprot_ll_peri1_get_intr_ena_bit();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
*enable_bit = memprot_ll_peri2_get_intr_ena_bit();
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_intr_on_bit(mem_type_prot_t mem_type, uint32_t *intr_on_bit)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (intr_on_bit == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*intr_on_bit = memprot_ll_iram0_get_intr_on_bit();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*intr_on_bit = memprot_ll_dram0_get_intr_on_bit();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
*intr_on_bit = memprot_ll_peri1_get_intr_on_bit();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
*intr_on_bit = memprot_ll_peri2_get_intr_on_bit();
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_intr_clr_bit(mem_type_prot_t mem_type, uint32_t *clear_bit)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (clear_bit == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*clear_bit = memprot_ll_iram0_get_intr_clr_bit();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*clear_bit = memprot_ll_dram0_get_intr_clr_bit();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
*clear_bit = memprot_ll_peri1_get_intr_clr_bit();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
*clear_bit = memprot_ll_peri2_get_intr_clr_bit();
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_uni_block_read_bit(mem_type_prot_t mem_type, uint32_t block, uint32_t *read_bit)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (read_bit == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t ret = ESP_OK;
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
if (!memprot_ll_iram0_sram_get_uni_block_read_bit(block, read_bit)) {
|
|
|
|
ret = ESP_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
if (!memprot_ll_dram0_sram_get_uni_block_read_bit(block, read_bit)) {
|
|
|
|
ret = ESP_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
ret = ESP_ERR_NOT_SUPPORTED;
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ret;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_uni_block_write_bit(mem_type_prot_t mem_type, uint32_t block, uint32_t *write_bit)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (write_bit == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t ret = ESP_OK;
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
if (!memprot_ll_iram0_sram_get_uni_block_write_bit(block, write_bit)) {
|
|
|
|
ret = ESP_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
if (!memprot_ll_dram0_sram_get_uni_block_write_bit(block, write_bit)) {
|
|
|
|
ret = ESP_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
ret = ESP_ERR_NOT_SUPPORTED;
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ret;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_uni_block_exec_bit(mem_type_prot_t mem_type, uint32_t block, uint32_t *exec_bit)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (exec_bit == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
if (!memprot_ll_iram0_sram_get_uni_block_exec_bit(block, exec_bit)) {
|
|
|
|
return ESP_ERR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_uni_block_perm_dram(mem_type_prot_t mem_type, uint32_t block, bool write_perm, bool read_perm)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
return esp_memprot_ll_err_to_esp_err(memprot_ll_dram0_sram_set_uni_block_perm(block, write_perm, read_perm));
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_perm_uni_reg(mem_type_prot_t mem_type, uint32_t *perm_reg)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (perm_reg == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
*perm_reg = memprot_ll_iram0_sram_get_perm_uni_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
*perm_reg = memprot_ll_dram0_sram_get_perm_reg();
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_perm_split_reg(mem_type_prot_t mem_type, uint32_t *split_reg)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (split_reg == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
*split_reg = memprot_ll_iram0_sram_get_perm_split_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*split_reg = memprot_ll_iram0_rtcfast_get_perm_split_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
*split_reg = memprot_ll_dram0_sram_get_perm_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
*split_reg = memprot_ll_dram0_rtcfast_get_perm_split_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
*split_reg = memprot_ll_peri1_rtcslow_get_conf_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
2021-08-18 07:31:35 -04:00
|
|
|
*split_reg = memprot_ll_peri2_rtcslow_0_get_conf_reg();
|
|
|
|
break;
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
*split_reg = memprot_ll_peri2_rtcslow_1_get_conf_reg();
|
|
|
|
break;
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_prot_dram(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool hw, bool hr)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
return esp_memprot_ll_err_to_esp_err(memprot_ll_dram0_sram_set_prot(split_addr != NULL ? split_addr : esp_memprot_dram0_sram_get_min_split_addr(), lw, lr, hw, hr));
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
return esp_memprot_ll_err_to_esp_err(memprot_ll_dram0_rtcfast_set_prot(split_addr != NULL ? split_addr : esp_memprot_dram0_rtcfast_get_min_split_addr(), lw, lr, hw, hr));
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_uni_block_perm_iram(mem_type_prot_t mem_type, uint32_t block, bool write_perm, bool read_perm, bool exec_perm)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2020-10-07 23:19:23 -04:00
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
if (!memprot_ll_iram0_sram_set_uni_block_perm(block, write_perm, read_perm, exec_perm)) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_prot_iram(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool lx, bool hw, bool hr, bool hx)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
return esp_memprot_ll_err_to_esp_err(memprot_ll_iram0_sram_set_prot(split_addr != NULL ? split_addr : esp_memprot_iram0_sram_get_min_split_addr(), lw, lr, lx, hw, hr, hx));
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
return esp_memprot_ll_err_to_esp_err(memprot_ll_iram0_rtcfast_set_prot(split_addr != NULL ? split_addr : esp_memprot_iram0_rtcfast_get_min_split_addr(), lw, lr, lx, hw, hr, hx));
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_perm_split_bits_iram(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *lx, bool *hw, bool *hr, bool *hx)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (lw == NULL || lr == NULL || lx == NULL || hw == NULL || hr == NULL || hx == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_sram_get_split_sgnf_bits(lw, lr, lx, hw, hr, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_rtcfast_get_split_sgnf_bits(lw, lr, lx, hw, hr, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_perm_split_bits_dram(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *hw, bool *hr)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (lw == NULL || lr == NULL || hw == NULL || hr == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_sram_get_split_sgnf_bits(lw, lr, hw, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_rtcfast_get_split_sgnf_bits(lw, lr, hw, hr);
|
2020-03-10 11:46:10 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_perm_split_bits_peri1(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *hw, bool *hr)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (lw == NULL || lr == NULL || hw == NULL || hr == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri1_rtcslow_get_split_sgnf_bits(lw, lr, hw, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_prot_peri1(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool hw, bool hr)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
return esp_memprot_ll_err_to_esp_err(
|
|
|
|
memprot_ll_peri1_rtcslow_set_prot(
|
|
|
|
split_addr != NULL ? split_addr : esp_memprot_peri1_rtcslow_get_min_split_addr(),
|
|
|
|
lw,
|
|
|
|
lr,
|
|
|
|
hw,
|
|
|
|
hr)
|
|
|
|
);
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_perm_split_bits_peri2(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *lx, bool *hw, bool *hr, bool *hx)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (lw == NULL || lr == NULL || lx == NULL || hw == NULL || hr == NULL || hx == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_0_get_split_sgnf_bits(lw, lr, lx, hw, hr, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_1_get_split_sgnf_bits(lw, lr, lx, hw, hr, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_prot_peri2(mem_type_prot_t mem_type, uint32_t *split_addr, bool lw, bool lr, bool lx, bool hw, bool hr, bool hx)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
2020-03-10 11:46:10 -04:00
|
|
|
switch (mem_type) {
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
2021-08-18 07:31:35 -04:00
|
|
|
return esp_memprot_ll_err_to_esp_err(
|
|
|
|
memprot_ll_peri2_rtcslow_0_set_prot(
|
|
|
|
split_addr != NULL ? split_addr : esp_memprot_peri2_rtcslow_0_get_min_split_addr(),
|
|
|
|
lw,
|
|
|
|
lr,
|
|
|
|
lx,
|
|
|
|
hw,
|
|
|
|
hr,
|
|
|
|
hx)
|
|
|
|
);
|
2020-10-07 23:19:23 -04:00
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
return esp_memprot_ll_err_to_esp_err(
|
|
|
|
memprot_ll_peri2_rtcslow_1_set_prot(
|
|
|
|
split_addr != NULL ? split_addr : esp_memprot_peri2_rtcslow_1_get_min_split_addr(),
|
|
|
|
lw,
|
|
|
|
lr,
|
|
|
|
lx,
|
|
|
|
hw,
|
|
|
|
hr,
|
|
|
|
hx)
|
|
|
|
);
|
2020-03-10 11:46:10 -04:00
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_prot(bool invoke_panic_handler, bool lock_feature, uint32_t *mem_type_mask)
|
2020-03-10 11:46:10 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t ret;
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
//any IRAM0/DRAM0 enable/disable call applies to all memory modules connected
|
|
|
|
uint32_t required_mem_prot = mem_type_mask == NULL ? (uint32_t)MEMPROT_ALL : *mem_type_mask;
|
|
|
|
bool use_iram0 = required_mem_prot & MEMPROT_IRAM0_SRAM || required_mem_prot & MEMPROT_IRAM0_RTCFAST;
|
|
|
|
bool use_dram0 = required_mem_prot & MEMPROT_DRAM0_SRAM || required_mem_prot & MEMPROT_DRAM0_RTCFAST;
|
|
|
|
bool use_peri1 = required_mem_prot & MEMPROT_PERI1_RTCSLOW;
|
|
|
|
bool use_peri2 = required_mem_prot & MEMPROT_PERI2_RTCSLOW_0 || required_mem_prot & MEMPROT_PERI2_RTCSLOW_1;
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
//disable protection
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_iram0 && (ret = esp_memprot_intr_ena(MEMPROT_IRAM0_SRAM, false)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_dram0 && (ret = esp_memprot_intr_ena(MEMPROT_DRAM0_SRAM, false)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_peri1 && (ret = esp_memprot_intr_ena(MEMPROT_PERI1_RTCSLOW, false)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_peri2 && (ret = esp_memprot_intr_ena(MEMPROT_PERI2_RTCSLOW_0, false)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
2021-10-04 00:37:56 -04:00
|
|
|
//if being debugged check we are not glitched and dont enable Memprot
|
2022-07-19 01:20:07 -04:00
|
|
|
if (esp_cpu_dbgr_is_attached()) {
|
|
|
|
ESP_FAULT_ASSERT(esp_cpu_dbgr_is_attached());
|
2021-10-04 00:37:56 -04:00
|
|
|
} else {
|
2020-10-07 23:19:23 -04:00
|
|
|
//initialize for specific buses (any memory type does the job)
|
|
|
|
if (invoke_panic_handler) {
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_iram0 && (ret = esp_memprot_intr_init(MEMPROT_IRAM0_SRAM)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_dram0 && (ret = esp_memprot_intr_init(MEMPROT_DRAM0_SRAM)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_peri1 && (ret = esp_memprot_intr_init(MEMPROT_PERI1_RTCSLOW)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_peri2 && (ret = esp_memprot_intr_init(MEMPROT_PERI2_RTCSLOW_0)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
//set permissions
|
|
|
|
if (required_mem_prot & MEMPROT_IRAM0_SRAM) {
|
2021-08-18 07:31:35 -04:00
|
|
|
ret = esp_memprot_set_prot_iram(MEMPROT_IRAM0_SRAM, DEF_SPLIT_LINE, WR_LOW_DIS, RD_LOW_ENA, EX_LOW_ENA, WR_HIGH_DIS, RD_HIGH_DIS, EX_HIGH_DIS);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
if (required_mem_prot & MEMPROT_IRAM0_RTCFAST) {
|
2021-08-18 07:31:35 -04:00
|
|
|
ret = esp_memprot_set_prot_iram(MEMPROT_IRAM0_RTCFAST, DEF_SPLIT_LINE, WR_LOW_DIS, RD_LOW_ENA, EX_LOW_ENA, WR_HIGH_DIS, RD_HIGH_DIS, EX_HIGH_DIS);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
if (required_mem_prot & MEMPROT_DRAM0_SRAM) {
|
2021-08-18 07:31:35 -04:00
|
|
|
ret = esp_memprot_set_prot_dram(MEMPROT_DRAM0_SRAM, DEF_SPLIT_LINE, WR_LOW_DIS, RD_LOW_ENA, WR_HIGH_ENA, RD_HIGH_ENA);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
if (required_mem_prot & MEMPROT_DRAM0_RTCFAST) {
|
2021-08-18 07:31:35 -04:00
|
|
|
ret = esp_memprot_set_prot_dram(MEMPROT_DRAM0_RTCFAST, DEF_SPLIT_LINE, WR_LOW_DIS, RD_LOW_ENA, WR_HIGH_ENA, RD_HIGH_ENA);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
if (required_mem_prot & MEMPROT_PERI1_RTCSLOW) {
|
2021-08-18 07:31:35 -04:00
|
|
|
ret = esp_memprot_set_prot_peri1(MEMPROT_PERI1_RTCSLOW, DEF_SPLIT_LINE, WR_LOW_DIS, RD_LOW_DIS, WR_HIGH_DIS, RD_HIGH_DIS);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
if (required_mem_prot & MEMPROT_PERI2_RTCSLOW_0) {
|
2021-08-18 07:31:35 -04:00
|
|
|
ret = esp_memprot_set_prot_peri2(MEMPROT_PERI2_RTCSLOW_0, DEF_SPLIT_LINE, WR_LOW_ENA, RD_LOW_ENA, EX_LOW_DIS, WR_HIGH_ENA, RD_HIGH_ENA, EX_HIGH_DIS);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
if (required_mem_prot & MEMPROT_PERI2_RTCSLOW_1) {
|
2021-08-18 07:31:35 -04:00
|
|
|
ret = esp_memprot_set_prot_peri2(MEMPROT_PERI2_RTCSLOW_1, DEF_SPLIT_LINE, WR_LOW_DIS, RD_LOW_DIS, EX_LOW_DIS, WR_HIGH_DIS, RD_HIGH_DIS, EX_HIGH_DIS);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
//reenable protection (bus based)
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_iram0 && (ret = esp_memprot_intr_ena(MEMPROT_IRAM0_SRAM, true)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_dram0 && (ret = esp_memprot_intr_ena(MEMPROT_DRAM0_SRAM, true)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_peri1 && (ret = esp_memprot_intr_ena(MEMPROT_PERI1_RTCSLOW, true)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_peri2 && (ret = esp_memprot_intr_ena(MEMPROT_PERI2_RTCSLOW_0, true)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
//lock if required (bus based)
|
|
|
|
if (lock_feature) {
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_iram0 && (ret = esp_memprot_set_lock(MEMPROT_IRAM0_SRAM)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_dram0 && (ret = esp_memprot_set_lock(MEMPROT_DRAM0_SRAM)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_peri1 && (ret = esp_memprot_set_lock(MEMPROT_PERI1_RTCSLOW)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
if (use_peri2 && (ret = esp_memprot_set_lock(MEMPROT_PERI2_RTCSLOW_0)) != ESP_OK) {
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-03-10 11:46:10 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_permissions(mem_type_prot_t mem_type, bool *lw, bool *lr, bool *lx, bool *hw, bool *hr, bool *hx)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (lw == NULL || lr == NULL || lx == NULL || hw == NULL || hr == NULL || hx == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-10-07 23:19:23 -04:00
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_sram_get_split_sgnf_bits(lw, lr, lx, hw, hr, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_sram_get_split_sgnf_bits(lw, lr, hw, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_rtcfast_get_split_sgnf_bits(lw, lr, lx, hw, hr, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_rtcfast_get_split_sgnf_bits(lw, lr, hw, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri1_rtcslow_get_split_sgnf_bits(lw, lr, hw, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_0_get_split_sgnf_bits(lw, lr, lx, hw, hr, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_1_get_split_sgnf_bits(lw, lr, lx, hw, hr, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_perm_read(mem_type_prot_t mem_type, bool *lr, bool *hr)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
|
|
|
bool _lw, _lr, _lx, _hw, _hr, _hx;
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t ret = esp_memprot_get_permissions(mem_type, &_lw, &_lr, &_lx, &_hw, &_hr, &_hx);
|
|
|
|
if (ret == ESP_OK) {
|
|
|
|
*lr = _lr;
|
|
|
|
*hr = _hr;
|
|
|
|
}
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_perm_write(mem_type_prot_t mem_type, bool *lw, bool *hw)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
|
|
|
bool _lw, _lr, _lx, _hw, _hr, _hx;
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t ret = esp_memprot_get_permissions(mem_type, &_lw, &_lr, &_lx, &_hw, &_hr, &_hx);
|
|
|
|
if (ret == ESP_OK) {
|
|
|
|
*lw = _lw;
|
|
|
|
*hw = _hw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_get_perm_exec(mem_type_prot_t mem_type, bool *lx, bool *hx)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
2021-08-18 07:31:35 -04:00
|
|
|
if (mem_type == MEMPROT_DRAM0_SRAM ||
|
2020-10-07 23:19:23 -04:00
|
|
|
mem_type == MEMPROT_DRAM0_RTCFAST ||
|
2021-08-18 07:31:35 -04:00
|
|
|
mem_type == MEMPROT_PERI1_RTCSLOW) {
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool _lw, _lr, _lx, _hw, _hr, _hx;
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t ret = esp_memprot_get_permissions(mem_type, &_lw, &_lr, &_lx, &_hw, &_hr, &_hx);
|
|
|
|
if (ret == ESP_OK) {
|
|
|
|
*lx = _lx;
|
|
|
|
*hx = _hx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t esp_memprot_get_low_limit(mem_type_prot_t mem_type)
|
|
|
|
{
|
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
return IRAM0_SRAM_ADDRESS_LOW;
|
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
return DRAM0_SRAM_ADDRESS_LOW;
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
|
|
|
return IRAM0_RTCFAST_ADDRESS_LOW;
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
|
|
|
return DRAM0_RTCFAST_ADDRESS_LOW;
|
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
|
|
|
return PERI1_RTCSLOW_ADDRESS_LOW;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
return PERI2_RTCSLOW_0_ADDRESS_LOW;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
|
|
|
return PERI2_RTCSLOW_1_ADDRESS_LOW;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return MEMPROT_INVALID_ADDRESS;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t esp_memprot_get_high_limit(mem_type_prot_t mem_type)
|
|
|
|
{
|
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_IRAM0_SRAM:
|
|
|
|
return IRAM0_SRAM_ADDRESS_HIGH;
|
|
|
|
case MEMPROT_DRAM0_SRAM:
|
|
|
|
return DRAM0_SRAM_ADDRESS_HIGH;
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
|
|
|
return IRAM0_RTCFAST_ADDRESS_HIGH;
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
|
|
|
return DRAM0_RTCFAST_ADDRESS_HIGH;
|
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
|
|
|
return PERI1_RTCSLOW_ADDRESS_HIGH;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
|
|
|
return PERI2_RTCSLOW_0_ADDRESS_HIGH;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
|
|
|
return PERI2_RTCSLOW_1_ADDRESS_HIGH;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return MEMPROT_INVALID_ADDRESS;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_read_perm(mem_type_prot_t mem_type, bool lr, bool hr)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_sram_set_read_perm(lr, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_sram_set_read_perm(lr, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_rtcfast_set_read_perm(lr, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_rtcfast_set_read_perm(lr, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri1_rtcslow_set_read_perm(lr, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_0_set_read_perm(lr, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_1_set_read_perm(lr, hr);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_write_perm(mem_type_prot_t mem_type, bool lw, bool hw)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_sram_set_write_perm(lw, hw);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_DRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_sram_set_write_perm(lw, hw);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_rtcfast_set_write_perm(lw, hw);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_DRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_dram0_rtcfast_set_write_perm(lw, hw);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI1_RTCSLOW:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri1_rtcslow_set_write_perm(lw, hw);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_0_set_write_perm(lw, hw);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_1_set_write_perm(lw, hw);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t esp_memprot_set_exec_perm(mem_type_prot_t mem_type, bool lx, bool hx)
|
2020-10-07 23:19:23 -04:00
|
|
|
{
|
|
|
|
switch (mem_type) {
|
|
|
|
case MEMPROT_IRAM0_SRAM:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_sram_set_exec_perm(lx, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_IRAM0_RTCFAST:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_iram0_rtcfast_set_exec_perm(lx, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_0:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_0_set_exec_perm(lx, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
case MEMPROT_PERI2_RTCSLOW_1:
|
2021-08-18 07:31:35 -04:00
|
|
|
memprot_ll_peri2_rtcslow_1_set_exec_perm(lx, hx);
|
2020-10-07 23:19:23 -04:00
|
|
|
break;
|
|
|
|
default:
|
2021-08-18 07:31:35 -04:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|
2021-08-18 07:31:35 -04:00
|
|
|
|
|
|
|
return ESP_OK;
|
2020-10-07 23:19:23 -04:00
|
|
|
}
|