-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for partition tables larger than 4MB with "linux" target (IDFGH-14080) #14894
Comments
This should work with just nvs_flash_init, at least in recent IDF versions. The fact that you get a segfault in esp_partition_read is probably a bug, although I can't reproduce it with the following simple example: project CMakeLists.txt cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(COMPONENTS main)
project(test) main/CMakeLists.txt idf_component_register(SRCS "test.c"
INCLUDE_DIRS "."
PRIV_REQUIRES "nvs_flash") main/test.c #include <stdio.h>
#include "esp_err.h"
#include "nvs_flash.h"
#include "nvs.h"
void app_main(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
nvs_handle_t nvs;
ESP_ERROR_CHECK(nvs_open("storage", NVS_READWRITE, &nvs));
ESP_ERROR_CHECK(nvs_set_u32(nvs, "key", 42));
ESP_ERROR_CHECK(nvs_commit(nvs));
nvs_close(nvs);
ESP_ERROR_CHECK(nvs_open("storage", NVS_READONLY, &nvs));
uint32_t value;
ESP_ERROR_CHECK(nvs_get_u32(nvs, "key", &value));
nvs_close(nvs);
printf("Value: %d\n", value);
} results in (output)
Could you please add more details to help us reproduce or troubleshoot this segfault you are getting? (IDF version, code snippet if possible, whether you are mocking any of the components mentioned in the |
Interesting. You're right, I just tested this on a new project and with default settings it really does work out of the box.
Yes sure. I'm using ESP-IDF v5.3, the project uses a custom directory layout with a "src" component as main and a "tests" folder as... well, test component. You have already listed the issue however! It seems to be related to a custom partition table. If I use the default one all is fine, no segfault occurs. However if I switch to my custom one # ESP-IDF Partition Table
# Name, Type, SubType, Offset, Size, Flags
otadata, data, ota, , 8K,
ota_0, app, ota_0, , 6M,
ota_1, app, ota_1, , 6M,
nvs, data, nvs, , 6M,
data, data, littlefs,, 14272K, things explode fish: Job 1, './build/ESP32BuildSystem.elf' terminated by signal SIGSEGV (Address boundary error) |
I see, thanks for the reproducer. Indeed there is a leftover in spi_flash component emulation, total emulated flash size doesn't automatically follow the size occupied by all the partitions. Please add this to your app as a temporary workaround:
we also need to improve bounds checking in |
Is your feature request related to a problem?
I'm currently trying to get NVS running on a Linux target. Sadly this is more difficult than I've had anticipated. Just calling
nvs_flash_init()
doesn't do it. It segfaults a couple of levels deep inside
esp_partition_read
.The documentation is lacking a meaningful example so far, or at least I couldn't find one. I found the NVS host tests inside the nvs_flash components folder but that's quite a lot of code to go through for "just writing a blob to wherever". My best guess after maybe half an hour of reading through the test code is that I need some kind of mmap file first?
Describe the solution you'd like.
Could we maybe get a minimal example of "here is how to read and write NVS on Linux"?
I assume the functions for doing that in a couple of lines are already there... but I just can't find them.
Describe alternatives you've considered.
I've tried to extract what little I need from the test code that's already in ESP-IDF but that's a tedious task for what I assume is maybe 2 or 3 function calls.
Additional context.
No response
The text was updated successfully, but these errors were encountered: