From 618037ed95e7cc7212b669d59d2b752d1c117255 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 11 Nov 2023 16:09:00 +0100 Subject: [PATCH 1/4] Partition Wizard can be loaded dynamically --- CHANGELOG.md | 1 + lib/libesp32/berry/src/be_bytecode.c | 35 ++++---- lib/libesp32/berry/src/be_bytecode.h | 1 + .../Partition_Wizard/partition_wizard.bec | Bin 0 -> 16720 bytes .../xdrv_23_zigbee_7_6_flash_fs.ino | 8 +- .../xdrv_52_0_berry_struct.ino | 3 + .../tasmota_xdrv_driver/xdrv_52_9_berry.ino | 84 ++++++++++++++++++ 7 files changed, 116 insertions(+), 16 deletions(-) create mode 100644 tasmota/berry/modules/Partition_Wizard/partition_wizard.bec diff --git a/CHANGELOG.md b/CHANGELOG.md index 38e54d0b1679..2c7ab8cec43c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - NeoPool sensor delta trigger (command ``NPTelePeriod``) (#19973) - NeoPool store settings on unified file system (#19973) - NeoPool command ``NPBoost`` (#19973) +- Partition Wizard can be loaded dynamically ### Breaking Changed diff --git a/lib/libesp32/berry/src/be_bytecode.c b/lib/libesp32/berry/src/be_bytecode.c index 133a96618075..a636567facf1 100644 --- a/lib/libesp32/berry/src/be_bytecode.c +++ b/lib/libesp32/berry/src/be_bytecode.c @@ -596,6 +596,24 @@ void load_global_info(bvm *vm, void *fp) be_global_release_space(vm); } +bclosure* be_bytecode_load_from_fs(bvm *vm, void *fp) +{ + int version = load_head(fp); + if (version == BYTECODE_VERSION) { + bclosure *cl = be_newclosure(vm, 0); + var_setclosure(vm->top, cl); + be_stackpush(vm); + load_global_info(vm, fp); + load_proto(vm, fp, &cl->proto, -1, version); + be_stackpop(vm, 2); /* pop the closure and list */ + be_fclose(fp); + return cl; + } + bytecode_error(vm, be_pushfstring(vm, + "invalid bytecode version.")); + return NULL; +} + bclosure* be_bytecode_load(bvm *vm, const char *filename) { void *fp = be_fopen(filename, "rb"); @@ -603,22 +621,9 @@ bclosure* be_bytecode_load(bvm *vm, const char *filename) bytecode_error(vm, be_pushfstring(vm, "can not open file '%s'.", filename)); } else { - int version = load_head(fp); - if (version == BYTECODE_VERSION) { - bclosure *cl = be_newclosure(vm, 0); - var_setclosure(vm->top, cl); - be_stackpush(vm); - load_global_info(vm, fp); - load_proto(vm, fp, &cl->proto, -1, version); - be_stackpop(vm, 2); /* pop the closure and list */ - be_fclose(fp); - return cl; - } - bytecode_error(vm, be_pushfstring(vm, - "invalid bytecode version '%s'.", filename)); + return be_bytecode_load_from_fs(vm, fp); } - bytecode_error(vm, be_pushfstring(vm, - "invalid bytecode file '%s'.", filename)); return NULL; } + #endif /* BE_USE_BYTECODE_LOADER */ diff --git a/lib/libesp32/berry/src/be_bytecode.h b/lib/libesp32/berry/src/be_bytecode.h index 08affe1decfa..61223952c6ba 100644 --- a/lib/libesp32/berry/src/be_bytecode.h +++ b/lib/libesp32/berry/src/be_bytecode.h @@ -12,6 +12,7 @@ void be_bytecode_save(bvm *vm, const char *filename, bproto *proto); bclosure* be_bytecode_load(bvm *vm, const char *filename); +bclosure* be_bytecode_load_from_fs(bvm *vm, void *fp); bbool be_bytecode_check(const char *path); #endif diff --git a/tasmota/berry/modules/Partition_Wizard/partition_wizard.bec b/tasmota/berry/modules/Partition_Wizard/partition_wizard.bec new file mode 100644 index 0000000000000000000000000000000000000000..e6e82953351dc4f9cefc1fa6255d1485af6aa58d GIT binary patch literal 16720 zcmcgz&u<$^b}n`|n@zGwwkTSrWm>M$P?pB4v8W$2@!FE?@!GRHS&gmCa55gm0Y#B5 zi7-WS*)5x15Lg`+SRDwg4-Syy1`v=v?7@c|bO>_IDgQwJg5;D-t~<*2s=CP*MR|#G#vHfzbfkK$EYxs#XwuRcKOkrKdlz&wi zLs|U(%RN;uhIHliX&k?X@>-88uhHg&Df&rBK{=_MM48fImU7G(>Qt@A6s^mWv6E=n zK-qf6G@~0+sccaHCm8DxV=~K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U@**9gXkwG2@ z@(A^eCY&5YKO}M0IUI80+`M+~=cm{2#4x=g?(&_@J;V;fW+1mQ3Gx&! zN>+F@e;dq_EhE4R@O?YtX{=6exk9@k5_&UbMT#I^8l zl@%lj=Me!%f~uL-#4mgR`J2~HfBPf)a>x|FNd!C7d8FIl=rH5PNf@CAJq|Azo}~XJ z5_!JDtH(J1Nh$Z<{F695{yg!jhbekrfJUL-p-|-sktlb7eWlCSw|7f&7k(o48v(^V zKS(ENJ1cd@nJcR3V91ile> zpgwJyDfk#q*PZ(o_~JVdb;S5C)8k(9KfbZahUjAf|1;zMM*;F9$KX9R7}^%9%*X}r zpZVai|B0hqK}(30KV$J_(HTWXQ$iX+Uzs7nlN4C#`KUU)22v=<{l{zczrVy93Fjb9 z8RrNw{PFY>QYg$f_rS4-BDo_aBAqsJD8E;wV|gln&2@@{q5huyH7QQVObc2`J7l_k zhz|n>4uvnc!x~|rXfMcqx}X|10=|y#wTaJ6we*Qf3_U*CU~;ALg%fs3i=FtNnc~xq zIkEcQXQuuR3L^nhy5Y8)PK%PNgwGj(3=xL!qa9>=AUYkAACUe~ko<@4%N_ZEcI50K z+4OfM>wO0>POckv=Xvu8x{vrY7!&_LSNt4y literal 0 HcmV?d00001 diff --git a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_7_6_flash_fs.ino b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_7_6_flash_fs.ino index 0554c8de4b67..e555f7d5e0f7 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_7_6_flash_fs.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_7_6_flash_fs.ino @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#ifdef USE_ZIGBEE +#if defined(USE_ZIGBEE) || defined(USE_BERRY) #ifdef ESP32 #include @@ -43,6 +43,12 @@ public: _seek = 0; } + FlashFileImpl(const void* buf, size_t len) { + _buf = (const char*)buf; + _len = len; + _seek = 0; + } + virtual ~FlashFileImpl() {} size_t write(const uint8_t *buf, size_t size) { diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_0_berry_struct.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_0_berry_struct.ino index ba32bd06f5a3..04dfede3409e 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_0_berry_struct.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_0_berry_struct.ino @@ -93,6 +93,9 @@ public: int32_t timeout = 0; // Berry heartbeat timeout, preventing code to run for too long. `0` means not enabled bool rules_busy = false; // are we already processing rules, avoid infinite loop bool web_add_handler_done = false; // did we already sent `web_add_handler` event +#ifdef USE_BERRY_PARTITION_WIZARD + bool partition_wizard_loaded = false; // did we already load Parition_Wizard +#endif // USE_BERRY_PARTITION_WIZARD bool autoexec_done = false; // do we still need to load 'autoexec.be' bool repl_active = false; // is REPL running (activates log recording) // output log is stored as a LinkedList of buffers diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino index 0a356e59e5a1..49938e0bd692 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino @@ -23,6 +23,9 @@ #define XDRV_52 52 #include +extern "C" { + #include "be_bytecode.h" +} #include "berry_tasmota.h" #ifdef USE_MATTER_DEVICE #include "berry_matter.h" @@ -757,6 +760,79 @@ void HandleBerryConsole(void) WSContentStop(); } +// Display a Button to dynamically load the Partition Wizard +void HandleBerryPartiionWizardLoaderButton(void) { + WSContentSend_P("

"); +} + +#define PARTITION_WIZARD_URL "http://ota.tasmota.com/tapp/partition_wizard.bec" + +void HandleBerryPartitionWizardLoader(void) { + if (BerryBECLoader(PARTITION_WIZARD_URL)) { + // All good, redirect + Webserver->sendHeader("Location", "/part_wiz", true); + Webserver->send(302, "text/plain", ""); + berry.partition_wizard_loaded = true; + } else { + Webserver->sendHeader("Location", "/mn?", true); + Webserver->send(302, "text/plain", ""); + } +} + +// return true if successful +bool BerryBECLoader(const char * url) { + bvm *vm = berry.vm; + + HTTPClientLight cl; + cl.setUserAgent(USE_BERRY_WEBCLIENT_USERAGENT); + cl.setConnectTimeout(USE_BERRY_WEBCLIENT_TIMEOUT); // set default timeout + cl.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); + + if (!cl.begin(url)) { + AddLog(LOG_LEVEL_INFO, "BRY: unable to load URL '%s'", url); + // cl.end(); + return false; + } + + uint32_t http_connect_time = millis(); + int32_t httpCode = cl.GET(); + if (httpCode != 200) { + AddLog(LOG_LEVEL_INFO, "BRY: unable to load URL '%s' code %i", url, httpCode); + // cl.end(); + return false; + } + + int32_t sz = cl.getSize(); + AddLog(LOG_LEVEL_DEBUG, "BRY: Response http_code %i size %i bytes in %i ms", httpCode, sz, millis() - http_connect_time); + // abort if we exceed 32KB size, things will not go well otherwise + if (sz >= 32767 || sz <= 0) { + AddLog(LOG_LEVEL_DEBUG, "BRY: Response size too big %i bytes", sz); + return false; + } + + // create a bytes object at top of stack. + // the streamwriter knows how to get it. + uint8_t * buf = (uint8_t*) be_pushbytes(vm, nullptr, sz); + StreamBeBytesWriter memory_writer(vm); + int32_t written = cl.writeToStream(&memory_writer); + cl.end(); // free allocated memory ~16KB + + size_t loaded_sz = 0; + const void * loaded_buf = be_tobytes(vm, -1, &loaded_sz); + + FlashFileImplPtr fp = FlashFileImplPtr(new FlashFileImpl(loaded_buf, loaded_sz)); + File * f_ptr = new File(fp); // we need to allocate dynamically because be_close calls `delete` on it + bclosure* loaded_bec = be_bytecode_load_from_fs(vm, f_ptr); + be_pop(vm, 1); + if (loaded_bec != NULL) { + be_pushclosure(vm, loaded_bec); + be_call(vm, 0); + be_pop(vm, 1); + } + be_gc_collect(vm); // force a GC to free the buffer now + return true; +} + #endif // USE_WEBSERVER /*********************************************************************************************\ @@ -839,6 +915,11 @@ bool Xdrv52(uint32_t function) XdrvMailbox.index++; } else { WSContentSend_P(HTTP_BTN_BERRY_CONSOLE); +#ifdef USE_BERRY_PARTITION_WIZARD + if (!berry.partition_wizard_loaded) { + HandleBerryPartiionWizardLoaderButton(); + } +#endif // USE_BERRY_PARTITION_WIZARD callBerryEventDispatcher(PSTR("web_add_button"), nullptr, 0, nullptr); callBerryEventDispatcher(PSTR("web_add_console_button"), nullptr, 0, nullptr); } @@ -858,6 +939,9 @@ bool Xdrv52(uint32_t function) berry.web_add_handler_done = true; } WebServer_on(PSTR("/bc"), HandleBerryConsole); +#ifdef USE_BERRY_PARTITION_WIZARD + Webserver->on("/tapp", HTTP_GET, HandleBerryPartitionWizardLoader); +#endif // USE_BERRY_PARTITION_WIZARD break; #endif // USE_WEBSERVER case FUNC_SAVE_BEFORE_RESTART: From 0713cd14872045c7049a71d44e6216e988af88ac Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 11 Nov 2023 16:15:43 +0100 Subject: [PATCH 2/4] Centralize config --- tasmota/my_user_config.h | 2 ++ tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index f8e3fd4a1086..7e918a675fd1 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -1141,6 +1141,8 @@ // Note that only one cipher is enabled: ECDHE_RSA_WITH_AES_128_GCM_SHA256 which is very commonly used and highly secure #define USE_BERRY_WEBCLIENT_USERAGENT "TasmotaClient" // default user-agent used, can be changed with `wc.set_useragent()` #define USE_BERRY_WEBCLIENT_TIMEOUT 2000 // Default timeout in milliseconds + #define USE_BERRY_PARTITION_WIZARD // Add a button to dynamically load the Partion Wizard from a bec file online (+1.3KB Flash) + #define USE_BERRY_PARTITION_WIZARD_URL "http://ota.tasmota.com/tapp/partition_wizard.bec" #define USE_BERRY_TCPSERVER // Enable TCP socket server (+0.6k) // #define USE_BERRY_ULP // Enable ULP (Ultra Low Power) support (+4.9k) // Berry crypto extensions below: diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino index 49938e0bd692..324684a9cf93 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino @@ -765,10 +765,8 @@ void HandleBerryPartiionWizardLoaderButton(void) { WSContentSend_P("

"); } -#define PARTITION_WIZARD_URL "http://ota.tasmota.com/tapp/partition_wizard.bec" - void HandleBerryPartitionWizardLoader(void) { - if (BerryBECLoader(PARTITION_WIZARD_URL)) { + if (BerryBECLoader(USE_BERRY_PARTITION_WIZARD_URL)) { // All good, redirect Webserver->sendHeader("Location", "/part_wiz", true); Webserver->send(302, "text/plain", ""); From 4f45adf84ba942eddc9bd1cd4f8be2a48e746d8b Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 11 Nov 2023 19:08:57 +0100 Subject: [PATCH 3/4] Don't display duplicate buttons --- tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino index 324684a9cf93..61e95b85bf53 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino @@ -25,6 +25,7 @@ #include extern "C" { #include "be_bytecode.h" + #include "be_var.h" } #include "berry_tasmota.h" #ifdef USE_MATTER_DEVICE @@ -762,7 +763,15 @@ void HandleBerryConsole(void) // Display a Button to dynamically load the Partition Wizard void HandleBerryPartiionWizardLoaderButton(void) { - WSContentSend_P("

"); + bvm * vm = berry.vm; + static const char PARTITION_WIZARD_NAME[] = "partition_wizard"; + if (!berry.partition_wizard_loaded) { + if (!be_global_find(vm, be_newstr(vm, PARTITION_WIZARD_NAME)) < 0) { // the global name `partition_wizard` doesn't exist + WSContentSend_P("

"); + } else { + berry.partition_wizard_loaded = true; + } + } } void HandleBerryPartitionWizardLoader(void) { @@ -914,9 +923,7 @@ bool Xdrv52(uint32_t function) } else { WSContentSend_P(HTTP_BTN_BERRY_CONSOLE); #ifdef USE_BERRY_PARTITION_WIZARD - if (!berry.partition_wizard_loaded) { - HandleBerryPartiionWizardLoaderButton(); - } + HandleBerryPartiionWizardLoaderButton(); #endif // USE_BERRY_PARTITION_WIZARD callBerryEventDispatcher(PSTR("web_add_button"), nullptr, 0, nullptr); callBerryEventDispatcher(PSTR("web_add_console_button"), nullptr, 0, nullptr); From dec52e19ed0d51292a79c18ec786fb183e3c4e99 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 11 Nov 2023 19:10:11 +0100 Subject: [PATCH 4/4] Fix test --- tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino index 61e95b85bf53..c4505b0af96d 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino @@ -766,7 +766,7 @@ void HandleBerryPartiionWizardLoaderButton(void) { bvm * vm = berry.vm; static const char PARTITION_WIZARD_NAME[] = "partition_wizard"; if (!berry.partition_wizard_loaded) { - if (!be_global_find(vm, be_newstr(vm, PARTITION_WIZARD_NAME)) < 0) { // the global name `partition_wizard` doesn't exist + if (be_global_find(vm, be_newstr(vm, PARTITION_WIZARD_NAME)) < 0) { // the global name `partition_wizard` doesn't exist WSContentSend_P("

"); } else { berry.partition_wizard_loaded = true;