This commit is contained in:
Stephan Hadinger 2021-06-19 16:41:56 +02:00
parent 032ca2f56c
commit e78396f95e
2 changed files with 54 additions and 33 deletions

View File

@ -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

View File

@ -24,14 +24,18 @@ class Partition_manager : Driver
# Show a single OTA Partition
#
def page_show_partition(slot, active)
webserver.content_send("<fieldset><legend><b>&nbsp;" + slot.label)
if active
webserver.content_send(" (active)")
end
webserver.content_send("</b></legend>")
webserver.content_send(string.format("<fieldset><legend><b title='Start: 0x%03X 000'>&nbsp;%s%s</b></legend>",
slot.start / 0x1000, slot.label, active ? " (active)" : ""))
webserver.content_send(string.format("<p><b>Start: </b>0x<b>%03x</b> 000</p>", slot.start / 0x1000))
webserver.content_send(string.format("<p><b>Size: </b>%i KB</p>", slot.size / 1024))
webserver.content_send(string.format("<p><b>Partition size: </b>%i KB</p>", slot.size / 1024))
var used = slot.get_image_size()
if used >= 0
webserver.content_send(string.format("<p><b>Used: </b>%i KB</p>", used / 1024))
webserver.content_send(string.format("<p><b>Free: </b>%i KB</p>", (slot.size - used) / 1024))
else
webserver.content_send("<p><b>Used: unknwon")
webserver.content_send("<p><b>Free: unknwon")
end
webserver.content_send("<p></p></fieldset><p></p>")
end
@ -41,11 +45,10 @@ class Partition_manager : Driver
# Show a single OTA Partition
#
def page_show_spiffs(slot, free_mem)
webserver.content_send("<fieldset><legend><b>&nbsp;" + slot.label)
webserver.content_send("</b></legend>")
webserver.content_send(string.format("<fieldset><legend><b title='Start: 0x%03X 000'>&nbsp;%s</b></legend>",
slot.start / 0x1000, slot.label))
webserver.content_send(string.format("<p><b>Start: </b>0x<b>%03x</b> 000</p>", slot.start / 0x1000))
webserver.content_send(string.format("<p><b>Size: </b>%i KB</p>", slot.size / 1024))
webserver.content_send(string.format("<p><b>Partition size: </b>%i KB</p>", slot.size / 1024))
if free_mem != nil
webserver.content_send(string.format("<p><b>Unallocated: </b>%i KB</p>", 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("<p><b>Esp32 Partition Manager</b></p><p></p>") #- send any html -#
webserver.content_send("<fieldset><legend><b>&nbsp;Partition Manager</b></legend><p></p>")
self.page_show_partitions()
webserver.content_send("<p></p></fieldset><p></p>")
webserver.content_button(webserver.BUTTON_MANAGEMENT) #- button back to management page -#
webserver.content_stop() #- end of web page -#