Skip to content

Commit 59fab44

Browse files
committed
zephyr: Move hardware init dependencies
Move some hardware initialization from components to zephyr folder. Signed-off-by: Lucas Tamborrino <[email protected]>
1 parent 8d7054f commit 59fab44

35 files changed

+3133
-75
lines changed

components/bootloader_support/bootloader_flash/src/flash_qio_mode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "soc/efuse_periph.h"
1919
#include "soc/io_mux_reg.h"
2020
#include "esp_private/spi_flash_os.h"
21-
21+
#include "soc_flash_init.h"
2222

2323
static const char *TAG = "qio_mode";
2424

@@ -107,7 +107,7 @@ static void s_flash_set_qio_pins(void)
107107
#if SOC_SPI_MEM_SUPPORT_CONFIG_GPIO_BY_EFUSE
108108

109109
#if CONFIG_IDF_TARGET_ESP32
110-
esp_rom_spiflash_select_qio_pins(bootloader_flash_get_wp_pin(), esp_rom_efuse_get_flash_gpio_info());
110+
esp_rom_spiflash_select_qio_pins(flash_get_wp_pin(), esp_rom_efuse_get_flash_gpio_info());
111111
#else
112112
esp_rom_spiflash_select_qio_pins(esp_rom_efuse_get_flash_wp_gpio(), esp_rom_efuse_get_flash_gpio_info());
113113
#endif // CONFIG_IDF_TARGET_ESP32

components/esp_psram/esp32/esp_psram_impl_quad.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "esp_private/periph_ctrl.h"
3535
#include "bootloader_common.h"
3636
#include "esp_rom_gpio.h"
37-
#include "bootloader_flash_config.h"
37+
#include "soc_flash_init.h"
3838
#include "esp_private/esp_gpio_reserve.h"
3939

4040
#if CONFIG_SPIRAM
@@ -907,7 +907,7 @@ esp_err_t IRAM_ATTR esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode) //psra
907907
psram_io.psram_spiq_sd0_io = EFUSE_SPICONFIG_RET_SPIQ(spiconfig);
908908
psram_io.psram_spid_sd1_io = EFUSE_SPICONFIG_RET_SPID(spiconfig);
909909
psram_io.psram_spihd_sd2_io = EFUSE_SPICONFIG_RET_SPIHD(spiconfig);
910-
psram_io.psram_spiwp_sd3_io = bootloader_flash_get_wp_pin();
910+
psram_io.psram_spiwp_sd3_io = flash_get_wp_pin();
911911
}
912912

913913
assert(mode < PSRAM_CACHE_MAX && "we don't support any other mode for now.");
@@ -944,7 +944,17 @@ esp_err_t IRAM_ATTR esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode) //psra
944944
}
945945

946946
// Rise VDDSIO for 1.8V psram.
947-
bootloader_common_vddsdio_configure();
947+
#if CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V
948+
rtc_vddsdio_config_t cfg = rtc_vddsdio_get_config();
949+
if (cfg.enable == 1 && cfg.tieh == RTC_VDDSDIO_TIEH_1_8V) { // VDDSDIO regulator is enabled @ 1.8V
950+
cfg.drefh = 3;
951+
cfg.drefm = 3;
952+
cfg.drefl = 3;
953+
cfg.force = 1;
954+
rtc_vddsdio_set_config(cfg);
955+
esp_rom_delay_us(10); // wait for regulator to become stable
956+
}
957+
#endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST
948958
// GPIO related settings
949959
psram_gpio_config(&psram_io, mode);
950960

components/spi_flash/flash_ops.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "esp_private/esp_clk.h"
2525
#include "esp_private/esp_gpio_reserve.h"
2626
#if CONFIG_IDF_TARGET_ESP32
27+
#include "soc_flash_init.h"
2728
#include "esp32/rom/cache.h"
2829
#include "esp32/rom/spi_flash.h"
2930
#elif CONFIG_IDF_TARGET_ESP32S2
@@ -154,19 +155,6 @@ void IRAM_ATTR esp_mspi_pin_init(void)
154155
esp_gpio_reserve_pins(reserve_pin_mask);
155156
}
156157

