I need to write a value (0 or 1) to flash storage in order to save it permanently. I need to do this in my custom bootloader (the bootloader_main.c code).
The way I do it now is I have a seperate partition to which i write the value with the function
Code: Select all
void write_boot_index(esp_partition_pos_t *pos, int boot_index)
{
bootloader_flash_erase_range(pos->offset, 4096);
esp_err_t write_ret = bootloader_flash_write(pos->offset, &boot_index, 4, false);
if (write_ret != ESP_OK) {
ESP_LOGE("CUSTOM", "Failed to write to flash");
}
}
Is there a better way to do this?
Also: The data needs to be saved even if the ESP loses power.