Merge pull request #15504 from s-hadinger/berry_flash_more2

Berry flash.factory()
This commit is contained in:
s-hadinger 2022-05-01 17:38:04 +02:00 committed by GitHub
commit b65cad3584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -2,9 +2,9 @@
static be_define_const_map_slots(m_libflash_map) {
{ be_const_key(write, -1), be_const_func(p_flash_write) },
{ be_const_key(read, 2), be_const_func(p_flash_read) },
{ be_const_key(factory, 2), be_const_ctype_func(p_factory) },
{ be_const_key(erase, 3), be_const_func(p_flash_erase) },
{ be_const_key(rollback, -1), be_const_ctype_func(p_rollback) },
{ be_const_key(read, -1), be_const_func(p_flash_read) },
};
static be_define_const_map(

View File

@ -8,12 +8,16 @@
#include "be_constobj.h"
#include "be_mapping.h"
#include "esp_ota_ops.h"
#include "esp_partition.h"
void p_rollback(void) {
esp_ota_mark_app_invalid_rollback_and_reboot();
// Forces the next restart to use the `factory` partition if any is present
void p_factory(void) {
const esp_partition_t *otadata_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
if (otadata_partition) {
esp_partition_erase_range(otadata_partition, 0, SPI_FLASH_SEC_SIZE * 2);
}
}
BE_FUNC_CTYPE_DECLARE(p_rollback, "", "");
BE_FUNC_CTYPE_DECLARE(p_factory, "", "");
extern int p_flash_read(bvm *vm);
extern int p_flash_write(bvm *vm);
@ -25,7 +29,7 @@ module flash (scope: global) {
write, func(p_flash_write)
erase, func(p_flash_erase)
rollback, ctype_func(p_rollback)
factory, ctype_func(p_factory)
}
@const_object_info_end */
#include "be_fixed_flash.h"