Add tasmota magic bits, Tasmota compat check (#1152)

This commit is contained in:
Otto Winter 2020-07-15 15:29:41 +02:00 committed by GitHub
parent 4752096520
commit 0cc3902ffc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -1,6 +1,7 @@
#include "esphome/core/application.h" #include "esphome/core/application.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/version.h" #include "esphome/core/version.h"
#include "esphome/core/esphal.h"
#ifdef USE_STATUS_LED #ifdef USE_STATUS_LED
#include "esphome/components/status_led/status_led.h" #include "esphome/components/status_led/status_led.h"
@ -58,6 +59,9 @@ void Application::setup() {
ESP_LOGI(TAG, "setup() finished successfully!"); ESP_LOGI(TAG, "setup() finished successfully!");
this->schedule_dump_config(); this->schedule_dump_config();
this->calculate_looping_components_(); this->calculate_looping_components_();
// Dummy function to link some symbols into the binary.
force_link_symbols();
} }
void Application::loop() { void Application::loop() {
uint32_t new_app_state = 0; uint32_t new_app_state = 0;

View file

@ -271,6 +271,22 @@ ISRInternalGPIOPin *GPIOPin::to_isr() const {
this->gpio_read_, this->gpio_mask_, this->inverted_); this->gpio_read_, this->gpio_mask_, this->inverted_);
} }
void force_link_symbols() {
#ifdef ARDUINO_ARCH_ESP8266
// Tasmota uses magic bytes in the binary to check if an OTA firmware is compatible
// with their settings - ESPHome uses a different settings system (that can also survive
// erases). So set magic bytes indicating all tasmota versions are supported.
// This only adds 12 bytes of binary size, which is an acceptable price to pay for easier support
// for Tasmota.
// https://github.com/arendst/Tasmota/blob/b05301b1497942167a015a6113b7f424e42942cd/tasmota/settings.ino#L346-L380
// https://github.com/arendst/Tasmota/blob/b05301b1497942167a015a6113b7f424e42942cd/tasmota/i18n.h#L652-L654
const static uint32_t TASMOTA_MAGIC_BYTES[] PROGMEM = {0x5AA55AA5, 0xFFFFFFFF, 0xA55AA55A};
// Force link symbol by using a volatile integer (GCC attribute used does not work because of LTO)
volatile int x = 0;
x = TASMOTA_MAGIC_BYTES[x];
#endif
}
} // namespace esphome } // namespace esphome
#ifdef ARDUINO_ESP8266_RELEASE_2_3_0 #ifdef ARDUINO_ESP8266_RELEASE_2_3_0

View file

@ -116,4 +116,12 @@ class GPIOPin {
template<typename T> void GPIOPin::attach_interrupt(void (*func)(T *), T *arg, int mode) const { template<typename T> void GPIOPin::attach_interrupt(void (*func)(T *), T *arg, int mode) const {
this->attach_interrupt_(reinterpret_cast<void (*)(void *)>(func), arg, mode); this->attach_interrupt_(reinterpret_cast<void (*)(void *)>(func), arg, mode);
} }
/** This function can be used by the HAL to force-link specific symbols
* into the generated binary without modifying the linker script.
*
* It is called by the application very early on startup and should not be used for anything
* other than forcing symbols to be linked.
*/
void force_link_symbols();
} // namespace esphome } // namespace esphome