2017-06-13 10:48:38 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2017-08-18 15:15:47 -07:00
|
|
|
/* Include esp-idf headers first to avoid redefining BIT() macro */
|
2023-12-20 12:24:13 -03:00
|
|
|
#include <soc.h>
|
2017-06-13 10:48:38 -07:00
|
|
|
#include <soc/rtc_cntl_reg.h>
|
|
|
|
#include <soc/timer_group_reg.h>
|
2022-05-06 11:11:04 +02:00
|
|
|
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
|
2017-06-13 10:48:38 -07:00
|
|
|
#include <xtensa/config/core-isa.h>
|
|
|
|
#include <xtensa/corebits.h>
|
2024-03-06 23:47:31 -03:00
|
|
|
#include <esp_private/spi_flash_os.h>
|
|
|
|
#include <esp_private/esp_mmu_map_private.h>
|
2024-09-10 10:22:46 -03:00
|
|
|
#include <esp_flash_internal.h>
|
2024-03-06 23:47:31 -03:00
|
|
|
#if CONFIG_ESP_SPIRAM
|
2024-08-14 08:03:56 -03:00
|
|
|
#include "psram.h"
|
2024-03-06 23:47:31 -03:00
|
|
|
#endif
|
2017-08-18 15:15:47 -07:00
|
|
|
|
2022-05-06 11:11:04 +02:00
|
|
|
#include <zephyr/kernel_structs.h>
|
2017-08-18 15:15:47 -07:00
|
|
|
#include <string.h>
|
2023-09-14 11:47:58 +02:00
|
|
|
#include <zephyr/toolchain.h>
|
2017-06-13 10:48:38 -07:00
|
|
|
#include <zephyr/types.h>
|
2022-03-02 17:21:41 -03:00
|
|
|
#include <zephyr/linker/linker-defs.h>
|
|
|
|
#include <kernel_internal.h>
|
2017-06-13 10:48:38 -07:00
|
|
|
|
2024-03-06 23:47:31 -03:00
|
|
|
#include <esp_private/system_internal.h>
|
|
|
|
#include <esp32/rom/cache.h>
|
|
|
|
#include <esp_cpu.h>
|
|
|
|
#include <hal/soc_hal.h>
|
|
|
|
#include <hal/cpu_hal.h>
|
|
|
|
#include <soc/gpio_periph.h>
|
|
|
|
#include <esp_err.h>
|
|
|
|
#include <esp_timer.h>
|
|
|
|
#include <hal/wdt_hal.h>
|
|
|
|
#include <esp_app_format.h>
|
2023-05-09 11:10:05 +02:00
|
|
|
|
2022-09-14 22:23:15 +02:00
|
|
|
#ifndef CONFIG_SOC_ENABLE_APPCPU
|
2022-08-23 17:40:25 -03:00
|
|
|
#include "esp_clk_internal.h"
|
2022-09-14 22:23:15 +02:00
|
|
|
#endif /* CONFIG_SOC_ENABLE_APPCPU */
|
2023-05-09 11:10:05 +02:00
|
|
|
|
2022-08-08 21:20:44 -03:00
|
|
|
#include <zephyr/sys/printk.h>
|
2024-07-29 15:01:55 -03:00
|
|
|
#include "esp_log.h"
|
|
|
|
|
|
|
|
#define TAG "boot.esp32"
|
2022-07-14 18:30:44 -03:00
|
|
|
|
2024-07-06 15:31:13 -04:00
|
|
|
extern void z_prep_c(void);
|
2023-11-23 09:35:12 -03:00
|
|
|
extern void esp_reset_reason_init(void);
|
2024-11-19 15:35:41 +00:00
|
|
|
extern int esp_appcpu_init(void);
|
2022-08-23 17:40:25 -03:00
|
|
|
|
2017-06-13 10:48:38 -07:00
|
|
|
/*
|
|
|
|
* This is written in C rather than assembly since, during the port bring up,
|
|
|
|
* Zephyr is being booted by the Espressif bootloader. With it, the C stack
|
|
|
|
* is already set up.
|
|
|
|
*/
|
2024-02-14 11:48:14 +01:00
|
|
|
void IRAM_ATTR __esp_platform_start(void)
|
2017-06-13 10:48:38 -07:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
extern uint32_t _init_start;
|
2017-06-13 10:48:38 -07:00
|
|
|
|
|
|
|
/* Move the exception vector table to IRAM. */
|
2024-11-19 15:35:41 +00:00
|
|
|
__asm__ __volatile__ ("wsr %0, vecbase" : : "r"(&_init_start));
|
2017-06-13 10:48:38 -07:00
|
|
|
|
2022-03-02 17:21:41 -03:00
|
|
|
z_bss_zero();
|
|
|
|
|
2024-11-19 15:35:41 +00:00
|
|
|
__asm__ __volatile__ ("" : : "g"(&__bss_start) : "memory");
|
2017-06-13 10:48:38 -07:00
|
|
|
|
|
|
|
/* Disable normal interrupts. */
|
2024-11-19 15:35:41 +00:00
|
|
|
__asm__ __volatile__ ("wsr %0, PS" : : "r"(PS_INTLEVEL(XCHAL_EXCM_LEVEL) | PS_UM | PS_WOE));
|
2017-06-13 10:48:38 -07:00
|
|
|
|
2018-01-25 16:39:35 -08:00
|
|
|
/* Initialize the architecture CPU pointer. Some of the
|
2025-01-07 12:00:43 -05:00
|
|
|
* initialization code wants a valid _current before
|
2024-07-06 15:31:13 -04:00
|
|
|
* z_prep_c() is invoked.
|
2018-01-25 16:39:35 -08:00
|
|
|
*/
|
2024-03-06 23:47:31 -03:00
|
|
|
__asm__ __volatile__("wsr.MISC0 %0; rsync" : : "r"(&_kernel.cpus[0]));
|
2018-01-25 16:39:35 -08:00
|
|
|
|
2023-11-23 09:35:12 -03:00
|
|
|
esp_reset_reason_init();
|
|
|
|
|
2024-02-14 11:48:14 +01:00
|
|
|
#ifndef CONFIG_MCUBOOT
|
2023-05-09 11:10:05 +02:00
|
|
|
/* ESP-IDF/MCUboot 2nd stage bootloader enables RTC WDT to check
|
|
|
|
* on startup sequence related issues in application. Hence disable that
|
|
|
|
* as we are about to start Zephyr environment.
|
2020-08-03 20:23:18 +05:30
|
|
|
*/
|
2023-05-09 11:10:05 +02: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);
|
2018-01-25 16:39:35 -08:00
|
|
|
|
2022-08-15 15:21:19 -03:00
|
|
|
esp_timer_early_init();
|
|
|
|
|
2024-03-06 23:47:31 -03:00
|
|
|
esp_mspi_pin_init();
|
2024-09-10 10:22:46 -03:00
|
|
|
|
|
|
|
esp_flash_app_init();
|
|
|
|
|
|
|
|
esp_mmu_map_init();
|
2024-03-06 23:47:31 -03:00
|
|
|
|
2020-12-03 18:44:56 +05:30
|
|
|
#if CONFIG_ESP_SPIRAM
|
2024-08-14 08:03:56 -03:00
|
|
|
esp_init_psram();
|
2024-02-14 11:48:14 +01:00
|
|
|
#endif /* CONFIG_ESP_SPIRAM */
|
2020-12-03 18:44:56 +05:30
|
|
|
|
2024-02-14 11:48:14 +01:00
|
|
|
#endif /* !CONFIG_MCUBOOT */
|
2023-05-09 11:10:05 +02:00
|
|
|
|
2021-04-12 16:13:54 -03:00
|
|
|
esp_intr_initialize();
|
2022-07-14 18:30:44 -03:00
|
|
|
|
2024-08-14 08:03:56 -03:00
|
|
|
#if CONFIG_ESP_SPIRAM
|
|
|
|
/* Init Shared Multi Heap for PSRAM */
|
|
|
|
int err = esp_psram_smh_init();
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
printk("Failed to initialize PSRAM shared multi heap (%d)\n", err);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-13 10:48:38 -07:00
|
|
|
/* Start Zephyr */
|
2024-07-06 15:31:13 -04:00
|
|
|
z_prep_c();
|
2017-06-13 10:48:38 -07:00
|
|
|
|
|
|
|
CODE_UNREACHABLE;
|
|
|
|
}
|
2018-11-14 11:19:24 -08:00
|
|
|
|
2019-06-18 14:45:40 -04:00
|
|
|
/* Boot-time static default printk handler, possibly to be overridden later. */
|
2021-01-15 12:03:57 +05:30
|
|
|
int IRAM_ATTR arch_printk_char_out(int c)
|
2018-11-14 11:19:24 -08:00
|
|
|
{
|
|
|
|
if (c == '\n') {
|
2021-10-13 14:51:33 -03:00
|
|
|
esp_rom_uart_tx_one_char('\r');
|
2018-11-14 11:19:24 -08:00
|
|
|
}
|
2021-10-13 14:51:33 -03:00
|
|
|
esp_rom_uart_tx_one_char(c);
|
2018-11-14 11:19:24 -08:00
|
|
|
return 0;
|
|
|
|
}
|
2020-09-22 11:43:57 -03:00
|
|
|
|
|
|
|
void sys_arch_reboot(int type)
|
|
|
|
{
|
|
|
|
esp_restart_noos();
|
|
|
|
}
|
2024-11-19 15:35:41 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_SOC_ENABLE_APPCPU) && !defined(CONFIG_MCUBOOT)
|
|
|
|
extern int esp_appcpu_init(void);
|
|
|
|
SYS_INIT(esp_appcpu_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
|
|
|
|
#endif
|