mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-20 00:36:01 -04:00
Merge branch 'bugfix/nvs_flash_linux_target_cleanups' into 'master'
nvs_flash: cleanups related to linux target See merge request espressif/esp-idf!19570
This commit is contained in:
commit
d6f3666875
@ -30,9 +30,14 @@ class intrusive_list
|
||||
|
||||
public:
|
||||
|
||||
class iterator : public std::iterator<std::forward_iterator_tag, T>
|
||||
class iterator
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = T;
|
||||
using difference_type = ptrdiff_t;
|
||||
using pointer = T*;
|
||||
using reference = T&;
|
||||
|
||||
iterator() : mPos(nullptr) {}
|
||||
|
||||
|
@ -116,7 +116,7 @@ extern "C" esp_err_t nvs_flash_init_partition_ptr(const esp_partition_t *partiti
|
||||
return init_res;
|
||||
}
|
||||
|
||||
#ifndef LINUX_TARGET
|
||||
#ifndef LINUX_HOST_LEGACY_TEST
|
||||
extern "C" esp_err_t nvs_flash_init_partition(const char *part_name)
|
||||
{
|
||||
esp_err_t lock_result = Lock::init();
|
||||
@ -239,7 +239,7 @@ extern "C" esp_err_t nvs_flash_erase(void)
|
||||
{
|
||||
return nvs_flash_erase_partition(NVS_DEFAULT_PART_NAME);
|
||||
}
|
||||
#endif // ! LINUX_TARGET
|
||||
#endif // LINUX_HOST_LEGACY_TEST
|
||||
|
||||
extern "C" esp_err_t nvs_flash_deinit_partition(const char* partition_name)
|
||||
{
|
||||
|
@ -128,37 +128,11 @@ esp_err_t Page::writeEntryData(const uint8_t* data, size_t size)
|
||||
NVS_ASSERT_OR_RETURN(mFirstUsedEntry != INVALID_ENTRY, ESP_FAIL);
|
||||
const uint16_t count = size / ENTRY_SIZE;
|
||||
|
||||
const uint8_t* buf = data;
|
||||
|
||||
#if !defined LINUX_TARGET
|
||||
// TODO: check whether still necessary with esp_partition* API
|
||||
/* On the ESP32, data can come from DROM, which is not accessible by spi_flash_write
|
||||
* function. To work around this, we copy the data to heap if it came from DROM.
|
||||
* Hopefully this won't happen very often in practice. For data from DRAM, we should
|
||||
* still be able to write it to flash directly.
|
||||
* TODO: figure out how to make this platform-specific check nicer (probably by introducing
|
||||
* a platform-specific flash layer).
|
||||
*/
|
||||
if ((uint32_t) data < 0x3ff00000) {
|
||||
buf = (uint8_t*) malloc(size);
|
||||
if (!buf) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
memcpy((void*)buf, data, size);
|
||||
}
|
||||
#endif // ! LINUX_TARGET
|
||||
|
||||
uint32_t phyAddr;
|
||||
esp_err_t rc = getEntryAddress(mNextFreeEntry, &phyAddr);
|
||||
if (rc == ESP_OK) {
|
||||
rc = mPartition->write(phyAddr, buf, size);
|
||||
rc = mPartition->write(phyAddr, data, size);
|
||||
}
|
||||
|
||||
#if !defined LINUX_TARGET
|
||||
if (buf != data) {
|
||||
free((void*)buf);
|
||||
}
|
||||
#endif // ! LINUX_TARGET
|
||||
if (rc != ESP_OK) {
|
||||
mState = PageState::INVALID;
|
||||
return rc;
|
||||
|
@ -47,7 +47,10 @@ esp_err_t PageManager::load(Partition *partition, uint32_t baseSector, uint32_t
|
||||
return activatePage();
|
||||
} else {
|
||||
uint32_t lastSeqNo;
|
||||
ESP_ERROR_CHECK( mPageList.back().getSeqNumber(lastSeqNo) );
|
||||
auto err = mPageList.back().getSeqNumber(lastSeqNo);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
mSeqNumber = lastSeqNo + 1;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,10 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "nvs_storage.hpp"
|
||||
#if __has_include(<bsd/string.h>)
|
||||
// for strlcpy
|
||||
#include <bsd/string.h>
|
||||
#endif
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
// We need NO_DEBUG_STORAGE here since the integration tests on the host add some debug code.
|
||||
@ -305,7 +309,10 @@ esp_err_t Storage::writeItem(uint8_t nsIndex, ItemType datatype, const char* key
|
||||
|
||||
if (findPage->state() == Page::PageState::UNINITIALIZED ||
|
||||
findPage->state() == Page::PageState::INVALID) {
|
||||
ESP_ERROR_CHECK(findItem(nsIndex, datatype, key, findPage, item));
|
||||
err = findItem(nsIndex, datatype, key, findPage, item);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
/* Get the version of the previous index with same <ns,key> */
|
||||
prevStart = item.blobIndex.chunkStart;
|
||||
@ -383,7 +390,10 @@ esp_err_t Storage::writeItem(uint8_t nsIndex, ItemType datatype, const char* key
|
||||
if (findPage) {
|
||||
if (findPage->state() == Page::PageState::UNINITIALIZED ||
|
||||
findPage->state() == Page::PageState::INVALID) {
|
||||
ESP_ERROR_CHECK(findItem(nsIndex, datatype, key, findPage, item));
|
||||
err = findItem(nsIndex, datatype, key, findPage, item);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
err = findPage->eraseItem(nsIndex, datatype, key);
|
||||
if (err == ESP_ERR_FLASH_OP_FAIL) {
|
||||
@ -749,11 +759,7 @@ void Storage::fillEntryInfo(Item &item, nvs_entry_info_t &info)
|
||||
|
||||
for (auto &name : mNamespaces) {
|
||||
if(item.nsIndex == name.mIndex) {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
strncpy(info.namespace_name, name.mName, sizeof(info.namespace_name) - 1);
|
||||
#pragma GCC diagnostic pop
|
||||
info.namespace_name[sizeof(info.namespace_name) -1] = '\0';
|
||||
strlcpy(info.namespace_name, name.mName, sizeof(info.namespace_name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -38,10 +38,14 @@ COMPILER := gcc
|
||||
endif
|
||||
|
||||
CPPFLAGS += -I../private_include -I../include -I../src -I../../esp_rom/include -I../../esp_rom/include/linux -I../../log/include -I./ -I../../esp_common/include -I../../esp32/include -I ../../mbedtls/mbedtls/include -I ../../spi_flash/include -I ../../hal/include -I ../../xtensa/include -I ../../../tools/catch -fprofile-arcs -ftest-coverage -g2 -ggdb
|
||||
CFLAGS += -fprofile-arcs -ftest-coverage -DLINUX_TARGET
|
||||
CXXFLAGS += -std=c++11 -Wall -Werror -DLINUX_TARGET
|
||||
CFLAGS += -fprofile-arcs -ftest-coverage -DLINUX_TARGET -DLINUX_HOST_LEGACY_TEST
|
||||
CXXFLAGS += -std=c++11 -Wall -Werror -DLINUX_TARGET -DLINUX_HOST_LEGACY_TEST
|
||||
LDFLAGS += -lstdc++ -Wall -fprofile-arcs -ftest-coverage
|
||||
|
||||
ifeq ($(shell uname -s),Linux)
|
||||
LDFLAGS += -lbsd
|
||||
endif
|
||||
|
||||
ifeq ($(COMPILER),clang)
|
||||
CFLAGS += -fsanitize=address
|
||||
CXXFLAGS += -fsanitize=address
|
||||
@ -52,13 +56,16 @@ OBJ_FILES = $(SOURCE_FILES:.cpp=.o)
|
||||
OBJ_FILES_C = $(SOURCE_FILES_C:.c=.o)
|
||||
|
||||
COVERAGE_FILES = $(OBJ_FILES:.o=.gc*)
|
||||
MBEDTLS_LIB := ../../mbedtls/mbedtls/library/libmbedcrypto.a
|
||||
|
||||
$(OBJ_FILES): %.o: %.cpp
|
||||
$(OBJ_FILES_C): %.c: %.c
|
||||
|
||||
$(TEST_PROGRAM): clean-coverage $(OBJ_FILES) $(OBJ_FILES_C)
|
||||
$(MBEDTLS_LIB):
|
||||
$(MAKE) -C ../../mbedtls/mbedtls/ lib
|
||||
g++ $(LDFLAGS) -o $(TEST_PROGRAM) $(OBJ_FILES) $(OBJ_FILES_C) ../../mbedtls/mbedtls/library/libmbedcrypto.a
|
||||
|
||||
$(TEST_PROGRAM): $(OBJ_FILES) $(OBJ_FILES_C) $(MBEDTLS_LIB) | clean-coverage
|
||||
g++ -o $@ $^ $(LDFLAGS)
|
||||
|
||||
$(OUTPUT_DIR):
|
||||
mkdir -p $(OUTPUT_DIR)
|
||||
|
Loading…
Reference in New Issue
Block a user