From e78396f95ed8bcaf719c01a3e45420b5259650f0 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 19 Jun 2021 16:41:56 +0200 Subject: [PATCH] Update --- tasmota/berry/modules/partition.be | 59 ++++++++++++++-------- tasmota/berry/modules/partition_manager.be | 28 +++++----- 2 files changed, 54 insertions(+), 33 deletions(-) diff --git a/tasmota/berry/modules/partition.be b/tasmota/berry/modules/partition.be index 8c4cc457c..de0fcff96 100644 --- a/tasmota/berry/modules/partition.be +++ b/tasmota/berry/modules/partition.be @@ -129,30 +129,35 @@ class Partition_info # returns -1 if the partition is not an app ota partition def get_image_size() if self.is_ota() == nil return -1 end - var addr = self.start - var magic_byte = flash.read(addr, 1).get(0, 1) - if magic_byte != 0xE9 raise "internal_error", string.format("Invalid magic_byte 0x%02X (should be 0xE9)", magic_byte) end - - var seg_count = flash.read(addr+1, 1).get(0, 1) - # print("Segment count", seg_count) - - var seg_offset = addr + 0x20 # sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) = 24 + 8 - var seg_size = 0 + try + var addr = self.start + var magic_byte = flash.read(addr, 1).get(0, 1) + if magic_byte != 0xE9 raise "internal_error", string.format("Invalid magic_byte 0x%02X (should be 0xE9)", magic_byte) end + + var seg_count = flash.read(addr+1, 1).get(0, 1) + # print("Segment count", seg_count) + + var seg_offset = addr + 0x20 # sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t) = 24 + 8 + var seg_size = 0 - for seg_num:0..seg_count-1 - # print(string.format("Reading 0x%08X", seg_offset)) - var segment_header = flash.read(seg_offset - 8, 8) - var seg_start_addr = segment_header.get(0, 4) - var seg_size = segment_header.get(4,4) - # print(string.format("Segment %i: flash_offset=0x%08X start_addr=0x%08X size=0x%08X", seg_num, seg_offset, seg_start_addr, seg_size)) + for seg_num:0..seg_count-1 + # print(string.format("Reading 0x%08X", seg_offset)) + var segment_header = flash.read(seg_offset - 8, 8) + var seg_start_addr = segment_header.get(0, 4) + var seg_size = segment_header.get(4,4) + # print(string.format("Segment %i: flash_offset=0x%08X start_addr=0x%08X size=0x%08X", seg_num, seg_offset, seg_start_addr, seg_size)) - seg_offset += seg_size + 8 # add segment_length + sizeof(esp_image_segment_header_t) + seg_offset += seg_size + 8 # add segment_length + sizeof(esp_image_segment_header_t) + end + var total_size = seg_offset - addr + 1 # add 1KB for safety + + # print(string.format("Total size = %i KB", total_size/1024)) + + return total_size + except .. as e, m + print(string.format("BRY: Exception> '%s' - %s", e, m)) + return -1 end - var total_size = seg_offset - addr + 1 # add 1KB for safety - - # print(string.format("Total size = %i KB", total_size/1024)) - - return total_size end def tostring() @@ -458,6 +463,18 @@ class Partition flash.write(0x8000, b) self.otadata.save() end + + #- invalidate SPIFFS partition to force format at next boot -# + #- we simply erase the first byte of the first 2 blocks in the SPIFFS partition -# + def invalidate_spiffs() + #- we expect the SPIFFS partition to be the last one -# + var spiffs = self.slots[-1] + if !spiffs.is_spiffs() raise 'value_error', 'No SPIFFS partition found' end + + var b = bytes("00") #- flash memory: we can turn bits from '1' to '0' -# + flash.write(spiffs.start , b) #- block #0 -# + flash.write(spiffs.start + 0x1000, b) #- block #1 -# + end end partition.Partition = Partition diff --git a/tasmota/berry/modules/partition_manager.be b/tasmota/berry/modules/partition_manager.be index 04745cf37..08506d73c 100644 --- a/tasmota/berry/modules/partition_manager.be +++ b/tasmota/berry/modules/partition_manager.be @@ -24,14 +24,18 @@ class Partition_manager : Driver # Show a single OTA Partition # def page_show_partition(slot, active) - webserver.content_send("
 " + slot.label) - if active - webserver.content_send(" (active)") - end - webserver.content_send("") + webserver.content_send(string.format("
 %s%s", + slot.start / 0x1000, slot.label, active ? " (active)" : "")) - webserver.content_send(string.format("

Start: 0x%03x 000

", slot.start / 0x1000)) - webserver.content_send(string.format("

Size: %i KB

", slot.size / 1024)) + webserver.content_send(string.format("

Partition size: %i KB

", slot.size / 1024)) + var used = slot.get_image_size() + if used >= 0 + webserver.content_send(string.format("

Used: %i KB

", used / 1024)) + webserver.content_send(string.format("

Free: %i KB

", (slot.size - used) / 1024)) + else + webserver.content_send("

Used: unknwon") + webserver.content_send("

Free: unknwon") + end webserver.content_send("

") end @@ -41,11 +45,10 @@ class Partition_manager : Driver # Show a single OTA Partition # def page_show_spiffs(slot, free_mem) - webserver.content_send("
 " + slot.label) - webserver.content_send("") + webserver.content_send(string.format("
 %s", + slot.start / 0x1000, slot.label)) - webserver.content_send(string.format("

Start: 0x%03x 000

", slot.start / 0x1000)) - webserver.content_send(string.format("

Size: %i KB

", slot.size / 1024)) + webserver.content_send(string.format("

Partition size: %i KB

", slot.size / 1024)) if free_mem != nil webserver.content_send(string.format("

Unallocated: %i KB

", free_mem / 1024)) end @@ -78,8 +81,9 @@ class Partition_manager : Driver webserver.content_start("Partition Manager") #- title of the web page -# webserver.content_send_style() #- send standard Tasmota styles -# - webserver.content_send("

Esp32 Partition Manager

") #- send any html -# + webserver.content_send("
 Partition Manager

") self.page_show_partitions() + webserver.content_send("

") webserver.content_button(webserver.BUTTON_MANAGEMENT) #- button back to management page -# webserver.content_stop() #- end of web page -#