Skip to content

Commit

Permalink
Merge branch 'bugfix/boot_flash_build_v4.4' into 'release/v4.4'
Browse files Browse the repository at this point in the history
bugfix(spi_flash): Fix build error when octal flash is enabled (backport v4.4)

See merge request espressif/esp-idf!28091
  • Loading branch information
jack0c committed Jan 2, 2024
2 parents ece1bf2 + ebb65b2 commit 8262c19
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
17 changes: 17 additions & 0 deletions components/bootloader_support/include/bootloader_flash.h
Expand Up @@ -9,6 +9,17 @@
#include <esp_spi_flash.h> /* including in bootloader for error values */
#include "sdkconfig.h"
#include "soc/soc_caps.h"
#if CONFIG_IDF_TARGET_ESP32
#include "esp32/rom/spi_flash.h"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/rom/spi_flash.h"
#elif CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/rom/spi_flash.h"
#elif CONFIG_IDF_TARGET_ESP32C3
#include "esp32c3/rom/spi_flash.h"
#elif CONFIG_IDF_TARGET_ESP32H2
#include "esp32h2/rom/spi_flash.h"
#endif
#include "bootloader_flash_override.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -48,6 +59,12 @@ esp_err_t bootloader_flash_xmc_startup(void);
*/
esp_err_t IRAM_ATTR __attribute__((weak)) bootloader_flash_unlock(void);

/**
* @brief Get the spi flash working mode.
*
* @return The mode of flash working mode, see `esp_rom_spiflash_read_mode_t`
*/
esp_rom_spiflash_read_mode_t bootloader_flash_get_spi_mode(void);

#ifdef __cplusplus
}
Expand Down
46 changes: 44 additions & 2 deletions components/bootloader_support/src/bootloader_flash.c
Expand Up @@ -145,6 +145,11 @@ esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size)
#include "esp32h2/rom/cache.h"
#include "soc/cache_memory.h"
#endif

#if CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/rom/opi_flash.h"
#endif

static const char *TAG = "bootloader_flash";

#if CONFIG_IDF_TARGET_ESP32
Expand Down Expand Up @@ -503,9 +508,9 @@ void bootloader_flash_32bits_address_map_enable(esp_rom_spiflash_read_mode_t fla
assert(false);
break;
}
cache_hal_disable(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
uint32_t autoload = Cache_Suspend_DCache();
esp_rom_opiflash_cache_mode_config(flash_mode, &cache_rd);
cache_hal_enable(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
Cache_Resume_DCache(autoload);
}
#endif

Expand Down Expand Up @@ -844,3 +849,40 @@ esp_err_t IRAM_ATTR bootloader_flash_xmc_startup(void)
}

#endif //XMC_SUPPORT

esp_rom_spiflash_read_mode_t bootloader_flash_get_spi_mode(void)
{
esp_rom_spiflash_read_mode_t spi_mode = ESP_ROM_SPIFLASH_FASTRD_MODE;
#if CONFIG_IDF_TARGET_ESP32
uint32_t spi_ctrl = REG_READ(SPI_CTRL_REG(0));
if (spi_ctrl & SPI_FREAD_QIO) {
spi_mode = ESP_ROM_SPIFLASH_QIO_MODE;
} else if (spi_ctrl & SPI_FREAD_QUAD) {
spi_mode = ESP_ROM_SPIFLASH_QOUT_MODE;
} else if (spi_ctrl & SPI_FREAD_DIO) {
spi_mode = ESP_ROM_SPIFLASH_DIO_MODE;
} else if (spi_ctrl & SPI_FREAD_DUAL) {
spi_mode = ESP_ROM_SPIFLASH_DOUT_MODE;
} else if (spi_ctrl & SPI_FASTRD_MODE) {
spi_mode = ESP_ROM_SPIFLASH_FASTRD_MODE;
} else {
spi_mode = ESP_ROM_SPIFLASH_SLOWRD_MODE;
}
#else
uint32_t spi_ctrl = REG_READ(SPI_MEM_CTRL_REG(0));
if (spi_ctrl & SPI_MEM_FREAD_QIO) {
spi_mode = ESP_ROM_SPIFLASH_QIO_MODE;
} else if (spi_ctrl & SPI_MEM_FREAD_QUAD) {
spi_mode = ESP_ROM_SPIFLASH_QOUT_MODE;
} else if (spi_ctrl & SPI_MEM_FREAD_DIO) {
spi_mode = ESP_ROM_SPIFLASH_DIO_MODE;
} else if (spi_ctrl & SPI_MEM_FREAD_DUAL) {
spi_mode = ESP_ROM_SPIFLASH_DOUT_MODE;
} else if (spi_ctrl & SPI_MEM_FASTRD_MODE) {
spi_mode = ESP_ROM_SPIFLASH_FASTRD_MODE;
} else {
spi_mode = ESP_ROM_SPIFLASH_SLOWRD_MODE;
}
#endif
return spi_mode;
}
2 changes: 2 additions & 0 deletions components/spi_flash/spi_flash_hpm_enable.c
Expand Up @@ -10,7 +10,9 @@
#include "esp_log.h"
#include "spi_flash_defs.h"
#include "esp_rom_sys.h"
#if CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/rom/spi_flash.h"
#endif
#include "spi_flash_override.h"

// TODO: These dependencies will be removed after remove bootloader_flash to G0.IDF-4609
Expand Down

0 comments on commit 8262c19

Please sign in to comment.