From 9d30b04f6804eae6e73838e33f5b6a3f91ae59ad Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Thu, 12 Sep 2019 02:23:44 +0800 Subject: [PATCH] coredump: use esp_flash api in coredump Also put esp_flash functions into noflash region, when ESP32_PANIC_HANDLER_IRAM and coredump are enabled. The option disables the re-enabling of the CPU-cache when it's disabled during coredump. This requires all the coredump functions including the flash API to be in the D/IRAM. --- components/espcoredump/linker.lf | 11 +++++++++- components/espcoredump/src/core_dump_flash.c | 22 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/components/espcoredump/linker.lf b/components/espcoredump/linker.lf index 131e10c30..17470b53a 100644 --- a/components/espcoredump/linker.lf +++ b/components/espcoredump/linker.lf @@ -1,6 +1,6 @@ [mapping:espcoredump] archive: libespcoredump.a -entries: +entries: if ESP32_PANIC_HANDLER_IRAM = y: core_dump_uart (noflash_text) core_dump_flash (noflash_text) @@ -8,3 +8,12 @@ entries: core_dump_port (noflash_text) else: * (default) + +[mapping:spi_flash_override] +archive: libspi_flash.a +entries: + if ESP32_PANIC_HANDLER_IRAM = y && ESP32_ENABLE_COREDUMP_TO_FLASH = y: + esp_flash_api (noflash_text) + esp_flash_spi_init (noflash_text) + else: + * (default) diff --git a/components/espcoredump/src/core_dump_flash.c b/components/espcoredump/src/core_dump_flash.c index 5705e94bb..569852536 100644 --- a/components/espcoredump/src/core_dump_flash.c +++ b/components/espcoredump/src/core_dump_flash.c @@ -17,6 +17,8 @@ #include "esp_core_dump_priv.h" #include "esp_flash_internal.h" +#include "sdkconfig.h" + const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_flash"; #if CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH @@ -83,7 +85,11 @@ static uint32_t esp_core_dump_write_flash_padded(size_t off, uint8_t *data, uint assert((off + data_len + (data_size % sizeof(uint32_t) ? sizeof(uint32_t) : 0)) <= s_core_flash_config.partition.start + s_core_flash_config.partition.size); +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL err = spi_flash_write(off, data, data_len); +#else + err = esp_flash_write(esp_flash_default_chip, data, off, data_len); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to write data to flash (%d)!", err); return 0; @@ -96,7 +102,11 @@ static uint32_t esp_core_dump_write_flash_padded(size_t off, uint8_t *data, uint for (k = 0; k < len; k++) { rom_data.data8[k] = *(data + data_len + k); } +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL err = spi_flash_write(off + data_len, &rom_data, sizeof(uint32_t)); +#else + err = esp_flash_write(esp_flash_default_chip, &rom_data, off + data_len, sizeof(uint32_t)); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to finish write data to flash (%d)!", err); return 0; @@ -128,7 +138,11 @@ static esp_err_t esp_core_dump_flash_write_prepare(void *priv, uint32_t *data_le sec_num++; } assert(sec_num * SPI_FLASH_SEC_SIZE <= s_core_flash_config.partition.size); +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL err = spi_flash_erase_range(s_core_flash_config.partition.start + 0, sec_num * SPI_FLASH_SEC_SIZE); +#else + err = esp_flash_erase_region(esp_flash_default_chip, s_core_flash_config.partition.start + 0, sec_num * SPI_FLASH_SEC_SIZE); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to erase flash (%d)!", err); return err; @@ -142,7 +156,11 @@ static esp_err_t esp_core_dump_flash_write_word(core_dump_write_flash_data_t *wr uint32_t data32 = word; assert(wr_data->off + sizeof(uint32_t) <= s_core_flash_config.partition.size); +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL err = spi_flash_write(s_core_flash_config.partition.start + wr_data->off, &data32, sizeof(uint32_t)); +#else + err = esp_flash_write(esp_flash_default_chip, &data32, s_core_flash_config.partition.start + wr_data->off, sizeof(uint32_t)); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to write to flash (%d)!", err); return err; @@ -167,7 +185,11 @@ static esp_err_t esp_core_dump_flash_write_end(void *priv) uint32_t data32[4]; } rom_data; +#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL esp_err_t err = spi_flash_read(s_core_flash_config.partition.start + 0, &rom_data, sizeof(rom_data)); +#else + esp_err_t err = esp_flash_read(esp_flash_default_chip, &rom_data, s_core_flash_config.partition.start + 0, sizeof(rom_data)); +#endif if (err != ESP_OK) { ESP_COREDUMP_LOGE("Failed to read flash (%d)!", err); return err;