From 032ca2f56ceda50ba962355b5d87a85ab96f16e3 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 19 Jun 2021 12:05:54 +0200 Subject: [PATCH] Added features --- tasmota/berry/modules/partition.be | 36 ++++++++++++++++++++++ tasmota/berry/modules/partition_manager.be | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/tasmota/berry/modules/partition.be b/tasmota/berry/modules/partition.be index 631a05fd3..8c4cc457c 100644 --- a/tasmota/berry/modules/partition.be +++ b/tasmota/berry/modules/partition.be @@ -119,6 +119,42 @@ class Partition_info end end + # check if the parition is a SPIFFS partition + # returns bool + def is_spiffs() + return self.type == 1 && self.subtype == 130 + end + + # get the actual image size give of the partition + # 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 + + 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) + 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() import string var type_s = "" diff --git a/tasmota/berry/modules/partition_manager.be b/tasmota/berry/modules/partition_manager.be index 7db4b16f5..04745cf37 100644 --- a/tasmota/berry/modules/partition_manager.be +++ b/tasmota/berry/modules/partition_manager.be @@ -63,7 +63,7 @@ class Partition_manager : Driver if ota_num != nil # we have an OTA partition self.page_show_partition(slot, ota_num == p.otadata.active_otadata) - elif slot.type == 1 && slot.subtype == 130 + elif slot.is_spiffs() var flash_size = tasmota.memory()['flash'] * 1024 var used_size = (slot.start + slot.size) self.page_show_spiffs(slot, slot == p.slots[-1] ? flash_size - used_size : nil)