2021-09-09 03:34:42 -04:00
|
|
|
/*
|
2024-01-01 22:16:55 -05:00
|
|
|
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
2021-09-09 03:34:42 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2020-03-02 23:22:41 -05:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "esp_attr.h"
|
|
|
|
#include "esp_err.h"
|
|
|
|
|
|
|
|
#include "esp_log.h"
|
2022-01-12 01:53:47 -05:00
|
|
|
#include "esp_chip_info.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2021-11-23 07:11:33 -05:00
|
|
|
#include "esp_private/cache_err_int.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
#include "esp_clk_internal.h"
|
2021-01-26 08:07:22 -05:00
|
|
|
|
|
|
|
#include "esp_rom_uart.h"
|
2020-07-21 01:07:34 -04:00
|
|
|
#include "esp_rom_sys.h"
|
2022-07-04 02:17:54 -04:00
|
|
|
#include "esp_rom_caps.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-11-26 03:56:13 -05:00
|
|
|
#include "soc/dport_reg.h"
|
2020-06-23 04:07:09 -04:00
|
|
|
#include "esp32/rtc.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
#include "esp32/rom/cache.h"
|
2022-05-23 00:36:02 -04:00
|
|
|
#include "esp32/rom/secure_boot.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
2020-06-23 04:07:09 -04:00
|
|
|
#include "esp32s2/rtc.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
#include "esp32s2/rom/cache.h"
|
2022-05-23 00:36:02 -04:00
|
|
|
#include "esp32s2/rom/secure_boot.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
#include "esp32s2/memprot.h"
|
2020-07-29 01:13:51 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
#include "esp32s3/rtc.h"
|
|
|
|
#include "esp32s3/rom/cache.h"
|
2022-05-23 00:36:02 -04:00
|
|
|
#include "esp32s3/rom/secure_boot.h"
|
2021-09-06 04:22:40 -04:00
|
|
|
#include "esp_memprot.h"
|
2020-07-29 01:13:51 -04:00
|
|
|
#include "soc/assist_debug_reg.h"
|
2020-11-26 03:56:13 -05:00
|
|
|
#include "soc/system_reg.h"
|
2021-04-15 05:13:48 -04:00
|
|
|
#include "esp32s3/rom/opi_flash.h"
|
2023-03-08 14:03:53 -05:00
|
|
|
#include "hal/cache_hal.h"
|
2020-11-26 03:56:13 -05:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32C3
|
|
|
|
#include "esp32c3/rtc.h"
|
2021-04-23 06:10:45 -04:00
|
|
|
#include "esp32c3/rom/cache.h"
|
2022-05-23 00:36:02 -04:00
|
|
|
#include "esp32c3/rom/secure_boot.h"
|
2021-09-06 04:22:40 -04:00
|
|
|
#include "esp_memprot.h"
|
2022-07-12 08:42:28 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32C6
|
|
|
|
#include "esp32c6/rtc.h"
|
|
|
|
#include "esp32c6/rom/cache.h"
|
|
|
|
#include "esp_memprot.h"
|
2024-01-01 22:16:55 -05:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32C5
|
|
|
|
#include "esp32c5/rtc.h"
|
|
|
|
#include "esp32c5/rom/cache.h"
|
|
|
|
#include "esp_memprot.h"
|
2022-12-06 00:46:03 -05:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32H2
|
|
|
|
#include "esp32h2/rtc.h"
|
|
|
|
#include "esp32h2/rom/cache.h"
|
|
|
|
#include "esp_memprot.h"
|
2022-01-17 21:32:56 -05:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32C2
|
|
|
|
#include "esp32c2/rtc.h"
|
|
|
|
#include "esp32c2/rom/cache.h"
|
|
|
|
#include "esp32c2/rom/rtc.h"
|
2022-05-23 00:36:02 -04:00
|
|
|
#include "esp32c2/rom/secure_boot.h"
|
2023-07-21 00:36:57 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32P4
|
|
|
|
#include "esp32p4/rtc.h"
|
|
|
|
#include "soc/hp_sys_clkrst_reg.h"
|
2023-10-30 14:18:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SOC_KEY_MANAGER_SUPPORTED
|
|
|
|
#include "hal/key_mgr_hal.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
#endif
|
|
|
|
|
2023-12-22 05:44:51 -05:00
|
|
|
#include "esp_private/rtc_clk.h"
|
|
|
|
#include "esp_private/esp_ldo_psram.h"
|
2023-12-28 21:59:55 -05:00
|
|
|
|
|
|
|
#if SOC_INT_CLIC_SUPPORTED
|
|
|
|
#include "hal/interrupt_clic_ll.h"
|
|
|
|
#endif // SOC_INT_CLIC_SUPPORTED
|
|
|
|
|
2022-11-02 07:11:45 -04:00
|
|
|
#include "esp_private/esp_mmu_map_private.h"
|
2022-05-10 22:32:56 -04:00
|
|
|
#if CONFIG_SPIRAM
|
|
|
|
#include "esp_psram.h"
|
2023-03-06 04:55:16 -05:00
|
|
|
#include "esp_private/mmu_psram_flash.h"
|
2022-05-10 22:32:56 -04:00
|
|
|
#include "esp_private/esp_psram_extram.h"
|
|
|
|
#endif
|
|
|
|
|
2021-09-09 03:34:42 -04:00
|
|
|
#include "esp_private/spi_flash_os.h"
|
2023-01-05 02:24:08 -05:00
|
|
|
#include "esp_private/mspi_timing_tuning.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
#include "bootloader_flash_config.h"
|
2021-05-07 03:25:06 -04:00
|
|
|
#include "bootloader_flash.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
#include "esp_private/crosscore_int.h"
|
|
|
|
#include "esp_flash_encrypt.h"
|
|
|
|
|
2022-10-27 03:09:34 -04:00
|
|
|
#include "esp_private/sleep_gpio.h"
|
2020-07-27 07:50:23 -04:00
|
|
|
#include "hal/wdt_hal.h"
|
2020-07-29 01:13:51 -04:00
|
|
|
#include "soc/rtc.h"
|
2023-03-08 14:03:53 -05:00
|
|
|
#include "hal/cache_ll.h"
|
2021-12-22 09:18:43 -05:00
|
|
|
#include "hal/efuse_ll.h"
|
2020-07-29 01:13:51 -04:00
|
|
|
#include "soc/periph_defs.h"
|
2021-12-13 23:38:15 -05:00
|
|
|
#include "esp_cpu.h"
|
2022-03-25 06:41:25 -04:00
|
|
|
#include "esp_private/esp_clk.h"
|
2022-06-27 03:24:07 -04:00
|
|
|
#include "spi_flash_mmap.h"
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2021-10-22 16:32:36 -04:00
|
|
|
#if CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX || CONFIG_ESP32S3_TRAX
|
2021-11-23 07:11:33 -05:00
|
|
|
#include "esp_private/trax.h"
|
2020-11-05 23:00:07 -05:00
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
|
|
|
#include "bootloader_mem.h"
|
|
|
|
|
2023-01-30 05:03:41 -05:00
|
|
|
#if CONFIG_APP_BUILD_TYPE_RAM
|
2021-09-28 02:12:56 -04:00
|
|
|
#include "esp_rom_spiflash.h"
|
2023-01-30 05:03:41 -05:00
|
|
|
#include "bootloader_init.h"
|
2023-08-26 10:08:23 -04:00
|
|
|
#include "esp_private/bootloader_flash_internal.h"
|
2023-01-30 05:03:41 -05:00
|
|
|
#endif // CONFIG_APP_BUILD_TYPE_RAM
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2022-02-11 02:30:54 -05:00
|
|
|
//This dependency will be removed in the future
|
|
|
|
#include "soc/ext_mem_defs.h"
|
2021-01-26 08:07:22 -05:00
|
|
|
|
2020-02-16 08:29:29 -05:00
|
|
|
#include "esp_private/startup_internal.h"
|
2020-06-23 04:46:06 -04:00
|
|
|
#include "esp_private/system_internal.h"
|
2020-02-13 07:43:23 -05:00
|
|
|
|
2024-02-12 00:51:25 -05:00
|
|
|
#if SOC_MEM_NON_CONTIGUOUS_SRAM
|
|
|
|
extern int _bss_start_low, _bss_start_high;
|
|
|
|
extern int _bss_end_low, _bss_end_high;
|
|
|
|
#else
|
2020-03-02 23:22:41 -05:00
|
|
|
extern int _bss_start;
|
|
|
|
extern int _bss_end;
|
2024-02-12 00:51:25 -05:00
|
|
|
#endif // SOC_MEM_NON_CONTIGUOUS_SRAM
|
2020-03-02 23:22:41 -05:00
|
|
|
extern int _rtc_bss_start;
|
|
|
|
extern int _rtc_bss_end;
|
2023-10-08 04:08:47 -04:00
|
|
|
#if CONFIG_BT_LE_RELEASE_IRAM_SUPPORTED
|
|
|
|
extern int _bss_bt_start;
|
|
|
|
extern int _bss_bt_end;
|
|
|
|
#endif // CONFIG_BT_LE_RELEASE_IRAM_SUPPORTED
|
2023-03-03 05:21:31 -05:00
|
|
|
extern int _instruction_reserved_start;
|
|
|
|
extern int _instruction_reserved_end;
|
|
|
|
extern int _rodata_reserved_start;
|
|
|
|
extern int _rodata_reserved_end;
|
|
|
|
|
2020-12-22 02:41:43 -05:00
|
|
|
extern int _vector_table;
|
2023-07-20 23:54:29 -04:00
|
|
|
#if SOC_INT_CLIC_SUPPORTED
|
|
|
|
extern int _mtvt_table;
|
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
|
|
|
static const char *TAG = "cpu_start";
|
|
|
|
|
|
|
|
#if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
|
|
|
|
extern int _ext_ram_bss_start;
|
|
|
|
extern int _ext_ram_bss_end;
|
|
|
|
#endif
|
2021-08-25 04:06:28 -04:00
|
|
|
|
2020-03-02 23:22:41 -05:00
|
|
|
#ifdef CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY
|
|
|
|
extern int _iram_bss_start;
|
|
|
|
extern int _iram_bss_end;
|
|
|
|
#endif
|
|
|
|
|
2020-02-13 07:43:23 -05:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2020-02-05 09:40:15 -05:00
|
|
|
static volatile bool s_cpu_up[SOC_CPU_CORES_NUM] = { false };
|
|
|
|
static volatile bool s_cpu_inited[SOC_CPU_CORES_NUM] = { false };
|
2020-02-13 07:43:23 -05:00
|
|
|
|
2020-02-05 09:40:15 -05:00
|
|
|
static volatile bool s_resume_cores;
|
2020-02-13 07:43:23 -05:00
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2021-10-14 05:51:00 -04:00
|
|
|
static void core_intr_matrix_clear(void)
|
2021-10-11 11:17:27 -04:00
|
|
|
{
|
2022-07-21 07:24:42 -04:00
|
|
|
uint32_t core_id = esp_cpu_get_core_id();
|
2021-10-11 11:17:27 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < ETS_MAX_INTR_SOURCE; i++) {
|
2023-12-28 21:59:55 -05:00
|
|
|
#if SOC_INT_CLIC_SUPPORTED
|
|
|
|
interrupt_clic_ll_route(core_id, i, ETS_INVALID_INUM);
|
2023-07-20 23:54:29 -04:00
|
|
|
#else
|
2022-01-17 04:44:25 -05:00
|
|
|
esp_rom_route_intr_matrix(core_id, i, ETS_INVALID_INUM);
|
2023-12-28 21:59:55 -05:00
|
|
|
#endif // SOC_INT_CLIC_SUPPORTED
|
2021-10-11 11:17:27 -04:00
|
|
|
}
|
2023-08-14 03:44:24 -04:00
|
|
|
|
|
|
|
#if SOC_INT_CLIC_SUPPORTED
|
|
|
|
for (int i = 0; i < 32; i++) {
|
|
|
|
/* Set all the CPU interrupt lines to vectored by default, as it is on other RISC-V targets */
|
2023-12-28 21:59:55 -05:00
|
|
|
esprv_int_set_vectored(i, true);
|
2023-08-14 03:44:24 -04:00
|
|
|
}
|
|
|
|
#endif // SOC_INT_CLIC_SUPPORTED
|
|
|
|
|
2021-10-11 11:17:27 -04:00
|
|
|
}
|
|
|
|
|
2020-02-13 07:43:23 -05:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2020-02-05 09:40:15 -05:00
|
|
|
void startup_resume_other_cores(void)
|
|
|
|
{
|
|
|
|
s_resume_cores = true;
|
|
|
|
}
|
|
|
|
|
2020-03-02 23:22:41 -05:00
|
|
|
void IRAM_ATTR call_start_cpu1(void)
|
|
|
|
{
|
2023-07-21 00:36:57 -04:00
|
|
|
#ifdef __riscv
|
|
|
|
// Configure the global pointer register
|
|
|
|
// (This should be the first thing IDF app does, as any other piece of code could be
|
|
|
|
// relaxed by the linker to access something relative to __global_pointer$)
|
2024-01-29 20:40:10 -05:00
|
|
|
__asm__ __volatile__(
|
2023-07-21 00:36:57 -04:00
|
|
|
".option push\n"
|
|
|
|
".option norelax\n"
|
|
|
|
"la gp, __global_pointer$\n"
|
|
|
|
".option pop"
|
|
|
|
);
|
|
|
|
#endif //#ifdef __riscv
|
|
|
|
|
2023-07-20 23:51:38 -04:00
|
|
|
#if SOC_BRANCH_PREDICTOR_SUPPORTED
|
|
|
|
esp_cpu_branch_prediction_enable();
|
|
|
|
#endif //#if SOC_BRANCH_PREDICTOR_SUPPORTED
|
|
|
|
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_set_ivt_addr(&_vector_table);
|
2023-07-20 23:54:29 -04:00
|
|
|
#if SOC_INT_CLIC_SUPPORTED
|
2023-09-01 05:18:39 -04:00
|
|
|
/* When hardware vectored interrupts are enabled in CLIC,
|
|
|
|
* the CPU jumps to this base address + 4 * interrupt_id.
|
|
|
|
*/
|
2023-07-20 23:54:29 -04:00
|
|
|
esp_cpu_intr_set_mtvt_addr(&_mtvt_table);
|
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
|
|
|
ets_set_appcpu_boot_addr(0);
|
|
|
|
|
|
|
|
bootloader_init_mem();
|
|
|
|
|
2022-03-15 04:28:53 -04:00
|
|
|
#if CONFIG_ESP_CONSOLE_NONE
|
2020-07-29 01:13:51 -04:00
|
|
|
esp_rom_install_channel_putc(1, NULL);
|
|
|
|
esp_rom_install_channel_putc(2, NULL);
|
2022-03-15 04:28:53 -04:00
|
|
|
#else // CONFIG_ESP_CONSOLE_NONE
|
2020-12-01 22:43:13 -05:00
|
|
|
esp_rom_install_uart_printf();
|
2024-01-17 04:19:49 -05:00
|
|
|
esp_rom_output_set_as_console(CONFIG_ESP_CONSOLE_ROM_SERIAL_PORT_NUM);
|
2020-03-02 23:22:41 -05:00
|
|
|
#endif
|
|
|
|
|
2020-07-29 01:13:51 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-02-05 09:40:15 -05:00
|
|
|
DPORT_REG_SET_BIT(DPORT_APP_CPU_RECORD_CTRL_REG, DPORT_APP_CPU_PDEBUG_ENABLE | DPORT_APP_CPU_RECORD_ENABLE);
|
|
|
|
DPORT_REG_CLR_BIT(DPORT_APP_CPU_RECORD_CTRL_REG, DPORT_APP_CPU_RECORD_ENABLE);
|
2023-07-21 00:36:57 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32P4
|
|
|
|
//TODO: IDF-7688
|
2020-07-29 01:13:51 -04:00
|
|
|
#else
|
|
|
|
REG_WRITE(ASSIST_DEBUG_CORE_1_RCD_PDEBUGENABLE_REG, 1);
|
|
|
|
REG_WRITE(ASSIST_DEBUG_CORE_1_RCD_RECORDING_REG, 1);
|
|
|
|
#endif
|
2020-02-05 09:40:15 -05:00
|
|
|
|
|
|
|
s_cpu_up[1] = true;
|
2023-09-15 11:10:41 -04:00
|
|
|
ESP_EARLY_LOGD(TAG, "App cpu up");
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2021-10-11 11:17:27 -04:00
|
|
|
// Clear interrupt matrix for APP CPU core
|
2021-10-14 05:51:00 -04:00
|
|
|
core_intr_matrix_clear();
|
2021-10-11 11:17:27 -04:00
|
|
|
|
2023-01-30 05:03:41 -05:00
|
|
|
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
2020-03-02 23:22:41 -05:00
|
|
|
//Take care putting stuff here: if asked, FreeRTOS will happily tell you the scheduler
|
|
|
|
//has started, but it isn't active *on this CPU* yet.
|
|
|
|
esp_cache_err_int_init();
|
2023-01-30 05:03:41 -05:00
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2021-10-22 16:32:36 -04:00
|
|
|
#if (CONFIG_IDF_TARGET_ESP32 && CONFIG_ESP32_TRAX_TWOBANKS) || \
|
|
|
|
(CONFIG_IDF_TARGET_ESP32S3 && CONFIG_ESP32S3_TRAX_TWOBANKS)
|
2020-03-02 23:22:41 -05:00
|
|
|
trax_start_trace(TRAX_DOWNCOUNT_WORDS);
|
|
|
|
#endif
|
|
|
|
|
2020-02-05 09:40:15 -05:00
|
|
|
s_cpu_inited[1] = true;
|
|
|
|
|
2020-06-08 20:17:48 -04:00
|
|
|
while (!s_resume_cores) {
|
2020-07-21 01:07:34 -04:00
|
|
|
esp_rom_delay_us(100);
|
2020-02-05 09:40:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SYS_STARTUP_FN();
|
2020-03-02 23:22:41 -05:00
|
|
|
}
|
2020-02-13 07:43:23 -05:00
|
|
|
|
|
|
|
static void start_other_core(void)
|
|
|
|
{
|
2020-10-05 06:50:09 -04:00
|
|
|
esp_chip_info_t chip_info;
|
|
|
|
esp_chip_info(&chip_info);
|
|
|
|
|
|
|
|
// If not the single core variant of a target - check this since there is
|
2020-02-13 07:43:23 -05:00
|
|
|
// no separate soc_caps.h for the single core variant.
|
2020-10-05 06:50:09 -04:00
|
|
|
if (!(chip_info.cores > 1)) {
|
|
|
|
ESP_EARLY_LOGE(TAG, "Running on single core variant of a chip, but app is built with multi-core support.");
|
|
|
|
ESP_EARLY_LOGE(TAG, "Check that CONFIG_FREERTOS_UNICORE is enabled in menuconfig");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2023-09-15 11:10:41 -04:00
|
|
|
ESP_EARLY_LOGD(TAG, "Starting app cpu, entry point is %p", call_start_cpu1);
|
2020-02-13 07:43:23 -05:00
|
|
|
|
2023-01-30 05:03:41 -05:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32 && !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
2020-10-05 06:50:09 -04:00
|
|
|
Cache_Flush(1);
|
|
|
|
Cache_Read_Enable(1);
|
2023-01-30 05:03:41 -05:00
|
|
|
#endif // #if CONFIG_IDF_TARGET_ESP32 && !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
2020-02-13 07:43:23 -05:00
|
|
|
|
2020-10-05 06:50:09 -04:00
|
|
|
esp_cpu_unstall(1);
|
|
|
|
|
|
|
|
// Enable clock and reset APP CPU. Note that OpenOCD may have already
|
|
|
|
// enabled clock and taken APP CPU out of reset. In this case don't reset
|
|
|
|
// APP CPU again, as that will clear the breakpoints which may have already
|
|
|
|
// been set.
|
2020-07-29 01:13:51 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-10-05 06:50:09 -04:00
|
|
|
if (!DPORT_GET_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN)) {
|
|
|
|
DPORT_SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN);
|
|
|
|
DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_C_REG, DPORT_APPCPU_RUNSTALL);
|
|
|
|
DPORT_SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING);
|
|
|
|
DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING);
|
|
|
|
}
|
2020-07-29 01:13:51 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
2020-10-05 06:50:09 -04:00
|
|
|
if (!REG_GET_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_CLKGATE_EN)) {
|
|
|
|
REG_SET_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_CLKGATE_EN);
|
|
|
|
REG_CLR_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_RUNSTALL);
|
|
|
|
REG_SET_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_RESETING);
|
|
|
|
REG_CLR_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_RESETING);
|
|
|
|
}
|
2023-07-21 00:36:57 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32P4
|
|
|
|
if (!REG_GET_BIT(HP_SYS_CLKRST_SOC_CLK_CTRL0_REG, HP_SYS_CLKRST_REG_CORE1_CPU_CLK_EN)) {
|
|
|
|
REG_SET_BIT(HP_SYS_CLKRST_SOC_CLK_CTRL0_REG, HP_SYS_CLKRST_REG_CORE1_CPU_CLK_EN);
|
|
|
|
}
|
2024-01-29 20:40:10 -05:00
|
|
|
if (REG_GET_BIT(HP_SYS_CLKRST_HP_RST_EN0_REG, HP_SYS_CLKRST_REG_RST_EN_CORE1_GLOBAL)) {
|
2023-07-21 00:36:57 -04:00
|
|
|
REG_CLR_BIT(HP_SYS_CLKRST_HP_RST_EN0_REG, HP_SYS_CLKRST_REG_RST_EN_CORE1_GLOBAL);
|
|
|
|
}
|
2023-10-30 14:18:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SOC_KEY_MANAGER_SUPPORTED
|
2023-11-06 08:24:22 -05:00
|
|
|
// The following operation makes the Key Manager to use eFuse key for ECDSA and XTS-AES operation by default
|
|
|
|
// This is to keep the default behavior same as the other chips
|
|
|
|
// If the Key Manager configuration is already locked then following operation does not have any effect
|
2023-10-30 14:18:46 -04:00
|
|
|
key_mgr_hal_set_key_usage(ESP_KEY_MGR_ECDSA_KEY, ESP_KEY_MGR_USE_EFUSE_KEY);
|
|
|
|
key_mgr_hal_set_key_usage(ESP_KEY_MGR_XTS_AES_128_KEY, ESP_KEY_MGR_USE_EFUSE_KEY);
|
2020-07-29 01:13:51 -04:00
|
|
|
#endif
|
2020-10-05 06:50:09 -04:00
|
|
|
ets_set_appcpu_boot_addr((uint32_t)call_start_cpu1);
|
2020-02-13 07:43:23 -05:00
|
|
|
|
2020-10-05 06:50:09 -04:00
|
|
|
bool cpus_up = false;
|
2020-02-13 07:43:23 -05:00
|
|
|
|
2020-10-05 06:50:09 -04:00
|
|
|
while (!cpus_up) {
|
|
|
|
cpus_up = true;
|
|
|
|
for (int i = 0; i < SOC_CPU_CORES_NUM; i++) {
|
|
|
|
cpus_up &= s_cpu_up[i];
|
2020-02-13 07:43:23 -05:00
|
|
|
}
|
2020-10-05 06:50:09 -04:00
|
|
|
esp_rom_delay_us(100);
|
2020-02-13 07:43:23 -05:00
|
|
|
}
|
|
|
|
}
|
2023-03-08 14:03:53 -05:00
|
|
|
|
2023-09-18 11:37:31 -04:00
|
|
|
#if !SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
|
2023-03-08 14:03:53 -05:00
|
|
|
// This function is needed to make the multicore app runnable on a unicore bootloader (built with FREERTOS UNICORE).
|
|
|
|
// It does some cache settings for other CPUs.
|
|
|
|
void IRAM_ATTR do_multicore_settings(void)
|
|
|
|
{
|
|
|
|
// We intentionally do not check the cache settings before changing them,
|
|
|
|
// because it helps to get the application to run on older bootloaders.
|
|
|
|
#ifdef CONFIG_IDF_TARGET_ESP32
|
|
|
|
if (!efuse_ll_get_disable_app_cpu()) {
|
|
|
|
Cache_Read_Disable(1);
|
|
|
|
Cache_Flush(1);
|
|
|
|
DPORT_REG_SET_BIT(DPORT_APP_CACHE_CTRL1_REG, DPORT_APP_CACHE_MMU_IA_CLR);
|
|
|
|
DPORT_REG_CLR_BIT(DPORT_APP_CACHE_CTRL1_REG, DPORT_APP_CACHE_MMU_IA_CLR);
|
|
|
|
// We do not enable cache for CPU1 now because it will be done later in start_other_core().
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cache_bus_mask_t cache_bus_mask_core0 = cache_ll_l1_get_enabled_bus(0);
|
|
|
|
#ifndef CONFIG_IDF_TARGET_ESP32
|
|
|
|
// 1. disable the cache before changing its settings.
|
2023-09-15 08:11:52 -04:00
|
|
|
cache_hal_disable(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
|
2023-03-08 14:03:53 -05:00
|
|
|
#endif
|
|
|
|
for (unsigned core = 1; core < SOC_CPU_CORES_NUM; core++) {
|
|
|
|
// 2. change cache settings. All cores must have the same settings.
|
|
|
|
cache_ll_l1_enable_bus(core, cache_bus_mask_core0);
|
|
|
|
}
|
|
|
|
#ifndef CONFIG_IDF_TARGET_ESP32
|
|
|
|
// 3. enable the cache after changing its settings.
|
2023-09-15 08:11:52 -04:00
|
|
|
cache_hal_enable(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
|
2023-03-08 14:03:53 -05:00
|
|
|
#endif
|
|
|
|
}
|
2023-09-18 11:37:31 -04:00
|
|
|
#endif // !SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
|
2020-02-13 07:43:23 -05:00
|
|
|
#endif // !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
|
2020-03-02 23:22:41 -05:00
|
|
|
/*
|
|
|
|
* We arrive here after the bootloader finished loading the program from flash. The hardware is mostly uninitialized,
|
|
|
|
* and the app CPU is in reset. We do have a stack, so we can do the initialization in C.
|
|
|
|
*/
|
|
|
|
void IRAM_ATTR call_start_cpu0(void)
|
|
|
|
{
|
2020-02-13 07:43:23 -05:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2021-07-12 22:45:06 -04:00
|
|
|
soc_reset_reason_t rst_reas[SOC_CPU_CORES_NUM];
|
2020-02-13 07:43:23 -05:00
|
|
|
#else
|
2021-11-06 05:24:45 -04:00
|
|
|
soc_reset_reason_t __attribute__((unused)) rst_reas[1];
|
2020-02-13 07:43:23 -05:00
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2020-11-05 23:00:07 -05:00
|
|
|
#ifdef __riscv
|
2022-07-21 07:24:42 -04:00
|
|
|
if (esp_cpu_dbgr_is_attached()) {
|
2021-05-28 17:20:02 -04:00
|
|
|
/* Let debugger some time to detect that target started, halt it, enable ebreaks and resume.
|
|
|
|
500ms should be enough. */
|
|
|
|
for (uint32_t ms_num = 0; ms_num < 2; ms_num++) {
|
|
|
|
esp_rom_delay_us(100000);
|
|
|
|
}
|
|
|
|
}
|
2020-11-05 23:00:07 -05:00
|
|
|
// Configure the global pointer register
|
|
|
|
// (This should be the first thing IDF app does, as any other piece of code could be
|
|
|
|
// relaxed by the linker to access something relative to __global_pointer$)
|
2024-01-29 20:40:10 -05:00
|
|
|
__asm__ __volatile__(
|
2021-01-04 13:38:10 -05:00
|
|
|
".option push\n"
|
2020-11-05 23:00:07 -05:00
|
|
|
".option norelax\n"
|
|
|
|
"la gp, __global_pointer$\n"
|
|
|
|
".option pop"
|
2021-01-04 13:38:10 -05:00
|
|
|
);
|
2020-11-05 23:00:07 -05:00
|
|
|
#endif
|
|
|
|
|
2023-07-20 23:51:38 -04:00
|
|
|
#if SOC_BRANCH_PREDICTOR_SUPPORTED
|
|
|
|
esp_cpu_branch_prediction_enable();
|
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
// Move exception vectors to IRAM
|
2022-07-21 07:24:42 -04:00
|
|
|
esp_cpu_intr_set_ivt_addr(&_vector_table);
|
2023-07-20 23:54:29 -04:00
|
|
|
#if SOC_INT_CLIC_SUPPORTED
|
2023-09-01 05:18:39 -04:00
|
|
|
/* When hardware vectored interrupts are enabled in CLIC,
|
|
|
|
* the CPU jumps to this base address + 4 * interrupt_id.
|
|
|
|
*/
|
2023-07-20 23:54:29 -04:00
|
|
|
esp_cpu_intr_set_mtvt_addr(&_mtvt_table);
|
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2021-07-12 22:45:06 -04:00
|
|
|
rst_reas[0] = esp_rom_get_reset_reason(0);
|
2020-02-13 07:43:23 -05:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2021-07-12 22:45:06 -04:00
|
|
|
rst_reas[1] = esp_rom_get_reset_reason(1);
|
2020-03-02 23:22:41 -05:00
|
|
|
#endif
|
|
|
|
|
2023-01-30 05:03:41 -05:00
|
|
|
//Clear BSS. Please do not attempt to do any complex stuff (like early logging) before this.
|
2024-02-12 00:51:25 -05:00
|
|
|
#if SOC_MEM_NON_CONTIGUOUS_SRAM
|
|
|
|
memset(&_bss_start_low, 0, (&_bss_end_low - &_bss_start_low) * sizeof(_bss_start_low));
|
|
|
|
memset(&_bss_start_high, 0, (&_bss_end_high - &_bss_start_high) * sizeof(_bss_start_high));
|
|
|
|
#else
|
2023-01-30 05:03:41 -05:00
|
|
|
memset(&_bss_start, 0, (&_bss_end - &_bss_start) * sizeof(_bss_start));
|
2024-02-12 00:51:25 -05:00
|
|
|
#endif // SOC_MEM_NON_CONTIGUOUS_SRAM
|
2023-01-30 05:03:41 -05:00
|
|
|
|
2023-10-08 04:08:47 -04:00
|
|
|
#if CONFIG_BT_LE_RELEASE_IRAM_SUPPORTED
|
|
|
|
// Clear Bluetooth bss
|
|
|
|
memset(&_bss_bt_start, 0, (&_bss_bt_end - &_bss_bt_start) * sizeof(_bss_bt_start));
|
|
|
|
#endif // CONFIG_BT_LE_RELEASE_IRAM_SUPPORTED
|
|
|
|
|
2023-01-30 05:03:41 -05:00
|
|
|
#if defined(CONFIG_IDF_TARGET_ESP32) && defined(CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY)
|
|
|
|
// Clear IRAM BSS
|
|
|
|
memset(&_iram_bss_start, 0, (&_iram_bss_end - &_iram_bss_start) * sizeof(_iram_bss_start));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SOC_RTC_FAST_MEM_SUPPORTED || SOC_RTC_SLOW_MEM_SUPPORTED
|
|
|
|
/* Unless waking from deep sleep (implying RTC memory is intact), clear RTC bss */
|
|
|
|
if (rst_reas[0] != RESET_REASON_CORE_DEEP_SLEEP) {
|
|
|
|
memset(&_rtc_bss_start, 0, (&_rtc_bss_end - &_rtc_bss_start) * sizeof(_rtc_bss_start));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-03-08 14:03:53 -05:00
|
|
|
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
|
|
|
#if CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
ESP_EARLY_LOGI(TAG, "Unicore app");
|
|
|
|
#else
|
|
|
|
ESP_EARLY_LOGI(TAG, "Multicore app");
|
2023-09-18 11:37:31 -04:00
|
|
|
#if !SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
|
2023-03-08 14:03:53 -05:00
|
|
|
// It helps to fix missed cache settings for other cores. It happens when bootloader is unicore.
|
|
|
|
do_multicore_settings();
|
2023-09-18 11:37:31 -04:00
|
|
|
#endif // !SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
|
2023-03-08 14:03:53 -05:00
|
|
|
#endif
|
|
|
|
#endif // !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
|
|
|
|
2023-01-30 05:03:41 -05:00
|
|
|
// When the APP is loaded into ram for execution, some hardware initialization behaviors
|
|
|
|
// in the bootloader are still necessary
|
|
|
|
#if CONFIG_APP_BUILD_TYPE_RAM
|
2023-08-26 10:08:23 -04:00
|
|
|
bootloader_init();
|
2023-03-14 22:46:13 -04:00
|
|
|
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
2023-08-26 10:08:23 -04:00
|
|
|
bootloader_flash_hardware_init();
|
2023-03-14 22:46:13 -04:00
|
|
|
#endif //#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
|
|
|
#endif //#if CONFIG_APP_BUILD_TYPE_RAM
|
2023-01-30 05:03:41 -05:00
|
|
|
|
2020-02-05 09:40:15 -05:00
|
|
|
#ifndef CONFIG_BOOTLOADER_WDT_ENABLE
|
2020-03-02 23:22:41 -05:00
|
|
|
// from panic handler we can be reset by RWDT or TG0WDT
|
2021-07-12 22:45:06 -04:00
|
|
|
if (rst_reas[0] == RESET_REASON_CORE_RTC_WDT || rst_reas[0] == RESET_REASON_CORE_MWDT0
|
2020-02-13 07:43:23 -05:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2021-08-18 07:31:35 -04:00
|
|
|
|| rst_reas[1] == RESET_REASON_CORE_RTC_WDT || rst_reas[1] == RESET_REASON_CORE_MWDT0
|
2020-03-02 23:22:41 -05:00
|
|
|
#endif
|
2020-07-13 09:33:23 -04:00
|
|
|
) {
|
2023-02-14 22:54:00 -05:00
|
|
|
wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
|
2020-03-02 23:22:41 -05:00
|
|
|
wdt_hal_write_protect_disable(&rtc_wdt_ctx);
|
|
|
|
wdt_hal_disable(&rtc_wdt_ctx);
|
|
|
|
wdt_hal_write_protect_enable(&rtc_wdt_ctx);
|
|
|
|
}
|
2020-02-05 09:40:15 -05:00
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2023-01-30 05:03:41 -05:00
|
|
|
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
2020-03-02 23:22:41 -05:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S2
|
|
|
|
/* Configure the mode of instruction cache : cache size, cache associated ways, cache line size. */
|
|
|
|
extern void esp_config_instruction_cache_mode(void);
|
|
|
|
esp_config_instruction_cache_mode();
|
|
|
|
|
|
|
|
/* If we need use SPIRAM, we should use data cache, or if we want to access rodata, we also should use data cache.
|
|
|
|
Configure the mode of data : cache size, cache associated ways, cache line size.
|
|
|
|
Enable data cache, so if we don't use SPIRAM, it just works. */
|
|
|
|
extern void esp_config_data_cache_mode(void);
|
|
|
|
esp_config_data_cache_mode();
|
|
|
|
Cache_Enable_DCache(0);
|
|
|
|
#endif
|
|
|
|
|
2020-07-29 01:13:51 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
/* Configure the mode of instruction cache : cache size, cache line size. */
|
|
|
|
extern void rom_config_instruction_cache_mode(uint32_t cfg_cache_size, uint8_t cfg_cache_ways, uint8_t cfg_cache_line_size);
|
|
|
|
rom_config_instruction_cache_mode(CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE, CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS, CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE);
|
|
|
|
|
|
|
|
/* If we need use SPIRAM, we should use data cache.
|
|
|
|
Configure the mode of data : cache size, cache line size.*/
|
|
|
|
Cache_Suspend_DCache();
|
|
|
|
extern void rom_config_data_cache_mode(uint32_t cfg_cache_size, uint8_t cfg_cache_ways, uint8_t cfg_cache_line_size);
|
|
|
|
rom_config_data_cache_mode(CONFIG_ESP32S3_DATA_CACHE_SIZE, CONFIG_ESP32S3_DCACHE_ASSOCIATED_WAYS, CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE);
|
|
|
|
Cache_Resume_DCache(0);
|
2020-12-22 02:38:37 -05:00
|
|
|
#endif // CONFIG_IDF_TARGET_ESP32S3
|
2020-08-27 23:53:28 -04:00
|
|
|
|
2023-07-21 00:37:06 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32P4
|
2023-09-14 00:14:08 -04:00
|
|
|
//TODO: IDF-5670, add cache init API
|
2023-07-27 03:10:50 -04:00
|
|
|
extern void esp_config_l2_cache_mode(void);
|
|
|
|
esp_config_l2_cache_mode();
|
2023-07-21 00:37:06 -04:00
|
|
|
#endif
|
2021-08-11 10:06:48 -04:00
|
|
|
|
2023-08-31 00:45:08 -04:00
|
|
|
#if ESP_ROM_NEEDS_SET_CACHE_MMU_SIZE
|
2023-03-17 00:11:54 -04:00
|
|
|
#if CONFIG_APP_BUILD_TYPE_ELF_RAM
|
|
|
|
// For RAM loadable ELF case, we don't need to reserve IROM/DROM as instructions and data
|
|
|
|
// are all in internal RAM. If the RAM loadable ELF has any requirement to memory map the
|
|
|
|
// external flash then it should use flash or partition mmap APIs.
|
|
|
|
uint32_t cache_mmu_irom_size = 0;
|
|
|
|
__attribute__((unused)) uint32_t cache_mmu_drom_size = 0;
|
|
|
|
#else // CONFIG_APP_BUILD_TYPE_ELF_RAM
|
2023-03-03 05:21:31 -05:00
|
|
|
uint32_t _instruction_size = (uint32_t)&_instruction_reserved_end - (uint32_t)&_instruction_reserved_start;
|
|
|
|
uint32_t cache_mmu_irom_size = ((_instruction_size + SPI_FLASH_MMU_PAGE_SIZE - 1) / SPI_FLASH_MMU_PAGE_SIZE) * sizeof(uint32_t);
|
2020-10-10 04:22:49 -04:00
|
|
|
|
2023-03-06 04:20:56 -05:00
|
|
|
uint32_t _rodata_size = (uint32_t)&_rodata_reserved_end - (uint32_t)&_rodata_reserved_start;
|
2023-03-06 04:55:16 -05:00
|
|
|
__attribute__((unused)) uint32_t cache_mmu_drom_size = ((_rodata_size + SPI_FLASH_MMU_PAGE_SIZE - 1) / SPI_FLASH_MMU_PAGE_SIZE) * sizeof(uint32_t);
|
2023-03-17 00:11:54 -04:00
|
|
|
#endif // !CONFIG_APP_BUILD_TYPE_ELF_RAM
|
2020-09-27 22:19:56 -04:00
|
|
|
|
2023-03-03 05:21:31 -05:00
|
|
|
/* Configure the Cache MMU size for instruction and rodata in flash. */
|
2020-08-27 23:53:28 -04:00
|
|
|
Cache_Set_IDROM_MMU_Size(cache_mmu_irom_size, CACHE_DROM_MMU_MAX_END - cache_mmu_irom_size);
|
2023-08-31 00:45:08 -04:00
|
|
|
#endif // ESP_ROM_NEEDS_SET_CACHE_MMU_SIZE
|
2020-07-29 01:13:51 -04:00
|
|
|
|
2022-09-23 05:32:16 -04:00
|
|
|
#if CONFIG_ESPTOOLPY_OCT_FLASH && !CONFIG_ESPTOOLPY_FLASH_MODE_AUTO_DETECT
|
2021-12-22 09:18:43 -05:00
|
|
|
bool efuse_opflash_en = efuse_ll_get_flash_type();
|
2021-04-15 05:13:48 -04:00
|
|
|
if (!efuse_opflash_en) {
|
|
|
|
ESP_EARLY_LOGE(TAG, "Octal Flash option selected, but EFUSE not configured!");
|
|
|
|
abort();
|
|
|
|
}
|
2021-08-12 23:30:54 -04:00
|
|
|
#endif
|
2023-12-22 05:44:51 -05:00
|
|
|
|
2021-09-09 03:34:42 -04:00
|
|
|
esp_mspi_pin_init();
|
|
|
|
// For Octal flash, it's hard to implement a read_id function in OPI mode for all vendors.
|
|
|
|
// So we have to read it here in SPI mode, before entering the OPI mode.
|
|
|
|
bootloader_flash_update_id();
|
|
|
|
/**
|
|
|
|
* This function initialise the Flash chip to the user-defined settings.
|
|
|
|
*
|
|
|
|
* In bootloader, we only init Flash (and MSPI) to a preliminary state, for being flexible to
|
|
|
|
* different chips.
|
|
|
|
* In this stage, we re-configure the Flash (and MSPI) to required configuration
|
|
|
|
*/
|
|
|
|
spi_flash_init_chip_state();
|
2023-11-07 03:16:23 -05:00
|
|
|
|
|
|
|
// In earlier version of ESP-IDF, the PLL provided by bootloader is not stable enough.
|
|
|
|
// Do calibration again here so that we can use better clock for the timing tuning.
|
|
|
|
#if CONFIG_ESP_SYSTEM_BBPLL_RECALIB
|
|
|
|
rtc_clk_recalib_bbpll();
|
|
|
|
#endif
|
2023-01-05 02:24:08 -05:00
|
|
|
#if SOC_MEMSPI_SRC_FREQ_120M
|
2023-11-07 03:16:23 -05:00
|
|
|
// This function needs to be called when PLL is enabled
|
2023-01-05 02:24:08 -05:00
|
|
|
mspi_timing_flash_tuning();
|
2021-04-15 05:13:48 -04:00
|
|
|
#endif
|
|
|
|
|
2022-11-02 07:11:45 -04:00
|
|
|
esp_mmu_map_init();
|
|
|
|
|
2020-03-02 23:22:41 -05:00
|
|
|
#if CONFIG_SPIRAM_BOOT_INIT
|
2022-05-10 22:32:56 -04:00
|
|
|
if (esp_psram_init() != ESP_OK) {
|
2020-03-02 23:22:41 -05:00
|
|
|
#if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
|
|
|
|
ESP_EARLY_LOGE(TAG, "Failed to init external RAM, needed for external .bss segment");
|
|
|
|
abort();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_SPIRAM_IGNORE_NOTFOUND
|
|
|
|
ESP_EARLY_LOGI(TAG, "Failed to init external RAM; continuing without it.");
|
|
|
|
#else
|
|
|
|
ESP_EARLY_LOGE(TAG, "Failed to init external RAM!");
|
|
|
|
abort();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2023-01-30 05:03:41 -05:00
|
|
|
#endif // !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
|
|
|
|
|
|
|
bootloader_init_mem();
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2020-02-13 07:43:23 -05:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2020-02-05 09:40:15 -05:00
|
|
|
s_cpu_up[0] = true;
|
2020-08-14 11:42:57 -04:00
|
|
|
#endif
|
2020-07-29 01:13:51 -04:00
|
|
|
|
2023-09-15 11:10:41 -04:00
|
|
|
ESP_EARLY_LOGD(TAG, "Pro cpu up");
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2020-06-17 05:13:55 -04:00
|
|
|
#if SOC_CPU_CORES_NUM > 1 // there is no 'single-core mode' for natively single-core processors
|
2020-02-13 07:43:23 -05:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
start_other_core();
|
2020-06-17 05:13:55 -04:00
|
|
|
#else
|
|
|
|
ESP_EARLY_LOGI(TAG, "Single core mode");
|
2020-07-29 01:13:51 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-06-17 05:13:55 -04:00
|
|
|
DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN); // stop the other core
|
2020-07-29 01:13:51 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
REG_CLR_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_CLKGATE_EN);
|
2021-06-30 08:33:07 -04:00
|
|
|
#if SOC_APPCPU_HAS_CLOCK_GATING_BUG
|
|
|
|
/* The clock gating signal of the App core is invalid. We use RUNSTALL and RESETING
|
|
|
|
signals to ensure that the App core stops running in single-core mode. */
|
|
|
|
REG_SET_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_RUNSTALL);
|
|
|
|
REG_CLR_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_RESETING);
|
2020-07-29 01:13:51 -04:00
|
|
|
#endif
|
2021-06-30 08:33:07 -04:00
|
|
|
#endif // CONFIG_IDF_TARGET_ESP32
|
2020-06-17 05:13:55 -04:00
|
|
|
#endif // !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
#endif // SOC_CPU_CORES_NUM > 1
|
2020-03-02 23:22:41 -05:00
|
|
|
|
|
|
|
#if CONFIG_SPIRAM_MEMTEST
|
2022-05-26 10:48:49 -04:00
|
|
|
if (esp_psram_is_initialized()) {
|
2022-05-10 22:32:56 -04:00
|
|
|
bool ext_ram_ok = esp_psram_extram_test();
|
2020-03-02 23:22:41 -05:00
|
|
|
if (!ext_ram_ok) {
|
|
|
|
ESP_EARLY_LOGE(TAG, "External RAM failed memory test!");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
2022-01-12 02:03:50 -05:00
|
|
|
#endif //CONFIG_SPIRAM_MEMTEST
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2023-01-30 05:03:41 -05:00
|
|
|
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
2022-05-10 22:32:56 -04:00
|
|
|
//TODO: IDF-5023, replace with MMU driver
|
2022-01-12 02:03:50 -05:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S3
|
2020-10-10 04:22:49 -04:00
|
|
|
int s_instr_flash2spiram_off = 0;
|
|
|
|
int s_rodata_flash2spiram_off = 0;
|
|
|
|
#if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
|
|
|
|
s_instr_flash2spiram_off = instruction_flash2spiram_offset();
|
|
|
|
#endif
|
|
|
|
#if CONFIG_SPIRAM_RODATA
|
|
|
|
s_rodata_flash2spiram_off = rodata_flash2spiram_offset();
|
|
|
|
#endif
|
2021-09-06 04:22:40 -04:00
|
|
|
Cache_Set_IDROM_MMU_Info(cache_mmu_irom_size / sizeof(uint32_t), \
|
|
|
|
cache_mmu_drom_size / sizeof(uint32_t), \
|
|
|
|
(uint32_t)&_rodata_reserved_start, \
|
|
|
|
(uint32_t)&_rodata_reserved_end, \
|
|
|
|
s_instr_flash2spiram_off, \
|
|
|
|
s_rodata_flash2spiram_off);
|
2023-03-06 04:20:56 -05:00
|
|
|
#endif // CONFIG_IDF_TARGET_ESP32S3
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2020-10-10 04:22:49 -04:00
|
|
|
#if CONFIG_ESP32S2_INSTRUCTION_CACHE_WRAP || CONFIG_ESP32S2_DATA_CACHE_WRAP || \
|
|
|
|
CONFIG_ESP32S3_INSTRUCTION_CACHE_WRAP || CONFIG_ESP32S3_DATA_CACHE_WRAP
|
2020-03-02 23:22:41 -05:00
|
|
|
uint32_t icache_wrap_enable = 0, dcache_wrap_enable = 0;
|
2020-10-10 04:22:49 -04:00
|
|
|
#if CONFIG_ESP32S2_INSTRUCTION_CACHE_WRAP || CONFIG_ESP32S3_INSTRUCTION_CACHE_WRAP
|
2020-03-02 23:22:41 -05:00
|
|
|
icache_wrap_enable = 1;
|
|
|
|
#endif
|
2020-10-10 04:22:49 -04:00
|
|
|
#if CONFIG_ESP32S2_DATA_CACHE_WRAP || CONFIG_ESP32S3_DATA_CACHE_WRAP
|
2020-03-02 23:22:41 -05:00
|
|
|
dcache_wrap_enable = 1;
|
|
|
|
#endif
|
|
|
|
extern void esp_enable_cache_wrap(uint32_t icache_wrap_enable, uint32_t dcache_wrap_enable);
|
|
|
|
esp_enable_cache_wrap(icache_wrap_enable, dcache_wrap_enable);
|
|
|
|
#endif
|
|
|
|
|
2020-10-10 04:22:49 -04:00
|
|
|
#if CONFIG_ESP32S3_DATA_CACHE_16KB
|
|
|
|
Cache_Invalidate_DCache_All();
|
|
|
|
Cache_Occupy_Addr(SOC_DROM_LOW, 0x4000);
|
|
|
|
#endif
|
|
|
|
|
2022-01-17 21:32:56 -05:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32C2
|
2022-07-12 08:42:28 -04:00
|
|
|
// TODO : IDF-5020
|
2022-01-17 21:32:56 -05:00
|
|
|
#if CONFIG_ESP32C2_INSTRUCTION_CACHE_WRAP
|
2021-11-06 05:24:45 -04:00
|
|
|
extern void esp_enable_cache_wrap(uint32_t icache_wrap_enable);
|
|
|
|
esp_enable_cache_wrap(1);
|
|
|
|
#endif
|
|
|
|
#endif
|
2023-01-30 05:03:41 -05:00
|
|
|
#endif // !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
2021-11-06 05:24:45 -04:00
|
|
|
|
2020-03-02 23:22:41 -05:00
|
|
|
#if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
|
|
|
|
memset(&_ext_ram_bss_start, 0, (&_ext_ram_bss_end - &_ext_ram_bss_start) * sizeof(_ext_ram_bss_start));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//Enable trace memory and immediately start trace.
|
2021-10-22 16:32:36 -04:00
|
|
|
#if CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX || CONFIG_ESP32S3_TRAX
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
#if CONFIG_ESP32_TRAX_TWOBANKS || CONFIG_ESP32S3_TRAX_TWOBANKS
|
2020-07-13 09:33:23 -04:00
|
|
|
trax_enable(TRAX_ENA_PRO_APP);
|
|
|
|
#else
|
|
|
|
trax_enable(TRAX_ENA_PRO);
|
|
|
|
#endif
|
2020-02-16 08:29:29 -05:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
2020-03-02 23:22:41 -05:00
|
|
|
trax_enable(TRAX_ENA_PRO);
|
|
|
|
#endif
|
|
|
|
trax_start_trace(TRAX_DOWNCOUNT_WORDS);
|
2021-10-22 16:32:36 -04:00
|
|
|
#endif // CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX || CONFIG_ESP32S3_TRAX
|
2020-03-02 23:22:41 -05:00
|
|
|
|
|
|
|
esp_clk_init();
|
|
|
|
esp_perip_clk_init();
|
2020-06-23 04:46:06 -04:00
|
|
|
|
|
|
|
// Now that the clocks have been set-up, set the startup time from RTC
|
|
|
|
// and default RTC-backed system time provider.
|
|
|
|
g_startup_time = esp_rtc_get_time_us();
|
|
|
|
|
2021-10-11 11:17:27 -04:00
|
|
|
// Clear interrupt matrix for PRO CPU core
|
2021-10-14 05:51:00 -04:00
|
|
|
core_intr_matrix_clear();
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2020-05-01 04:09:20 -04:00
|
|
|
#ifndef CONFIG_IDF_ENV_FPGA // TODO: on FPGA it should be possible to configure this, not currently working with APB_CLK_FREQ changed
|
2020-04-30 10:48:49 -04:00
|
|
|
#ifdef CONFIG_ESP_CONSOLE_UART
|
2022-03-25 06:41:25 -04:00
|
|
|
uint32_t clock_hz = esp_clk_apb_freq();
|
2022-07-04 02:17:54 -04:00
|
|
|
#if ESP_ROM_UART_CLK_IS_XTAL
|
|
|
|
clock_hz = esp_clk_xtal_freq(); // From esp32-s3 on, UART clock source is selected to XTAL in ROM
|
2020-07-29 01:13:51 -04:00
|
|
|
#endif
|
2024-01-17 04:19:49 -05:00
|
|
|
esp_rom_output_tx_wait_idle(CONFIG_ESP_CONSOLE_ROM_SERIAL_PORT_NUM);
|
2023-09-24 23:12:09 -04:00
|
|
|
|
|
|
|
// In a single thread mode, the freertos is not started yet. So don't have to use a critical section.
|
2024-01-29 20:40:10 -05:00
|
|
|
int __DECLARE_RCC_ATOMIC_ENV __attribute__((unused)); // To avoid build errors about spinlock's __DECLARE_RCC_ATOMIC_ENV
|
2024-01-17 04:19:49 -05:00
|
|
|
esp_rom_uart_set_clock_baudrate(CONFIG_ESP_CONSOLE_ROM_SERIAL_PORT_NUM, clock_hz, CONFIG_ESP_CONSOLE_UART_BAUDRATE);
|
2020-03-02 23:22:41 -05:00
|
|
|
#endif
|
2020-05-01 04:09:20 -04:00
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2024-01-01 22:16:55 -05:00
|
|
|
#if !CONFIG_IDF_TARGET_ESP32P4 && !CONFIG_IDF_TARGET_ESP32C5 //TODO: IDF-7529, IDF-8638
|
2022-10-27 03:09:34 -04:00
|
|
|
// Need to unhold the IOs that were hold right before entering deep sleep, which are used as wakeup pins
|
|
|
|
if (rst_reas[0] == RESET_REASON_CORE_DEEP_SLEEP) {
|
|
|
|
esp_deep_sleep_wakeup_io_reset();
|
|
|
|
}
|
2024-01-01 22:16:55 -05:00
|
|
|
#endif //#if !CONFIG_IDF_TARGET_ESP32P4 & !CONFIG_IDF_TARGET_ESP32C5
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2023-01-30 05:03:41 -05:00
|
|
|
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
2020-03-02 23:22:41 -05:00
|
|
|
esp_cache_err_int_init();
|
2023-01-30 05:03:41 -05:00
|
|
|
#endif
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2021-09-06 04:22:40 -04:00
|
|
|
#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE && !CONFIG_ESP_SYSTEM_MEMPROT_TEST
|
2021-05-31 18:07:09 -04:00
|
|
|
// Memprot cannot be locked during OS startup as the lock-on prevents any PMS changes until a next reboot
|
|
|
|
// If such a situation appears, it is likely an malicious attempt to bypass the system safety setup -> print error & reset
|
2021-09-06 04:22:40 -04:00
|
|
|
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32S2
|
2021-08-18 07:31:35 -04:00
|
|
|
if (esp_memprot_is_locked_any()) {
|
2021-09-06 04:22:40 -04:00
|
|
|
#else
|
|
|
|
bool is_locked = false;
|
|
|
|
if (esp_mprot_is_conf_locked_any(&is_locked) != ESP_OK || is_locked) {
|
|
|
|
#endif
|
2021-05-31 18:07:09 -04:00
|
|
|
ESP_EARLY_LOGE(TAG, "Memprot feature locked after the system reset! Potential safety corruption, rebooting.");
|
2023-04-25 04:28:10 -04:00
|
|
|
esp_restart_noos();
|
2021-05-31 18:07:09 -04:00
|
|
|
}
|
2021-09-06 04:22:40 -04:00
|
|
|
|
|
|
|
//default configuration of PMS Memprot
|
2021-08-18 07:31:35 -04:00
|
|
|
esp_err_t memp_err = ESP_OK;
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32S2 //specific for ESP32S2 unless IDF-3024 is merged
|
2021-09-06 04:22:40 -04:00
|
|
|
#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK
|
|
|
|
memp_err = esp_memprot_set_prot(PANIC_HNDL_ON, MEMPROT_LOCK, NULL);
|
2020-02-05 09:40:15 -05:00
|
|
|
#else
|
2021-09-06 04:22:40 -04:00
|
|
|
memp_err = esp_memprot_set_prot(PANIC_HNDL_ON, MEMPROT_UNLOCK, NULL);
|
2020-02-05 09:40:15 -05:00
|
|
|
#endif
|
2021-09-06 04:22:40 -04:00
|
|
|
#else //CONFIG_IDF_TARGET_ESP32S2 specific end
|
|
|
|
esp_memp_config_t memp_cfg = ESP_MEMPROT_DEFAULT_CONFIG();
|
|
|
|
#if !CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK
|
|
|
|
memp_cfg.lock_feature = false;
|
2021-08-18 07:31:35 -04:00
|
|
|
#endif
|
2021-09-06 04:22:40 -04:00
|
|
|
memp_err = esp_mprot_set_prot(&memp_cfg);
|
|
|
|
#endif //other IDF_TARGETS end
|
|
|
|
|
2021-08-18 07:31:35 -04:00
|
|
|
if (memp_err != ESP_OK) {
|
2021-09-06 04:22:40 -04:00
|
|
|
ESP_EARLY_LOGE(TAG, "Failed to set Memprot feature (0x%08X: %s), rebooting.", memp_err, esp_err_to_name(memp_err));
|
2023-04-25 04:28:10 -04:00
|
|
|
esp_restart_noos();
|
2021-08-18 07:31:35 -04:00
|
|
|
}
|
2021-09-06 04:22:40 -04:00
|
|
|
#endif //CONFIG_ESP_SYSTEM_MEMPROT_FEATURE && !CONFIG_ESP_SYSTEM_MEMPROT_TEST
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2023-08-26 10:08:23 -04:00
|
|
|
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
|
|
|
// External devices (including SPI0/1, cache) should be initialized
|
|
|
|
|
|
|
|
#if !CONFIG_APP_BUILD_TYPE_RAM
|
|
|
|
// Normal startup flow. We arrive here with the help of 1st, 2nd bootloader. There are valid headers (app/bootloader)
|
|
|
|
|
2020-03-02 23:22:41 -05:00
|
|
|
// Read the application binary image header. This will also decrypt the header if the image is encrypted.
|
2020-08-23 23:09:33 -04:00
|
|
|
__attribute__((unused)) esp_image_header_t fhdr = {0};
|
2020-03-02 23:22:41 -05:00
|
|
|
|
|
|
|
// This assumes that DROM is the first segment in the application binary, i.e. that we can read
|
|
|
|
// the binary header through cache by accessing SOC_DROM_LOW address.
|
2022-11-18 12:42:43 -05:00
|
|
|
hal_memcpy(&fhdr, (void *) SOC_DROM_LOW, sizeof(fhdr));
|
2022-05-30 01:13:23 -04:00
|
|
|
|
2020-08-23 23:09:33 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
|
|
|
#if !CONFIG_SPIRAM_BOOT_INIT
|
2020-03-02 23:22:41 -05:00
|
|
|
// If psram is uninitialized, we need to improve some flash configuration.
|
|
|
|
bootloader_flash_clock_config(&fhdr);
|
|
|
|
bootloader_flash_gpio_config(&fhdr);
|
|
|
|
bootloader_flash_dummy_config(&fhdr);
|
|
|
|
bootloader_flash_cs_timing_config();
|
|
|
|
#endif //!CONFIG_SPIRAM_BOOT_INIT
|
2020-08-23 23:09:33 -04:00
|
|
|
#endif //CONFIG_IDF_TARGET_ESP32
|
|
|
|
|
|
|
|
#if CONFIG_SPI_FLASH_SIZE_OVERRIDE
|
|
|
|
int app_flash_size = esp_image_get_flash_size(fhdr.spi_size);
|
|
|
|
if (app_flash_size < 1 * 1024 * 1024) {
|
2022-07-31 23:12:14 -04:00
|
|
|
ESP_EARLY_LOGE(TAG, "Invalid flash size in app image header.");
|
2020-08-23 23:09:33 -04:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
bootloader_flash_update_size(app_flash_size);
|
|
|
|
#endif //CONFIG_SPI_FLASH_SIZE_OVERRIDE
|
2023-08-26 10:08:23 -04:00
|
|
|
#else
|
|
|
|
// CONFIG_APP_BUILD_TYPE_RAM && !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
|
|
|
bootloader_flash_unlock();
|
|
|
|
#endif
|
2023-01-30 05:03:41 -05:00
|
|
|
#endif //!CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
|
2020-03-02 23:22:41 -05:00
|
|
|
|
2020-02-13 07:43:23 -05:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2020-02-05 09:40:15 -05:00
|
|
|
s_cpu_inited[0] = true;
|
|
|
|
|
|
|
|
volatile bool cpus_inited = false;
|
|
|
|
|
2020-06-08 20:17:48 -04:00
|
|
|
while (!cpus_inited) {
|
2020-02-05 09:40:15 -05:00
|
|
|
cpus_inited = true;
|
|
|
|
for (int i = 0; i < SOC_CPU_CORES_NUM; i++) {
|
|
|
|
cpus_inited &= s_cpu_inited[i];
|
|
|
|
}
|
2020-07-21 01:07:34 -04:00
|
|
|
esp_rom_delay_us(100);
|
2020-02-05 09:40:15 -05:00
|
|
|
}
|
2020-02-13 07:43:23 -05:00
|
|
|
#endif
|
2020-02-05 09:40:15 -05:00
|
|
|
|
|
|
|
SYS_STARTUP_FN();
|
2020-08-14 11:42:57 -04:00
|
|
|
}
|