Berry flash.factory and partition_core

This commit is contained in:
Stephan Hadinger 2022-05-06 20:31:24 +02:00
parent cf8fe9e147
commit 190b9ca17f
7 changed files with 2435 additions and 2261 deletions

View File

@ -190,7 +190,7 @@ extern const bcstring be_const_str__X3Cbutton_X20name_X3D_X27zipapply_X27_X20cla
extern const bcstring be_const_str__X3Cfieldset_X3E_X3Cstyle_X3E_X2Ebdis_X7Bbackground_X3A_X23888_X3B_X7D_X2Ebdis_X3Ahover_X7Bbackground_X3A_X23888_X3B_X7D_X3C_X2Fstyle_X3E;
extern const bcstring be_const_str__X3Cinstance_X3A_X20Partition_X28_X5B_X0A;
extern const bcstring be_const_str__X3Cinstance_X3A_X20Partition_info_X28_X25d_X25s_X2C_X25d_X25s_X2C0x_X2508X_X2C0x_X2508X_X2C_X27_X25s_X27_X2C0x_X25X_X29_X3E;
extern const bcstring be_const_str__X3Cinstance_X3A_X20Partition_otadata_X28ota_active_X3A_X25d_X2C_X20ota_seq_X3D_X5B_X25d_X2C_X25d_X5D_X2C_X20ota_max_X3D_X25d_X29_X3E;
extern const bcstring be_const_str__X3Cinstance_X3A_X20Partition_otadata_X28ota_active_X3A_X25s_X2C_X20ota_seq_X3D_X5B_X25d_X2C_X25d_X5D_X2C_X20ota_max_X3D_X25d_X29_X3E;
extern const bcstring be_const_str__X3Cinstance_X3A_X20_X25s_X28_X25s_X2C_X20_X25s_X2C_X20_X25s_X29;
extern const bcstring be_const_str__X3Clabel_X3EChoose_X20a_X20device_X20configuration_X3A_X3C_X2Flabel_X3E_X3Cbr_X3E;
extern const bcstring be_const_str__X3Clambda_X3E;
@ -547,6 +547,7 @@ extern const bcstring be_const_str_groups;
extern const bcstring be_const_str_h;
extern const bcstring be_const_str_has;
extern const bcstring be_const_str_has_arg;
extern const bcstring be_const_str_has_factory;
extern const bcstring be_const_str_height_def;
extern const bcstring be_const_str_hex;
extern const bcstring be_const_str_hour;
@ -694,7 +695,7 @@ extern const bcstring be_const_str_on;
extern const bcstring be_const_str_onsubmit_X3D_X27return_X20confirm_X28_X22This_X20will_X20cause_X20a_X20restart_X2E_X22_X29_X3B_X27_X3E;
extern const bcstring be_const_str_onsubmit_X3D_X27return_X20confirm_X28_X22This_X20will_X20change_X20the_X20current_X20configuration_X20and_X20cause_X20a_X20restart_X2E_X22_X29_X3B_X27_X3E;
extern const bcstring be_const_str_open;
extern const bcstring be_const_str_ota;
extern const bcstring be_const_str_ota_;
extern const bcstring be_const_str_ota_max;
extern const bcstring be_const_str_otadata;
extern const bcstring be_const_str_out_X20of_X20range;
@ -913,6 +914,7 @@ extern const bcstring be_const_str_strptime;
extern const bcstring be_const_str_style_prop_arr;
extern const bcstring be_const_str_subscribe;
extern const bcstring be_const_str_subtype;
extern const bcstring be_const_str_subtype_to_string;
extern const bcstring be_const_str_success;
extern const bcstring be_const_str_super;
extern const bcstring be_const_str_switch_factory;
@ -958,6 +960,7 @@ extern const bcstring be_const_str_try_rule;
extern const bcstring be_const_str_try_run_compiled;
extern const bcstring be_const_str_type;
extern const bcstring be_const_str_type_error;
extern const bcstring be_const_str_type_to_string;
extern const bcstring be_const_str_udp;
extern const bcstring be_const_str_unknown_X20instruction;
extern const bcstring be_const_str_unsubscribe;

File diff suppressed because it is too large Load Diff

View File

@ -11,13 +11,8 @@
#include "esp_partition.h"
// 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_factory, "", "");
extern void p_factory(bbool force_ota);
BE_FUNC_CTYPE_DECLARE(p_factory, "", "b");
extern int p_flash_read(bvm *vm);
extern int p_flash_write(bvm *vm);

File diff suppressed because it is too large Load Diff

View File

