diff --git a/lib/libesp32/berry_tasmota/src/embedded/partition_core.be b/lib/libesp32/berry_tasmota/src/embedded/partition_core.be index abf48e8137b8..08736292c421 100644 --- a/lib/libesp32/berry_tasmota/src/embedded/partition_core.be +++ b/lib/libesp32/berry_tasmota/src/embedded/partition_core.be @@ -300,8 +300,8 @@ class Partition_otadata #- load otadata from SPI Flash -# def load() import flash - var otadata0 = flash.read(0xE000, 32) - var otadata1 = flash.read(0xF000, 32) + var otadata0 = flash.read(self.offset, 32) + var otadata1 = flash.read(self.offset + 0x1000, 32) self.seq0 = otadata0.get(0, 4) #- ota_seq for block 1 -# self.seq1 = otadata1.get(0, 4) #- ota_seq for block 2 -# var valid0 = otadata0.get(28, 4) == self.crc32_ota_seq(self.seq0) #- is CRC32 valid? -# diff --git a/lib/libesp32/berry_tasmota/src/solidify/solidified_partition_core.h b/lib/libesp32/berry_tasmota/src/solidify/solidified_partition_core.h index d523d13313c0..caadd3a25e97 100644 --- a/lib/libesp32/berry_tasmota/src/solidify/solidified_partition_core.h +++ b/lib/libesp32/berry_tasmota/src/solidify/solidified_partition_core.h @@ -248,65 +248,68 @@ be_local_closure(Partition_otadata_load, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 8]) { /* constants */ + ( &(const bvalue[ 9]) { /* constants */ /* K0 */ be_nested_str(flash), /* K1 */ be_nested_str(read), - /* K2 */ be_nested_str(seq0), - /* K3 */ be_nested_str(get), - /* K4 */ be_const_int(0), - /* K5 */ be_nested_str(seq1), - /* K6 */ be_nested_str(crc32_ota_seq), - /* K7 */ be_nested_str(_validate), + /* K2 */ be_nested_str(offset), + /* K3 */ be_nested_str(seq0), + /* K4 */ be_nested_str(get), + /* K5 */ be_const_int(0), + /* K6 */ be_nested_str(seq1), + /* K7 */ be_nested_str(crc32_ota_seq), + /* K8 */ be_nested_str(_validate), }), &be_const_str_load, &be_const_str_solidified, - ( &(const binstruction[46]) { /* code */ + ( &(const binstruction[48]) { /* code */ 0xA4060000, // 0000 IMPORT R1 K0 0x8C080301, // 0001 GETMET R2 R1 K1 - 0x5412DFFF, // 0002 LDINT R4 57344 + 0x88100102, // 0002 GETMBR R4 R0 K2 0x5416001F, // 0003 LDINT R5 32 0x7C080600, // 0004 CALL R2 3 0x8C0C0301, // 0005 GETMET R3 R1 K1 - 0x5416EFFF, // 0006 LDINT R5 61440 - 0x541A001F, // 0007 LDINT R6 32 - 0x7C0C0600, // 0008 CALL R3 3 - 0x8C100503, // 0009 GETMET R4 R2 K3 - 0x58180004, // 000A LDCONST R6 K4 - 0x541E0003, // 000B LDINT R7 4 - 0x7C100600, // 000C CALL R4 3 - 0x90020404, // 000D SETMBR R0 K2 R4 - 0x8C100703, // 000E GETMET R4 R3 K3 - 0x58180004, // 000F LDCONST R6 K4 - 0x541E0003, // 0010 LDINT R7 4 - 0x7C100600, // 0011 CALL R4 3 - 0x90020A04, // 0012 SETMBR R0 K5 R4 - 0x8C100503, // 0013 GETMET R4 R2 K3 - 0x541A001B, // 0014 LDINT R6 28 - 0x541E0003, // 0015 LDINT R7 4 - 0x7C100600, // 0016 CALL R4 3 - 0x8C140106, // 0017 GETMET R5 R0 K6 - 0x881C0102, // 0018 GETMBR R7 R0 K2 - 0x7C140400, // 0019 CALL R5 2 - 0x1C100805, // 001A EQ R4 R4 R5 - 0x8C140703, // 001B GETMET R5 R3 K3 - 0x541E001B, // 001C LDINT R7 28 - 0x54220003, // 001D LDINT R8 4 - 0x7C140600, // 001E CALL R5 3 - 0x8C180106, // 001F GETMET R6 R0 K6 - 0x88200105, // 0020 GETMBR R8 R0 K5 - 0x7C180400, // 0021 CALL R6 2 - 0x1C140A06, // 0022 EQ R5 R5 R6 - 0x5C180800, // 0023 MOVE R6 R4 - 0x741A0001, // 0024 JMPT R6 #0027 - 0x4C180000, // 0025 LDNIL R6 - 0x90020406, // 0026 SETMBR R0 K2 R6 - 0x5C180A00, // 0027 MOVE R6 R5 - 0x741A0001, // 0028 JMPT R6 #002B - 0x4C180000, // 0029 LDNIL R6 - 0x90020A06, // 002A SETMBR R0 K5 R6 - 0x8C180107, // 002B GETMET R6 R0 K7 - 0x7C180200, // 002C CALL R6 1 - 0x80000000, // 002D RET 0 + 0x88140102, // 0006 GETMBR R5 R0 K2 + 0x541A0FFF, // 0007 LDINT R6 4096 + 0x00140A06, // 0008 ADD R5 R5 R6 + 0x541A001F, // 0009 LDINT R6 32 + 0x7C0C0600, // 000A CALL R3 3 + 0x8C100504, // 000B GETMET R4 R2 K4 + 0x58180005, // 000C LDCONST R6 K5 + 0x541E0003, // 000D LDINT R7 4 + 0x7C100600, // 000E CALL R4 3 + 0x90020604, // 000F SETMBR R0 K3 R4 + 0x8C100704, // 0010 GETMET R4 R3 K4 + 0x58180005, // 0011 LDCONST R6 K5 + 0x541E0003, // 0012 LDINT R7 4 + 0x7C100600, // 0013 CALL R4 3 + 0x90020C04, // 0014 SETMBR R0 K6 R4 + 0x8C100504, // 0015 GETMET R4 R2 K4 + 0x541A001B, // 0016 LDINT R6 28 + 0x541E0003, // 0017 LDINT R7 4 + 0x7C100600, // 0018 CALL R4 3 + 0x8C140107, // 0019 GETMET R5 R0 K7 + 0x881C0103, // 001A GETMBR R7 R0 K3 + 0x7C140400, // 001B CALL R5 2 + 0x1C100805, // 001C EQ R4 R4 R5 + 0x8C140704, // 001D GETMET R5 R3 K4 + 0x541E001B, // 001E LDINT R7 28 + 0x54220003, // 001F LDINT R8 4 + 0x7C140600, // 0020 CALL R5 3 + 0x8C180107, // 0021 GETMET R6 R0 K7 + 0x88200106, // 0022 GETMBR R8 R0 K6 + 0x7C180400, // 0023 CALL R6 2 + 0x1C140A06, // 0024 EQ R5 R5 R6 + 0x5C180800, // 0025 MOVE R6 R4 + 0x741A0001, // 0026 JMPT R6 #0029 + 0x4C180000, // 0027 LDNIL R6 + 0x90020606, // 0028 SETMBR R0 K3 R6 + 0x5C180A00, // 0029 MOVE R6 R5 + 0x741A0001, // 002A JMPT R6 #002D + 0x4C180000, // 002B LDNIL R6 + 0x90020C06, // 002C SETMBR R0 K6 R6 + 0x8C180108, // 002D GETMET R6 R0 K8 + 0x7C180200, // 002E CALL R6 1 + 0x80000000, // 002F RET 0 }) ) ); diff --git a/tasmota/berry/modules/Partition_Wizard.tapp b/tasmota/berry/modules/Partition_Wizard.tapp index 9b19600a23fc..98bfc21b98ba 100644 Binary files a/tasmota/berry/modules/Partition_Wizard.tapp and b/tasmota/berry/modules/Partition_Wizard.tapp differ diff --git a/tasmota/berry/modules/Partition_Wizard/partition_wizard.bec b/tasmota/berry/modules/Partition_Wizard/partition_wizard.bec index b5227ecd6505..786b64901bbf 100644 Binary files a/tasmota/berry/modules/Partition_Wizard/partition_wizard.bec and b/tasmota/berry/modules/Partition_Wizard/partition_wizard.bec differ diff --git a/tasmota/berry/modules/partition_wizard.be b/tasmota/berry/modules/partition_wizard.be index abda199564ba..9db98990145b 100644 --- a/tasmota/berry/modules/partition_wizard.be +++ b/tasmota/berry/modules/partition_wizard.be @@ -24,25 +24,49 @@ class Partition_wizard_UI if persist.find("factory_migrate") == true # remove marker to avoid bootloop if something goes wrong + tasmota.log("UPL: Resuming after step 1", 2) persist.remove("factory_migrate") persist.save() # continue the migration process 5 seconds after Wifi is connected def continue_after_5s() - tasmota.remove_rule("parwiz_5s") # first remove rule to avoid firing it again at Wifi reconnect + tasmota.remove_rule("parwiz_5s1") # first remove rule to avoid firing it again at Wifi reconnect + tasmota.remove_rule("parwiz_5s2") # first remove rule to avoid firing it again at Wifi reconnect tasmota.set_timer(5000, /-> self.do_safeboot_partitioning()) # delay by 5 s end - tasmota.add_rule("Wifi#Connected=1", continue_after_5s, "parwiz_5s") + tasmota.add_rule("Wifi#Connected=1", continue_after_5s, "parwiz_5s1") + tasmota.add_rule("Wifi#Connected==1", continue_after_5s, "parwiz_5s2") end end + # ---------------------------------------------------------------------- + # Patch partition core since we can't chang the solidified code + # ---------------------------------------------------------------------- + def patch_partition_core(p) + var otadata = p.otadata + + # patch load + import flash + var otadata0 = flash.read(otadata.offset, 32) + var otadata1 = flash.read(otadata.offset + 0x1000, 32) + otadata.seq0 = otadata0.get(0, 4) #- ota_seq for block 1 -# + otadata.seq1 = otadata1.get(0, 4) #- ota_seq for block 2 -# + var valid0 = otadata0.get(28, 4) == otadata.crc32_ota_seq(otadata.seq0) #- is CRC32 valid? -# + var valid1 = otadata1.get(28, 4) == otadata.crc32_ota_seq(otadata.seq1) #- is CRC32 valid? -# + if !valid0 otadata.seq0 = nil end + if !valid1 otadata.seq1 = nil end + + otadata._validate() + end + def default_safeboot_URL() + import string var arch_sub = tasmota.arch() if arch_sub[0..4] == "esp32" arch_sub = arch_sub[5..] # get the esp32 variant end - return format(self._default_safeboot_URL, arch_sub) + return string.format(self._default_safeboot_URL, arch_sub) end # create a method for adding a button to the main menu @@ -53,15 +77,34 @@ class Partition_wizard_UI "
") end + # ---------------------------------------------------------------------- + # Get last fs + # + # Get the last fs partition + # Return the actual slot + # ---------------------------------------------------------------------- + def get_last_fs(p) + var sz = size(p.slots) + var idx = 1 + while idx < sz + var slot = p.slots[-idx] + if slot.is_spiffs() + return slot + end + idx += 1 + end + return nil + end + #- ---------------------------------------------------------------------- -# #- Get fs unallocated size #- ---------------------------------------------------------------------- -# def get_unallocated_k(p) - var last_slot = p.slots[-1] - if last_slot.is_spiffs() + var last_fs = self.get_last_fs(p) + if last_fs != nil # verify that last slot is filesystem var flash_size_k = self.get_max_flash_size_k(p) - var partition_end_k = (last_slot.start + last_slot.sz) / 1024 # last kb used for fs + var partition_end_k = (last_fs.start + last_fs.sz) / 1024 # last kb used for fs if partition_end_k < flash_size_k return flash_size_k - partition_end_k end @@ -73,8 +116,8 @@ class Partition_wizard_UI #- Get max fs start address when expanded to maximum #- ---------------------------------------------------------------------- -# def get_max_fs_start_k(p) - var last_slot = p.slots[-1] - if last_slot.is_spiffs() # verify that last slot is filesystem + var last_fs = p.slots[-1] + if last_fs != nil # verify that last slot is filesystem # get end of previous partition slot var last_app = p.slots[-2] # round upper 64kB @@ -85,7 +128,7 @@ class Partition_wizard_UI end #- ---------------------------------------------------------------------- -# - #- Get max falsh size + #- Get max flash size # # Takes into account that the flash size written may not be accurate # and the flash chip may be larger @@ -99,15 +142,40 @@ class Partition_wizard_UI return flash_size_k end + # ---------------------------------------------------------------------- + # Remove any non wanted partion after last FS + # ---------------------------------------------------------------------- + def remove_partition_after_last_fs(p) + # remove any partition after last fs + do + var last_fs = self.get_last_fs(p) + var changed = false + if last_fs != nil + while true + var last_slot = p.slots[-1] + if !last_slot.is_spiffs() && (last_slot.type != 0) + p.slots.remove(size(p.slots) - 1) # remove last slot + changed = true + else + break + end + end + if changed p.save() end + end + end + end + #- ---------------------------------------------------------------------- -# #- Resize flash definition if needed #- ---------------------------------------------------------------------- -# def resize_max_flash_size_k(p) + self.remove_partition_after_last_fs(p) var flash_size_k = tasmota.memory()['flash'] var flash_size_real_k = tasmota.memory().find("flash_real", flash_size_k) var flash_definition_sector = self.get_flash_definition_sector(p) if (flash_size_k != flash_size_real_k) && flash_definition_sector != nil import flash + import string flash_size_k = flash_size_real_k # try to expand the flash size definition @@ -131,7 +199,7 @@ class Partition_wizard_UI var old_def = flash_def[3] flash_def[3] = (flash_def[3] & 0x0F) | flash_size_code flash.write(flash_definition_sector, flash_def) - tasmota.log(format("UPL: changing flash definition from 0x02X to 0x%02X", old_def, flash_def[3]), 3) + tasmota.log(string.format("UPL: changing flash definition from 0x02X to 0x%02X", old_def, flash_def[3]), 3) else raise "internal_error", "wrong flash size "+str(flash_size_real_m) end @@ -142,9 +210,9 @@ class Partition_wizard_UI #- Get current fs size #- ---------------------------------------------------------------------- -# def get_cur_fs_size_k(p) - var last_slot = p.slots[-1] - if last_slot.is_spiffs() # verify that last slot is filesystem - return (last_slot.sz + 1023) / 1024 + var last_fs = p.slots[-1] + if last_fs != nil + return (last_fs.sz + 1023) / 1024 end return 0 end @@ -171,13 +239,14 @@ class Partition_wizard_UI #- ---------------------------------------------------------------------- -# def show_resize_fs(p) import webserver + import string var unallocated = self.get_unallocated_k(p) # if there is unallocated space, propose only to claim it if unallocated > 0 webserver.content_send("