kopia lustrzana https://github.com/espressif/esp-idf
esp_flash: fix coredump for legacy spi flash API
When legacy mode is used, the coredump still fails during linking because "esp_flash_init_default_chip", "esp_flash_app_init" and "esp_flash_default_chip " are not compiled and linked. Instead of using ``if`` macros in callers, these functions are protected by ``if`` macros in the header, and also not compiled in the sources. "esp_flash_default_chip" variable is compiled with safe default value.pull/4139/head
rodzic
c27fd32fbe
commit
6139864a4c
|
@ -43,7 +43,7 @@
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
#include "esp_spi_flash.h"
|
#include "esp_spi_flash.h"
|
||||||
#include "esp_flash.h"
|
#include "esp_flash_internal.h"
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
#include "esp_event.h"
|
#include "esp_event.h"
|
||||||
#include "esp_spi_flash.h"
|
#include "esp_spi_flash.h"
|
||||||
|
@ -395,11 +395,9 @@ void start_cpu0_default(void)
|
||||||
/* init default OS-aware flash access critical section */
|
/* init default OS-aware flash access critical section */
|
||||||
spi_flash_guard_set(&g_flash_guard_default_ops);
|
spi_flash_guard_set(&g_flash_guard_default_ops);
|
||||||
|
|
||||||
#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
|
||||||
esp_flash_app_init();
|
esp_flash_app_init();
|
||||||
esp_err_t flash_ret = esp_flash_init_default_chip();
|
esp_err_t flash_ret = esp_flash_init_default_chip();
|
||||||
assert(flash_ret == ESP_OK);
|
assert(flash_ret == ESP_OK);
|
||||||
#endif
|
|
||||||
|
|
||||||
uint8_t revision = esp_efuse_get_chip_ver();
|
uint8_t revision = esp_efuse_get_chip_ver();
|
||||||
ESP_LOGI(TAG, "Chip Revision: %d", revision);
|
ESP_LOGI(TAG, "Chip Revision: %d", revision);
|
||||||
|
|
|
@ -13,7 +13,6 @@ menu "Core dump"
|
||||||
config ESP32_ENABLE_COREDUMP_TO_FLASH
|
config ESP32_ENABLE_COREDUMP_TO_FLASH
|
||||||
bool "Flash"
|
bool "Flash"
|
||||||
select ESP32_ENABLE_COREDUMP
|
select ESP32_ENABLE_COREDUMP
|
||||||
select SPI_FLASH_USE_LEGACY_IMPL
|
|
||||||
config ESP32_ENABLE_COREDUMP_TO_UART
|
config ESP32_ENABLE_COREDUMP_TO_UART
|
||||||
bool "UART"
|
bool "UART"
|
||||||
select ESP32_ENABLE_COREDUMP
|
select ESP32_ENABLE_COREDUMP
|
||||||
|
|
|
@ -4,21 +4,24 @@ if(BOOTLOADER_BUILD)
|
||||||
# need other parts of this component
|
# need other parts of this component
|
||||||
set(srcs "spi_flash_rom_patch.c")
|
set(srcs "spi_flash_rom_patch.c")
|
||||||
else()
|
else()
|
||||||
set(srcs
|
set(srcs
|
||||||
"cache_utils.c"
|
"cache_utils.c"
|
||||||
"flash_mmap.c"
|
"flash_mmap.c"
|
||||||
"flash_ops.c"
|
"flash_ops.c"
|
||||||
"partition.c"
|
"partition.c"
|
||||||
"spi_flash_rom_patch.c"
|
"spi_flash_rom_patch.c"
|
||||||
|
)
|
||||||
|
# New implementation
|
||||||
|
list(APPEND srcs
|
||||||
"spi_flash_chip_drivers.c"
|
"spi_flash_chip_drivers.c"
|
||||||
"spi_flash_chip_generic.c"
|
"spi_flash_chip_generic.c"
|
||||||
"spi_flash_chip_issi.c"
|
"spi_flash_chip_issi.c"
|
||||||
"spi_flash_os_func_app.c"
|
"spi_flash_os_func_app.c"
|
||||||
"spi_flash_os_func_noos.c"
|
"spi_flash_os_func_noos.c"
|
||||||
"memspi_host_driver.c")
|
"memspi_host_driver.c"
|
||||||
if(NOT CONFIG_SPI_FLASH_USE_LEGACY_IMPL)
|
"esp_flash_api.c"
|
||||||
list(APPEND srcs "esp_flash_api.c" "esp_flash_spi_init.c")
|
"esp_flash_spi_init.c"
|
||||||
endif()
|
)
|
||||||
set(priv_requires bootloader_support app_update soc)
|
set(priv_requires bootloader_support app_update soc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -294,14 +294,15 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui
|
||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t err = spiflash_start(chip);
|
esp_err_t err = ESP_OK;
|
||||||
if (err != ESP_OK) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for write protected regions overlapping the erase region
|
// Check for write protected regions overlapping the erase region
|
||||||
if (chip->chip_drv->get_protected_regions != NULL &&
|
if (chip->chip_drv->get_protected_regions != NULL &&
|
||||||
chip->chip_drv->num_protectable_regions > 0) {
|
chip->chip_drv->num_protectable_regions > 0) {
|
||||||
|
|
||||||
|
err = spiflash_start(chip);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
uint64_t protected = 0;
|
uint64_t protected = 0;
|
||||||
err = chip->chip_drv->get_protected_regions(chip, &protected);
|
err = chip->chip_drv->get_protected_regions(chip, &protected);
|
||||||
if (err == ESP_OK && protected != 0) {
|
if (err == ESP_OK && protected != 0) {
|
||||||
|
@ -313,10 +314,10 @@ esp_err_t IRAM_ATTR esp_flash_erase_region(esp_flash_t *chip, uint32_t start, ui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Don't lock the SPI flash for the entire erase, as this may be very long
|
||||||
|
err = spiflash_end(chip, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't lock the SPI flash for the entire erase, as this may be very long
|
|
||||||
err = spiflash_end(chip, err);
|
|
||||||
|
|
||||||
while (err == ESP_OK && len >= sector_size) {
|
while (err == ESP_OK && len >= sector_size) {
|
||||||
err = spiflash_start(chip);
|
err = spiflash_start(chip);
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "hal/spi_types.h"
|
#include "hal/spi_types.h"
|
||||||
#include "driver/spi_common.h"
|
#include "driver/spi_common.h"
|
||||||
|
|
||||||
static const char TAG[] = "spi_flash";
|
__attribute__((unused)) static const char TAG[] = "spi_flash";
|
||||||
|
|
||||||
#ifdef CONFIG_ESPTOOLPY_FLASHFREQ_80M
|
#ifdef CONFIG_ESPTOOLPY_FLASHFREQ_80M
|
||||||
#define DEFAULT_FLASH_SPEED ESP_FLASH_80MHZ
|
#define DEFAULT_FLASH_SPEED ESP_FLASH_80MHZ
|
||||||
|
@ -49,6 +49,18 @@ static const char TAG[] = "spi_flash";
|
||||||
#define DEFAULT_FLASH_MODE SPI_FLASH_FASTRD
|
#define DEFAULT_FLASH_MODE SPI_FLASH_FASTRD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ESP_FLASH_HOST_CONFIG_DEFAULT() (memspi_host_config_t){ \
|
||||||
|
.host_id = SPI_HOST,\
|
||||||
|
.speed = DEFAULT_FLASH_SPEED, \
|
||||||
|
.cs_num = 0, \
|
||||||
|
.iomux = false, \
|
||||||
|
.input_delay_ns = 0,\
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
esp_flash_t *esp_flash_default_chip = NULL;
|
||||||
|
|
||||||
|
|
||||||
static IRAM_ATTR void cs_initialize(esp_flash_t *chip, const esp_flash_spi_device_config_t *config, bool use_iomux)
|
static IRAM_ATTR void cs_initialize(esp_flash_t *chip, const esp_flash_spi_device_config_t *config, bool use_iomux)
|
||||||
{
|
{
|
||||||
//Not using spicommon_cs_initialize since we don't want to put the whole
|
//Not using spicommon_cs_initialize since we don't want to put the whole
|
||||||
|
@ -151,29 +163,22 @@ esp_err_t spi_bus_remove_flash_device(esp_flash_t *chip)
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ESP_FLASH_HOST_CONFIG_DEFAULT() (memspi_host_config_t){ \
|
|
||||||
.host_id = SPI_HOST,\
|
|
||||||
.speed = DEFAULT_FLASH_SPEED, \
|
|
||||||
.cs_num = 0, \
|
|
||||||
.iomux = false, \
|
|
||||||
.input_delay_ns = 0,\
|
|
||||||
}
|
|
||||||
|
|
||||||
static DRAM_ATTR spi_flash_host_driver_t esp_flash_default_host_drv = ESP_FLASH_DEFAULT_HOST_DRIVER();
|
|
||||||
|
|
||||||
static DRAM_ATTR memspi_host_data_t default_driver_data;
|
|
||||||
|
|
||||||
/* The default (ie initial boot) no-OS ROM esp_flash_os_functions_t */
|
/* The default (ie initial boot) no-OS ROM esp_flash_os_functions_t */
|
||||||
extern const esp_flash_os_functions_t esp_flash_noos_functions;
|
extern const esp_flash_os_functions_t esp_flash_noos_functions;
|
||||||
|
|
||||||
|
#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
||||||
|
|
||||||
|
static DRAM_ATTR memspi_host_data_t default_driver_data;
|
||||||
|
static DRAM_ATTR spi_flash_host_driver_t esp_flash_default_host_drv = ESP_FLASH_DEFAULT_HOST_DRIVER();
|
||||||
|
|
||||||
|
|
||||||
static DRAM_ATTR esp_flash_t default_chip = {
|
static DRAM_ATTR esp_flash_t default_chip = {
|
||||||
.read_mode = DEFAULT_FLASH_MODE,
|
.read_mode = DEFAULT_FLASH_MODE,
|
||||||
.host = &esp_flash_default_host_drv,
|
.host = &esp_flash_default_host_drv,
|
||||||
.os_func = &esp_flash_noos_functions,
|
.os_func = &esp_flash_noos_functions,
|
||||||
};
|
};
|
||||||
|
|
||||||
esp_flash_t *esp_flash_default_chip = NULL;
|
|
||||||
|
|
||||||
esp_err_t esp_flash_init_default_chip(void)
|
esp_err_t esp_flash_init_default_chip(void)
|
||||||
{
|
{
|
||||||
memspi_host_config_t cfg = ESP_FLASH_HOST_CONFIG_DEFAULT();
|
memspi_host_config_t cfg = ESP_FLASH_HOST_CONFIG_DEFAULT();
|
||||||
|
@ -204,3 +209,5 @@ esp_err_t esp_flash_app_init(void)
|
||||||
{
|
{
|
||||||
return esp_flash_init_os_functions(&default_chip, 0);
|
return esp_flash_init_os_functions(&default_chip, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -282,33 +282,6 @@ esp_err_t esp_flash_read_encrypted(esp_flash_t *chip, uint32_t address, void *ou
|
||||||
*/
|
*/
|
||||||
extern esp_flash_t *esp_flash_default_chip;
|
extern esp_flash_t *esp_flash_default_chip;
|
||||||
|
|
||||||
/** @brief Initialise the default SPI flash chip
|
|
||||||
*
|
|
||||||
* Called by OS startup code. You do not need to call this in your own applications.
|
|
||||||
*/
|
|
||||||
esp_err_t esp_flash_init_default_chip(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable OS-level SPI flash protections in IDF
|
|
||||||
*
|
|
||||||
* Called by OS startup code. You do not need to call this in your own applications.
|
|
||||||
*
|
|
||||||
* @return ESP_OK if success, otherwise failed. See return value of ``esp_flash_init_os_functions``.
|
|
||||||
*/
|
|
||||||
esp_err_t esp_flash_app_init(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable OS-level SPI flash for a specific chip.
|
|
||||||
*
|
|
||||||
* @param chip The chip to init os functions.
|
|
||||||
* @param host_id Which SPI host to use, 1 for SPI1, 2 for SPI2 (HSPI), 3 for SPI3 (VSPI)
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* - ESP_OK if success
|
|
||||||
* - ESP_ERR_INVALID_ARG if host_id is invalid
|
|
||||||
*/
|
|
||||||
esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
#include "esp_flash.h"
|
||||||
|
|
||||||
|
/** Internal API, don't use in the applications */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/** @brief Initialise the default SPI flash chip
|
||||||
|
*
|
||||||
|
* Called by OS startup code. You do not need to call this in your own applications.
|
||||||
|
*/
|
||||||
|
#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
||||||
|
#define esp_flash_init_default_chip(...) ({ESP_OK;})
|
||||||
|
#else
|
||||||
|
esp_err_t esp_flash_init_default_chip(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable OS-level SPI flash protections in IDF
|
||||||
|
*
|
||||||
|
* Called by OS startup code. You do not need to call this in your own applications.
|
||||||
|
*
|
||||||
|
* @return ESP_OK if success, otherwise failed. See return value of ``esp_flash_init_os_functions``.
|
||||||
|
*/
|
||||||
|
#ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
||||||
|
#define esp_flash_app_init(...) ({ESP_OK;})
|
||||||
|
#else
|
||||||
|
esp_err_t esp_flash_app_init(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize OS-level functions for a specific chip.
|
||||||
|
*
|
||||||
|
* @param chip The chip to init os functions.
|
||||||
|
* @param host_id Which SPI host to use, 1 for SPI1, 2 for SPI2 (HSPI), 3 for SPI3 (VSPI)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK if success
|
||||||
|
* - ESP_ERR_INVALID_ARG if host_id is invalid
|
||||||
|
*/
|
||||||
|
esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -172,9 +172,7 @@ static esp_err_t load_partitions(void)
|
||||||
err = ESP_ERR_NO_MEM;
|
err = ESP_ERR_NO_MEM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
|
||||||
item->info.flash_chip = esp_flash_default_chip;
|
item->info.flash_chip = esp_flash_default_chip;
|
||||||
#endif
|
|
||||||
item->info.address = it->pos.offset;
|
item->info.address = it->pos.offset;
|
||||||
item->info.size = it->pos.size;
|
item->info.size = it->pos.size;
|
||||||
item->info.type = it->type;
|
item->info.type = it->type;
|
||||||
|
@ -336,11 +334,10 @@ esp_err_t esp_partition_read(const esp_partition_t* partition,
|
||||||
#endif // CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
#endif // CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
||||||
} else {
|
} else {
|
||||||
#if CONFIG_SECURE_FLASH_ENC_ENABLED
|
#if CONFIG_SECURE_FLASH_ENC_ENABLED
|
||||||
#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
|
||||||
if (partition->flash_chip != esp_flash_default_chip) {
|
if (partition->flash_chip != esp_flash_default_chip) {
|
||||||
return ESP_ERR_NOT_SUPPORTED;
|
return ESP_ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
/* Encrypted partitions need to be read via a cache mapping */
|
/* Encrypted partitions need to be read via a cache mapping */
|
||||||
const void *buf;
|
const void *buf;
|
||||||
spi_flash_mmap_handle_t handle;
|
spi_flash_mmap_handle_t handle;
|
||||||
|
@ -379,11 +376,9 @@ esp_err_t esp_partition_write(const esp_partition_t* partition,
|
||||||
#endif // CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
#endif // CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
||||||
} else {
|
} else {
|
||||||
#if CONFIG_SECURE_FLASH_ENC_ENABLED
|
#if CONFIG_SECURE_FLASH_ENC_ENABLED
|
||||||
#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
|
||||||
if (partition->flash_chip != esp_flash_default_chip) {
|
if (partition->flash_chip != esp_flash_default_chip) {
|
||||||
return ESP_ERR_NOT_SUPPORTED;
|
return ESP_ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return spi_flash_write_encrypted(dst_offset, src, size);
|
return spi_flash_write_encrypted(dst_offset, src, size);
|
||||||
#else
|
#else
|
||||||
return ESP_ERR_NOT_SUPPORTED;
|
return ESP_ERR_NOT_SUPPORTED;
|
||||||
|
@ -433,11 +428,9 @@ esp_err_t esp_partition_mmap(const esp_partition_t* partition, size_t offset, si
|
||||||
if (offset + size > partition->size) {
|
if (offset + size > partition->size) {
|
||||||
return ESP_ERR_INVALID_SIZE;
|
return ESP_ERR_INVALID_SIZE;
|
||||||
}
|
}
|
||||||
#ifndef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
|
|
||||||
if (partition->flash_chip != esp_flash_default_chip) {
|
if (partition->flash_chip != esp_flash_default_chip) {
|
||||||
return ESP_ERR_NOT_SUPPORTED;
|
return ESP_ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
size_t phys_addr = partition->address + offset;
|
size_t phys_addr = partition->address + offset;
|
||||||
// offset within 64kB block
|
// offset within 64kB block
|
||||||
size_t region_offset = phys_addr & 0xffff;
|
size_t region_offset = phys_addr & 0xffff;
|
||||||
|
|
Ładowanie…
Reference in New Issue