@ -140,30 +140,39 @@ class Partition_info
end
end
def type_to_string()
if self.type == 0 return "app"
elif self.type == 1 return "data"
end
end
def subtype_to_string()
if self.type == 0
if self.subtype == 0 return "factory"
elif self.subtype >= 0x10 && self.subtype < 0x20 return "ota_" + str(self.subtype - 0x10)
elif self.subtype == 0x20 return "test"
end
elif self.type == 1
if self.subtype == 0x00 return "otadata"
elif self.subtype == 0x01 return "phy"
elif self.subtype == 0x02 return "nvs"
elif self.subtype == 0x03 return "coredump"
elif self.subtype == 0x04 return "nvskeys"
elif self.subtype == 0x05 return "efuse_em"
elif self.subtype == 0x80 return "esphttpd"
elif self.subtype == 0x81 return "fat"
elif self.subtype == 0x82 return "spiffs"
end
end
end
# Human readable version of Partition information
# this method is not included in the solidified version to save space,
# it is included only in the optional application `tapp` version
def tostring()
import string
var type_s = ""
var subtype_s = ""
if self.type == 0 type_s = "app"
if self.subtype == 0 subtype_s = "factory"
elif self.subtype >= 0x10 && self.subtype < 0x20 subtype_s = "ota" + str(self.subtype - 0x10)
elif self.subtype == 0x20 subtype_s = "test"
end
elif self.type == 1 type_s = "data"
if self.subtype == 0x00 subtype_s = "otadata"
elif self.subtype == 0x01 subtype_s = "phy"
elif self.subtype == 0x02 subtype_s = "nvs"
elif self.subtype == 0x03 subtype_s = "coredump"
elif self.subtype == 0x04 subtype_s = "nvskeys"
elif self.subtype == 0x05 subtype_s = "efuse_em"
elif self.subtype == 0x80 subtype_s = "esphttpd"
elif self.subtype == 0x81 subtype_s = "fat"
elif self.subtype == 0x82 subtype_s = "spiffs"
end
end
var type_s = self.type_to_string()
var subtype_s = self.subtype_to_string()
# reformat strings
if type_s != "" type_s = " (" + type_s + ")" end
@ -223,11 +232,12 @@ partition_core.Partition_info = Partition_info
seq will add (x + n*1 + 1 - seq)%n
-------------------------------------------------------------#
class Partition_otadata
var maxota #- number of highest OTA partition, default 1 (double ota0/ota1) -#
var offset #- offset of the otadata partition (0x2000 in length), default 0xE000 -#
var active_otadata #- which otadata block is active, 0 or 1, i.e. 0xE000 or 0xF000 -#
var seq0 #- ota_seq of first block -#
var seq1 #- ota_seq of second block -#
var maxota # number of highest OTA partition, default 1 (double ota0/ota1)
var has_factory # is there a factory partition
var offset # offset of the otadata partition (0x2000 in length), default 0xE000
var active_otadata # which otadata block is active, 0 or 1, i.e. 0xE000 or 0xF000 -- or -1 if no OTA active, i.e. boot on factory
var seq0 # ota_seq of first block
var seq1 # ota_seq of second block
#- crc32 for ota_seq as 32 bits unsigned, with init vector -1 -#
static def crc32_ota_seq(seq)
@ -238,12 +248,13 @@ class Partition_otadata
#---------------------------------------------------------------------#
# Rest of the class
#---------------------------------------------------------------------#
def init(maxota, offset)
def init(maxota, has_factory, offset)
self.maxota = maxota
self.has_factory = has_factory
if self.maxota == nil self.maxota = 1 end
self.offset = offset
if self.offset == nil self.offset = 0xE000 end
self.active_otadata = 0
self.active_otadata = -1
self.load()
end
@ -300,7 +311,7 @@ class Partition_otadata
#- internally used, validate data -#
def _validate()
self.active_otadata = 0 #- if none is valid, default to OTA0 -#
self.active_otadata = self.has_factory ? -1 : 0 # if no valid otadata, then use factory (-1) if any, or ota_0
if self.seq0 != nil
self.active_otadata = (self.seq0 - 1) % (self.maxota + 1)
end
@ -344,8 +355,9 @@ class Partition_otadata
# Produce a human-readable representation of the object with relevant information
def tostring()
import string
return string.format("<instance: Partition_otadata(ota_active:%d, ota_seq=[%d,%d], ota_max=%d)>",
self.active_otadata, self.seq0, self.seq1, self.maxota)
return string.format("<instance: Partition_otadata(ota_active:%s, ota_seq=[%d,%d], ota_max=%d)>",
self.active_otadata >= 0 ? "ota_" + str(self.active_otadata) : "factory",
self.seq0, self.seq1, self.maxota)
end
end
partition_core.Partition_otadata = Partition_otadata
@ -408,6 +420,15 @@ class Partition
return ota_max
end
def has_factory()
for slot:self.slots
if (slot.type == 0) && (slot.subtype == 0)
return true
end
end
return false
end
def load_otadata()
#- look for otadata partition offset, and max_ota -#
var otadata_offset = 0xE000 #- default value -#
@ -418,7 +439,7 @@ class Partition
end
end
self.otadata = partition_core.Partition_otadata(ota_max, otadata_offset)
self.otadata = partition_core.Partition_otadata(ota_max, self.has_factory(), otadata_offset)
end
# get the active OTA app partition number

View File

@ -313,7 +313,6 @@ uint32_t EspRunningFactoryPartition(void) {
}
void EspPrepRestartToSafeBoot(void) {
// esp_ota_mark_app_invalid_rollback_and_reboot(); // Doesn't work 20220501
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);

View File

@ -139,6 +139,16 @@ extern "C" {
be_raise(vm, kTypeError, nullptr);
}
// Forces the next restart to use the `factory` partition if any is present
void p_factory(bbool force_ota) {
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);
}
if (force_ota) {
RtcSettings.ota_loader = 1; // force OTA at next reboot
}
}
}
#endif // USE_BERRY