mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/bootloader_minor_enhancements' into 'master'
Feature/bootloader minor enhancements See merge request idf/esp-idf!3111
This commit is contained in:
commit
084ca82f96
@ -36,11 +36,12 @@ SECTIONS
|
||||
{
|
||||
. = ALIGN (16);
|
||||
_stext = .;
|
||||
_text_start = ABSOLUTE(.);
|
||||
_loader_text_start = ABSOLUTE(.);
|
||||
*(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
|
||||
*(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
|
||||
*liblog.a:(.literal .text .literal.* .text.*)
|
||||
*libgcc.a:(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_common.o(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_flash.o(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_random.o(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_utility.o(.literal .text .literal.* .text.*)
|
||||
@ -56,7 +57,7 @@ SECTIONS
|
||||
*(.fini.literal)
|
||||
*(.fini)
|
||||
*(.gnu.version)
|
||||
_text_end = ABSOLUTE(.);
|
||||
_loader_text_end = ABSOLUTE(.);
|
||||
_etext = .;
|
||||
} > iram_loader_seg
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "esp_spi_flash.h"
|
||||
|
||||
#define FLASH_SECTOR_SIZE 0x1000
|
||||
#define FLASH_BLOCK_SIZE 0x10000
|
||||
|
||||
/* Provide a Flash API for bootloader_support code,
|
||||
that can be used from bootloader or app code.
|
||||
@ -100,4 +101,14 @@ esp_err_t bootloader_flash_write(size_t dest_addr, void *src, size_t size, bool
|
||||
*/
|
||||
esp_err_t bootloader_flash_erase_sector(size_t sector);
|
||||
|
||||
/**
|
||||
* @brief Erase the Flash range.
|
||||
*
|
||||
* @param start_addr start address of flash offset
|
||||
* @param size sector aligned size to be erased
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size);
|
||||
|
||||
#endif
|
||||
|
@ -106,8 +106,8 @@ bool bootloader_common_erase_part_type_data(const char *list_erase, bool ota_dat
|
||||
|
||||
partitions = bootloader_mmap(ESP_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_MAX_LEN);
|
||||
if (!partitions) {
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", ESP_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_MAX_LEN);
|
||||
return false;
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", ESP_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_MAX_LEN);
|
||||
return false;
|
||||
}
|
||||
ESP_LOGD(TAG, "mapped partition table 0x%x at 0x%x", ESP_PARTITION_TABLE_OFFSET, (intptr_t)partitions);
|
||||
|
||||
@ -128,7 +128,7 @@ bool bootloader_common_erase_part_type_data(const char *list_erase, bool ota_dat
|
||||
// partition->label is not null-terminated string.
|
||||
strncpy(label, (char *)&partition->label, sizeof(label) - 1);
|
||||
if (fl_ota_data_erase == true || (bootloader_common_label_search(list_erase, label) == true)) {
|
||||
err = esp_rom_spiflash_erase_area(partition->pos.offset, partition->pos.size);
|
||||
err = bootloader_flash_erase_range(partition->pos.offset, partition->pos.size);
|
||||
if (err != ESP_OK) {
|
||||
ret = false;
|
||||
marker = "err";
|
||||
|
@ -73,6 +73,11 @@ esp_err_t bootloader_flash_erase_sector(size_t sector)
|
||||
return spi_flash_erase_sector(sector);
|
||||
}
|
||||
|
||||
esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size)
|
||||
{
|
||||
return spi_flash_erase_range(start_addr, size);
|
||||
}
|
||||
|
||||
#else
|
||||
/* Bootloader version, uses ROM functions only */
|
||||
#include <soc/dport_reg.h>
|
||||
@ -247,4 +252,28 @@ esp_err_t bootloader_flash_erase_sector(size_t sector)
|
||||
return spi_to_esp_err(esp_rom_spiflash_erase_sector(sector));
|
||||
}
|
||||
|
||||
esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size)
|
||||
{
|
||||
if (start_addr % FLASH_SECTOR_SIZE != 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (size % FLASH_SECTOR_SIZE != 0) {
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
size_t start = start_addr / FLASH_SECTOR_SIZE;
|
||||
size_t end = start + size / FLASH_SECTOR_SIZE;
|
||||
const size_t sectors_per_block = FLASH_BLOCK_SIZE / FLASH_SECTOR_SIZE;
|
||||
|
||||
esp_rom_spiflash_result_t rc = ESP_ROM_SPIFLASH_RESULT_OK;
|
||||
for (size_t sector = start; sector != end && rc == ESP_ROM_SPIFLASH_RESULT_OK; ) {
|
||||
if (sector % sectors_per_block == 0 && end - sector >= sectors_per_block) {
|
||||
rc = esp_rom_spiflash_erase_block(sector / sectors_per_block);
|
||||
sector += sectors_per_block;
|
||||
} else {
|
||||
rc = esp_rom_spiflash_erase_sector(sector);
|
||||
++sector;
|
||||
}
|
||||
}
|
||||
return spi_to_esp_err(rc);
|
||||
}
|
||||
#endif
|
||||
|
@ -218,7 +218,7 @@ esp_err_t IRAM_ATTR spi_flash_erase_range(uint32_t start_addr, uint32_t size)
|
||||
if (rc == ESP_ROM_SPIFLASH_RESULT_OK) {
|
||||
for (size_t sector = start; sector != end && rc == ESP_ROM_SPIFLASH_RESULT_OK; ) {
|
||||
spi_flash_guard_start();
|
||||
if (sector % sectors_per_block == 0 && end - sector > sectors_per_block) {
|
||||
if (sector % sectors_per_block == 0 && end - sector >= sectors_per_block) {
|
||||
rc = esp_rom_spiflash_erase_block(sector / sectors_per_block);
|
||||
sector += sectors_per_block;
|
||||
COUNTER_ADD_BYTES(erase, sectors_per_block * SPI_FLASH_SEC_SIZE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user