mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'refactor/remove_spi_flash_include' into 'master'
refactor: remove dependency on spi_flash include for sector size See merge request espressif/esp-idf!31392
This commit is contained in:
commit
82b1d5ed0d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -80,7 +80,7 @@ static const esp_partition_t *read_otadata(esp_ota_select_entry_t *two_otadata)
|
||||
return NULL;
|
||||
} else {
|
||||
memcpy(&two_otadata[0], result, sizeof(esp_ota_select_entry_t));
|
||||
memcpy(&two_otadata[1], result + SPI_FLASH_SEC_SIZE, sizeof(esp_ota_select_entry_t));
|
||||
memcpy(&two_otadata[1], result + otadata_partition->erase_size, sizeof(esp_ota_select_entry_t));
|
||||
esp_partition_munmap(ota_data_map);
|
||||
}
|
||||
return otadata_partition;
|
||||
@ -149,7 +149,7 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp
|
||||
if ((image_size == 0) || (image_size == OTA_SIZE_UNKNOWN)) {
|
||||
ret = esp_partition_erase_range(partition, 0, partition->size);
|
||||
} else {
|
||||
const int aligned_erase_size = (image_size + SPI_FLASH_SEC_SIZE - 1) & ~(SPI_FLASH_SEC_SIZE - 1);
|
||||
const int aligned_erase_size = (image_size + partition->erase_size - 1) & ~(partition->erase_size - 1);
|
||||
ret = esp_partition_erase_range(partition, 0, aligned_erase_size);
|
||||
}
|
||||
if (ret != ESP_OK) {
|
||||
@ -192,14 +192,14 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
|
||||
if (it->handle == handle) {
|
||||
if (it->need_erase) {
|
||||
// must erase the partition before writing to it
|
||||
uint32_t first_sector = it->wrote_size / SPI_FLASH_SEC_SIZE; // first affected sector
|
||||
uint32_t last_sector = (it->wrote_size + size - 1) / SPI_FLASH_SEC_SIZE; // last affected sector
|
||||
uint32_t first_sector = it->wrote_size / it->part->erase_size; // first affected sector
|
||||
uint32_t last_sector = (it->wrote_size + size - 1) / it->part->erase_size; // last affected sector
|
||||
|
||||
ret = ESP_OK;
|
||||
if ((it->wrote_size % SPI_FLASH_SEC_SIZE) == 0) {
|
||||
ret = esp_partition_erase_range(it->part, it->wrote_size, ((last_sector - first_sector) + 1) * SPI_FLASH_SEC_SIZE);
|
||||
if ((it->wrote_size % it->part->erase_size) == 0) {
|
||||
ret = esp_partition_erase_range(it->part, it->wrote_size, ((last_sector - first_sector) + 1) * it->part->erase_size);
|
||||
} else if (first_sector != last_sector) {
|
||||
ret = esp_partition_erase_range(it->part, (first_sector + 1) * SPI_FLASH_SEC_SIZE, (last_sector - first_sector) * SPI_FLASH_SEC_SIZE);
|
||||
ret = esp_partition_erase_range(it->part, (first_sector + 1) * it->part->erase_size, (last_sector - first_sector) * it->part->erase_size);
|
||||
}
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
@ -369,11 +369,11 @@ static esp_err_t rewrite_ota_seq(esp_ota_select_entry_t *two_otadata, uint32_t s
|
||||
|
||||
two_otadata[sec_id].ota_seq = seq;
|
||||
two_otadata[sec_id].crc = bootloader_common_ota_select_crc(&two_otadata[sec_id]);
|
||||
esp_err_t ret = esp_partition_erase_range(ota_data_partition, sec_id * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE);
|
||||
esp_err_t ret = esp_partition_erase_range(ota_data_partition, sec_id * ota_data_partition->erase_size, ota_data_partition->erase_size);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
} else {
|
||||
return esp_partition_write(ota_data_partition, SPI_FLASH_SEC_SIZE * sec_id, &two_otadata[sec_id], sizeof(esp_ota_select_entry_t));
|
||||
return esp_partition_write(ota_data_partition, ota_data_partition->erase_size * sec_id, &two_otadata[sec_id], sizeof(esp_ota_select_entry_t));
|
||||
}
|
||||
}
|
||||
|
||||
@ -906,7 +906,7 @@ esp_err_t esp_ota_erase_last_boot_app_partition(void)
|
||||
}
|
||||
|
||||
int sec_id = inactive_otadata;
|
||||
err = esp_partition_erase_range(ota_data_partition, sec_id * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE);
|
||||
err = esp_partition_erase_range(ota_data_partition, sec_id * ota_data_partition->erase_size, ota_data_partition->erase_size);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -177,7 +177,7 @@ static void erase_ota_data(void)
|
||||
{
|
||||
const esp_partition_t *data_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
|
||||
TEST_ASSERT_NOT_EQUAL(NULL, data_partition);
|
||||
TEST_ESP_OK(esp_partition_erase_range(data_partition, 0, 2 * SPI_FLASH_SEC_SIZE));
|
||||
TEST_ESP_OK(esp_partition_erase_range(data_partition, 0, 2 * data_partition->erase_size));
|
||||
}
|
||||
|
||||
/* @brief Reboots ESP using mode deep sleep. This mode guaranty that RTC_DATA_ATTR variables is not reset.
|
||||
@ -251,7 +251,7 @@ static void get_ota_data(const esp_partition_t *otadata_partition, esp_ota_selec
|
||||
TEST_ASSERT_NOT_EQUAL(NULL, ota_select_map);
|
||||
|
||||
memcpy(ota_data_0, ota_select_map, sizeof(esp_ota_select_entry_t));
|
||||
memcpy(ota_data_1, (uint8_t *)ota_select_map + SPI_FLASH_SEC_SIZE, sizeof(esp_ota_select_entry_t));
|
||||
memcpy(ota_data_1, (uint8_t *)ota_select_map + otadata_partition->erase_size, sizeof(esp_ota_select_entry_t));
|
||||
bootloader_munmap(ota_select_map);
|
||||
}
|
||||
}
|
||||
@ -264,7 +264,7 @@ static void get_ota_data(const esp_partition_t *otadata_partition, esp_ota_selec
|
||||
*/
|
||||
static void write_ota_data(const esp_partition_t *otadata_partition, esp_ota_select_entry_t *ota_data, int sec_id)
|
||||
{
|
||||
esp_partition_write(otadata_partition, SPI_FLASH_SEC_SIZE * sec_id, &ota_data[sec_id], sizeof(esp_ota_select_entry_t));
|
||||
esp_partition_write(otadata_partition, otadata_partition->erase_size * sec_id, &ota_data[sec_id], sizeof(esp_ota_select_entry_t));
|
||||
}
|
||||
|
||||
/* @brief Makes a corrupt of ota_data.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -10,7 +10,6 @@
|
||||
#include "esp_flash_spi_init.h"
|
||||
#include "test_utils.h"
|
||||
#include "test_spi_utils.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "unity.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
@ -146,7 +145,7 @@ static void write_large_buffer(esp_flash_t *chip, const esp_partition_t *part, c
|
||||
{
|
||||
printf("Erasing chip %p, %d bytes\n", chip, length);
|
||||
|
||||
TEST_ESP_OK(esp_flash_erase_region(chip, part->address, (length + SPI_FLASH_SEC_SIZE) & ~(SPI_FLASH_SEC_SIZE - 1)));
|
||||
TEST_ESP_OK(esp_flash_erase_region(chip, part->address, (length + part->erase_size) & ~(part->erase_size - 1)));
|
||||
|
||||
printf("Writing chip %p, %d bytes from source %p\n", chip, length, source);
|
||||
// note writing to unaligned address
|
||||
@ -195,7 +194,7 @@ void spi_task4(void* arg)
|
||||
|
||||
ESP_LOGI(TAG, "Testing chip %p...", chip);
|
||||
const esp_partition_t *part = get_test_data_partition();
|
||||
TEST_ASSERT(part->size > test_len + 2 + SPI_FLASH_SEC_SIZE);
|
||||
TEST_ASSERT(part->size > test_len + 2 + part->erase_size);
|
||||
|
||||
write_large_buffer(chip, part, source_buf, test_len);
|
||||
read_and_check(chip, part, source_buf, test_len);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -464,6 +464,14 @@ esp_err_t esp_partition_deregister_external(const esp_partition_t* partition);
|
||||
*/
|
||||
void esp_partition_unload_all(void);
|
||||
|
||||
/**
|
||||
* @brief Get the main flash sector size
|
||||
* @return
|
||||
* - SPI_FLASH_SEC_SIZE - For esp32xx target
|
||||
* - ESP_PARTITION_EMULATED_SECTOR_SIZE - For linux target
|
||||
*/
|
||||
uint32_t esp_partition_get_main_flash_sector_size(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -547,6 +547,11 @@ esp_partition_file_mmap_ctrl_t *esp_partition_get_file_mmap_ctrl_act(void)
|
||||
return &s_esp_partition_file_mmap_ctrl_act;
|
||||
}
|
||||
|
||||
uint32_t esp_partition_get_main_flash_sector_size(void)
|
||||
{
|
||||
return ESP_PARTITION_EMULATED_SECTOR_SIZE;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ESP_PARTITION_ENABLE_STATS
|
||||
// timing data for ESP8266, 160MHz CPU frequency, 80MHz flash frequency
|
||||
// all values in microseconds
|
||||
|
@ -233,3 +233,8 @@ bool esp_partition_main_flash_region_safe(size_t addr, size_t size)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t esp_partition_get_main_flash_sector_size(void)
|
||||
{
|
||||
return SPI_FLASH_SEC_SIZE;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ idf_component_register(SRCS "${srcs}"
|
||||
REQUIRES "${requires}"
|
||||
PRIV_REQUIRES "${priv_requires}"
|
||||
INCLUDE_DIRS "include"
|
||||
"../spi_flash/include"
|
||||
PRIV_INCLUDE_DIRS "private_include")
|
||||
|
||||
# If we use the linux target, we need to redirect the crc functions to the linux
|
||||
|
@ -9,7 +9,8 @@ idf_component_register(SRCS "test_nvs.cpp"
|
||||
"../../../private_include"
|
||||
"../../../../mbedtls/mbedtls/include"
|
||||
WHOLE_ARCHIVE
|
||||
REQUIRES nvs_flash)
|
||||
REQUIRES nvs_flash
|
||||
PRIV_REQUIRES spi_flash)
|
||||
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE -std=gnu++20)
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <random>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include "esp_partition.h"
|
||||
|
||||
class PartitionEmulationFixture {
|
||||
public:
|
||||
@ -22,8 +23,9 @@ public:
|
||||
FAIL("Failed to initialize esp_partition_file_mmap");
|
||||
}
|
||||
|
||||
esp_partition.address = start_sector * SPI_FLASH_SEC_SIZE;
|
||||
esp_partition.size = (start_sector + sector_size) * SPI_FLASH_SEC_SIZE;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
esp_partition.address = start_sector * sec_size;
|
||||
esp_partition.size = (start_sector + sector_size) * sec_size;
|
||||
esp_partition.erase_size = ESP_PARTITION_EMULATED_SECTOR_SIZE;
|
||||
esp_partition.type = ESP_PARTITION_TYPE_DATA;
|
||||
esp_partition.subtype = ESP_PARTITION_SUBTYPE_DATA_NVS;
|
||||
@ -42,6 +44,7 @@ public:
|
||||
off_t size = -1;
|
||||
void *p_buff = nullptr;
|
||||
char const *fail_msg = nullptr;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
|
||||
do {
|
||||
// get file size
|
||||
@ -57,7 +60,7 @@ public:
|
||||
}
|
||||
|
||||
// check if file fits into the partitiion
|
||||
if (size > sector_size * SPI_FLASH_SEC_SIZE) {
|
||||
if (size > sector_size * sec_size) {
|
||||
fail_msg = "file with partition content doesn't fit into the partition";
|
||||
break;
|
||||
}
|
||||
@ -82,7 +85,7 @@ public:
|
||||
}
|
||||
|
||||
// erase whole partition
|
||||
if (ESP_OK != esp_partition_erase_range(&esp_partition, 0, sector_size * SPI_FLASH_SEC_SIZE)) {
|
||||
if (ESP_OK != esp_partition_erase_range(&esp_partition, 0, sector_size * sec_size)) {
|
||||
fail_msg = "cannot erase partition prior to write partition binary from file";
|
||||
break;
|
||||
}
|
||||
@ -123,7 +126,8 @@ public:
|
||||
// absolute sectorNumber is used here
|
||||
bool erase(size_t sectorNumber)
|
||||
{
|
||||
size_t offset = sectorNumber * SPI_FLASH_SEC_SIZE;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
size_t offset = sectorNumber * sec_size;
|
||||
|
||||
// check the upper bound
|
||||
esp_partition_file_mmap_ctrl_t *p_ctrl = esp_partition_get_file_mmap_ctrl_act();
|
||||
@ -135,7 +139,7 @@ public:
|
||||
// esp_partition_erase_range uses offset relative to the beginning of partition
|
||||
return (esp_partition_erase_range(&esp_partition,
|
||||
offset - esp_partition.address,
|
||||
SPI_FLASH_SEC_SIZE) == ESP_OK);
|
||||
sec_size) == ESP_OK);
|
||||
}
|
||||
|
||||
~PartitionEmulationFixture()
|
||||
@ -175,9 +179,10 @@ public:
|
||||
) :
|
||||
PartitionEmulationFixture(start_sector1, sector_size1, partition_name1), esp_partition2()
|
||||
{
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
// for 2nd partition
|
||||
esp_partition2.address = start_sector2 * SPI_FLASH_SEC_SIZE;
|
||||
esp_partition2.size = (start_sector2 + sector_size2) * SPI_FLASH_SEC_SIZE;
|
||||
esp_partition2.address = start_sector2 * sec_size;
|
||||
esp_partition2.size = (start_sector2 + sector_size2) * sec_size;
|
||||
esp_partition2.erase_size = ESP_PARTITION_EMULATED_SECTOR_SIZE;
|
||||
esp_partition2.type = ESP_PARTITION_TYPE_DATA;
|
||||
esp_partition2.subtype = ESP_PARTITION_SUBTYPE_DATA_NVS;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
#include <random>
|
||||
#include "test_fixtures.hpp"
|
||||
#include "spi_flash_mmap.h"
|
||||
|
||||
#define TEST_ESP_ERR(rc, res) CHECK((rc) == (res))
|
||||
#define TEST_ESP_OK(rc) CHECK((rc) == ESP_OK)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -9,6 +9,7 @@
|
||||
#include "nvs_partition.hpp"
|
||||
#include "test_fixtures.hpp"
|
||||
#include <string.h>
|
||||
#include "esp_partition.h"
|
||||
|
||||
TEST_CASE("nvs_flash_init_partition_ptr fails due to nullptr arg", "[nvs_custom_part]")
|
||||
{
|
||||
@ -22,13 +23,15 @@ TEST_CASE("nvs_flash_init_partition_ptr inits one partition", "[nvs_custom_part]
|
||||
{
|
||||
const uint32_t NVS_FLASH_SECTOR = 6;
|
||||
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
|
||||
uint8_t *p_part_desc_addr_start;
|
||||
CHECK(esp_partition_file_mmap((const uint8_t **)&p_part_desc_addr_start) == ESP_OK);
|
||||
|
||||
esp_partition_t partition = {};
|
||||
strcpy(partition.label, "test");
|
||||
partition.address = NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE;
|
||||
partition.size = NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE;
|
||||
partition.address = NVS_FLASH_SECTOR * sec_size;
|
||||
partition.size = NVS_FLASH_SECTOR_COUNT_MIN * sec_size;
|
||||
|
||||
CHECK(nvs_flash_init_partition_ptr(&partition) == ESP_OK);
|
||||
CHECK(nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test") != nullptr);
|
||||
|
@ -4,7 +4,8 @@ idf_component_register(SRCS "nvs_page_test.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../../src"
|
||||
PRIV_INCLUDE_DIRS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../../private_include"
|
||||
REQUIRES nvs_flash)
|
||||
REQUIRES nvs_flash
|
||||
PRIV_REQUIRES spi_flash)
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PUBLIC --coverage)
|
||||
target_link_libraries(${COMPONENT_LIB} --coverage)
|
||||
|
@ -9,6 +9,7 @@ static const char* TAG = "nvs_page_host_test";
|
||||
#include "unity.h"
|
||||
#include "test_fixtures.hpp"
|
||||
#include "esp_log.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
|
||||
#if defined(SEGGER_H) && defined(GLOBAL_H)
|
||||
NVS_GUARD_SYSVIEW_MACRO_EXPANSION_PUSH();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -37,8 +37,9 @@ public:
|
||||
TEST_FAIL_MESSAGE("Failed to initialize esp_partition_file_mmap");
|
||||
}
|
||||
|
||||
esp_partition.address = start_sector * SPI_FLASH_SEC_SIZE;
|
||||
esp_partition.size = (start_sector + sector_count) * SPI_FLASH_SEC_SIZE;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
esp_partition.address = start_sector * sec_size;
|
||||
esp_partition.size = (start_sector + sector_count) * sec_size;
|
||||
esp_partition.erase_size = ESP_PARTITION_EMULATED_SECTOR_SIZE;
|
||||
esp_partition.type = ESP_PARTITION_TYPE_DATA;
|
||||
esp_partition.subtype = ESP_PARTITION_SUBTYPE_DATA_NVS;
|
||||
|
@ -108,9 +108,10 @@ extern "C" esp_err_t nvs_flash_init_partition_ptr(const esp_partition_t *partiti
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
esp_err_t init_res = NVSPartitionManager::get_instance()->init_custom(part,
|
||||
0,
|
||||
partition->size / SPI_FLASH_SEC_SIZE);
|
||||
partition->size / sec_size);
|
||||
|
||||
if (init_res != ESP_OK) {
|
||||
delete part;
|
||||
|
@ -9,11 +9,14 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include "nvs_internal.h"
|
||||
#include "esp_partition.h"
|
||||
|
||||
namespace nvs {
|
||||
|
||||
Page::Page() : mPartition(nullptr) { }
|
||||
|
||||
const uint32_t nvs::Page::SEC_SIZE = esp_partition_get_main_flash_sector_size();
|
||||
|
||||
uint32_t Page::Header::calculateCrc32()
|
||||
{
|
||||
return esp_rom_crc32_le(0xffffffff,
|
||||
@ -49,7 +52,7 @@ esp_err_t Page::load(Partition *partition, uint32_t sectorNumber)
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < SPI_FLASH_SEC_SIZE; i += 4 * BLOCK_SIZE) {
|
||||
for (uint32_t i = 0; i < SEC_SIZE; i += 4 * BLOCK_SIZE) {
|
||||
rc = mPartition->read_raw(mBaseAddress + i, block, 4 * BLOCK_SIZE);
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
@ -1020,7 +1023,7 @@ esp_err_t Page::setVersion(uint8_t ver)
|
||||
|
||||
esp_err_t Page::erase()
|
||||
{
|
||||
auto rc = mPartition->erase_range(mBaseAddress, SPI_FLASH_SEC_SIZE);
|
||||
auto rc = mPartition->erase_range(mBaseAddress, SEC_SIZE);
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include <type_traits>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "compressed_enum_table.hpp"
|
||||
#include "intrusive_list.h"
|
||||
#include "nvs_item_hash_list.hpp"
|
||||
@ -34,7 +33,7 @@ public:
|
||||
static const uint32_t ESB_WRITTEN = 0x1;
|
||||
static const uint32_t ESB_ERASED = 0x2;
|
||||
|
||||
static const uint32_t SEC_SIZE = SPI_FLASH_SEC_SIZE;
|
||||
static const uint32_t SEC_SIZE;
|
||||
|
||||
static const size_t ENTRY_SIZE = 32;
|
||||
static const size_t ENTRY_COUNT = 126;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -33,6 +33,7 @@ esp_err_t NVSPartitionManager::init_partition(const char *partition_label)
|
||||
}
|
||||
|
||||
uint32_t size;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
Storage* mStorage;
|
||||
|
||||
mStorage = lookup_storage_from_name(partition_label);
|
||||
@ -40,7 +41,7 @@ esp_err_t NVSPartitionManager::init_partition(const char *partition_label)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
NVS_ASSERT_OR_RETURN(SPI_FLASH_SEC_SIZE != 0, ESP_FAIL);
|
||||
NVS_ASSERT_OR_RETURN(sec_size != 0, ESP_FAIL);
|
||||
|
||||
NVSPartition *p = nullptr;
|
||||
esp_err_t result = partition_lookup::lookup_nvs_partition(partition_label, &p);
|
||||
@ -51,7 +52,7 @@ esp_err_t NVSPartitionManager::init_partition(const char *partition_label)
|
||||
|
||||
size = p->get_size();
|
||||
|
||||
result = init_custom(p, 0, size / SPI_FLASH_SEC_SIZE);
|
||||
result = init_custom(p, 0, size / sec_size);
|
||||
if (result != ESP_OK) {
|
||||
goto error;
|
||||
}
|
||||
@ -127,8 +128,9 @@ esp_err_t NVSPartitionManager::secure_init_partition(const char *part_name, nvs_
|
||||
}
|
||||
|
||||
uint32_t size = p->get_size();
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
|
||||
result = init_custom(p, 0, size / SPI_FLASH_SEC_SIZE);
|
||||
result = init_custom(p, 0, size / sec_size);
|
||||
if (result != ESP_OK) {
|
||||
delete p;
|
||||
return result;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#endif // !ESP_PLATFORM
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#define TAG "nvs_storage"
|
||||
|
||||
#if defined(SEGGER_H) && defined(GLOBAL_H)
|
||||
|
@ -1,6 +1,6 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_REQUIRES cmock test_utils nvs_flash nvs_sec_provider
|
||||
bootloader_support spi_flash esp_psram
|
||||
bootloader_support esp_psram
|
||||
EMBED_TXTFILES encryption_keys.bin partition_encrypted.bin
|
||||
partition_encrypted_hmac.bin sample.bin
|
||||
WHOLE_ARCHIVE)
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_system.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
@ -664,20 +663,20 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
|
||||
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS, NULL);
|
||||
|
||||
assert(key_part && "partition table must have a KEY partition");
|
||||
TEST_ASSERT_TRUE((nvs_key_end - nvs_key_start - 1) == SPI_FLASH_SEC_SIZE);
|
||||
TEST_ASSERT_TRUE((nvs_key_end - nvs_key_start - 1) == key_part->erase_size);
|
||||
|
||||
ESP_ERROR_CHECK(esp_partition_erase_range(key_part, 0, key_part->size));
|
||||
|
||||
for (int i = 0; i < key_part->size; i+= SPI_FLASH_SEC_SIZE) {
|
||||
ESP_ERROR_CHECK( esp_partition_write(key_part, i, nvs_key_start + i, SPI_FLASH_SEC_SIZE) );
|
||||
for (int i = 0; i < key_part->size; i+= key_part->erase_size) {
|
||||
ESP_ERROR_CHECK( esp_partition_write(key_part, i, nvs_key_start + i, key_part->erase_size) );
|
||||
}
|
||||
|
||||
const int content_size = nvs_data_sch0_end - nvs_data_sch0_start - 1;
|
||||
TEST_ASSERT_TRUE((content_size % SPI_FLASH_SEC_SIZE) == 0);
|
||||
TEST_ASSERT_TRUE((content_size % key_part->erase_size) == 0);
|
||||
|
||||
const int size_to_write = MIN(content_size, nvs_part->size);
|
||||
for (int i = 0; i < size_to_write; i+= SPI_FLASH_SEC_SIZE) {
|
||||
ESP_ERROR_CHECK( esp_partition_write(nvs_part, i, nvs_data_sch0_start + i, SPI_FLASH_SEC_SIZE) );
|
||||
for (int i = 0; i < size_to_write; i+= nvs_part->erase_size) {
|
||||
ESP_ERROR_CHECK( esp_partition_write(nvs_part, i, nvs_data_sch0_start + i, nvs_part->erase_size) );
|
||||
}
|
||||
|
||||
err = nvs_flash_read_security_cfg(key_part, &xts_cfg);
|
||||
@ -686,11 +685,11 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
|
||||
extern const char nvs_data_sch1_end[] asm("_binary_partition_encrypted_hmac_bin_end");
|
||||
|
||||
const int content_size = nvs_data_sch1_end - nvs_data_sch1_start - 1;
|
||||
TEST_ASSERT_TRUE((content_size % SPI_FLASH_SEC_SIZE) == 0);
|
||||
TEST_ASSERT_TRUE((content_size % nvs_part->erase_size) == 0);
|
||||
|
||||
const int size_to_write = MIN(content_size, nvs_part->size);
|
||||
for (int i = 0; i < size_to_write; i+= SPI_FLASH_SEC_SIZE) {
|
||||
ESP_ERROR_CHECK( esp_partition_write(nvs_part, i, nvs_data_sch1_start + i, SPI_FLASH_SEC_SIZE) );
|
||||
for (int i = 0; i < size_to_write; i+= nvs_part->erase_size) {
|
||||
ESP_ERROR_CHECK( esp_partition_write(nvs_part, i, nvs_data_sch1_start + i, nvs_part->erase_size) );
|
||||
}
|
||||
|
||||
nvs_sec_scheme_t *scheme_cfg = nvs_flash_get_default_security_scheme();
|
||||
|
@ -24,6 +24,7 @@ SOURCE_FILES = \
|
||||
test_nvs.cpp \
|
||||
test_nvs_partition.cpp \
|
||||
test_partition_manager.cpp \
|
||||
test_partition_linux.cpp \
|
||||
main.cpp
|
||||
|
||||
SOURCE_FILES_C = ../../esp_rom/linux/esp_rom_crc.c esp_err_check_mock.c
|
||||
|
@ -1,10 +1,11 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "esp_partition.h"
|
||||
#include "spi_flash_emulation.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
|
||||
static SpiFlashEmulator* s_emulator = nullptr;
|
||||
|
||||
@ -20,16 +21,17 @@ esp_err_t esp_partition_erase_range(const esp_partition_t* partition,
|
||||
return ESP_ERR_FLASH_OP_TIMEOUT;
|
||||
}
|
||||
|
||||
if (size % SPI_FLASH_SEC_SIZE != 0) {
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
if (size % sec_size != 0) {
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
if (offset % SPI_FLASH_SEC_SIZE != 0) {
|
||||
if (offset % sec_size != 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
size_t start_sector = offset / SPI_FLASH_SEC_SIZE;
|
||||
size_t num_sectors = size / SPI_FLASH_SEC_SIZE;
|
||||
size_t start_sector = offset / sec_size;
|
||||
size_t num_sectors = size / sec_size;
|
||||
for (size_t sector = start_sector; sector < (start_sector + num_sectors); sector++) {
|
||||
if (!s_emulator->erase(sector)) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -10,7 +10,7 @@
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "esp_partition.h"
|
||||
#include "catch.hpp"
|
||||
|
||||
class SpiFlashEmulator;
|
||||
@ -22,7 +22,8 @@ class SpiFlashEmulator
|
||||
public:
|
||||
SpiFlashEmulator(size_t sectorCount) : mUpperSectorBound(sectorCount)
|
||||
{
|
||||
mData.resize(sectorCount * SPI_FLASH_SEC_SIZE / 4, 0xffffffff);
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
mData.resize(sectorCount * sec_size / 4, 0xffffffff);
|
||||
mEraseCnt.resize(sectorCount);
|
||||
spi_flash_emulator_set(this);
|
||||
}
|
||||
@ -30,9 +31,10 @@ public:
|
||||
SpiFlashEmulator(const char *filename)
|
||||
{
|
||||
load(filename);
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
// At least one page should be free, hence we create mData of size of 2 sectors.
|
||||
mData.resize(mData.size() + SPI_FLASH_SEC_SIZE / 4, 0xffffffff);
|
||||
mUpperSectorBound = mData.size() * 4 / SPI_FLASH_SEC_SIZE;
|
||||
mData.resize(mData.size() + sec_size / 4, 0xffffffff);
|
||||
mUpperSectorBound = mData.size() * 4 / sec_size;
|
||||
spi_flash_emulator_set(this);
|
||||
}
|
||||
|
||||
@ -59,7 +61,8 @@ public:
|
||||
|
||||
bool write(size_t dstAddr, const uint32_t* src, size_t size)
|
||||
{
|
||||
uint32_t sectorNumber = dstAddr/SPI_FLASH_SEC_SIZE;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
uint32_t sectorNumber = dstAddr/sec_size;
|
||||
if (sectorNumber < mLowerSectorBound || sectorNumber >= mUpperSectorBound) {
|
||||
WARN("invalid flash operation detected: erase sector=" << sectorNumber);
|
||||
return false;
|
||||
@ -95,7 +98,8 @@ public:
|
||||
|
||||
bool erase(size_t sectorNumber)
|
||||
{
|
||||
size_t offset = sectorNumber * SPI_FLASH_SEC_SIZE / 4;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
size_t offset = sectorNumber * sec_size / 4;
|
||||
if (offset > mData.size()) {
|
||||
return false;
|
||||
}
|
||||
@ -109,7 +113,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
std::fill_n(begin(mData) + offset, SPI_FLASH_SEC_SIZE / 4, 0xffffffff);
|
||||
std::fill_n(begin(mData) + offset, sec_size / 4, 0xffffffff);
|
||||
|
||||
++mEraseOps;
|
||||
mEraseCnt[sectorNumber]++;
|
||||
@ -142,22 +146,26 @@ public:
|
||||
|
||||
void load(const char* filename)
|
||||
{
|
||||
const uint32_t sector_size = esp_partition_get_main_flash_sector_size();
|
||||
size_t sec_size = sector_size;
|
||||
FILE* f = fopen(filename, "rb");
|
||||
fseek(f, 0, SEEK_END);
|
||||
off_t size = ftell(f);
|
||||
assert(size % SPI_FLASH_SEC_SIZE == 0);
|
||||
assert(size % sec_size == 0);
|
||||
mData.resize(size / sizeof(uint32_t));
|
||||
fseek(f, 0, SEEK_SET);
|
||||
auto s = fread(mData.data(), SPI_FLASH_SEC_SIZE, size / SPI_FLASH_SEC_SIZE, f);
|
||||
assert(s == static_cast<size_t>(size / SPI_FLASH_SEC_SIZE));
|
||||
auto s = fread(mData.data(), sec_size, size / sec_size, f);
|
||||
assert(s == static_cast<size_t>(size / sec_size));
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void save(const char* filename)
|
||||
{
|
||||
const uint32_t sector_size = esp_partition_get_main_flash_sector_size();
|
||||
size_t sec_size = sector_size;
|
||||
FILE* f = fopen(filename, "wb");
|
||||
auto n_sectors = mData.size() * sizeof(uint32_t) / SPI_FLASH_SEC_SIZE;
|
||||
auto s = fwrite(mData.data(), SPI_FLASH_SEC_SIZE, n_sectors, f);
|
||||
auto n_sectors = mData.size() * sizeof(uint32_t) / sec_size;
|
||||
auto s = fwrite(mData.data(), sec_size, n_sectors, f);
|
||||
assert(s == n_sectors);
|
||||
fclose(f);
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "nvs_partition.hpp"
|
||||
#include "nvs_encrypted_partition.hpp"
|
||||
#include "spi_flash_emulation.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "nvs.h"
|
||||
|
||||
class PartitionEmulation : public nvs::Partition {
|
||||
@ -65,16 +66,17 @@ public:
|
||||
|
||||
esp_err_t erase_range(size_t dst_offset, size_t size) override
|
||||
{
|
||||
if (size % SPI_FLASH_SEC_SIZE != 0) {
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
if (size % sec_size != 0) {
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
if (dst_offset % SPI_FLASH_SEC_SIZE != 0) {
|
||||
if (dst_offset % sec_size != 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
size_t start_sector = dst_offset / SPI_FLASH_SEC_SIZE;
|
||||
size_t num_sectors = size / SPI_FLASH_SEC_SIZE;
|
||||
size_t start_sector = dst_offset / sec_size;
|
||||
size_t num_sectors = size / sec_size;
|
||||
for (size_t sector = start_sector; sector < (start_sector + num_sectors); sector++) {
|
||||
if (!flash_emu->erase(sector)) {
|
||||
return ESP_ERR_FLASH_OP_FAIL;
|
||||
@ -116,7 +118,7 @@ struct PartitionEmulationFixture {
|
||||
uint32_t sector_size = 1,
|
||||
const char *partition_name = NVS_DEFAULT_PART_NAME)
|
||||
: emu(start_sector + sector_size),
|
||||
part(&emu, start_sector * SPI_FLASH_SEC_SIZE, sector_size * SPI_FLASH_SEC_SIZE, partition_name) {
|
||||
part(&emu, start_sector * esp_partition_get_main_flash_sector_size(), sector_size * esp_partition_get_main_flash_sector_size(), partition_name) {
|
||||
}
|
||||
|
||||
~PartitionEmulationFixture() { }
|
||||
@ -133,8 +135,9 @@ struct EncryptedPartitionFixture {
|
||||
const char *partition_name = NVS_DEFAULT_PART_NAME)
|
||||
: esp_partition(), emu(start_sector + sector_size),
|
||||
part(&esp_partition) {
|
||||
esp_partition.address = start_sector * SPI_FLASH_SEC_SIZE;
|
||||
esp_partition.size = sector_size * SPI_FLASH_SEC_SIZE;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
esp_partition.address = start_sector * sec_size;
|
||||
esp_partition.size = sector_size * sec_size;
|
||||
strncpy(esp_partition.label, partition_name, PART_NAME_MAX_SIZE);
|
||||
assert(part.init(cfg) == ESP_OK);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -44,10 +44,11 @@ static void check_nvs_part_gen_args(SpiFlashEmulator *spi_flash_emulator,
|
||||
{
|
||||
nvs_handle_t handle;
|
||||
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
esp_partition_t esp_part;
|
||||
esp_part.encrypted = false; // we're not testing generic flash encryption here, only the legacy NVS encryption
|
||||
esp_part.address = 0;
|
||||
esp_part.size = size * SPI_FLASH_SEC_SIZE;
|
||||
esp_part.size = size * sec_size;
|
||||
strncpy(esp_part.label, part_name, PART_NAME_MAX_SIZE);
|
||||
unique_ptr<nvs::Partition> part;
|
||||
|
||||
@ -136,10 +137,11 @@ static void check_nvs_part_gen_args_mfg(SpiFlashEmulator *spi_flash_emulator,
|
||||
{
|
||||
nvs_handle_t handle;
|
||||
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
esp_partition_t esp_part;
|
||||
esp_part.encrypted = false; // we're not testing generic flash encryption here, only the legacy NVS encryption
|
||||
esp_part.address = 0;
|
||||
esp_part.size = size * SPI_FLASH_SEC_SIZE;
|
||||
esp_part.size = size * sec_size;
|
||||
strncpy(esp_part.label, part_name, PART_NAME_MAX_SIZE);
|
||||
unique_ptr<nvs::Partition> part;
|
||||
|
||||
|
12
components/nvs_flash/test_nvs_host/test_partition_linux.cpp
Normal file
12
components/nvs_flash/test_nvs_host/test_partition_linux.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "esp_private/partition_linux.h"
|
||||
#include "esp_partition.h"
|
||||
|
||||
uint32_t esp_partition_get_main_flash_sector_size(void)
|
||||
{
|
||||
return ESP_PARTITION_EMULATED_SECTOR_SIZE;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -12,6 +12,7 @@
|
||||
#include "spi_flash_emulation.h"
|
||||
#include "nvs_test_api.h"
|
||||
#include "test_fixtures.hpp"
|
||||
#include "esp_partition.h"
|
||||
|
||||
/*
|
||||
TEST_CASE("Partition manager initializes multiple partitions", "[partition_mgr]")
|
||||
@ -19,8 +20,9 @@ TEST_CASE("Partition manager initializes multiple partitions", "[partition_mgr]"
|
||||
const uint32_t NVS_FLASH_SECTOR = 6;
|
||||
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
|
||||
SpiFlashEmulator emu(10);
|
||||
PartitionEmulation part_0(&emu, NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE, NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE, "test1");
|
||||
PartitionEmulation part_1(&emu, NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE, NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE, "test2");
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
PartitionEmulation part_0(&emu, NVS_FLASH_SECTOR * sec_size, NVS_FLASH_SECTOR_COUNT_MIN * sec_size, "test1");
|
||||
PartitionEmulation part_1(&emu, NVS_FLASH_SECTOR * sec_size, NVS_FLASH_SECTOR_COUNT_MIN * sec_size, "test2");
|
||||
|
||||
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&part_0, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
|
||||
== ESP_OK);
|
||||
|
@ -1,12 +1,12 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "catch.hpp"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "esp_partition.h"
|
||||
#include "spi_flash_emulation.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include <functional>
|
||||
|
||||
template <typename Tit>
|
||||
@ -26,7 +26,8 @@ TEST_CASE("flash starts with all bytes == 0xff", "[spi_flash_emu]")
|
||||
{
|
||||
FlashEmuFixture f(4);
|
||||
|
||||
uint8_t sector[SPI_FLASH_SEC_SIZE];
|
||||
uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
uint8_t sector[sec_size];
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
CHECK(esp_partition_read(&f.esp_part, 0, sector, sizeof(sector)) == ESP_OK);
|
||||
@ -71,7 +72,8 @@ TEST_CASE("after erase the sector is set to 0xff", "[spi_flash_emu]")
|
||||
CHECK(range_empty_n(f.emu.words() + 1, 4096 / 4 - 2));
|
||||
CHECK(f.emu.words()[4096 / 4 - 1] == val2);
|
||||
|
||||
CHECK(esp_partition_erase_range(&f.esp_part, 0, SPI_FLASH_SEC_SIZE) == ESP_OK);
|
||||
uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
CHECK(esp_partition_erase_range(&f.esp_part, 0, sec_size) == ESP_OK);
|
||||
|
||||
CHECK(f.emu.words()[0] == 0xffffffff);
|
||||
CHECK(range_empty_n(f.emu.words() + 1, 4096 / 4 - 2));
|
||||
@ -158,7 +160,8 @@ TEST_CASE("read/write/erase operation times are calculated correctly", "[spi_fla
|
||||
CHECK(f.emu.getTotalTime() == (205+417)/2);
|
||||
f.emu.clearStats();
|
||||
|
||||
esp_partition_erase_range(&f.esp_part, 0, SPI_FLASH_SEC_SIZE);
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
esp_partition_erase_range(&f.esp_part, 0, sec_size);
|
||||
CHECK(f.emu.getEraseOps() == 1);
|
||||
CHECK(f.emu.getTotalTime() == 37142);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@ -15,7 +15,6 @@
|
||||
#include "esp_private/spi_common_internal.h"
|
||||
#include "esp_flash_spi_init.h"
|
||||
#include "memspi_host_driver.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include <esp_attr.h>
|
||||
#include "esp_log.h"
|
||||
#include "test_utils.h"
|
||||
@ -24,12 +23,12 @@
|
||||
#include "soc/io_mux_reg.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "esp_spi_flash_counters.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_rom_gpio.h"
|
||||
#include "esp_rom_sys.h"
|
||||
#include "esp_timer.h"
|
||||
#include "test_esp_flash_def.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "esp_private/spi_flash_os.h"
|
||||
#include "ccomp_timer.h"
|
||||
|
||||
@ -656,7 +655,7 @@ void test_permutations_chip(const flashtest_config_t* config)
|
||||
// Get test partition, and locate temporary partitions according to the default one
|
||||
const esp_partition_t* test_part = get_test_data_partition();
|
||||
const int length = sizeof(large_const_buffer);
|
||||
TEST_ASSERT(test_part->size > length + 2 + SPI_FLASH_SEC_SIZE);
|
||||
TEST_ASSERT(test_part->size > length + 2 + test_part->erase_size);
|
||||
|
||||
esp_partition_t part[2] = {};
|
||||
part[0] = *test_part;
|
||||
@ -738,7 +737,7 @@ static void write_large_buffer(const esp_partition_t *part, const uint8_t *sourc
|
||||
esp_flash_t* chip = part->flash_chip;
|
||||
|
||||
printf("Writing chip %p %p, %u bytes from source %p\n", chip, (void*)part->address, length, source);
|
||||
ESP_ERROR_CHECK( esp_flash_erase_region(chip, part->address, (length + SPI_FLASH_SEC_SIZE) & ~(SPI_FLASH_SEC_SIZE - 1)) );
|
||||
ESP_ERROR_CHECK( esp_flash_erase_region(chip, part->address, (length + part->erase_size) & ~(part->erase_size - 1)) );
|
||||
|
||||
// note writing to unaligned address
|
||||
ESP_ERROR_CHECK( esp_flash_write(chip, source, part->address + 1, length) );
|
||||
@ -771,7 +770,7 @@ static void read_and_check(const esp_partition_t *part, const uint8_t *source, s
|
||||
|
||||
static void test_write_large_buffer(const esp_partition_t* part, const uint8_t *source, size_t length)
|
||||
{
|
||||
TEST_ASSERT(part->size > length + 2 + SPI_FLASH_SEC_SIZE);
|
||||
TEST_ASSERT(part->size > length + 2 + part->erase_size);
|
||||
|
||||
write_large_buffer(part, source, length);
|
||||
read_and_check(part, source, length);
|
||||
@ -804,7 +803,7 @@ static uint32_t time_measure_end(time_meas_ctx_t* ctx)
|
||||
|
||||
static uint32_t measure_erase(const esp_partition_t* part)
|
||||
{
|
||||
const int total_len = SPI_FLASH_SEC_SIZE * TEST_SECTORS;
|
||||
const int total_len = part->erase_size * TEST_SECTORS;
|
||||
time_meas_ctx_t time_ctx = {.name = "erase", .len = total_len};
|
||||
|
||||
time_measure_start(&time_ctx);
|
||||
@ -816,7 +815,7 @@ static uint32_t measure_erase(const esp_partition_t* part)
|
||||
// should called after measure_erase
|
||||
static uint32_t measure_write(const char* name, const esp_partition_t* part, const uint8_t* data_to_write, int seg_len)
|
||||
{
|
||||
const int total_len = SPI_FLASH_SEC_SIZE;
|
||||
const int total_len = part->erase_size;
|
||||
time_meas_ctx_t time_ctx = {.name = name, .len = total_len * TEST_TIMES};
|
||||
|
||||
time_measure_start(&time_ctx);
|
||||
@ -839,7 +838,7 @@ static uint32_t measure_write(const char* name, const esp_partition_t* part, con
|
||||
|
||||
static uint32_t measure_read(const char* name, const esp_partition_t* part, uint8_t* data_read, int seg_len)
|
||||
{
|
||||
const int total_len = SPI_FLASH_SEC_SIZE;
|
||||
const int total_len = part->erase_size;
|
||||
time_meas_ctx_t time_ctx = {.name = name, .len = total_len * TEST_TIMES};
|
||||
|
||||
time_measure_start(&time_ctx);
|
||||
@ -896,7 +895,7 @@ static const char* get_chip_vendor(uint32_t id)
|
||||
static void test_flash_read_write_performance(const esp_partition_t *part)
|
||||
{
|
||||
esp_flash_t* chip = part->flash_chip;
|
||||
const int total_len = SPI_FLASH_SEC_SIZE;
|
||||
const int total_len = part->erase_size;
|
||||
uint8_t *data_to_write = heap_caps_malloc(total_len, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
uint8_t *data_read = heap_caps_malloc(total_len, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -14,7 +14,6 @@
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_rom_spiflash.h"
|
||||
#include "esp_private/cache_utils.h"
|
||||
@ -63,14 +62,14 @@ TEST_CASE("Test flash write large RAM buffer", "[spi_flash][esp_flash]")
|
||||
static void test_write_large_buffer(const uint8_t *source, size_t length)
|
||||
{
|
||||
const esp_partition_t *part = get_test_data_partition();
|
||||
TEST_ASSERT(part->size > length + 2 + SPI_FLASH_SEC_SIZE);
|
||||
TEST_ASSERT(part->size > length + 2 + part->erase_size);
|
||||
|
||||
printf("Writing %d bytes from source %p\n", length, source);
|
||||
|
||||
uint8_t *buf = malloc(length);
|
||||
TEST_ASSERT_NOT_NULL(buf);
|
||||
|
||||
TEST_ESP_OK( esp_flash_erase_region(NULL, part->address, (length + SPI_FLASH_SEC_SIZE) & ~(SPI_FLASH_SEC_SIZE-1)) );
|
||||
TEST_ESP_OK( esp_flash_erase_region(NULL, part->address, (length + part->erase_size) & ~(part->erase_size-1)) );
|
||||
|
||||
// note writing to unaligned address
|
||||
TEST_ESP_OK( esp_flash_write(NULL, source, part->address + 1, length) );
|
||||
|
@ -342,12 +342,12 @@ TEST_CASE("esp_flash_write can write from external RAM buffer", "[spi_flash]")
|
||||
|
||||
/* Write to flash from buf_ext */
|
||||
const esp_partition_t *part = get_test_data_partition();
|
||||
TEST_ESP_OK(esp_flash_erase_region(NULL, part->address & ~(0x10000 - 1), SPI_FLASH_SEC_SIZE));
|
||||
TEST_ESP_OK(esp_flash_write(NULL, buf_ext, part->address, SPI_FLASH_SEC_SIZE));
|
||||
TEST_ESP_OK(esp_flash_erase_region(NULL, part->address & ~(0x10000 - 1), part->erase_size));
|
||||
TEST_ESP_OK(esp_flash_write(NULL, buf_ext, part->address, part->erase_size));
|
||||
|
||||
/* Read back to buf_int and compare */
|
||||
TEST_ESP_OK(esp_flash_read(NULL, buf_int, part->address, SPI_FLASH_SEC_SIZE));
|
||||
TEST_ASSERT_EQUAL(0, memcmp(buf_ext, buf_int, SPI_FLASH_SEC_SIZE));
|
||||
TEST_ESP_OK(esp_flash_read(NULL, buf_int, part->address, part->erase_size));
|
||||
TEST_ASSERT_EQUAL(0, memcmp(buf_ext, buf_int, part->erase_size));
|
||||
|
||||
free(buf_ext);
|
||||
free(buf_int);
|
||||
@ -367,7 +367,7 @@ TEST_CASE("spi_flash_read less than 16 bytes into buffer in external RAM", "[spi
|
||||
}
|
||||
|
||||
const esp_partition_t *part = get_test_data_partition();
|
||||
TEST_ESP_OK(esp_flash_erase_region(NULL, part->address & ~(0x10000 - 1), SPI_FLASH_SEC_SIZE));
|
||||
TEST_ESP_OK(esp_flash_erase_region(NULL, part->address & ~(0x10000 - 1), part->erase_size));
|
||||
TEST_ESP_OK(esp_flash_write(NULL, data_8, part->address, MIN_BLOCK_SIZE));
|
||||
TEST_ESP_OK(esp_flash_read(NULL, buf_ext_8, part->address, MIN_BLOCK_SIZE));
|
||||
TEST_ESP_OK(esp_flash_read(NULL, buf_int_8, part->address, MIN_BLOCK_SIZE));
|
||||
|
@ -17,7 +17,7 @@ idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "." "spiffs/src"
|
||||
REQUIRES esp_partition
|
||||
PRIV_REQUIRES ${pr} spi_flash)
|
||||
PRIV_REQUIRES ${pr})
|
||||
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
|
||||
set_source_files_properties(spiffs/src/spiffs_nucleus.c PROPERTIES COMPILE_FLAGS -Wno-stringop-truncation)
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "spiffs_nucleus.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_partition.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
@ -23,7 +23,7 @@ size_t Partition::get_flash_size()
|
||||
esp_err_t Partition::erase_sector(size_t sector)
|
||||
{
|
||||
esp_err_t result = ESP_OK;
|
||||
result = erase_range(sector * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE);
|
||||
result = erase_range(sector * this->partition->erase_size, this->partition->erase_size);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ esp_err_t Partition::read(size_t src_addr, void *dest, size_t size)
|
||||
|
||||
size_t Partition::get_sector_size()
|
||||
{
|
||||
return SPI_FLASH_SEC_SIZE;
|
||||
return this->partition->erase_size;
|
||||
}
|
||||
|
||||
bool Partition::is_readonly()
|
||||
|
@ -1,14 +1,14 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "SPI_Flash.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "esp_flash.h"
|
||||
#include <inttypes.h>
|
||||
#include "esp_partition.h"
|
||||
|
||||
static const char *TAG = "spi_flash";
|
||||
|
||||
@ -25,7 +25,8 @@ size_t SPI_Flash::get_flash_size()
|
||||
|
||||
esp_err_t SPI_Flash::erase_sector(size_t sector)
|
||||
{
|
||||
esp_err_t result = esp_flash_erase_region(NULL, sector * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE);;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
esp_err_t result = esp_flash_erase_region(NULL, sector * sec_size, sec_size);;
|
||||
if (result == ESP_OK) {
|
||||
ESP_LOGV(TAG, "erase_sector - sector=0x%08" PRIx32 ", result=0x%08x", (uint32_t) sector, result);
|
||||
} else {
|
||||
@ -35,8 +36,9 @@ esp_err_t SPI_Flash::erase_sector(size_t sector)
|
||||
}
|
||||
esp_err_t SPI_Flash::erase_range(size_t start_address, size_t size)
|
||||
{
|
||||
size = (size + SPI_FLASH_SEC_SIZE - 1) / SPI_FLASH_SEC_SIZE;
|
||||
size = size * SPI_FLASH_SEC_SIZE;
|
||||
const uint32_t sec_size = esp_partition_get_main_flash_sector_size();
|
||||
size = (size + sec_size - 1) / sec_size;
|
||||
size = size * sec_size;
|
||||
esp_err_t result = esp_flash_erase_region(NULL, start_address, size);
|
||||
if (result == ESP_OK) {
|
||||
ESP_LOGV(TAG, "erase_range - start_address=0x%08" PRIx32 ", size=0x%08" PRIx32 ", result=0x%08x", (uint32_t) start_address, (uint32_t) size, result);
|
||||
@ -70,7 +72,7 @@ esp_err_t SPI_Flash::read(size_t src_addr, void *dest, size_t size)
|
||||
|
||||
size_t SPI_Flash::get_sector_size()
|
||||
{
|
||||
return SPI_FLASH_SEC_SIZE;
|
||||
return esp_partition_get_main_flash_sector_size();;
|
||||
}
|
||||
|
||||
SPI_Flash::~SPI_Flash()
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include "Flash_Access.h"
|
||||
#include "esp_partition.h"
|
||||
#include "spi_flash_mmap.h" // for SPI_FLASH_SEC_SIZE
|
||||
|
||||
/**
|
||||
* @brief This class is used to access partition. Class implements Flash_Access interface
|
||||
|
@ -1,5 +1,5 @@
|
||||
idf_component_register(SRCS test_wl.c
|
||||
PRIV_INCLUDE_DIRS .
|
||||
PRIV_REQUIRES wear_levelling unity spi_flash
|
||||
PRIV_REQUIRES wear_levelling unity
|
||||
EMBED_FILES test_partition_v1.bin
|
||||
)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -15,7 +15,6 @@
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_cpu.h"
|
||||
#include "esp_system.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
|
||||
|
||||
TEST_GROUP(wear_levelling);
|
||||
@ -65,7 +64,7 @@ TEST(wear_levelling, wl_mount_checks_partition_params)
|
||||
esp_partition_erase_range(test_partition, 0, test_partition->size);
|
||||
// test small partition: result should be error
|
||||
for (int i = 0; i < 5; i++) {
|
||||
fake_partition.size = SPI_FLASH_SEC_SIZE * (i);
|
||||
fake_partition.size = test_partition->erase_size * (i);
|
||||
size_before = esp_get_free_heap_size();
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, wl_mount(&fake_partition, &handle));
|
||||
// test that we didn't leak any memory
|
||||
@ -74,7 +73,7 @@ TEST(wear_levelling, wl_mount_checks_partition_params)
|
||||
}
|
||||
|
||||
// test minimum size partition: result should be OK
|
||||
fake_partition.size = SPI_FLASH_SEC_SIZE * 5;
|
||||
fake_partition.size = test_partition->erase_size * 5;
|
||||
size_before = esp_get_free_heap_size();
|
||||
TEST_ESP_OK(wl_mount(&fake_partition, &handle));
|
||||
wl_unmount(handle);
|
||||
@ -217,7 +216,7 @@ TEST(wear_levelling, write_doesnt_touch_other_sectors)
|
||||
esp_partition_t fake_partition;
|
||||
memcpy(&fake_partition, partition, sizeof(fake_partition));
|
||||
|
||||
fake_partition.size = SPI_FLASH_SEC_SIZE * (4 + TEST_SECTORS_COUNT);
|
||||
fake_partition.size = partition->erase_size * (4 + TEST_SECTORS_COUNT);
|
||||
|
||||
wl_handle_t handle;
|
||||
TEST_ESP_OK(wl_mount(&fake_partition, &handle));
|
||||
|
@ -81,8 +81,8 @@ esp_err_t wl_mount(const esp_partition_t *partition, wl_handle_t *out_handle)
|
||||
|
||||
cfg.wl_partition_start_addr = WL_DEFAULT_START_ADDR;
|
||||
cfg.wl_partition_size = partition->size;
|
||||
cfg.wl_page_size = SPI_FLASH_SEC_SIZE;
|
||||
cfg.flash_sector_size = SPI_FLASH_SEC_SIZE; //default size is 4096
|
||||
cfg.wl_page_size = partition->erase_size;
|
||||
cfg.flash_sector_size = partition->erase_size; //default size is 4096
|
||||
cfg.wl_update_rate = WL_DEFAULT_UPDATERATE;
|
||||
cfg.wl_pos_update_record_size = WL_DEFAULT_WRITE_SIZE; //16 bytes per pos update will be stored
|
||||
cfg.version = WL_CURRENT_VERSION;
|
||||
|
@ -1,4 +1,3 @@
|
||||
idf_component_register(SRCS "main.c"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES esp_partition
|
||||
PRIV_REQUIRES spi_flash)
|
||||
REQUIRES esp_partition)
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "esp_partition.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "example";
|
||||
@ -46,7 +45,7 @@ void app_main(void)
|
||||
|
||||
// Erase the area where the data was written. Erase size should be a multiple of SPI_FLASH_SEC_SIZE
|
||||
// and also be SPI_FLASH_SEC_SIZE aligned
|
||||
ESP_ERROR_CHECK(esp_partition_erase_range(partition, 0, SPI_FLASH_SEC_SIZE));
|
||||
ESP_ERROR_CHECK(esp_partition_erase_range(partition, 0, partition->erase_size));
|
||||
|
||||
// Read back the data (should all now be 0xFF's)
|
||||
memset(store_data, 0xFF, sizeof(read_data));
|
||||
|
Loading…
Reference in New Issue
Block a user