From ab7b7f8c173cd42ea6b234f5ad759bbf10d3958f Mon Sep 17 00:00:00 2001 From: Thomas Brasser Date: Sat, 23 Dec 2023 16:58:41 +0100 Subject: [PATCH] Add Shelly Mini1G3, Mini1PMG3 and MiniPMG3 (#36) Co-authored-by: Thomas Brasser --- .../Shelly_Mini1G3/Partition_Wizard.tapp | Bin 0 -> 17544 bytes .../Shelly_Mini1G3/bootloader-tasmota-c3.bin | Bin 0 -> 10576 bytes raw/esp32c3/Shelly_Mini1G3/bootloader.be | 108 +++ raw/esp32c3/Shelly_Mini1G3/init.bat | 4 + raw/esp32c3/Shelly_Mini1G3/migrate_shelly.be | 70 ++ .../Shelly_Mini1G3/partition_core_shelly.be | 645 ++++++++++++++++++ .../Shelly_Mini1PMG3/Partition_Wizard.tapp | Bin 0 -> 17544 bytes .../bootloader-tasmota-c3.bin | Bin 0 -> 10576 bytes raw/esp32c3/Shelly_Mini1PMG3/bootloader.be | 108 +++ raw/esp32c3/Shelly_Mini1PMG3/init.bat | 4 + .../Shelly_Mini1PMG3/migrate_shelly.be | 70 ++ .../Shelly_Mini1PMG3/partition_core_shelly.be | 645 ++++++++++++++++++ .../Shelly_MiniPMG3/Partition_Wizard.tapp | Bin 0 -> 17544 bytes .../Shelly_MiniPMG3/bootloader-tasmota-c3.bin | Bin 0 -> 10576 bytes raw/esp32c3/Shelly_MiniPMG3/bootloader.be | 108 +++ raw/esp32c3/Shelly_MiniPMG3/init.bat | 5 + raw/esp32c3/Shelly_MiniPMG3/migrate_shelly.be | 70 ++ .../Shelly_MiniPMG3/partition_core_shelly.be | 645 ++++++++++++++++++ 18 files changed, 2482 insertions(+) create mode 100644 raw/esp32c3/Shelly_Mini1G3/Partition_Wizard.tapp create mode 100644 raw/esp32c3/Shelly_Mini1G3/bootloader-tasmota-c3.bin create mode 100644 raw/esp32c3/Shelly_Mini1G3/bootloader.be create mode 100644 raw/esp32c3/Shelly_Mini1G3/init.bat create mode 100644 raw/esp32c3/Shelly_Mini1G3/migrate_shelly.be create mode 100644 raw/esp32c3/Shelly_Mini1G3/partition_core_shelly.be create mode 100644 raw/esp32c3/Shelly_Mini1PMG3/Partition_Wizard.tapp create mode 100644 raw/esp32c3/Shelly_Mini1PMG3/bootloader-tasmota-c3.bin create mode 100644 raw/esp32c3/Shelly_Mini1PMG3/bootloader.be create mode 100644 raw/esp32c3/Shelly_Mini1PMG3/init.bat create mode 100644 raw/esp32c3/Shelly_Mini1PMG3/migrate_shelly.be create mode 100644 raw/esp32c3/Shelly_Mini1PMG3/partition_core_shelly.be create mode 100644 raw/esp32c3/Shelly_MiniPMG3/Partition_Wizard.tapp create mode 100644 raw/esp32c3/Shelly_MiniPMG3/bootloader-tasmota-c3.bin create mode 100644 raw/esp32c3/Shelly_MiniPMG3/bootloader.be create mode 100644 raw/esp32c3/Shelly_MiniPMG3/init.bat create mode 100644 raw/esp32c3/Shelly_MiniPMG3/migrate_shelly.be create mode 100644 raw/esp32c3/Shelly_MiniPMG3/partition_core_shelly.be diff --git a/raw/esp32c3/Shelly_Mini1G3/Partition_Wizard.tapp b/raw/esp32c3/Shelly_Mini1G3/Partition_Wizard.tapp new file mode 100644 index 0000000000000000000000000000000000000000..98bfc21b98ba0a2f175f3df902054f3f209d9854 GIT binary patch literal 17544 zcmb_k&u<$^b}n`|n@zGwwkTSrWm>M$P?p9kOO&jccs-Kr@z}FF8I7&=&>0V+fTGBj z#5F~7$<|oj5Lg9BusR5c4-OI_mtDZYE|5L=kN`Rax#X~?%^#3s4ncwd$t8ze*2?#) zy2&O*dW_7{Fj-w)UBBzS?|tvJ)<09V2&2yr|5|_am;dz7Ki@%`{zqAc75AOGePEa7 zw(LjwFjEg+{@2zYmG_8Rr3!yBCnpNa}2>z%&-=imI>AN=qK|2qGhJB-o)6#Cj< z9DOc{PTw?tQKtWWo&Lw)yw=cnmZmR!G`3f))KYAIKt(Lb7)O~XW1A@Xm?^BynDP$_ zV@QkNzr*jzEmhA4bmcjvPoqd1GOb7P%ajwQ=qCXM>9}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b$~^R1l*+; z^E_(Gg?eX|Miv0QCa;n)*P$ZYaW;w<*8*r9|4(-%7^~cbTGQ zHyV$2gUcEB!0ExNO+h>;Igm|eY!cWdGB5xNOVKTatr4+j-IZXs3;Tt$6etj6A^RUd zd2EO^LWLp@%sp@tllzc6br7`U5J&OQ13dJ`kl~CftVAvOEgHXHoOn(pexkTMCx9=a ztGYa=?sI*pT8iJNAbkqLH&XmFO6!O;jE}!0z7uZ(!Z(>k)S-OYA)MggP_t`7Q|pNQ zJ2#sNusQtIfb3%q32(aBV3G0}T&rv@A5FJyg#LZ*qM;&?4NNdsLEFZ;nI5GPooXEY13(cIH4X1NCGdb~Bu_%}= z13v3GSR`WJl*N18}KbdtB&2>2q(V(0%hQmf%Zlj=|P*_WU1VSVEZQLSTsv7 zFt9_4oXK!wckT%q5dH14`tB+VM2o!JHWQigaTjeQ}L*QMW5#FUT=Rz~P_d1)_# zGPl?Xpj>)6e2QMtLM=TGJ)I&Bm!XgRj4>C-HIIDOY<>Fps?1gxza}IJGtcplqUz~5+BA%?9 zGu680>B6}!y!Fss^fQnmBEq)Icvm0q@}DtV97S2_<^| ztVfWEKkL!=*D?GRp8abZ{t7|evW{blUKymn{UQGL25KJgcQ@8Q3zBODfzJy2Tm1g| HW4ii39kNrx literal 0 HcmV?d00001 diff --git a/raw/esp32c3/Shelly_Mini1G3/bootloader-tasmota-c3.bin b/raw/esp32c3/Shelly_Mini1G3/bootloader-tasmota-c3.bin new file mode 100644 index 0000000000000000000000000000000000000000..b5911365bddd5e5b1ab8e59d7a2e90df1a02abba GIT binary patch literal 10576 zcmZ8H4OmlGvganbxe0n5h9I<^k+A9Eg-LJEwox}Ok2B>W?v4?hXnQ)iPO^MgL$rss2C-#TZmV*93i1-t3x zmvdfFY}%?=lcJcvWA^-qcZ7uiUCO4H*@BlhZH2x+Zp!~7GVFLQhy4{o2(O_NBji$M zzhI{j%FDBMR>8PI_&+fxy2UlW4`KX0tV^-)FSHnim<$q0m9Et{XzX)JB!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$gcmA9K(o8WgZC8(*@PNCmx!GhRo&(s*kKFFY$PQVG+ z7*D7vy(0C+bTZX0J|>p?D}dSJzzxs%uyT+6Kq_h}m)?g*+Rux_?!)vYTqq%+))sLe z*170Hi5%*R_hYj)_Ulq<^nH|l3#|US-t7CZ&iPhG&Qzw|Pn$gt*971F4Hm@*&QVrg zZeRFMW$BfvGt-IG1U`nj^>$F!2RwpkznuGiBPUX0dSbb}Sq@{`d8|>mUrwPbDMD|; zUwGN50pyJ;$YR-1TxTVX0=!4A0c^EuOG|Qtfqj7!XtFp#eTn_aC{z#Mu&xW>#zucF zFs1Ep`M%{~yR)4%MAw1VNp{Mx|9le$@XO+1gsnKYKN{+qc%ROIU1s#*^X|wX8MSq; zF>E(0y(W;iSs6BTSOor{{BXuc$@bylWKPtWRVh#@tVpFif>g7rp)xa$a{FvQ9Aw^M z!b+`XuC#KHCegI$LA-KBDsHzlL!LTg^bYJfc$u=)7XCekOPy)Rfv*eb_XR&ES*mdl ziJ?p$f1zzLKT2*a<3TT~4{E_zE-?KDdlX|`SG&K)^{Dt@HlgdmQZ!{W82rEH2zo29 z^jY{qtN#$9LUL9N^qWC5BqgoBJUboTP87~Q z1C-Al>1~!W{ndkaX9mxc?u$=X7H+4h(PaEY&w~<@$SEydwr(f_<$7FamSaAyW zuKh8K#y|5{3e2^gQ?wpmcms9QrhOlB4w8JJzUtRsut1GT!`12nK45GEFLwGXyJO$s zwsF_9WI-9cjksR1zU+n{i{r!?t~J1VO&i|bypY`ZcGGu|A(RdHBMSIlfc$40sQf=e op?_HWXkPc3sFN|mr (0x8000 - addr) raise "internal_error", "bootloader is too large "+str(bl_size / 1024)+"kB" end + + cl.write_file("bootloader.bin") + cl.close() + end + + # returns true if ok + def flash(url) + var fname = "bootloader.bin" # default local name + if url != nil + if url[0..3] == "http" # if starts with 'http' download + self.download(url) + else + fname = url # else get from file system + end + end + # address to flash the bootloader + var addr = self.get_bootloader_address() + if addr == nil tasmota.log("OTA: can't find address for bootloader", 2) return false end + + var bl = open(fname, "r") + if bl.readbytes(size(self._sign)) != self._sign + tasmota.log("OTA: file does not contain a bootloader signature", 2) + return false + end + bl.seek(0) # reset to start of file + + var bl_size = bl.size() + if bl_size <= 8291 tasmota.log("OTA: wrong bootloader size "+str(bl_size), 2) return false end + if bl_size > (0x8000 - addr) tasmota.log("OTA: bootloader is too large "+str(bl_size / 1024)+"kB", 2) return false end + + tasmota.log("OTA: Flashing bootloader", 2) + # from now on there is no turning back, any failure means a bricked device + import flash + # read current value for bytes 2/3 + var cur_config = flash.read(addr, 4) + + flash.erase(addr, self._addr_high - addr) # erase the bootloader + var buf = bl.readbytes(0x1000) # read by chunks of 4kb + # put back signature + buf[2] = cur_config[2] + buf[3] = cur_config[3] + while size(buf) > 0 + flash.write(addr, buf, true) # set flag to no-erase since we already erased it + addr += size(buf) + buf = bl.readbytes(0x1000) # read next chunk + end + bl.close() + tasmota.log("OTA: Booloader flashed, please restart", 2) + return true + end +end + +return bootloader + +#- + +### FLASH +import bootloader +bootloader().flash('https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/sdk/esp32/bin/bootloader_dio_40m.bin') + +#bootloader().flash('https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/sdk/esp32/bin/bootloader_dout_40m.bin') + +### FLASH from local file +bootloader().flash("bootloader-tasmota-c3.bin") + +#### debug only +bl = bootloader() +print(format("0x%04X", bl.get_bootloader_address())) + +-# \ No newline at end of file diff --git a/raw/esp32c3/Shelly_Mini1G3/init.bat b/raw/esp32c3/Shelly_Mini1G3/init.bat new file mode 100644 index 00000000..35ec7ddd --- /dev/null +++ b/raw/esp32c3/Shelly_Mini1G3/init.bat @@ -0,0 +1,4 @@ +Br load("Shelly_Mini1G3.autoconf#migrate_shelly.be") +Template {"NAME":"Shelly Mini1G3","GPIO":[320,32,0,4736,0,0,0,224,0,0,192,0,0,0,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":1} +Module 0 +AdcParam1 2,10000,10000,3350 diff --git a/raw/esp32c3/Shelly_Mini1G3/migrate_shelly.be b/raw/esp32c3/Shelly_Mini1G3/migrate_shelly.be new file mode 100644 index 00000000..b09c9149 --- /dev/null +++ b/raw/esp32c3/Shelly_Mini1G3/migrate_shelly.be @@ -0,0 +1,70 @@ +# migration script for Shelly + +# simple function to copy from autoconfig archive to filesystem +# return true if ok +def cp(from, to) + import path + if to == nil to = from end # to is optional + if !path.exists(to) + try + # tasmota.log("f_in="+tasmota.wd + from) + var f_in = open(tasmota.wd + from) + var f_content = f_in.readbytes() + f_in.close() + var f_out = open(to, "w") + f_out.write(f_content) + f_out.close() + except .. as e,m + tasmota.log("OTA: Couldn't copy "+to+" "+e+" "+m,2) + return false + end + return true + end + return true +end + +# make some room if there are some leftovers from shelly +import path +path.remove("index.html.gz") + +# copy some files from autoconf to filesystem +var ok +ok = cp("bootloader-tasmota-c3.bin") +ok = cp("Partition_Wizard.tapp") + +# use an alternative to partition_core that can read Shelly's otadata +tasmota.log("OTA: loading "+tasmota.wd + "partition_core_shelly.be", 2) +load(tasmota.wd + "partition_core_shelly.be") + +# load bootloader flasher +tasmota.log("OTA: loading "+tasmota.wd + "bootloader.be", 2) +load(tasmota.wd + "bootloader.be") + + +# all good +if ok + # do some basic check that the bootloader is not already in place + import flash + if flash.read(0x1000, 4) == bytes('CD3F6395') + tasmota.log("OTA: bootloader already in place, not flashing it") + else + ok = global.bootloader().flash("bootloader-tasmota-c3.bin") + end + if ok + var p = global.partition_core_shelly.Partition() + p.save() # save with otadata compatible with new bootloader + tasmota.log("OTA: Shelly migration successful", 2) + end +end + +# dump logs to file +var lr = tasmota_log_reader() +var f_logs = open("migration_logs.txt", "w") +var logs = lr.get_log(2) +while logs != nil + f_logs.write(logs) + logs = lr.get_log(2) +end +f_logs.close() + +# Done diff --git a/raw/esp32c3/Shelly_Mini1G3/partition_core_shelly.be b/raw/esp32c3/Shelly_Mini1G3/partition_core_shelly.be new file mode 100644 index 00000000..80c809aa --- /dev/null +++ b/raw/esp32c3/Shelly_Mini1G3/partition_core_shelly.be @@ -0,0 +1,645 @@ +####################################################################### +# Partition manager for ESP32 - ESP32C3 - ESP32S2 +# +# use : `import partition_core_shelly` +# +# Provides low-level objects and a Web UI +####################################################################### + +var partition_core_shelly = module('partition_core_shelly') + +####################################################################### +# Class for a partition table entry +# +# typedef struct { +# uint16_t magic; +# uint8_t type; +# uint8_t subtype; +# uint32_t offset; +# uint32_t size; +# uint8_t label[16]; +# uint32_t flags; +# } esp_partition_info_t_simplified; +# +####################################################################### +class Partition_info + var type + var subtype + var start + var sz + var label + var flags + + #- remove trailing NULL chars from a bytes buffer before converting to string -# + #- Berry strings can contain NULL, but this messes up C-Berry interface -# + static def remove_trailing_zeroes(b) + var sz = size(b) + var i = 0 + while i < sz + if b[-1-i] != 0 break end + i += 1 + end + if i > 0 + b.resize(size(b)-i) + end + return b + end + + # Init the Parition information structure, either from a bytes() buffer or an empty if no buffer is provided + def init(raw) + self.type = 0 + self.subtype = 0 + self.start = 0 + self.sz = 0 + self.label = '' + self.flags = 0 + + if !issubclass(bytes, raw) # no payload, empty partition information + return + end + + #- we have a payload, parse it -# + var magic = raw.get(0,2) + if magic == 0x50AA #- partition entry -# + + self.type = raw.get(2,1) + self.subtype = raw.get(3,1) + self.start = raw.get(4,4) + self.sz = raw.get(8,4) + self.label = self.remove_trailing_zeroes(raw[12..27]).asstring() + self.flags = raw.get(28,4) + + # elif magic == 0xEBEB #- MD5 -# + else + import string + raise "internal_error", string.format("invalid magic number %02X", magic) + end + + end + + # check if the parition is an OTA partition + # if yes, return OTA number (starting at 0) + # if no, return nil + def is_ota() + var sub_type = self.subtype + if self.type == 0 && (sub_type >= 0x10 && sub_type < 0x20) + return sub_type - 0x10 + end + end + + # check if factory 'safeboot' partition + def is_factory() + return self.type == 0 && self.subtype == 0 + 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() + import flash + if self.is_ota() == nil && !self.is_factory() return -1 end + try + var addr = self.start + var sz = self.sz + var magic_byte = flash.read(addr, 1).get(0, 1) + if magic_byte != 0xE9 return -1 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_num = 0 + while seg_num < seg_count + # 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 sz=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) + if seg_offset >= (addr + sz) return -1 end + + seg_num += 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 + except .. as e, m + tasmota.log("BRY: Exception> '" + e + "' - " + m, 2) + return -1 + end + end + + def type_to_string() + if self.type == 0 return "app" + elif self.type == 1 return "data" + end + import string + return string.format("0x%02X", self.type) + 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 + import string + return string.format("0x%02X", self.subtype) + 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 = self.type_to_string() + var subtype_s = self.subtype_to_string() + + # reformat strings + if type_s != "" type_s = " (" + type_s + ")" end + if subtype_s != "" subtype_s = " (" + subtype_s + ")" end + return string.format("", + self.type, type_s, + self.subtype, subtype_s, + self.start, self.sz, + self.label, self.flags) + end + + def tobytes() + #- convert to raw bytes -# + var b = bytes('AA50') #- set magic number -# + b.resize(32).resize(2) #- pre-reserve 32 bytes -# + b.add(self.type, 1) + b.add(self.subtype, 1) + b.add(self.start, 4) + b.add(self.sz, 4) + var label = bytes().fromstring(self.label) + label.resize(16) + b = b + label + b.add(self.flags, 4) + return b + end + +end +partition_core_shelly.Partition_info = Partition_info + +#------------------------------------------------------------- + - OTA Data + - + - Selection of the active OTA partition + - + typedef struct { + uint32_t ota_seq; + uint8_t seq_label[20]; + uint32_t ota_state; + uint32_t crc; /* CRC32 of ota_seq field only */ + } esp_ota_select_entry_t; + + - Excerp from esp_ota_ops.c + esp32_idf use two sector for store information about which partition is running + it defined the two sector as ota data partition,two structure esp_ota_select_entry_t is saved in the two sector + named data in first sector as otadata[0], second sector data as otadata[1] + e.g. + if otadata[0].ota_seq == otadata[1].ota_seq == 0xFFFFFFFF,means ota info partition is in init status + so it will boot factory application(if there is),if there's no factory application,it will boot ota[0] application + if otadata[0].ota_seq != 0 and otadata[1].ota_seq != 0,it will choose a max seq ,and get value of max_seq%max_ota_app_number + and boot a subtype (mask 0x0F) value is (max_seq - 1)%max_ota_app_number,so if want switch to run ota[x],can use next formulas. + for example, if otadata[0].ota_seq = 4, otadata[1].ota_seq = 5, and there are 8 ota application, + current running is (5-1)%8 = 4,running ota[4],so if we want to switch to run ota[7], + we should add otadata[0].ota_seq (is 4) to 4 ,(8-1)%8=7,then it will boot ota[7] + if A=(B - C)%D + then B=(A + C)%D + D*n ,n= (0,1,2...) + so current ota app sub type id is x , dest bin subtype is y,total ota app count is n + 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 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) + import crc + return crc.crc32(0xFFFFFFFF, bytes().add(seq, 4)) + end + + #---------------------------------------------------------------------# + # Rest of the class + #---------------------------------------------------------------------# + 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 = -1 + self.load() + end + + #- update ota_max, needs to recompute everything -# + def set_ota_max(n) + self.maxota = n + end + + # change the active OTA partition + def set_active(n) + var seq_max = 0 #- current highest seq number -# + var block_act = 0 #- block number containing the highest seq number -# + + if self.seq0 != nil + seq_max = self.seq0 + block_act = 0 + end + if self.seq1 != nil && self.seq1 > seq_max + seq_max = self.seq1 + block_act = 1 + end + + #- compute the next sequence number -# + var actual_ota = (seq_max - 1) % (self.maxota + 1) + if actual_ota != n #- change only if different -# + if n > actual_ota seq_max += n - actual_ota + else seq_max += (self.maxota + 1) - actual_ota + n + end + + #- update internal structure -# + if block_act == 1 #- current block is 1, so update block 0 -# + self.seq0 = seq_max + else #- or write to block 1 -# + self.seq1 = seq_max + end + self._validate() + end + end + + #- load otadata from SPI Flash -# + def load() + import flash + 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? -# + # var valid1 = otadata1.get(28, 4) == self.crc32_ota_seq(self.seq1) #- is CRC32 valid? -# + # if !valid0 self.seq0 = nil end + # if !valid1 self.seq1 = nil end + + self._validate() + end + + #- internally used, validate data -# + def _validate() + 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 + if self.seq1 != nil && (self.seq0 == nil || self.seq1 > self.seq0) + self.active_otadata = (self.seq1 - 1) % (self.maxota + 1) + end + end + + # Save partition information to SPI Flash + def save() + import flash + #- check the block number to save, 0 or 1. Choose the highest ota_seq -# + var block_to_save = -1 #- invalid -# + var seq_to_save = -1 #- invalid value -# + + # check seq0 + if self.seq0 != nil + seq_to_save = self.seq0 + block_to_save = 0 + end + if (self.seq1 != nil) && (self.seq1 > seq_to_save) + seq_to_save = self.seq1 + block_to_save = 1 + end + # if none was good + if block_to_save < 0 block_to_save = 0 end + if seq_to_save < 0 seq_to_save = 1 end + + var offset_to_save = self.offset + 0x1000 * block_to_save #- default 0xE000 or 0xF000 -# + + var bytes_to_save = bytes() + bytes_to_save.add(seq_to_save, 4) + bytes_to_save += bytes("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") + bytes_to_save.add(self.crc32_ota_seq(seq_to_save), 4) + + #- erase flash area and write -# + flash.erase(offset_to_save, 0x1000) + flash.write(offset_to_save, bytes_to_save) + end + + # Produce a human-readable representation of the object with relevant information + def tostring() + import string + return string.format("", + self.active_otadata >= 0 ? "ota_" + str(self.active_otadata) : "factory", + self.seq0, self.seq1, self.maxota) + end +end +partition_core_shelly.Partition_otadata = Partition_otadata + +#------------------------------------------------------------- + - Class for a partition table entry + -------------------------------------------------------------# +class Partition + var raw #- raw bytes of the partition table in flash -# + var md5 #- md5 hash of partition list -# + var slots + var otadata #- instance of Partition_otadata() -# + + def init() + self.slots = [] + self.load() + self.parse() + self.load_otadata() + end + + # Load partition information from SPI Flash + def load() + import flash + self.raw = flash.read(0x8000,0x1000) + end + + #- parse the raw bytes to a structured list of partition items -# + def parse() + for i:0..94 # there are maximum 95 slots + md5 (0xC00) + var item_raw = self.raw[i*32..(i+1)*32-1] + var magic = item_raw.get(0,2) + if magic == 0x50AA #- partition entry -# + var slot = partition_core_shelly.Partition_info(item_raw) + self.slots.push(slot) + elif magic == 0xEBEB #- MD5 -# + self.md5 = self.raw[i*32+16..i*33-1] + break + else + break + end + end + end + + def get_ota_slot(n) + for slot: self.slots + if slot.is_ota() == n return slot end + end + return nil + end + + def get_factory_slot() + for slot: self.slots + if slot.is_factory() return slot end + end + end + + def has_factory() + return self.get_factory_slot() != nil + end + + #- compute the highest ota partition -# + def ota_max() + var ota_max = nil + for slot:self.slots + if slot.type == 0 && (slot.subtype >= 0x10 && slot.subtype < 0x20) + var ota_num = slot.subtype - 0x10 + if (ota_max == nil) || (ota_num > ota_max) ota_max = ota_num end + end + end + return ota_max + end + + # get the active OTA app partition number + def get_active() + return self.otadata.active_otadata + end + + def load_otadata() + #- look for otadata partition offset, and max_ota -# + var otadata_offset = 0xE000 #- default value -# + var ota_max = self.ota_max() + for slot:self.slots + if slot.type == 1 && slot.subtype == 0 #- otadata -# + otadata_offset = slot.start + end + end + + self.otadata = partition_core_shelly.Partition_otadata(ota_max, self.has_factory(), otadata_offset) + end + + #- change the active partition -# + def set_active(n) + if n < 0 || n > self.ota_max() raise "value_error", "Invalid ota partition number" end + self.otadata.set_ota_max(self.ota_max()) #- update ota_max if it changed -# + self.otadata.set_active(n) + 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 + #- convert to human readble -# + def tostring() + var ret = " 95 raise "value_error", "Too many partiition slots" end + var b = bytes() + for slot: self.slots + b += slot.tobytes() + end + #- compute MD5 -# + var md5 = MD5() + md5.update(b) + #- add the last segment -# + b += bytes("EBEBFFFFFFFFFFFFFFFFFFFFFFFFFFFF") + b += md5.finish() + #- complete -# + return b + end + + #- write back to flash -# + def save() + import flash + var b = self.tobytes() + #- erase flash area and write -# + flash.erase(0x8000, 0x1000) + flash.write(0x8000, b) + self.otadata.save() + end + + # Internal: returns which flash sector contains the partition definition + # Returns 0 or 1, or `nil` if something went wrong + # Note: partition flash sector vary from ESP32 to ESP32C3/S3 + static def get_flash_definition_sector() + import flash + for i:0..1 + var offset = i * 0x1000 + if flash.read(offset, 1) == bytes('E9') return offset end + end + end + + # Internal: returns the maximum flash size possible + # Returns max flash size ok kB + def get_max_flash_size_k() + var flash_size_k = tasmota.memory()['flash'] + var flash_size_real_k = tasmota.memory().find("flash_real", flash_size_k) + if (flash_size_k != flash_size_real_k) && self.get_flash_definition_sector() != nil + flash_size_k = flash_size_real_k # try to expand the flash size definition + end + return flash_size_k + end + + # Internal: returns the unallocated flash size (in kB) beyond the file-system + # this indicates that the file-system can be extended (although erased at the same time) + def get_unallocated_k() + var last_slot = self.slots[-1] + if last_slot.is_spiffs() + # verify that last slot is filesystem + var flash_size_k = self.get_max_flash_size_k() + var partition_end_k = (last_slot.start + last_slot.sz) / 1024 # last kb used for fs + if partition_end_k < flash_size_k + return flash_size_k - partition_end_k + end + end + return 0 + end + + #- ---------------------------------------------------------------------- -# + #- Resize flash definition if needed + #- ---------------------------------------------------------------------- -# + def resize_max_flash_size_k() + 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() + 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 + + var flash_def = flash.read(flash_definition_sector, 4) + var size_before = flash_def[3] + + var flash_size_code + var flash_size_real_m = flash_size_real_k / 1024 # size in MB + if flash_size_real_m == 1 flash_size_code = 0x00 + elif flash_size_real_m == 2 flash_size_code = 0x10 + elif flash_size_real_m == 4 flash_size_code = 0x20 + elif flash_size_real_m == 8 flash_size_code = 0x30 + elif flash_size_real_m == 16 flash_size_code = 0x40 + elif flash_size_real_m == 32 flash_size_code = 0x50 + elif flash_size_real_m == 64 flash_size_code = 0x60 + elif flash_size_real_m == 128 flash_size_code = 0x70 + end + + if flash_size_code != nil + # apply the update + 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(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 + end + end + + # Called at first boot + # Try to expand FS to max of flash size + def resize_fs_to_max() + import string + try + var unallocated = self.get_unallocated_k() + if unallocated <= 0 return nil end + + tasmota.log(string.format("BRY: Trying to expand FS by %i kB", unallocated), 2) + + self.resize_max_flash_size_k() # resize if needed + # since unallocated succeeded, we know the last slot is FS + var fs_slot = self.slots[-1] + fs_slot.sz += unallocated * 1024 + self.save() + self.invalidate_spiffs() # erase SPIFFS or data is corrupt + + # restart + tasmota.global.restart_flag = 2 + tasmota.log("BRY: Successfully resized FS, restarting", 2) + except .. as e, m + tasmota.log(string.format("BRY: Exception> '%s' - %s", e, m), 2) + end + 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() + import flash + #- 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 + + # switch to safeboot `factory` partition + def switch_factory(force_ota) + import flash + flash.factory(force_ota) + end +end +partition_core_shelly.Partition = Partition + +# init method to force the global `partition_core_shelly` is defined even if the import is done within a function +def init(m) + import global + global.partition_core_shelly = m + return m +end +partition_core_shelly.init = init + +return partition_core_shelly + +#- Example + +import partition_core_shelly + +# read +p = partition_core_shelly.Partition() +print(p) + +-# diff --git a/raw/esp32c3/Shelly_Mini1PMG3/Partition_Wizard.tapp b/raw/esp32c3/Shelly_Mini1PMG3/Partition_Wizard.tapp new file mode 100644 index 0000000000000000000000000000000000000000..98bfc21b98ba0a2f175f3df902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@8Q3zBODfzJy2Tm1g| HW4ii39kNrx literal 0 HcmV?d00001 diff --git a/raw/esp32c3/Shelly_Mini1PMG3/bootloader-tasmota-c3.bin b/raw/esp32c3/Shelly_Mini1PMG3/bootloader-tasmota-c3.bin new file mode 100644 index 0000000000000000000000000000000000000000..b5911365bddd5e5b1ab8e59d7a2e90df1a02abba GIT binary patch literal 10576 zcmZ8H4OmlGvganbxe0n5h9I<^k+A9Eg-LJEwox}Ok2B>W?v4?hXnQ)iPO^MgL$rss2C-#TZmV*93i1-t3x zmvdfFY}%?=lcJcvWA^-qcZ7uiUCO4H*@BlhZH2x+Zp!~7GVFLQhy4{o2(O_NBji$M zzhI{j%FDBMR>8PI_&+fxy2UlW4`KX0tV^-)FSHnim<$q0m9Et{XzX)JB!GQBuNS}1 zzhbA(kE=WSg`T^FVXmS9=v<1|-f$^(&j#ofdvX=d=Uht12A2Y@voh?BS^>w%nTj+b z&19fSnYd~Vo>vj`5koL#X`~a zA55XQP@;n%1HFCpmrJeuU}$z2GuB$6yseJqauwNWq+$G%FlJ_Izjbg-&gfJ7xxq1M z>RR5VL@9dtXsSfeYfEaY-U59Ys>s{O zHUHR>FsnT(flwN>)D2%@)XuVvW$HH9{MU3O;Ai{scLCpE2=uI-g?CEjphSgPW1V^e zI9oQkcHicYnEq(b*m$!`=}hF5xeCV;mr{|)Q=r$wln*pcN}Rb0-6PPi)n=Ye=C_

!p4Nd0$OZLGNozA!-4>ZiYw~k3b1=jr+XDY-2{HVhBzjvjUOfa>&-z) z9j^I~LX%+*==;0?KXq?l%{k|~l)5`LdcN`LS`2Xd}@ykinQQJC4WOg8kF; zWgSa?u37vDFBVPD-}lWD*r8)T*J`meI&W0|zQHB=aoR`n_l+(A%s$+M_0&i2%!}{P z!j76_DT$eBLE1E@uQ2j<`9CRj+eMp7F)CTK!OVP#W}4`&o@A|9FrhTy{toJ*Ez`90 zJG#IV4tu{+X(%wc=C8@%2T}G|3UGn!#bS4+ZLAfb4zJG}Szt4#n$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ndkaX9mxc?u$=X7H+4h(PaEY&w~<@$SEydwr(f_<$7FamSaAyW zuKh8K#y|5{3e2^gQ?wpmcms9QrhOlB4w8JJzUtRsut1GT!`12nK45GEFLwGXyJO$s zwsF_9WI-9cjksR1zU+n{i{r!?t~J1VO&i|bypY`ZcGGu|A(RdHBMSIlfc$40sQf=e op?_HWXkPc3sFN|mr (0x8000 - addr) raise "internal_error", "bootloader is too large "+str(bl_size / 1024)+"kB" end + + cl.write_file("bootloader.bin") + cl.close() + end + + # returns true if ok + def flash(url) + var fname = "bootloader.bin" # default local name + if url != nil + if url[0..3] == "http" # if starts with 'http' download + self.download(url) + else + fname = url # else get from file system + end + end + # address to flash the bootloader + var addr = self.get_bootloader_address() + if addr == nil tasmota.log("OTA: can't find address for bootloader", 2) return false end + + var bl = open(fname, "r") + if bl.readbytes(size(self._sign)) != self._sign + tasmota.log("OTA: file does not contain a bootloader signature", 2) + return false + end + bl.seek(0) # reset to start of file + + var bl_size = bl.size() + if bl_size <= 8291 tasmota.log("OTA: wrong bootloader size "+str(bl_size), 2) return false end + if bl_size > (0x8000 - addr) tasmota.log("OTA: bootloader is too large "+str(bl_size / 1024)+"kB", 2) return false end + + tasmota.log("OTA: Flashing bootloader", 2) + # from now on there is no turning back, any failure means a bricked device + import flash + # read current value for bytes 2/3 + var cur_config = flash.read(addr, 4) + + flash.erase(addr, self._addr_high - addr) # erase the bootloader + var buf = bl.readbytes(0x1000) # read by chunks of 4kb + # put back signature + buf[2] = cur_config[2] + buf[3] = cur_config[3] + while size(buf) > 0 + flash.write(addr, buf, true) # set flag to no-erase since we already erased it + addr += size(buf) + buf = bl.readbytes(0x1000) # read next chunk + end + bl.close() + tasmota.log("OTA: Booloader flashed, please restart", 2) + return true + end +end + +return bootloader + +#- + +### FLASH +import bootloader +bootloader().flash('https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/sdk/esp32/bin/bootloader_dio_40m.bin') + +#bootloader().flash('https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/sdk/esp32/bin/bootloader_dout_40m.bin') + +### FLASH from local file +bootloader().flash("bootloader-tasmota-c3.bin") + +#### debug only +bl = bootloader() +print(format("0x%04X", bl.get_bootloader_address())) + +-# \ No newline at end of file diff --git a/raw/esp32c3/Shelly_Mini1PMG3/init.bat b/raw/esp32c3/Shelly_Mini1PMG3/init.bat new file mode 100644 index 00000000..bdf323f4 --- /dev/null +++ b/raw/esp32c3/Shelly_Mini1PMG3/init.bat @@ -0,0 +1,4 @@ +Br load("Shelly_Plus1PMMini.autoconf#migrate_shelly.be") +Template {"NAME":"Shelly Plus1PMMini","GPIO":[576,32,0,4736,0,224,3200,8161,0,0,192,0,0,0,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":1} +Module 0 +AdcParam1 2,5600,4700,3350 diff --git a/raw/esp32c3/Shelly_Mini1PMG3/migrate_shelly.be b/raw/esp32c3/Shelly_Mini1PMG3/migrate_shelly.be new file mode 100644 index 00000000..b09c9149 --- /dev/null +++ b/raw/esp32c3/Shelly_Mini1PMG3/migrate_shelly.be @@ -0,0 +1,70 @@ +# migration script for Shelly + +# simple function to copy from autoconfig archive to filesystem +# return true if ok +def cp(from, to) + import path + if to == nil to = from end # to is optional + if !path.exists(to) + try + # tasmota.log("f_in="+tasmota.wd + from) + var f_in = open(tasmota.wd + from) + var f_content = f_in.readbytes() + f_in.close() + var f_out = open(to, "w") + f_out.write(f_content) + f_out.close() + except .. as e,m + tasmota.log("OTA: Couldn't copy "+to+" "+e+" "+m,2) + return false + end + return true + end + return true +end + +# make some room if there are some leftovers from shelly +import path +path.remove("index.html.gz") + +# copy some files from autoconf to filesystem +var ok +ok = cp("bootloader-tasmota-c3.bin") +ok = cp("Partition_Wizard.tapp") + +# use an alternative to partition_core that can read Shelly's otadata +tasmota.log("OTA: loading "+tasmota.wd + "partition_core_shelly.be", 2) +load(tasmota.wd + "partition_core_shelly.be") + +# load bootloader flasher +tasmota.log("OTA: loading "+tasmota.wd + "bootloader.be", 2) +load(tasmota.wd + "bootloader.be") + + +# all good +if ok + # do some basic check that the bootloader is not already in place + import flash + if flash.read(0x1000, 4) == bytes('CD3F6395') + tasmota.log("OTA: bootloader already in place, not flashing it") + else + ok = global.bootloader().flash("bootloader-tasmota-c3.bin") + end + if ok + var p = global.partition_core_shelly.Partition() + p.save() # save with otadata compatible with new bootloader + tasmota.log("OTA: Shelly migration successful", 2) + end +end + +# dump logs to file +var lr = tasmota_log_reader() +var f_logs = open("migration_logs.txt", "w") +var logs = lr.get_log(2) +while logs != nil + f_logs.write(logs) + logs = lr.get_log(2) +end +f_logs.close() + +# Done diff --git a/raw/esp32c3/Shelly_Mini1PMG3/partition_core_shelly.be b/raw/esp32c3/Shelly_Mini1PMG3/partition_core_shelly.be new file mode 100644 index 00000000..80c809aa --- /dev/null +++ b/raw/esp32c3/Shelly_Mini1PMG3/partition_core_shelly.be @@ -0,0 +1,645 @@ +####################################################################### +# Partition manager for ESP32 - ESP32C3 - ESP32S2 +# +# use : `import partition_core_shelly` +# +# Provides low-level objects and a Web UI +####################################################################### + +var partition_core_shelly = module('partition_core_shelly') + +####################################################################### +# Class for a partition table entry +# +# typedef struct { +# uint16_t magic; +# uint8_t type; +# uint8_t subtype; +# uint32_t offset; +# uint32_t size; +# uint8_t label[16]; +# uint32_t flags; +# } esp_partition_info_t_simplified; +# +####################################################################### +class Partition_info + var type + var subtype + var start + var sz + var label + var flags + + #- remove trailing NULL chars from a bytes buffer before converting to string -# + #- Berry strings can contain NULL, but this messes up C-Berry interface -# + static def remove_trailing_zeroes(b) + var sz = size(b) + var i = 0 + while i < sz + if b[-1-i] != 0 break end + i += 1 + end + if i > 0 + b.resize(size(b)-i) + end + return b + end + + # Init the Parition information structure, either from a bytes() buffer or an empty if no buffer is provided + def init(raw) + self.type = 0 + self.subtype = 0 + self.start = 0 + self.sz = 0 + self.label = '' + self.flags = 0 + + if !issubclass(bytes, raw) # no payload, empty partition information + return + end + + #- we have a payload, parse it -# + var magic = raw.get(0,2) + if magic == 0x50AA #- partition entry -# + + self.type = raw.get(2,1) + self.subtype = raw.get(3,1) + self.start = raw.get(4,4) + self.sz = raw.get(8,4) + self.label = self.remove_trailing_zeroes(raw[12..27]).asstring() + self.flags = raw.get(28,4) + + # elif magic == 0xEBEB #- MD5 -# + else + import string + raise "internal_error", string.format("invalid magic number %02X", magic) + end + + end + + # check if the parition is an OTA partition + # if yes, return OTA number (starting at 0) + # if no, return nil + def is_ota() + var sub_type = self.subtype + if self.type == 0 && (sub_type >= 0x10 && sub_type < 0x20) + return sub_type - 0x10 + end + end + + # check if factory 'safeboot' partition + def is_factory() + return self.type == 0 && self.subtype == 0 + 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() + import flash + if self.is_ota() == nil && !self.is_factory() return -1 end + try + var addr = self.start + var sz = self.sz + var magic_byte = flash.read(addr, 1).get(0, 1) + if magic_byte != 0xE9 return -1 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_num = 0 + while seg_num < seg_count + # 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 sz=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) + if seg_offset >= (addr + sz) return -1 end + + seg_num += 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 + except .. as e, m + tasmota.log("BRY: Exception> '" + e + "' - " + m, 2) + return -1 + end + end + + def type_to_string() + if self.type == 0 return "app" + elif self.type == 1 return "data" + end + import string + return string.format("0x%02X", self.type) + 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 + import string + return string.format("0x%02X", self.subtype) + 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 = self.type_to_string() + var subtype_s = self.subtype_to_string() + + # reformat strings + if type_s != "" type_s = " (" + type_s + ")" end + if subtype_s != "" subtype_s = " (" + subtype_s + ")" end + return string.format("", + self.type, type_s, + self.subtype, subtype_s, + self.start, self.sz, + self.label, self.flags) + end + + def tobytes() + #- convert to raw bytes -# + var b = bytes('AA50') #- set magic number -# + b.resize(32).resize(2) #- pre-reserve 32 bytes -# + b.add(self.type, 1) + b.add(self.subtype, 1) + b.add(self.start, 4) + b.add(self.sz, 4) + var label = bytes().fromstring(self.label) + label.resize(16) + b = b + label + b.add(self.flags, 4) + return b + end + +end +partition_core_shelly.Partition_info = Partition_info + +#------------------------------------------------------------- + - OTA Data + - + - Selection of the active OTA partition + - + typedef struct { + uint32_t ota_seq; + uint8_t seq_label[20]; + uint32_t ota_state; + uint32_t crc; /* CRC32 of ota_seq field only */ + } esp_ota_select_entry_t; + + - Excerp from esp_ota_ops.c + esp32_idf use two sector for store information about which partition is running + it defined the two sector as ota data partition,two structure esp_ota_select_entry_t is saved in the two sector + named data in first sector as otadata[0], second sector data as otadata[1] + e.g. + if otadata[0].ota_seq == otadata[1].ota_seq == 0xFFFFFFFF,means ota info partition is in init status + so it will boot factory application(if there is),if there's no factory application,it will boot ota[0] application + if otadata[0].ota_seq != 0 and otadata[1].ota_seq != 0,it will choose a max seq ,and get value of max_seq%max_ota_app_number + and boot a subtype (mask 0x0F) value is (max_seq - 1)%max_ota_app_number,so if want switch to run ota[x],can use next formulas. + for example, if otadata[0].ota_seq = 4, otadata[1].ota_seq = 5, and there are 8 ota application, + current running is (5-1)%8 = 4,running ota[4],so if we want to switch to run ota[7], + we should add otadata[0].ota_seq (is 4) to 4 ,(8-1)%8=7,then it will boot ota[7] + if A=(B - C)%D + then B=(A + C)%D + D*n ,n= (0,1,2...) + so current ota app sub type id is x , dest bin subtype is y,total ota app count is n + 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 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) + import crc + return crc.crc32(0xFFFFFFFF, bytes().add(seq, 4)) + end + + #---------------------------------------------------------------------# + # Rest of the class + #---------------------------------------------------------------------# + 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 = -1 + self.load() + end + + #- update ota_max, needs to recompute everything -# + def set_ota_max(n) + self.maxota = n + end + + # change the active OTA partition + def set_active(n) + var seq_max = 0 #- current highest seq number -# + var block_act = 0 #- block number containing the highest seq number -# + + if self.seq0 != nil + seq_max = self.seq0 + block_act = 0 + end + if self.seq1 != nil && self.seq1 > seq_max + seq_max = self.seq1 + block_act = 1 + end + + #- compute the next sequence number -# + var actual_ota = (seq_max - 1) % (self.maxota + 1) + if actual_ota != n #- change only if different -# + if n > actual_ota seq_max += n - actual_ota + else seq_max += (self.maxota + 1) - actual_ota + n + end + + #- update internal structure -# + if block_act == 1 #- current block is 1, so update block 0 -# + self.seq0 = seq_max + else #- or write to block 1 -# + self.seq1 = seq_max + end + self._validate() + end + end + + #- load otadata from SPI Flash -# + def load() + import flash + 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? -# + # var valid1 = otadata1.get(28, 4) == self.crc32_ota_seq(self.seq1) #- is CRC32 valid? -# + # if !valid0 self.seq0 = nil end + # if !valid1 self.seq1 = nil end + + self._validate() + end + + #- internally used, validate data -# + def _validate() + 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 + if self.seq1 != nil && (self.seq0 == nil || self.seq1 > self.seq0) + self.active_otadata = (self.seq1 - 1) % (self.maxota + 1) + end + end + + # Save partition information to SPI Flash + def save() + import flash + #- check the block number to save, 0 or 1. Choose the highest ota_seq -# + var block_to_save = -1 #- invalid -# + var seq_to_save = -1 #- invalid value -# + + # check seq0 + if self.seq0 != nil + seq_to_save = self.seq0 + block_to_save = 0 + end + if (self.seq1 != nil) && (self.seq1 > seq_to_save) + seq_to_save = self.seq1 + block_to_save = 1 + end + # if none was good + if block_to_save < 0 block_to_save = 0 end + if seq_to_save < 0 seq_to_save = 1 end + + var offset_to_save = self.offset + 0x1000 * block_to_save #- default 0xE000 or 0xF000 -# + + var bytes_to_save = bytes() + bytes_to_save.add(seq_to_save, 4) + bytes_to_save += bytes("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") + bytes_to_save.add(self.crc32_ota_seq(seq_to_save), 4) + + #- erase flash area and write -# + flash.erase(offset_to_save, 0x1000) + flash.write(offset_to_save, bytes_to_save) + end + + # Produce a human-readable representation of the object with relevant information + def tostring() + import string + return string.format("", + self.active_otadata >= 0 ? "ota_" + str(self.active_otadata) : "factory", + self.seq0, self.seq1, self.maxota) + end +end +partition_core_shelly.Partition_otadata = Partition_otadata + +#------------------------------------------------------------- + - Class for a partition table entry + -------------------------------------------------------------# +class Partition + var raw #- raw bytes of the partition table in flash -# + var md5 #- md5 hash of partition list -# + var slots + var otadata #- instance of Partition_otadata() -# + + def init() + self.slots = [] + self.load() + self.parse() + self.load_otadata() + end + + # Load partition information from SPI Flash + def load() + import flash + self.raw = flash.read(0x8000,0x1000) + end + + #- parse the raw bytes to a structured list of partition items -# + def parse() + for i:0..94 # there are maximum 95 slots + md5 (0xC00) + var item_raw = self.raw[i*32..(i+1)*32-1] + var magic = item_raw.get(0,2) + if magic == 0x50AA #- partition entry -# + var slot = partition_core_shelly.Partition_info(item_raw) + self.slots.push(slot) + elif magic == 0xEBEB #- MD5 -# + self.md5 = self.raw[i*32+16..i*33-1] + break + else + break + end + end + end + + def get_ota_slot(n) + for slot: self.slots + if slot.is_ota() == n return slot end + end + return nil + end + + def get_factory_slot() + for slot: self.slots + if slot.is_factory() return slot end + end + end + + def has_factory() + return self.get_factory_slot() != nil + end + + #- compute the highest ota partition -# + def ota_max() + var ota_max = nil + for slot:self.slots + if slot.type == 0 && (slot.subtype >= 0x10 && slot.subtype < 0x20) + var ota_num = slot.subtype - 0x10 + if (ota_max == nil) || (ota_num > ota_max) ota_max = ota_num end + end + end + return ota_max + end + + # get the active OTA app partition number + def get_active() + return self.otadata.active_otadata + end + + def load_otadata() + #- look for otadata partition offset, and max_ota -# + var otadata_offset = 0xE000 #- default value -# + var ota_max = self.ota_max() + for slot:self.slots + if slot.type == 1 && slot.subtype == 0 #- otadata -# + otadata_offset = slot.start + end + end + + self.otadata = partition_core_shelly.Partition_otadata(ota_max, self.has_factory(), otadata_offset) + end + + #- change the active partition -# + def set_active(n) + if n < 0 || n > self.ota_max() raise "value_error", "Invalid ota partition number" end + self.otadata.set_ota_max(self.ota_max()) #- update ota_max if it changed -# + self.otadata.set_active(n) + 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 + #- convert to human readble -# + def tostring() + var ret = " 95 raise "value_error", "Too many partiition slots" end + var b = bytes() + for slot: self.slots + b += slot.tobytes() + end + #- compute MD5 -# + var md5 = MD5() + md5.update(b) + #- add the last segment -# + b += bytes("EBEBFFFFFFFFFFFFFFFFFFFFFFFFFFFF") + b += md5.finish() + #- complete -# + return b + end + + #- write back to flash -# + def save() + import flash + var b = self.tobytes() + #- erase flash area and write -# + flash.erase(0x8000, 0x1000) + flash.write(0x8000, b) + self.otadata.save() + end + + # Internal: returns which flash sector contains the partition definition + # Returns 0 or 1, or `nil` if something went wrong + # Note: partition flash sector vary from ESP32 to ESP32C3/S3 + static def get_flash_definition_sector() + import flash + for i:0..1 + var offset = i * 0x1000 + if flash.read(offset, 1) == bytes('E9') return offset end + end + end + + # Internal: returns the maximum flash size possible + # Returns max flash size ok kB + def get_max_flash_size_k() + var flash_size_k = tasmota.memory()['flash'] + var flash_size_real_k = tasmota.memory().find("flash_real", flash_size_k) + if (flash_size_k != flash_size_real_k) && self.get_flash_definition_sector() != nil + flash_size_k = flash_size_real_k # try to expand the flash size definition + end + return flash_size_k + end + + # Internal: returns the unallocated flash size (in kB) beyond the file-system + # this indicates that the file-system can be extended (although erased at the same time) + def get_unallocated_k() + var last_slot = self.slots[-1] + if last_slot.is_spiffs() + # verify that last slot is filesystem + var flash_size_k = self.get_max_flash_size_k() + var partition_end_k = (last_slot.start + last_slot.sz) / 1024 # last kb used for fs + if partition_end_k < flash_size_k + return flash_size_k - partition_end_k + end + end + return 0 + end + + #- ---------------------------------------------------------------------- -# + #- Resize flash definition if needed + #- ---------------------------------------------------------------------- -# + def resize_max_flash_size_k() + 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() + 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 + + var flash_def = flash.read(flash_definition_sector, 4) + var size_before = flash_def[3] + + var flash_size_code + var flash_size_real_m = flash_size_real_k / 1024 # size in MB + if flash_size_real_m == 1 flash_size_code = 0x00 + elif flash_size_real_m == 2 flash_size_code = 0x10 + elif flash_size_real_m == 4 flash_size_code = 0x20 + elif flash_size_real_m == 8 flash_size_code = 0x30 + elif flash_size_real_m == 16 flash_size_code = 0x40 + elif flash_size_real_m == 32 flash_size_code = 0x50 + elif flash_size_real_m == 64 flash_size_code = 0x60 + elif flash_size_real_m == 128 flash_size_code = 0x70 + end + + if flash_size_code != nil + # apply the update + 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(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 + end + end + + # Called at first boot + # Try to expand FS to max of flash size + def resize_fs_to_max() + import string + try + var unallocated = self.get_unallocated_k() + if unallocated <= 0 return nil end + + tasmota.log(string.format("BRY: Trying to expand FS by %i kB", unallocated), 2) + + self.resize_max_flash_size_k() # resize if needed + # since unallocated succeeded, we know the last slot is FS + var fs_slot = self.slots[-1] + fs_slot.sz += unallocated * 1024 + self.save() + self.invalidate_spiffs() # erase SPIFFS or data is corrupt + + # restart + tasmota.global.restart_flag = 2 + tasmota.log("BRY: Successfully resized FS, restarting", 2) + except .. as e, m + tasmota.log(string.format("BRY: Exception> '%s' - %s", e, m), 2) + end + 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() + import flash + #- 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 + + # switch to safeboot `factory` partition + def switch_factory(force_ota) + import flash + flash.factory(force_ota) + end +end +partition_core_shelly.Partition = Partition + +# init method to force the global `partition_core_shelly` is defined even if the import is done within a function +def init(m) + import global + global.partition_core_shelly = m + return m +end +partition_core_shelly.init = init + +return partition_core_shelly + +#- Example + +import partition_core_shelly + +# read +p = partition_core_shelly.Partition() +print(p) + +-# diff --git a/raw/esp32c3/Shelly_MiniPMG3/Partition_Wizard.tapp b/raw/esp32c3/Shelly_MiniPMG3/Partition_Wizard.tapp new file mode 100644 index 0000000000000000000000000000000000000000..98bfc21b98ba0a2f175f3df902054f3f209d9854 GIT binary patch literal 17544 zcmb_k&u<$^b}n`|n@zGwwkTSrWm>M$P?p9kOO&jccs-Kr@z}FF8I7&=&>0V+fTGBj z#5F~7$<|oj5Lg9BusR5c4-OI_mtDZYE|5L=kN`Rax#X~?%^#3s4ncwd$t8ze*2?#) zy2&O*dW_7{Fj-w)UBBzS?|tvJ)<09V2&2yr|5|_am;dz7Ki@%`{zqAc75AOGePEa7 zw(LjwFjEg+{@2zYmG_8Rr3!yBCnpNa}2>z%&-=imI>AN=qK|2qGhJB-o)6#Cj< z9DOc{PTw?tQKtWWo&Lw)yw=cnmZmR!G`3f))KYAIKt(Lb7)O~XW1A@Xm?^BynDP$_ zV@QkNzr*jzEmhA4bmcjvPoqd1GOb7P%ajwQ=qCXM>9}$dX37Dxl$VSlPt}f@qP1B( zauN<2NLw3BGujcA(gwA4f_4wlKC`SdL$yX(clPCE6&`&$GB6i4uy^o3&9;jrr`~*4 z*sJU`i;i8etCgL~R@EMUXYk}GL4}>CYTeETf<`*PA_t5a>rB%QmChi{HB~dX|DGD? z4wf--KjXiT!HYU*rK}LEJH^6Y@c{cy%)^fD6ueQis&&VTGRmqJTgY!w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JNAbkqLH&XmFO6!O;jE}!0z7uZ(!Z(>k)S-OYA)MggP_t`7Q|pNQ zJ2#sNusQtIfb3%q32(aBV3G0}T&rv@A5FJyg#LZ*qM;&?4NNdsLEFZ;nI5GPooXEY13(cIH4X1NCGdb~Bu_%}= z13v3GSR`WJl*N18}KbdtB&2>2q(V(0%hQmf%Zlj=|P*_WU1VSVEZQLSTsv7 zFt9_4oXK!wckT%q5dH14`tB+VM2o!JHWQigaTjeQ}L*QMW5#FUT=Rz~P_d1)_# zGPl?Xpj>)6e2QMtLM=TGJ)I&Bm!XgRj4>C-HIIDOY<>Fps?1gxza}IJGtcplqUz~5+BA%?9 zGu680>B6}!y!Fss^fQnmBEq)Icvm0q@}DtV97S2_<^| ztVfWEKkL!=*D?GRp8abZ{t7|evW{blUKymn{UQGL25KJgcQ@8Q3zBODfzJy2Tm1g| HW4ii39kNrx literal 0 HcmV?d00001 diff --git a/raw/esp32c3/Shelly_MiniPMG3/bootloader-tasmota-c3.bin b/raw/esp32c3/Shelly_MiniPMG3/bootloader-tasmota-c3.bin new file mode 100644 index 0000000000000000000000000000000000000000..b5911365bddd5e5b1ab8e59d7a2e90df1a02abba GIT binary patch literal 10576 zcmZ8H4OmlGvganbxe0n5h9I<^k+A9Eg-LJEwox}Ok2B>W?v4?hXnQ)iPO^MgL$rss2C-#TZmV*93i1-t3x zmvdfFY}%?=lcJcvWA^-qcZ7uiUCO4H*@BlhZH2x+Zp!~7GVFLQhy4{o2(O_NBji$M zzhI{j%FDBMR>8PI_&+fxy2UlW4`KX0tV^-)FSHnim<$q0m9Et{XzX)JB!GQBuNS}1 zzhbA(kE=WSg`T^FVXmS9=v<1|-f$^(&j#ofdvX=d=Uht12A2Y@voh?BS^>w%nTj+b z&19fSnYd~Vo>vj`5koL#X`~a zA55XQP@;n%1HFCpmrJeuU}$z2GuB$6yseJqauwNWq+$G%FlJ_Izjbg-&gfJ7xxq1M z>RR5VL@9dtXsSfeYfEaY-U59Ys>s{O zHUHR>Fs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!2RwpkznuGiBPUX0dSbb}Sq@{`d8|>mUrwPbDMD|; zUwGN50pyJ;$YR-1TxTVX0=!4A0c^EuOG|Qtfqj7!XtFp#eTn_aC{z#Mu&xW>#zucF zFs1Ep`M%{~yR)4%MAw1VNp{Mx|9le$@XO+1gsnKYKN{+qc%ROIU1s#*^X|wX8MSq; zF>E(0y(W;iSs6BTSOor{{BXuc$@bylWKPtWRVh#@tVpFif>g7rp)xa$a{FvQ9Aw^M z!b+`XuC#KHCegI$LA-KBDsHzlL!LTg^bYJfc$u=)7XCekOPy)Rfv*eb_XR&ES*mdl ziJ?p$f1zzLKT2*a<3TT~4{E_zE-?KDdlX|`SG&K)^{Dt@HlgdmQZ!{W82rEH2zo29 z^jY{qtN#$9LUL9N^qWC5BqgoBJUboTP87~Q z1C-Al>1~!W{ndkaX9mxc?u$=X7H+4h(PaEY&w~<@$SEydwr(f_<$7FamSaAyW zuKh8K#y|5{3e2^gQ?wpmcms9QrhOlB4w8JJzUtRsut1GT!`12nK45GEFLwGXyJO$s zwsF_9WI-9cjksR1zU+n{i{r!?t~J1VO&i|bypY`ZcGGu|A(RdHBMSIlfc$40sQf=e op?_HWXkPc3sFN|mr (0x8000 - addr) raise "internal_error", "bootloader is too large "+str(bl_size / 1024)+"kB" end + + cl.write_file("bootloader.bin") + cl.close() + end + + # returns true if ok + def flash(url) + var fname = "bootloader.bin" # default local name + if url != nil + if url[0..3] == "http" # if starts with 'http' download + self.download(url) + else + fname = url # else get from file system + end + end + # address to flash the bootloader + var addr = self.get_bootloader_address() + if addr == nil tasmota.log("OTA: can't find address for bootloader", 2) return false end + + var bl = open(fname, "r") + if bl.readbytes(size(self._sign)) != self._sign + tasmota.log("OTA: file does not contain a bootloader signature", 2) + return false + end + bl.seek(0) # reset to start of file + + var bl_size = bl.size() + if bl_size <= 8291 tasmota.log("OTA: wrong bootloader size "+str(bl_size), 2) return false end + if bl_size > (0x8000 - addr) tasmota.log("OTA: bootloader is too large "+str(bl_size / 1024)+"kB", 2) return false end + + tasmota.log("OTA: Flashing bootloader", 2) + # from now on there is no turning back, any failure means a bricked device + import flash + # read current value for bytes 2/3 + var cur_config = flash.read(addr, 4) + + flash.erase(addr, self._addr_high - addr) # erase the bootloader + var buf = bl.readbytes(0x1000) # read by chunks of 4kb + # put back signature + buf[2] = cur_config[2] + buf[3] = cur_config[3] + while size(buf) > 0 + flash.write(addr, buf, true) # set flag to no-erase since we already erased it + addr += size(buf) + buf = bl.readbytes(0x1000) # read next chunk + end + bl.close() + tasmota.log("OTA: Booloader flashed, please restart", 2) + return true + end +end + +return bootloader + +#- + +### FLASH +import bootloader +bootloader().flash('https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/sdk/esp32/bin/bootloader_dio_40m.bin') + +#bootloader().flash('https://raw.githubusercontent.com/espressif/arduino-esp32/master/tools/sdk/esp32/bin/bootloader_dout_40m.bin') + +### FLASH from local file +bootloader().flash("bootloader-tasmota-c3.bin") + +#### debug only +bl = bootloader() +print(format("0x%04X", bl.get_bootloader_address())) + +-# \ No newline at end of file diff --git a/raw/esp32c3/Shelly_MiniPMG3/init.bat b/raw/esp32c3/Shelly_MiniPMG3/init.bat new file mode 100644 index 00000000..d13e597e --- /dev/null +++ b/raw/esp32c3/Shelly_MiniPMG3/init.bat @@ -0,0 +1,5 @@ +Br load("Shelly_PlusPMMini.autoconf#migrate_shelly.be") +Template {"NAME":"Shelly PlusPMMini","GPIO":[576,32,0,4736,0,0,3200,8161,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":1} +Module 0 +AdcParam1 2,5600,4700,3350 +so21 1 diff --git a/raw/esp32c3/Shelly_MiniPMG3/migrate_shelly.be b/raw/esp32c3/Shelly_MiniPMG3/migrate_shelly.be new file mode 100644 index 00000000..b09c9149 --- /dev/null +++ b/raw/esp32c3/Shelly_MiniPMG3/migrate_shelly.be @@ -0,0 +1,70 @@ +# migration script for Shelly + +# simple function to copy from autoconfig archive to filesystem +# return true if ok +def cp(from, to) + import path + if to == nil to = from end # to is optional + if !path.exists(to) + try + # tasmota.log("f_in="+tasmota.wd + from) + var f_in = open(tasmota.wd + from) + var f_content = f_in.readbytes() + f_in.close() + var f_out = open(to, "w") + f_out.write(f_content) + f_out.close() + except .. as e,m + tasmota.log("OTA: Couldn't copy "+to+" "+e+" "+m,2) + return false + end + return true + end + return true +end + +# make some room if there are some leftovers from shelly +import path +path.remove("index.html.gz") + +# copy some files from autoconf to filesystem +var ok +ok = cp("bootloader-tasmota-c3.bin") +ok = cp("Partition_Wizard.tapp") + +# use an alternative to partition_core that can read Shelly's otadata +tasmota.log("OTA: loading "+tasmota.wd + "partition_core_shelly.be", 2) +load(tasmota.wd + "partition_core_shelly.be") + +# load bootloader flasher +tasmota.log("OTA: loading "+tasmota.wd + "bootloader.be", 2) +load(tasmota.wd + "bootloader.be") + + +# all good +if ok + # do some basic check that the bootloader is not already in place + import flash + if flash.read(0x1000, 4) == bytes('CD3F6395') + tasmota.log("OTA: bootloader already in place, not flashing it") + else + ok = global.bootloader().flash("bootloader-tasmota-c3.bin") + end + if ok + var p = global.partition_core_shelly.Partition() + p.save() # save with otadata compatible with new bootloader + tasmota.log("OTA: Shelly migration successful", 2) + end +end + +# dump logs to file +var lr = tasmota_log_reader() +var f_logs = open("migration_logs.txt", "w") +var logs = lr.get_log(2) +while logs != nil + f_logs.write(logs) + logs = lr.get_log(2) +end +f_logs.close() + +# Done diff --git a/raw/esp32c3/Shelly_MiniPMG3/partition_core_shelly.be b/raw/esp32c3/Shelly_MiniPMG3/partition_core_shelly.be new file mode 100644 index 00000000..80c809aa --- /dev/null +++ b/raw/esp32c3/Shelly_MiniPMG3/partition_core_shelly.be @@ -0,0 +1,645 @@ +####################################################################### +# Partition manager for ESP32 - ESP32C3 - ESP32S2 +# +# use : `import partition_core_shelly` +# +# Provides low-level objects and a Web UI +####################################################################### + +var partition_core_shelly = module('partition_core_shelly') + +####################################################################### +# Class for a partition table entry +# +# typedef struct { +# uint16_t magic; +# uint8_t type; +# uint8_t subtype; +# uint32_t offset; +# uint32_t size; +# uint8_t label[16]; +# uint32_t flags; +# } esp_partition_info_t_simplified; +# +####################################################################### +class Partition_info + var type + var subtype + var start + var sz + var label + var flags + + #- remove trailing NULL chars from a bytes buffer before converting to string -# + #- Berry strings can contain NULL, but this messes up C-Berry interface -# + static def remove_trailing_zeroes(b) + var sz = size(b) + var i = 0 + while i < sz + if b[-1-i] != 0 break end + i += 1 + end + if i > 0 + b.resize(size(b)-i) + end + return b + end + + # Init the Parition information structure, either from a bytes() buffer or an empty if no buffer is provided + def init(raw) + self.type = 0 + self.subtype = 0 + self.start = 0 + self.sz = 0 + self.label = '' + self.flags = 0 + + if !issubclass(bytes, raw) # no payload, empty partition information + return + end + + #- we have a payload, parse it -# + var magic = raw.get(0,2) + if magic == 0x50AA #- partition entry -# + + self.type = raw.get(2,1) + self.subtype = raw.get(3,1) + self.start = raw.get(4,4) + self.sz = raw.get(8,4) + self.label = self.remove_trailing_zeroes(raw[12..27]).asstring() + self.flags = raw.get(28,4) + + # elif magic == 0xEBEB #- MD5 -# + else + import string + raise "internal_error", string.format("invalid magic number %02X", magic) + end + + end + + # check if the parition is an OTA partition + # if yes, return OTA number (starting at 0) + # if no, return nil + def is_ota() + var sub_type = self.subtype + if self.type == 0 && (sub_type >= 0x10 && sub_type < 0x20) + return sub_type - 0x10 + end + end + + # check if factory 'safeboot' partition + def is_factory() + return self.type == 0 && self.subtype == 0 + 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() + import flash + if self.is_ota() == nil && !self.is_factory() return -1 end + try + var addr = self.start + var sz = self.sz + var magic_byte = flash.read(addr, 1).get(0, 1) + if magic_byte != 0xE9 return -1 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_num = 0 + while seg_num < seg_count + # 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 sz=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) + if seg_offset >= (addr + sz) return -1 end + + seg_num += 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 + except .. as e, m + tasmota.log("BRY: Exception> '" + e + "' - " + m, 2) + return -1 + end + end + + def type_to_string() + if self.type == 0 return "app" + elif self.type == 1 return "data" + end + import string + return string.format("0x%02X", self.type) + 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 + import string + return string.format("0x%02X", self.subtype) + 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 = self.type_to_string() + var subtype_s = self.subtype_to_string() + + # reformat strings + if type_s != "" type_s = " (" + type_s + ")" end + if subtype_s != "" subtype_s = " (" + subtype_s + ")" end + return string.format("", + self.type, type_s, + self.subtype, subtype_s, + self.start, self.sz, + self.label, self.flags) + end + + def tobytes() + #- convert to raw bytes -# + var b = bytes('AA50') #- set magic number -# + b.resize(32).resize(2) #- pre-reserve 32 bytes -# + b.add(self.type, 1) + b.add(self.subtype, 1) + b.add(self.start, 4) + b.add(self.sz, 4) + var label = bytes().fromstring(self.label) + label.resize(16) + b = b + label + b.add(self.flags, 4) + return b + end + +end +partition_core_shelly.Partition_info = Partition_info + +#------------------------------------------------------------- + - OTA Data + - + - Selection of the active OTA partition + - + typedef struct { + uint32_t ota_seq; + uint8_t seq_label[20]; + uint32_t ota_state; + uint32_t crc; /* CRC32 of ota_seq field only */ + } esp_ota_select_entry_t; + + - Excerp from esp_ota_ops.c + esp32_idf use two sector for store information about which partition is running + it defined the two sector as ota data partition,two structure esp_ota_select_entry_t is saved in the two sector + named data in first sector as otadata[0], second sector data as otadata[1] + e.g. + if otadata[0].ota_seq == otadata[1].ota_seq == 0xFFFFFFFF,means ota info partition is in init status + so it will boot factory application(if there is),if there's no factory application,it will boot ota[0] application + if otadata[0].ota_seq != 0 and otadata[1].ota_seq != 0,it will choose a max seq ,and get value of max_seq%max_ota_app_number + and boot a subtype (mask 0x0F) value is (max_seq - 1)%max_ota_app_number,so if want switch to run ota[x],can use next formulas. + for example, if otadata[0].ota_seq = 4, otadata[1].ota_seq = 5, and there are 8 ota application, + current running is (5-1)%8 = 4,running ota[4],so if we want to switch to run ota[7], + we should add otadata[0].ota_seq (is 4) to 4 ,(8-1)%8=7,then it will boot ota[7] + if A=(B - C)%D + then B=(A + C)%D + D*n ,n= (0,1,2...) + so current ota app sub type id is x , dest bin subtype is y,total ota app count is n + 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 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) + import crc + return crc.crc32(0xFFFFFFFF, bytes().add(seq, 4)) + end + + #---------------------------------------------------------------------# + # Rest of the class + #---------------------------------------------------------------------# + 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 = -1 + self.load() + end + + #- update ota_max, needs to recompute everything -# + def set_ota_max(n) + self.maxota = n + end + + # change the active OTA partition + def set_active(n) + var seq_max = 0 #- current highest seq number -# + var block_act = 0 #- block number containing the highest seq number -# + + if self.seq0 != nil + seq_max = self.seq0 + block_act = 0 + end + if self.seq1 != nil && self.seq1 > seq_max + seq_max = self.seq1 + block_act = 1 + end + + #- compute the next sequence number -# + var actual_ota = (seq_max - 1) % (self.maxota + 1) + if actual_ota != n #- change only if different -# + if n > actual_ota seq_max += n - actual_ota + else seq_max += (self.maxota + 1) - actual_ota + n + end + + #- update internal structure -# + if block_act == 1 #- current block is 1, so update block 0 -# + self.seq0 = seq_max + else #- or write to block 1 -# + self.seq1 = seq_max + end + self._validate() + end + end + + #- load otadata from SPI Flash -# + def load() + import flash + 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? -# + # var valid1 = otadata1.get(28, 4) == self.crc32_ota_seq(self.seq1) #- is CRC32 valid? -# + # if !valid0 self.seq0 = nil end + # if !valid1 self.seq1 = nil end + + self._validate() + end + + #- internally used, validate data -# + def _validate() + 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 + if self.seq1 != nil && (self.seq0 == nil || self.seq1 > self.seq0) + self.active_otadata = (self.seq1 - 1) % (self.maxota + 1) + end + end + + # Save partition information to SPI Flash + def save() + import flash + #- check the block number to save, 0 or 1. Choose the highest ota_seq -# + var block_to_save = -1 #- invalid -# + var seq_to_save = -1 #- invalid value -# + + # check seq0 + if self.seq0 != nil + seq_to_save = self.seq0 + block_to_save = 0 + end + if (self.seq1 != nil) && (self.seq1 > seq_to_save) + seq_to_save = self.seq1 + block_to_save = 1 + end + # if none was good + if block_to_save < 0 block_to_save = 0 end + if seq_to_save < 0 seq_to_save = 1 end + + var offset_to_save = self.offset + 0x1000 * block_to_save #- default 0xE000 or 0xF000 -# + + var bytes_to_save = bytes() + bytes_to_save.add(seq_to_save, 4) + bytes_to_save += bytes("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") + bytes_to_save.add(self.crc32_ota_seq(seq_to_save), 4) + + #- erase flash area and write -# + flash.erase(offset_to_save, 0x1000) + flash.write(offset_to_save, bytes_to_save) + end + + # Produce a human-readable representation of the object with relevant information + def tostring() + import string + return string.format("", + self.active_otadata >= 0 ? "ota_" + str(self.active_otadata) : "factory", + self.seq0, self.seq1, self.maxota) + end +end +partition_core_shelly.Partition_otadata = Partition_otadata + +#------------------------------------------------------------- + - Class for a partition table entry + -------------------------------------------------------------# +class Partition + var raw #- raw bytes of the partition table in flash -# + var md5 #- md5 hash of partition list -# + var slots + var otadata #- instance of Partition_otadata() -# + + def init() + self.slots = [] + self.load() + self.parse() + self.load_otadata() + end + + # Load partition information from SPI Flash + def load() + import flash + self.raw = flash.read(0x8000,0x1000) + end + + #- parse the raw bytes to a structured list of partition items -# + def parse() + for i:0..94 # there are maximum 95 slots + md5 (0xC00) + var item_raw = self.raw[i*32..(i+1)*32-1] + var magic = item_raw.get(0,2) + if magic == 0x50AA #- partition entry -# + var slot = partition_core_shelly.Partition_info(item_raw) + self.slots.push(slot) + elif magic == 0xEBEB #- MD5 -# + self.md5 = self.raw[i*32+16..i*33-1] + break + else + break + end + end + end + + def get_ota_slot(n) + for slot: self.slots + if slot.is_ota() == n return slot end + end + return nil + end + + def get_factory_slot() + for slot: self.slots + if slot.is_factory() return slot end + end + end + + def has_factory() + return self.get_factory_slot() != nil + end + + #- compute the highest ota partition -# + def ota_max() + var ota_max = nil + for slot:self.slots + if slot.type == 0 && (slot.subtype >= 0x10 && slot.subtype < 0x20) + var ota_num = slot.subtype - 0x10 + if (ota_max == nil) || (ota_num > ota_max) ota_max = ota_num end + end + end + return ota_max + end + + # get the active OTA app partition number + def get_active() + return self.otadata.active_otadata + end + + def load_otadata() + #- look for otadata partition offset, and max_ota -# + var otadata_offset = 0xE000 #- default value -# + var ota_max = self.ota_max() + for slot:self.slots + if slot.type == 1 && slot.subtype == 0 #- otadata -# + otadata_offset = slot.start + end + end + + self.otadata = partition_core_shelly.Partition_otadata(ota_max, self.has_factory(), otadata_offset) + end + + #- change the active partition -# + def set_active(n) + if n < 0 || n > self.ota_max() raise "value_error", "Invalid ota partition number" end + self.otadata.set_ota_max(self.ota_max()) #- update ota_max if it changed -# + self.otadata.set_active(n) + 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 + #- convert to human readble -# + def tostring() + var ret = " 95 raise "value_error", "Too many partiition slots" end + var b = bytes() + for slot: self.slots + b += slot.tobytes() + end + #- compute MD5 -# + var md5 = MD5() + md5.update(b) + #- add the last segment -# + b += bytes("EBEBFFFFFFFFFFFFFFFFFFFFFFFFFFFF") + b += md5.finish() + #- complete -# + return b + end + + #- write back to flash -# + def save() + import flash + var b = self.tobytes() + #- erase flash area and write -# + flash.erase(0x8000, 0x1000) + flash.write(0x8000, b) + self.otadata.save() + end + + # Internal: returns which flash sector contains the partition definition + # Returns 0 or 1, or `nil` if something went wrong + # Note: partition flash sector vary from ESP32 to ESP32C3/S3 + static def get_flash_definition_sector() + import flash + for i:0..1 + var offset = i * 0x1000 + if flash.read(offset, 1) == bytes('E9') return offset end + end + end + + # Internal: returns the maximum flash size possible + # Returns max flash size ok kB + def get_max_flash_size_k() + var flash_size_k = tasmota.memory()['flash'] + var flash_size_real_k = tasmota.memory().find("flash_real", flash_size_k) + if (flash_size_k != flash_size_real_k) && self.get_flash_definition_sector() != nil + flash_size_k = flash_size_real_k # try to expand the flash size definition + end + return flash_size_k + end + + # Internal: returns the unallocated flash size (in kB) beyond the file-system + # this indicates that the file-system can be extended (although erased at the same time) + def get_unallocated_k() + var last_slot = self.slots[-1] + if last_slot.is_spiffs() + # verify that last slot is filesystem + var flash_size_k = self.get_max_flash_size_k() + var partition_end_k = (last_slot.start + last_slot.sz) / 1024 # last kb used for fs + if partition_end_k < flash_size_k + return flash_size_k - partition_end_k + end + end + return 0 + end + + #- ---------------------------------------------------------------------- -# + #- Resize flash definition if needed + #- ---------------------------------------------------------------------- -# + def resize_max_flash_size_k() + 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() + 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 + + var flash_def = flash.read(flash_definition_sector, 4) + var size_before = flash_def[3] + + var flash_size_code + var flash_size_real_m = flash_size_real_k / 1024 # size in MB + if flash_size_real_m == 1 flash_size_code = 0x00 + elif flash_size_real_m == 2 flash_size_code = 0x10 + elif flash_size_real_m == 4 flash_size_code = 0x20 + elif flash_size_real_m == 8 flash_size_code = 0x30 + elif flash_size_real_m == 16 flash_size_code = 0x40 + elif flash_size_real_m == 32 flash_size_code = 0x50 + elif flash_size_real_m == 64 flash_size_code = 0x60 + elif flash_size_real_m == 128 flash_size_code = 0x70 + end + + if flash_size_code != nil + # apply the update + 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(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 + end + end + + # Called at first boot + # Try to expand FS to max of flash size + def resize_fs_to_max() + import string + try + var unallocated = self.get_unallocated_k() + if unallocated <= 0 return nil end + + tasmota.log(string.format("BRY: Trying to expand FS by %i kB", unallocated), 2) + + self.resize_max_flash_size_k() # resize if needed + # since unallocated succeeded, we know the last slot is FS + var fs_slot = self.slots[-1] + fs_slot.sz += unallocated * 1024 + self.save() + self.invalidate_spiffs() # erase SPIFFS or data is corrupt + + # restart + tasmota.global.restart_flag = 2 + tasmota.log("BRY: Successfully resized FS, restarting", 2) + except .. as e, m + tasmota.log(string.format("BRY: Exception> '%s' - %s", e, m), 2) + end + 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() + import flash + #- 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 + + # switch to safeboot `factory` partition + def switch_factory(force_ota) + import flash + flash.factory(force_ota) + end +end +partition_core_shelly.Partition = Partition + +# init method to force the global `partition_core_shelly` is defined even if the import is done within a function +def init(m) + import global + global.partition_core_shelly = m + return m +end +partition_core_shelly.init = init + +return partition_core_shelly + +#- Example + +import partition_core_shelly + +# read +p = partition_core_shelly.Partition() +print(p) + +-#