2020-03-03 04:22:41 +00:00
|
|
|
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "esp_attr.h"
|
|
|
|
#include "esp_err.h"
|
|
|
|
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_system.h"
|
|
|
|
|
2021-01-26 13:07:22 +00:00
|
|
|
#include "esp_efuse.h"
|
2021-03-19 08:28:21 +00:00
|
|
|
#include "cache_err_int.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "esp_clk_internal.h"
|
2021-01-26 13:07:22 +00:00
|
|
|
|
2020-07-13 13:57:24 +00:00
|
|
|
#include "esp_rom_efuse.h"
|
2021-01-26 13:07:22 +00:00
|
|
|
#include "esp_rom_uart.h"
|
2020-07-21 05:07:34 +00:00
|
|
|
#include "esp_rom_sys.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-11-26 08:56:13 +00:00
|
|
|
#include "soc/dport_reg.h"
|
2020-06-23 08:07:09 +00:00
|
|
|
#include "esp32/rtc.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "esp32/rom/cache.h"
|
|
|
|
#include "esp32/spiram.h"
|
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
2020-06-23 08:07:09 +00:00
|
|
|
#include "esp32s2/rtc.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "esp32s2/rom/cache.h"
|
|
|
|
#include "esp32s2/spiram.h"
|
|
|
|
#include "esp32s2/dport_access.h"
|
|
|
|
#include "esp32s2/memprot.h"
|
2020-07-29 05:13:51 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
#include "esp32s3/rtc.h"
|
|
|
|
#include "esp32s3/rom/cache.h"
|
|
|
|
#include "esp32s3/spiram.h"
|
|
|
|
#include "esp32s3/dport_access.h"
|
|
|
|
#include "esp32s3/memprot.h"
|
|
|
|
#include "soc/assist_debug_reg.h"
|
2020-08-28 03:53:28 +00:00
|
|
|
#include "soc/cache_memory.h"
|
2020-11-26 08:56:13 +00:00
|
|
|
#include "soc/system_reg.h"
|
2021-04-15 09:13:48 +00:00
|
|
|
#include "esp32s3/rom/opi_flash.h"
|
2020-11-26 08:56:13 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32C3
|
|
|
|
#include "esp32c3/rtc.h"
|
2021-04-23 10:10:45 +00:00
|
|
|
#include "esp32c3/rom/cache.h"
|
2020-11-26 08:56:13 +00:00
|
|
|
#include "soc/cache_memory.h"
|
2021-01-04 18:38:10 +00:00
|
|
|
#include "esp32c3/memprot.h"
|
2021-06-10 07:22:43 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32H2
|
|
|
|
#include "esp32h2/rtc.h"
|
|
|
|
#include "esp32h2/rom/cache.h"
|
|
|
|
#include "soc/cache_memory.h"
|
|
|
|
#include "esp32h2/memprot.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
#endif
|
|
|
|
|
2021-04-15 09:13:48 +00:00
|
|
|
#include "spi_flash_private.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "bootloader_flash_config.h"
|
2021-05-07 07:25:06 +00:00
|
|
|
#include "bootloader_flash.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "esp_private/crosscore_int.h"
|
|
|
|
#include "esp_flash_encrypt.h"
|
|
|
|
|
|
|
|
#include "hal/rtc_io_hal.h"
|
2021-02-05 09:10:44 +00:00
|
|
|
#include "hal/gpio_hal.h"
|
2020-07-27 11:50:23 +00:00
|
|
|
#include "hal/wdt_hal.h"
|
2020-07-29 05:13:51 +00:00
|
|
|
#include "soc/rtc.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "soc/efuse_reg.h"
|
2020-07-29 05:13:51 +00:00
|
|
|
#include "soc/periph_defs.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "soc/cpu.h"
|
2020-06-23 08:46:06 +00:00
|
|
|
#include "soc/rtc.h"
|
|
|
|
#include "soc/spinlock.h"
|
2020-03-03 04:22:41 +00:00
|
|
|
|
2020-11-06 04:00:07 +00:00
|
|
|
#if CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "trax.h"
|
2020-11-06 04:00:07 +00:00
|
|
|
#endif
|
2020-03-03 04:22:41 +00:00
|
|
|
|
|
|
|
#include "bootloader_mem.h"
|
|
|
|
|
|
|
|
#if CONFIG_APP_BUILD_TYPE_ELF_RAM
|
2021-01-26 03:54:22 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-03-03 04:22:41 +00:00
|
|
|
#include "esp32/rom/spi_flash.h"
|
2021-04-23 10:10:45 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
2021-01-26 03:54:22 +00:00
|
|
|
#include "esp32s2/rom/spi_flash.h"
|
2021-04-23 10:10:45 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
2021-01-26 03:54:22 +00:00
|
|
|
#include "esp32s3/rom/spi_flash.h"
|
2021-04-23 10:10:45 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32C3
|
2021-01-26 03:54:22 +00:00
|
|
|
#include "esp32c3/rom/spi_flash.h"
|
2021-06-10 07:22:43 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32H2
|
|
|
|
#include "esp32h2/rom/spi_flash.h"
|
2021-04-23 10:10:45 +00:00
|
|
|
#endif
|
2020-03-03 04:22:41 +00:00
|
|
|
#endif // CONFIG_APP_BUILD_TYPE_ELF_RAM
|
|
|
|
|
2021-01-26 13:07:22 +00:00
|
|
|
// Set efuse ROM_LOG_MODE on first boot
|
|
|
|
//
|
|
|
|
// For CONFIG_BOOT_ROM_LOG_ALWAYS_ON (default) or undefined (ESP32), leave
|
|
|
|
// ROM_LOG_MODE undefined (no need to call this function during startup)
|
|
|
|
#if CONFIG_BOOT_ROM_LOG_ALWAYS_OFF
|
|
|
|
#define ROM_LOG_MODE ESP_EFUSE_ROM_LOG_ALWAYS_OFF
|
|
|
|
#elif CONFIG_BOOT_ROM_LOG_ON_GPIO_LOW
|
|
|
|
#define ROM_LOG_MODE ESP_EFUSE_ROM_LOG_ON_GPIO_LOW
|
|
|
|
#elif CONFIG_BOOT_ROM_LOG_ON_GPIO_HIGH
|
|
|
|
#define ROM_LOG_MODE ESP_EFUSE_ROM_LOG_ON_GPIO_HIGH
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-02-16 13:29:29 +00:00
|
|
|
#include "esp_private/startup_internal.h"
|
2020-06-23 08:46:06 +00:00
|
|
|
#include "esp_private/system_internal.h"
|
2020-02-13 12:43:23 +00:00
|
|
|
|
2020-03-03 04:22:41 +00:00
|
|
|
extern int _bss_start;
|
|
|
|
extern int _bss_end;
|
|
|
|
extern int _rtc_bss_start;
|
|
|
|
extern int _rtc_bss_end;
|
|
|
|
|
2020-12-22 07:41:43 +00:00
|
|
|
extern int _vector_table;
|
2020-03-03 04:22:41 +00: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 08:06:28 +00:00
|
|
|
|
2020-03-03 04:22:41 +00:00
|
|
|
#ifdef CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY
|
|
|
|
extern int _iram_bss_start;
|
|
|
|
extern int _iram_bss_end;
|
|
|
|
#endif
|
|
|
|
|
2020-02-13 12:43:23 +00:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2020-02-05 14:40:15 +00: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 12:43:23 +00:00
|
|
|
|
2020-02-05 14:40:15 +00:00
|
|
|
static volatile bool s_resume_cores;
|
2020-02-13 12:43:23 +00:00
|
|
|
#endif
|
2020-03-03 04:22:41 +00:00
|
|
|
|
2020-02-05 14:40:15 +00:00
|
|
|
// If CONFIG_SPIRAM_IGNORE_NOTFOUND is set and external RAM is not found or errors out on testing, this is set to false.
|
2020-03-03 04:22:41 +00:00
|
|
|
bool g_spiram_ok = true;
|
|
|
|
|
2020-02-13 12:43:23 +00:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2020-02-05 14:40:15 +00:00
|
|
|
void startup_resume_other_cores(void)
|
|
|
|
{
|
|
|
|
s_resume_cores = true;
|
|
|
|
}
|
|
|
|
|
2020-03-03 04:22:41 +00:00
|
|
|
void IRAM_ATTR call_start_cpu1(void)
|
|
|
|
{
|
2020-12-22 07:41:43 +00:00
|
|
|
cpu_hal_set_vecbase(&_vector_table);
|
2020-03-03 04:22:41 +00:00
|
|
|
|
|
|
|
ets_set_appcpu_boot_addr(0);
|
|
|
|
|
|
|
|
bootloader_init_mem();
|
|
|
|
|
|
|
|
#if CONFIG_ESP_CONSOLE_UART_NONE
|
2020-07-29 05:13:51 +00:00
|
|
|
esp_rom_install_channel_putc(1, NULL);
|
|
|
|
esp_rom_install_channel_putc(2, NULL);
|
2020-03-03 04:22:41 +00:00
|
|
|
#else // CONFIG_ESP_CONSOLE_UART_NONE
|
2020-12-02 03:43:13 +00:00
|
|
|
esp_rom_install_uart_printf();
|
2020-07-13 13:33:23 +00:00
|
|
|
esp_rom_uart_set_as_console(CONFIG_ESP_CONSOLE_UART_NUM);
|
2020-03-03 04:22:41 +00:00
|
|
|
#endif
|
|
|
|
|
2020-07-29 05:13:51 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-02-05 14:40:15 +00: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);
|
2020-07-29 05:13:51 +00: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 14:40:15 +00:00
|
|
|
|
|
|
|
s_cpu_up[1] = true;
|
2020-03-03 04:22:41 +00:00
|
|
|
ESP_EARLY_LOGI(TAG, "App cpu up.");
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
|
|
|
#if CONFIG_ESP32_TRAX_TWOBANKS
|
|
|
|
trax_start_trace(TRAX_DOWNCOUNT_WORDS);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-02-05 14:40:15 +00:00
|
|
|
s_cpu_inited[1] = true;
|
|
|
|
|
2020-06-09 00:17:48 +00:00
|
|
|
while (!s_resume_cores) {
|
2020-07-21 05:07:34 +00:00
|
|
|
esp_rom_delay_us(100);
|
2020-02-05 14:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYS_STARTUP_FN();
|
2020-03-03 04:22:41 +00:00
|
|
|
}
|
2020-02-13 12:43:23 +00:00
|
|
|
|
|
|
|
static void start_other_core(void)
|
|
|
|
{
|
2020-10-05 10:50:09 +00: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 12:43:23 +00:00
|
|
|
// no separate soc_caps.h for the single core variant.
|
2020-10-05 10:50:09 +00: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();
|
|
|
|
}
|
|
|
|
|
|
|
|
ESP_EARLY_LOGI(TAG, "Starting app cpu, entry point is %p", call_start_cpu1);
|
2020-02-13 12:43:23 +00:00
|
|
|
|
2020-07-29 05:13:51 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-10-05 10:50:09 +00:00
|
|
|
Cache_Flush(1);
|
|
|
|
Cache_Read_Enable(1);
|
2020-07-29 05:13:51 +00:00
|
|
|
#endif
|
2020-02-13 12:43:23 +00:00
|
|
|
|
2020-10-05 10:50:09 +00: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 05:13:51 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-10-05 10:50:09 +00: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 05:13:51 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
2020-10-05 10:50:09 +00: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);
|
|
|
|
}
|
2020-07-29 05:13:51 +00:00
|
|
|
#endif
|
2020-10-05 10:50:09 +00:00
|
|
|
ets_set_appcpu_boot_addr((uint32_t)call_start_cpu1);
|
2020-02-13 12:43:23 +00:00
|
|
|
|
2020-10-05 10:50:09 +00:00
|
|
|
bool cpus_up = false;
|
2020-02-13 12:43:23 +00:00
|
|
|
|
2020-10-05 10:50:09 +00: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 12:43:23 +00:00
|
|
|
}
|
2020-10-05 10:50:09 +00:00
|
|
|
esp_rom_delay_us(100);
|
2020-02-13 12:43:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
|
|
|
|
static void intr_matrix_clear(void)
|
|
|
|
{
|
2020-11-06 04:00:07 +00:00
|
|
|
for (int i = 0; i < ETS_MAX_INTR_SOURCE; i++) {
|
2020-02-13 12:43:23 +00:00
|
|
|
intr_matrix_set(0, i, ETS_INVALID_INUM);
|
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
intr_matrix_set(1, i, ETS_INVALID_INUM);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2020-03-03 04:22:41 +00: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 12:43:23 +00:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2021-07-13 02:45:06 +00:00
|
|
|
soc_reset_reason_t rst_reas[SOC_CPU_CORES_NUM];
|
2020-02-13 12:43:23 +00:00
|
|
|
#else
|
2021-07-13 02:45:06 +00:00
|
|
|
soc_reset_reason_t rst_reas[1];
|
2020-02-13 12:43:23 +00:00
|
|
|
#endif
|
2020-03-03 04:22:41 +00:00
|
|
|
|
2020-11-06 04:00:07 +00:00
|
|
|
#ifdef __riscv
|
2021-05-28 21:20:02 +00:00
|
|
|
if (cpu_hal_is_debugger_attached()) {
|
|
|
|
/* 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-06 04:00:07 +00: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$)
|
|
|
|
__asm__ __volatile__ (
|
2021-01-04 18:38:10 +00:00
|
|
|
".option push\n"
|
2020-11-06 04:00:07 +00:00
|
|
|
".option norelax\n"
|
|
|
|
"la gp, __global_pointer$\n"
|
|
|
|
".option pop"
|
2021-01-04 18:38:10 +00:00
|
|
|
);
|
2020-11-06 04:00:07 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-03 04:22:41 +00:00
|
|
|
// Move exception vectors to IRAM
|
2020-12-22 07:41:43 +00:00
|
|
|
cpu_hal_set_vecbase(&_vector_table);
|
2020-03-03 04:22:41 +00:00
|
|
|
|
2021-07-13 02:45:06 +00:00
|
|
|
rst_reas[0] = esp_rom_get_reset_reason(0);
|
2020-02-13 12:43:23 +00:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2021-07-13 02:45:06 +00:00
|
|
|
rst_reas[1] = esp_rom_get_reset_reason(1);
|
2020-03-03 04:22:41 +00:00
|
|
|
#endif
|
|
|
|
|
2020-02-05 14:40:15 +00:00
|
|
|
#ifndef CONFIG_BOOTLOADER_WDT_ENABLE
|
2020-03-03 04:22:41 +00:00
|
|
|
// from panic handler we can be reset by RWDT or TG0WDT
|
2021-07-13 02:45:06 +00:00
|
|
|
if (rst_reas[0] == RESET_REASON_CORE_RTC_WDT || rst_reas[0] == RESET_REASON_CORE_MWDT0
|
2020-02-13 12:43:23 +00:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2021-08-18 11:31:35 +00:00
|
|
|
|| rst_reas[1] == RESET_REASON_CORE_RTC_WDT || rst_reas[1] == RESET_REASON_CORE_MWDT0
|
2020-03-03 04:22:41 +00:00
|
|
|
#endif
|
2020-07-13 13:33:23 +00:00
|
|
|
) {
|
2020-03-03 04:22:41 +00:00
|
|
|
wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL};
|
|
|
|
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 14:40:15 +00:00
|
|
|
#endif
|
2020-03-03 04:22:41 +00:00
|
|
|
|
|
|
|
//Clear BSS. Please do not attempt to do any complex stuff (like early logging) before this.
|
|
|
|
memset(&_bss_start, 0, (&_bss_end - &_bss_start) * sizeof(_bss_start));
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
/* Unless waking from deep sleep (implying RTC memory is intact), clear RTC bss */
|
2021-07-13 02:45:06 +00:00
|
|
|
if (rst_reas[0] != RESET_REASON_CORE_DEEP_SLEEP) {
|
2020-03-03 04:22:41 +00:00
|
|
|
memset(&_rtc_bss_start, 0, (&_rtc_bss_end - &_rtc_bss_start) * sizeof(_rtc_bss_start));
|
|
|
|
}
|
|
|
|
|
|
|
|
#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. */
|
|
|
|
#if CONFIG_SPIRAM_BOOT_INIT
|
|
|
|
extern void esp_config_data_cache_mode(void);
|
|
|
|
esp_config_data_cache_mode();
|
|
|
|
Cache_Enable_DCache(0);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-07-29 05:13:51 +00: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 07:38:37 +00:00
|
|
|
#endif // CONFIG_IDF_TARGET_ESP32S3
|
2020-08-28 03:53:28 +00:00
|
|
|
|
2021-06-10 07:22:43 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2
|
2020-08-28 03:53:28 +00:00
|
|
|
/* Configure the Cache MMU size for instruction and rodata in flash. */
|
|
|
|
extern uint32_t Cache_Set_IDROM_MMU_Size(uint32_t irom_size, uint32_t drom_size);
|
2020-10-10 08:22:49 +00:00
|
|
|
extern int _rodata_reserved_start;
|
2020-08-28 03:53:28 +00:00
|
|
|
uint32_t rodata_reserved_start_align = (uint32_t)&_rodata_reserved_start & ~(MMU_PAGE_SIZE - 1);
|
|
|
|
uint32_t cache_mmu_irom_size = ((rodata_reserved_start_align - SOC_DROM_LOW) / MMU_PAGE_SIZE) * sizeof(uint32_t);
|
2020-10-10 08:22:49 +00:00
|
|
|
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
extern int _rodata_reserved_end;
|
2020-09-28 02:19:56 +00:00
|
|
|
uint32_t cache_mmu_drom_size = (((uint32_t)&_rodata_reserved_end - rodata_reserved_start_align + MMU_PAGE_SIZE - 1)/MMU_PAGE_SIZE)*sizeof(uint32_t);
|
2020-10-10 08:22:49 +00:00
|
|
|
#endif
|
2020-09-28 02:19:56 +00:00
|
|
|
|
2020-08-28 03:53:28 +00:00
|
|
|
Cache_Set_IDROM_MMU_Size(cache_mmu_irom_size, CACHE_DROM_MMU_MAX_END - cache_mmu_irom_size);
|
2021-06-10 07:22:43 +00:00
|
|
|
#endif // CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2
|
2020-07-29 05:13:51 +00:00
|
|
|
|
2021-08-02 09:15:07 +00:00
|
|
|
esp_mspi_pin_init();
|
2021-09-01 07:58:15 +00:00
|
|
|
// 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();
|
2021-04-15 09:13:48 +00:00
|
|
|
#if CONFIG_ESPTOOLPY_OCT_FLASH
|
|
|
|
bool efuse_opflash_en = REG_GET_FIELD(EFUSE_RD_REPEAT_DATA3_REG, EFUSE_FLASH_TYPE);
|
|
|
|
if (!efuse_opflash_en) {
|
|
|
|
ESP_EARLY_LOGE(TAG, "Octal Flash option selected, but EFUSE not configured!");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
esp_opiflash_init();
|
2021-08-13 03:30:54 +00:00
|
|
|
#endif
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
//On other chips, this feature is not provided by HW, or hasn't been tested yet.
|
2021-04-15 09:13:48 +00:00
|
|
|
spi_timing_flash_tuning();
|
|
|
|
#endif
|
|
|
|
|
2020-07-29 05:13:51 +00:00
|
|
|
bootloader_init_mem();
|
2020-03-03 04:22:41 +00:00
|
|
|
#if CONFIG_SPIRAM_BOOT_INIT
|
|
|
|
if (esp_spiram_init() != ESP_OK) {
|
2021-08-25 08:06:28 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
|
2020-03-03 04:22:41 +00: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
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_SPIRAM_IGNORE_NOTFOUND
|
|
|
|
ESP_EARLY_LOGI(TAG, "Failed to init external RAM; continuing without it.");
|
|
|
|
g_spiram_ok = false;
|
|
|
|
#else
|
|
|
|
ESP_EARLY_LOGE(TAG, "Failed to init external RAM!");
|
|
|
|
abort();
|
|
|
|
#endif
|
|
|
|
}
|
2020-11-03 07:55:34 +00:00
|
|
|
if (g_spiram_ok) {
|
|
|
|
esp_spiram_init_cache();
|
|
|
|
}
|
2020-03-03 04:22:41 +00:00
|
|
|
#endif
|
|
|
|
|
2020-02-13 12:43:23 +00:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2020-02-05 14:40:15 +00:00
|
|
|
s_cpu_up[0] = true;
|
2020-08-14 15:42:57 +00:00
|
|
|
#endif
|
2020-07-29 05:13:51 +00:00
|
|
|
|
2020-03-03 04:22:41 +00:00
|
|
|
ESP_EARLY_LOGI(TAG, "Pro cpu up.");
|
|
|
|
|
2020-06-17 09:13:55 +00:00
|
|
|
#if SOC_CPU_CORES_NUM > 1 // there is no 'single-core mode' for natively single-core processors
|
2020-02-13 12:43:23 +00:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
start_other_core();
|
2020-06-17 09:13:55 +00:00
|
|
|
#else
|
|
|
|
ESP_EARLY_LOGI(TAG, "Single core mode");
|
2020-07-29 05:13:51 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-06-17 09:13:55 +00:00
|
|
|
DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN); // stop the other core
|
2020-07-29 05:13:51 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
REG_CLR_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_CLKGATE_EN);
|
2021-06-30 12:33:07 +00: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 05:13:51 +00:00
|
|
|
#endif
|
2021-06-30 12:33:07 +00:00
|
|
|
#endif // CONFIG_IDF_TARGET_ESP32
|
2020-06-17 09:13:55 +00:00
|
|
|
#endif // !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
|
|
|
#endif // SOC_CPU_CORES_NUM > 1
|
2020-03-03 04:22:41 +00:00
|
|
|
|
|
|
|
#if CONFIG_SPIRAM_MEMTEST
|
|
|
|
if (g_spiram_ok) {
|
|
|
|
bool ext_ram_ok = esp_spiram_test();
|
|
|
|
if (!ext_ram_ok) {
|
|
|
|
ESP_EARLY_LOGE(TAG, "External RAM failed memory test!");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
|
|
|
|
extern void instruction_flash_page_info_init(void);
|
|
|
|
instruction_flash_page_info_init();
|
|
|
|
#endif
|
|
|
|
#if CONFIG_SPIRAM_RODATA
|
|
|
|
extern void rodata_flash_page_info_init(void);
|
|
|
|
rodata_flash_page_info_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_SPIRAM_FETCH_INSTRUCTIONS
|
|
|
|
extern void esp_spiram_enable_instruction_access(void);
|
|
|
|
esp_spiram_enable_instruction_access();
|
|
|
|
#endif
|
|
|
|
#if CONFIG_SPIRAM_RODATA
|
|
|
|
extern void esp_spiram_enable_rodata_access(void);
|
|
|
|
esp_spiram_enable_rodata_access();
|
2020-09-28 02:19:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32S3
|
2020-10-10 08:22:49 +00: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
|
|
|
|
|
2020-09-28 02:19:56 +00:00
|
|
|
extern void Cache_Set_IDROM_MMU_Info(uint32_t instr_page_num, uint32_t rodata_page_num, uint32_t rodata_start, uint32_t rodata_end, int i_off, int ro_off);
|
|
|
|
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);
|
2020-03-03 04:22:41 +00:00
|
|
|
#endif
|
|
|
|
|
2020-10-10 08:22:49 +00:00
|
|
|
#if CONFIG_ESP32S2_INSTRUCTION_CACHE_WRAP || CONFIG_ESP32S2_DATA_CACHE_WRAP || \
|
|
|
|
CONFIG_ESP32S3_INSTRUCTION_CACHE_WRAP || CONFIG_ESP32S3_DATA_CACHE_WRAP
|
2020-03-03 04:22:41 +00:00
|
|
|
uint32_t icache_wrap_enable = 0, dcache_wrap_enable = 0;
|
2020-10-10 08:22:49 +00:00
|
|
|
#if CONFIG_ESP32S2_INSTRUCTION_CACHE_WRAP || CONFIG_ESP32S3_INSTRUCTION_CACHE_WRAP
|
2020-03-03 04:22:41 +00:00
|
|
|
icache_wrap_enable = 1;
|
|
|
|
#endif
|
2020-10-10 08:22:49 +00:00
|
|
|
#if CONFIG_ESP32S2_DATA_CACHE_WRAP || CONFIG_ESP32S3_DATA_CACHE_WRAP
|
2020-03-03 04:22:41 +00: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 08:22:49 +00:00
|
|
|
#if CONFIG_ESP32S3_DATA_CACHE_16KB
|
|
|
|
Cache_Invalidate_DCache_All();
|
|
|
|
Cache_Occupy_Addr(SOC_DROM_LOW, 0x4000);
|
|
|
|
#endif
|
|
|
|
|
2020-03-03 04:22:41 +00: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.
|
|
|
|
#if CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2020-07-13 13:33:23 +00:00
|
|
|
#if CONFIG_ESP32_TRAX_TWOBANKS
|
|
|
|
trax_enable(TRAX_ENA_PRO_APP);
|
|
|
|
#else
|
|
|
|
trax_enable(TRAX_ENA_PRO);
|
|
|
|
#endif
|
2020-02-16 13:29:29 +00:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
2020-03-03 04:22:41 +00:00
|
|
|
trax_enable(TRAX_ENA_PRO);
|
|
|
|
#endif
|
|
|
|
trax_start_trace(TRAX_DOWNCOUNT_WORDS);
|
|
|
|
#endif // CONFIG_ESP32_TRAX || CONFIG_ESP32S2_TRAX
|
|
|
|
|
|
|
|
esp_clk_init();
|
|
|
|
esp_perip_clk_init();
|
2020-06-23 08:46:06 +00: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();
|
|
|
|
|
2020-03-03 04:22:41 +00:00
|
|
|
intr_matrix_clear();
|
|
|
|
|
2020-05-01 08:09:20 +00: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 14:48:49 +00:00
|
|
|
#ifdef CONFIG_ESP_CONSOLE_UART
|
2020-07-29 05:13:51 +00:00
|
|
|
uint32_t clock_hz = rtc_clk_apb_freq_get();
|
2021-06-10 07:22:43 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2
|
2020-07-29 05:13:51 +00:00
|
|
|
clock_hz = UART_CLK_FREQ_ROM; // From esp32-s3 on, UART clock source is selected to XTAL in ROM
|
|
|
|
#endif
|
2021-02-01 03:23:53 +00:00
|
|
|
esp_rom_uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
|
2020-07-29 05:13:51 +00:00
|
|
|
esp_rom_uart_set_clock_baudrate(CONFIG_ESP_CONSOLE_UART_NUM, clock_hz, CONFIG_ESP_CONSOLE_UART_BAUDRATE);
|
2020-03-03 04:22:41 +00:00
|
|
|
#endif
|
2020-05-01 08:09:20 +00:00
|
|
|
#endif
|
2020-03-03 04:22:41 +00:00
|
|
|
|
2021-02-05 09:10:44 +00:00
|
|
|
#if SOC_RTCIO_HOLD_SUPPORTED
|
2020-02-16 13:29:29 +00:00
|
|
|
rtcio_hal_unhold_all();
|
2021-02-05 09:10:44 +00:00
|
|
|
#else
|
|
|
|
gpio_hal_force_unhold_all();
|
|
|
|
#endif
|
2020-03-03 04:22:41 +00:00
|
|
|
|
|
|
|
esp_cache_err_int_init();
|
|
|
|
|
2021-01-04 18:38:10 +00:00
|
|
|
#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
|
2021-05-31 22:07:09 +00: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-08-18 11:31:35 +00:00
|
|
|
if (esp_memprot_is_locked_any()) {
|
2021-05-31 22:07:09 +00:00
|
|
|
ESP_EARLY_LOGE(TAG, "Memprot feature locked after the system reset! Potential safety corruption, rebooting.");
|
|
|
|
esp_restart_noos_dig();
|
|
|
|
}
|
2021-08-18 11:31:35 +00:00
|
|
|
esp_err_t memp_err = ESP_OK;
|
2021-01-04 18:38:10 +00:00
|
|
|
#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK
|
2021-08-18 11:31:35 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S2 //specific for ESP32S2 unless IDF-3024 is merged
|
|
|
|
memp_err = esp_memprot_set_prot(true, true, NULL);
|
|
|
|
#else
|
2020-10-08 03:19:23 +00:00
|
|
|
esp_memprot_set_prot(true, true, NULL);
|
2021-08-18 11:31:35 +00:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32S2 //specific for ESP32S2 unless IDF-3024 is merged
|
|
|
|
memp_err = esp_memprot_set_prot(true, false, NULL);
|
2020-02-05 14:40:15 +00:00
|
|
|
#else
|
2020-10-08 03:19:23 +00:00
|
|
|
esp_memprot_set_prot(true, false, NULL);
|
2020-02-05 14:40:15 +00:00
|
|
|
#endif
|
2021-08-18 11:31:35 +00:00
|
|
|
#endif
|
|
|
|
if (memp_err != ESP_OK) {
|
|
|
|
ESP_EARLY_LOGE(TAG, "Failed to set Memprot feature (error 0x%08X), rebooting.", memp_err);
|
|
|
|
esp_restart_noos_dig();
|
|
|
|
}
|
2020-02-05 14:40:15 +00:00
|
|
|
#endif
|
2020-03-03 04:22:41 +00:00
|
|
|
|
|
|
|
// Read the application binary image header. This will also decrypt the header if the image is encrypted.
|
2020-08-24 03:09:33 +00:00
|
|
|
__attribute__((unused)) esp_image_header_t fhdr = {0};
|
2020-03-03 04:22:41 +00:00
|
|
|
#ifdef CONFIG_APP_BUILD_TYPE_ELF_RAM
|
|
|
|
fhdr.spi_mode = ESP_IMAGE_SPI_MODE_DIO;
|
|
|
|
fhdr.spi_speed = ESP_IMAGE_SPI_SPEED_40M;
|
|
|
|
fhdr.spi_size = ESP_IMAGE_FLASH_SIZE_4MB;
|
|
|
|
|
|
|
|
extern void esp_rom_spiflash_attach(uint32_t, bool);
|
2020-07-13 13:57:24 +00:00
|
|
|
esp_rom_spiflash_attach(esp_rom_efuse_get_flash_gpio_info(), false);
|
2021-05-07 07:25:06 +00:00
|
|
|
bootloader_flash_unlock();
|
2020-03-03 04:22:41 +00:00
|
|
|
#else
|
|
|
|
// 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.
|
2020-07-13 13:33:23 +00:00
|
|
|
memcpy(&fhdr, (void *) SOC_DROM_LOW, sizeof(fhdr));
|
2020-03-03 04:22:41 +00:00
|
|
|
#endif // CONFIG_APP_BUILD_TYPE_ELF_RAM
|
|
|
|
|
2020-08-24 03:09:33 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
|
|
|
#if !CONFIG_SPIRAM_BOOT_INIT
|
2020-03-03 04:22:41 +00: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-24 03:09:33 +00: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) {
|
|
|
|
ESP_LOGE(TAG, "Invalid flash size in app image header.");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
bootloader_flash_update_size(app_flash_size);
|
|
|
|
#endif //CONFIG_SPI_FLASH_SIZE_OVERRIDE
|
2020-03-03 04:22:41 +00:00
|
|
|
|
2020-02-13 12:43:23 +00:00
|
|
|
#if !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
|
2020-02-05 14:40:15 +00:00
|
|
|
s_cpu_inited[0] = true;
|
|
|
|
|
|
|
|
volatile bool cpus_inited = false;
|
|
|
|
|
2020-06-09 00:17:48 +00:00
|
|
|
while (!cpus_inited) {
|
2020-02-05 14:40:15 +00:00
|
|
|
cpus_inited = true;
|
|
|
|
for (int i = 0; i < SOC_CPU_CORES_NUM; i++) {
|
|
|
|
cpus_inited &= s_cpu_inited[i];
|
|
|
|
}
|
2020-07-21 05:07:34 +00:00
|
|
|
esp_rom_delay_us(100);
|
2020-02-05 14:40:15 +00:00
|
|
|
}
|
2020-02-13 12:43:23 +00:00
|
|
|
#endif
|
2020-02-05 14:40:15 +00:00
|
|
|
|
2021-01-26 13:07:22 +00:00
|
|
|
#ifdef ROM_LOG_MODE
|
|
|
|
esp_efuse_set_rom_log_scheme(ROM_LOG_MODE);
|
|
|
|
#endif
|
|
|
|
|
2020-02-05 14:40:15 +00:00
|
|
|
SYS_STARTUP_FN();
|
2020-08-14 15:42:57 +00:00
|
|
|
}
|