soc: espressif: Add hardware initialization
Bring hardware initialization to zephyr code base. Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
This commit is contained in:
parent
2df905dc2c
commit
cdbd2b5558
21 changed files with 802 additions and 145 deletions
|
@ -10,6 +10,8 @@ zephyr_sources(
|
|||
|
||||
zephyr_include_directories(.)
|
||||
|
||||
zephyr_sources_ifndef(CONFIG_BOOTLOADER_MCUBOOT hw_init.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_PM power.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
|
||||
|
||||
|
|
|
@ -274,6 +274,13 @@ SECTIONS
|
|||
*(.iram0.literal .iram.literal .iram.text.literal .iram0.text .iram.text)
|
||||
*libzephyr.a:panic.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:loader.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:flash_init.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:soc_flash_init.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:console_init.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:soc_init.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:hw_init.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:soc_random.*(.literal .text .literal.* .text.*)
|
||||
|
||||
*libarch__riscv__core.a:(.literal .text .literal.* .text.*)
|
||||
*libsubsys__net__l2__ethernet.a:(.literal .text .literal.* .text.*)
|
||||
*libsubsys__net__lib__config.a:(.literal .text .literal.* .text.*)
|
||||
|
@ -385,10 +392,6 @@ SECTIONS
|
|||
*libzephyr.a:esp_cache.*(.literal .literal.* .text .text.*)
|
||||
*libzephyr.a:cache_utils.*(.literal .text .literal.* .text.*)
|
||||
|
||||
*libzephyr.a:bootloader_soc.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
|
||||
*libzephyr.a:bootloader_random*.*(.literal.bootloader_random_enable .text.bootloader_random_enable)
|
||||
|
||||
#if defined(CONFIG_ESP32_WIFI_IRAM_OPT)
|
||||
*libnet80211.a:( .wifi0iram .wifi0iram.* .wifislpiram .wifislpiram.* .wifiextrairam .wifiextrairam.* .wifi_extra_iram.*)
|
||||
*libpp.a:( .wifi0iram .wifi0iram.* .wifislpiram .wifislpiram.* .wifiextrairam .wifiextrairam.* .wifi_extra_iram.*)
|
||||
|
@ -417,21 +420,16 @@ SECTIONS
|
|||
{
|
||||
. = ALIGN(4);
|
||||
_loader_text_start = ABSOLUTE(.);
|
||||
*libzephyr.a:bootloader_init.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_esp32c6.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_clock_init.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_wdt.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_flash.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_flash_config_esp32c6.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_panic.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_mem.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_random.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_efuse.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_utility.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_sha.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:bootloader_console.*(.literal .text .literal.* .text.*)
|
||||
|
||||
*libzephyr.a:esp_image_format.*(.literal .text .literal.* .text.*)
|
||||
*libzephyr.a:flash_ops.*(.literal .text .literal.* .text.*)
|
||||
|
@ -529,6 +527,13 @@ SECTIONS
|
|||
*libdrivers__serial.a:uart_esp32.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:periph_ctrl.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:loader.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:flash_init.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:soc_flash_init.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:console_init.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:soc_init.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:hw_init.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:soc_random.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
|
||||
*libzephyr.a:cache_utils.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
|
||||
/* [mapping:hal] */
|
||||
|
@ -624,13 +629,9 @@ SECTIONS
|
|||
{
|
||||
. = ALIGN(4);
|
||||
_loader_data_start = ABSOLUTE(.);
|
||||
*libzephyr.a:bootloader_soc.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:bootloader_init.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:bootloader_esp32c6.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:bootloader_clock_init.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:bootloader_wdt.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:bootloader_flash.*(.srodata .srodata.* .rodata .rodata.*)
|
||||
*libzephyr.a:bootloader_flash_config_esp32c6.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:bootloader_clock_loader.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:bootloader_common_loader.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
*libzephyr.a:bootloader_panic.*(.rodata .rodata.* .srodata .srodata.*)
|
||||
|
|
115
soc/espressif/esp32c6/hw_init.c
Normal file
115
soc/espressif/esp32c6/hw_init.c
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "hw_init.h"
|
||||
#include <stdint.h>
|
||||
#include <esp_cpu.h>
|
||||
#include <soc/rtc.h>
|
||||
#include <esp_rom_sys.h>
|
||||
|
||||
#include <hal/cache_hal.h>
|
||||
#include <hal/mmu_hal.h>
|
||||
|
||||
#include <soc/hp_apm_reg.h>
|
||||
#include <soc/lp_apm_reg.h>
|
||||
#include <soc/lp_apm0_reg.h>
|
||||
#include <soc/pcr_reg.h>
|
||||
|
||||
#include <bootloader_clock.h>
|
||||
#include <bootloader_flash.h>
|
||||
#include <esp_flash_internal.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <console_init.h>
|
||||
#include <flash_init.h>
|
||||
#include <soc_flash_init.h>
|
||||
#include <soc_init.h>
|
||||
#include <soc_random.h>
|
||||
|
||||
const static char *TAG = "hw_init";
|
||||
|
||||
int hardware_init(void)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
soc_hw_init();
|
||||
|
||||
ana_reset_config();
|
||||
super_wdt_auto_feed();
|
||||
|
||||
/* By default, these access path filters are enable and allow the
|
||||
* access to masters only if they are in TEE mode. Since all masters
|
||||
* except HP CPU boots in REE mode, default setting of these filters
|
||||
* will deny the access to all masters except HP CPU.
|
||||
* So, at boot disabling these filters. They will enable as per the
|
||||
* use case by TEE initialization code.
|
||||
*/
|
||||
REG_WRITE(LP_APM_FUNC_CTRL_REG, 0);
|
||||
REG_WRITE(LP_APM0_FUNC_CTRL_REG, 0);
|
||||
REG_WRITE(HP_APM_FUNC_CTRL_REG, 0);
|
||||
|
||||
#ifdef CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE
|
||||
esp_cpu_configure_region_protection();
|
||||
#endif
|
||||
#if CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V
|
||||
rtc_vddsdio_config_t cfg = rtc_vddsdio_get_config();
|
||||
|
||||
if (cfg.enable == 1 && cfg.tieh == RTC_VDDSDIO_TIEH_1_8V) {
|
||||
cfg.drefh = 3;
|
||||
cfg.drefm = 3;
|
||||
cfg.drefl = 3;
|
||||
cfg.force = 1;
|
||||
rtc_vddsdio_set_config(cfg);
|
||||
esp_rom_delay_us(10);
|
||||
}
|
||||
#endif /* CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V */
|
||||
|
||||
bootloader_clock_configure();
|
||||
|
||||
/* initialize console, from now on, we can log */
|
||||
esp_console_init();
|
||||
print_banner();
|
||||
|
||||
spi_flash_init_chip_state();
|
||||
err = esp_flash_init_default_chip();
|
||||
if (err != 0) {
|
||||
ESP_EARLY_LOGE(TAG, "Failed to init flash chip, error %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
cache_hal_init();
|
||||
mmu_hal_init();
|
||||
|
||||
flash_update_id();
|
||||
|
||||
err = bootloader_flash_xmc_startup();
|
||||
if (err != 0) {
|
||||
ESP_EARLY_LOGE(TAG, "failed when running XMC startup flow, reboot!");
|
||||
return err;
|
||||
}
|
||||
|
||||
err = read_bootloader_header();
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = check_bootloader_validity();
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = init_spi_flash();
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
check_wdt_reset();
|
||||
config_wdt();
|
||||
|
||||
soc_random_enable();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue