From b601dd3b24053ad4b1e6d3e7e343b6d3a6826a19 Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Mon, 29 Aug 2022 17:23:51 +0800 Subject: [PATCH] re-enable some dummy based HPM flash chips --- .../include_bootloader/bootloader_flash_priv.h | 8 ++++++++ components/bootloader_support/src/bootloader_flash.c | 6 ++++++ .../src/esp32s3/bootloader_esp32s3.c | 5 +++++ components/esptool_py/project_include.cmake | 12 +++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/components/bootloader_support/include_bootloader/bootloader_flash_priv.h b/components/bootloader_support/include_bootloader/bootloader_flash_priv.h index 5639da4050..98d0b26808 100644 --- a/components/bootloader_support/include_bootloader/bootloader_flash_priv.h +++ b/components/bootloader_support/include_bootloader/bootloader_flash_priv.h @@ -174,4 +174,12 @@ uint32_t bootloader_flash_read_sfdp(uint32_t sfdp_addr, unsigned int miso_byte_n */ void bootloader_enable_wp(void); +/** + * @brief Once this function is called, + * any on-going internal operations will be terminated and the device will return to its default power-on + * state and lose all the current volatile settings, such as Volatile Status Register bits, Write Enable Latch + * (WEL) status, Program/Erase Suspend status, etc. + */ +void bootloader_spi_flash_reset(void); + #endif diff --git a/components/bootloader_support/src/bootloader_flash.c b/components/bootloader_support/src/bootloader_flash.c index d968c503c4..d358bcf904 100644 --- a/components/bootloader_support/src/bootloader_flash.c +++ b/components/bootloader_support/src/bootloader_flash.c @@ -677,6 +677,12 @@ uint32_t IRAM_ATTR bootloader_read_flash_id(void) return id; } +void bootloader_spi_flash_reset(void) +{ + bootloader_execute_flash_command(0x66, 0, 0, 0); + bootloader_execute_flash_command(0x99, 0, 0, 0); +} + #if SOC_CACHE_SUPPORT_WRAP esp_err_t bootloader_flash_wrap_set(spi_flash_wrap_mode_t mode) { diff --git a/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c b/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c index 2cfabce583..eaa655a6a2 100644 --- a/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c +++ b/components/bootloader_support/src/esp32s3/bootloader_esp32s3.c @@ -218,6 +218,11 @@ static esp_err_t bootloader_init_spi_flash(void) } #endif +#if CONFIG_SPI_FLASH_HPM_ENABLE + // Reset flash, clear volatile bits DC[0:1]. Make it work under default mode to boot. + bootloader_spi_flash_reset(); +#endif + bootloader_flash_unlock(); #if CONFIG_ESPTOOLPY_FLASHMODE_QIO || CONFIG_ESPTOOLPY_FLASHMODE_QOUT diff --git a/components/esptool_py/project_include.cmake b/components/esptool_py/project_include.cmake index b7eff251ff..ae37888280 100644 --- a/components/esptool_py/project_include.cmake +++ b/components/esptool_py/project_include.cmake @@ -15,7 +15,17 @@ set(ESPSECUREPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espsecure.py") set(ESPEFUSEPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espefuse.py") set(ESPMONITOR ${python} "${idf_path}/tools/idf_monitor.py") -set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE}) +if(CONFIG_SPI_FLASH_HPM_ENABLE) +# When set flash frequency to 120M, must keep 1st bootloader work under ``DOUT`` mode +# because on some flash chips, 120M will modify the status register, +# which will make ROM won't work. +# This change intends to be for esptool only and the bootloader should keep use +# ``DOUT`` mode. + set(ESPFLASHMODE "dout") + message("Note: HPM is enabled for the flash, force the ROM bootloader into DOUT mode for stable boot on") +else() + set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE}) +endif() set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ}) set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})