157-
esp_err_t IRAM_ATTR spi_flash_init_chip_state(void)
158-
{
159-
#if SOC_SPI_MEM_SUPPORT_OPI_MODE
160-
if (bootloader_flash_is_octal_mode_enabled()) {
161-
return esp_opiflash_init(rom_spiflash_legacy_data->chip.device_id);
162-
}
163-
#endif
164-
#if CONFIG_SPI_FLASH_HPM_ON
165-
return spi_flash_enable_high_performance_mode();
166-
#endif // CONFIG_SPI_FLASH_HPM_ON
167-
return ESP_OK;
168-
}
169-
170158
void IRAM_ATTR spi_flash_set_rom_required_regs(void)
171159
{
172160
#if SOC_SPI_MEM_SUPPORT_OPI_MODE
@@ -239,7 +227,7 @@ uint8_t esp_mspi_get_io(esp_mspi_io_t io)
239227
* 2. rom code take 0x3f as invalid wp pad num, but take 0 as other invalid mspi pads num
240228
*/
241229
#if CONFIG_IDF_TARGET_ESP32
242-
return bootloader_flash_get_wp_pin();
230+
return flash_get_wp_pin();
243231
#else
244232
spiconfig = esp_rom_efuse_get_flash_wp_gpio();
245233
return (spiconfig == 0x3f) ? s_mspi_io_num_default[io] : spiconfig & 0x3f;

components/spi_flash/include/esp_private/spi_flash_os.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ typedef enum {
4545
ESP_MSPI_IO_MAX, /* Maximum IO MSPI occupied */
4646
} esp_mspi_io_t;
4747

48-
/**
49-
* @brief To setup Flash chip
50-
*/
51-
esp_err_t spi_flash_init_chip_state(void);
52-
5348
/**
5449
* @brief To initislize the MSPI pins
5550
*/

zephyr/common/console_init.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/sys/util.h>
8+
#include "stubs.h"
9+
#include "console_init.h"
10+
#include "soc/uart_periph.h"
11+
#include "soc/uart_channel.h"
12+
#include "soc/io_mux_reg.h"
13+
#include "soc/gpio_periph.h"
14+
#include "soc/gpio_sig_map.h"
15+
#include "soc/rtc.h"
16+
#include "hal/clk_gate_ll.h"
17+
#include "hal/gpio_hal.h"
18+
#if CONFIG_SOC_SERIES_ESP32S2
19+
#include "esp32s2/rom/usb/cdc_acm.h"
20+
#include "esp32s2/rom/usb/usb_common.h"
21+
#include "esp32s2/rom/usb/usb_persist.h"
22+
#endif
23+
#include "esp_rom_gpio.h"
24+
#include "esp_rom_uart.h"
25+
#include "esp_rom_sys.h"
26+
#include "esp_rom_caps.h"
27+
28+
void esp_console_deinit(void)
29+
{
30+
#ifdef CONFIG_ESP_CONSOLE_UART
31+
/* Ensure any buffered log output is displayed */
32+
esp_rom_uart_flush_tx(CONFIG_ESP_CONSOLE_UART_NUM);
33+
#endif /* CONFIG_ESP_CONSOLE_UART */
34+
}
35+
36+
#ifdef CONFIG_ESP_CONSOLE_UART
37+
void esp_console_init(void)
38+
{
39+
const int uart_num = CONFIG_ESP_CONSOLE_UART_NUM;
40+
41+
esp_rom_install_uart_printf();
42+
43+
esp_rom_uart_tx_wait_idle(0);
44+
45+
/* Set configured UART console baud rate */
46+
uint32_t clock_hz = rtc_clk_apb_freq_get();
47+
#if ESP_ROM_UART_CLK_IS_XTAL
48+
/* From esp32-s3 on, UART clk source is selected to XTAL in ROM */
49+
clock_hz = (uint32_t)rtc_clk_xtal_freq_get() * MHZ(1);
50+
#endif
51+
esp_rom_uart_set_clock_baudrate(uart_num, clock_hz, CONFIG_ESP_CONSOLE_UART_BAUDRATE);
52+
}
53+
#endif /* CONFIG_ESP_CONSOLE_UART */
54+
55+
#ifdef CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
56+
void esp_console_init(void)
57+
{
58+
esp_rom_uart_switch_buffer(ESP_ROM_USB_SERIAL_DEVICE_NUM);
59+
}
60+
#endif /* CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG */

zephyr/common/flash_init.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "flash_init.h"
8+
9+
#include <stdbool.h>
10+
#include <bootloader_flash_priv.h>
11+
#include <hal/efuse_ll.h>
12+
#include <hal/efuse_hal.h>
13+
#include "esp_private/spi_flash_os.h"
14+
#if CONFIG_SOC_SERIES_ESP32S3
15+
#include <esp32s3/opi_flash_private.h>
16+
#endif
17+
18+
bool flash_is_octal_mode_enabled(void)
19+
{
20+
#if SOC_SPI_MEM_SUPPORT_OPI_MODE
21+
return efuse_ll_get_flash_type();
22+
#else
23+
return false;
24+
#endif
25+
}
26+
27+
int spi_flash_init_chip_state(void)
28+
{
29+
#if SOC_SPI_MEM_SUPPORT_OPI_MODE
30+
if (flash_is_octal_mode_enabled()) {
31+
return esp_opiflash_init(rom_spiflash_legacy_data->chip.device_id);
32+
}
33+
#endif
34+
#if CONFIG_SPI_FLASH_HPM_ON
35+
/* Currently, only esp32s3 allows high performance mode. */
36+
return spi_flash_enable_high_performance_mode();
37+
#else
38+
return 0;
39+
#endif /* CONFIG_SOC_SERIES_ESP32S3 */
40+
}

zephyr/common/include/console_init.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
void esp_console_init(void);
10+
11+
void esp_console_deinit(void);
12+
13+
void esp_console_write_char_usb(char c);

zephyr/common/include/flash_init.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
8+
#include <stdint.h>
9+
#include <stdbool.h>
10+
11+
int spi_flash_init_chip_state(void);
12+
13+
bool flash_is_octal_mode_enabled(void);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
11+
void flash_update_id(void);
12+
13+
int init_spi_flash(void);
14+
15+
#ifdef CONFIG_SOC_SERIES_ESP32
16+
int flash_get_wp_pin(void);
17+
#endif

zephyr/common/include/soc_init.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
8+
#include <stdbool.h>
9+
10+
void print_banner(void);
11+
int read_bootloader_header(void);
12+
int check_bootloader_validity(void);
13+
void config_wdt(void);
14+
15+
16+
#if defined(CONFIG_SOC_SERIES_ESP32) || defined (CONFIG_SOC_SERIES_ESP32S3)
17+
void wdt_reset_info_dump(int cpu);
18+
#endif
19+
20+
void wdt_reset_cpu0_info_enable(void);
21+
22+
#if defined(CONFIG_SOC_SERIES_ESP32)
23+
void reset_mmu(void);
24+
#endif
25+
26+
#if !defined(CONFIG_SOC_SERIES_ESP32)
27+
void super_wdt_auto_feed(void);
28+
#endif
29+
30+
31+
void check_wdt_reset(void);
32+
33+
void soc_hw_init(void);
34+
35+
void ana_super_wdt_reset_config(bool enable);
36+
37+
void ana_bod_reset_config(bool enable);
38+
39+
void ana_clock_glitch_reset_config(bool enable);
40+
41+
void ana_reset_config(void);

zephyr/common/include/soc_random.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
8+
void soc_random_enable(void);
9+
10+
void soc_random_disable(void);

0 commit comments

Comments
 (0)