Skip to content

Commit

Permalink
Merge branch 'release/v0.4.4' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
yaourdt committed Dec 30, 2020
2 parents 8aea75a + 8c75a1a commit cbc7057
Show file tree
Hide file tree
Showing 14 changed files with 594 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
needs: release
strategy:
matrix:
hwModel: [Shelly1, Shelly1PM, ShellyPlugS, ShellyPlug2, ShellyUni, Shelly2, Shelly25, ShellyRGBW2, ShellyDimmer1, ShellyDimmer2, ShellyEM, ShellyBulb, ShellyVintage, ShellyPlugUS, ShellyHT, ShellyBulbDuo, ShellyI3, Shelly1L]
hwModel: [Shelly1, Shelly1PM, ShellyPlugS, ShellyPlug2, ShellyUni, Shelly2, Shelly25, ShellyRGBW2, ShellyDimmer1, ShellyDimmer2, ShellyEM, ShellyBulb, ShellyVintage, ShellyPlugUS, ShellyHT, ShellyDuo, ShellyI3, Shelly1L]
hwPlatform: [esp8266]
targetFw: [tasmota, haa, espurna]
runs-on: ubuntu-latest
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ know how to flash a new firmware over a wired connection.
but be aware that if something fails, your device may be bricked, if you don't
know how to flash a new firmware over a wired connection.

> Instead of flashing the device manually (see below), you may try the new automagic [flashing script](tools/flash-shelly.py). The script requires Python 3 to be installed on your computer. After downloading the script, run `python3 flash-shelly.py -a` from the download location. All Shelly devices with stock firmware, which are connected to the same WIFI network, will be found. For each device that is found, you will be asked if you like to convert it.
>
> Use `python3 flash-shelly.py -a -t haa` or `python3 flash-shelly.py -a -t espurna` to install alternate targets.
>
> ⚠ The script is still in an early testing stage, and I would appreciate your feedback. If you want to give feedback, please open an issue.
Before flashing this firmware, connect your device to a WIFI network with
internet access. From your browser, open the update URL for your device from the
table below. Replace `shellyip` with the IP address of your Shelly. The device
Expand Down Expand Up @@ -53,14 +59,14 @@ Shelly 1PM | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmo
Shelly Plug S | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyPlugS.zip` | `{"NAME":"Shelly Plug S","GPIO":[57,255,56,255,0,134,0,0,131,17,132,21,0],"FLAG":2,"BASE":45}`
Shelly 2 | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-Shelly2.zip` | `{"NAME":"Shelly 2","GPIO":[0,135,0,136,21,22,0,0,9,0,10,137,0],"FLAG":0,"BASE":47}`
Shelly 2.5 | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-Shelly25.zip` | `{"NAME":"Shelly 2.5","GPIO":[56,0,17,0,21,83,0,0,6,82,5,22,156],"FLAG":2,"BASE":18}`
Shelly RGBW2 | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyRGBW2.zip` | `{"NAME":"Shelly RGBW2","GPIO":[0,0,52,0,40,255,0,0,37,17,39,38,0],"FLAG":0,"BASE":18}`
Shelly RGBW2 (color mode) | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyRGBW2.zip` | `{"NAME":"Shelly RGBW2","GPIO":[0,0,52,0,40,255,0,0,37,17,39,38,0],"FLAG":0,"BASE":18}`
Shelly Dimmer 1 | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyDimmer1.zip` | `{"NAME":"Shelly Dimmer 1","GPIO":[0,3200,0,3232,5504,5536,0,0,192,0,193,288,0,4736],"FLAG":0,"BASE":18}`
Shelly Dimmer 2 | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyDimmer2.zip` | `{"NAME":"Shelly Dimmer 2","GPIO":[0,3200,0,3232,5504,5536,0,0,193,0,192,0,320,4736],"FLAG":0,"BASE":18}`
Shelly EM | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyEM.zip` | `{"NAME":"Shelly EM","GPIO":[0,0,0,0,0,0,0,0,6,156,5,21,0],"FLAG":15,"BASE":18}`
Shelly Bulb | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyBulb.zip` | **not yet available, only flash if you a perfectly certain about what you are doing**
Shelly Vintage | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyVintage.zip` | **not yet available, only flash if you a perfectly certain about what you are doing**
Shelly Plug US | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyPlugUS.zip` | `{"NAME":"ShellyPlugUS","GPIO":[52,255,57,255,21,134,0,0,131,17,132,157,0],"FLAG":0,"BASE":45}`
Shelly Duo | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyBulbDuo.zip` | `{"NAME":"Shelly Duo","GPIO":[0,0,0,0,38,37,0,0,0,0,0,0,0],"FLAG":0,"BASE":18}`
Shelly Duo | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyDuo.zip` | `{"NAME":"Shelly Duo","GPIO":[0,0,0,0,38,37,0,0,0,0,0,0,0],"FLAG":0,"BASE":18}`
Shelly H&T | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyHT.zip` | **not yet available, only flash if you a perfectly certain about what you are doing**
Shelly i3 | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-ShellyI3.zip` | `{"NAME":"Shelly i3","GPIO":[0,0,0,0,0,0,0,0,83,84,82,0,0],"FLAG":2,"BASE":18}`
Shelly 1L | `http://shellyip/ota?url=http://dl.dasker.eu/firmware/mg2tasmota-Shelly1L.zip` | `{"NAME":"Shelly 1L","GPIO":[320,0,0,0,192,224,0,0,0,0,193,0,0,4736],"FLAG":0,"BASE":18}`
Expand Down Expand Up @@ -98,6 +104,9 @@ the initial code.
This firmware is build using a fork of [Mongoose OS docker action](https://github.com/dea82/mongoose-os-action)
which can be found [here](https://github.com/yaourdt/mongoose-os-action).

The flash-script is a modified version from [mongoose-os-apps/shelly-homekit](https://github.com/mongoose-os-apps/shelly-homekit),
originally written by [andyblac](https://github.com/andyblac) and [rojer](https://github.com/rojer).

## License

Copyright (C) 2020, Mark Dornbach
Expand Down
Binary file removed binary/espurna-1.14.1-espurna-base-1MB.bin
Binary file not shown.
Binary file removed binary/fullhaaboot-2.5.7.bin
Binary file not shown.
Binary file removed binary/fullhaaboot-3.4.0.bin
Binary file not shown.
Binary file removed binary/fullhaaboot-4.2.1.bin
Binary file not shown.
Binary file removed binary/fullhaaboot-4.3.0.bin
Binary file not shown.
Binary file removed binary/fullhaaboot-4.3.1.bin
Binary file not shown.
Binary file removed binary/haaboot.bin
Binary file not shown.
Binary file removed binary/tasmota-8.5.bin
Binary file not shown.
Binary file removed binary/tasmota.bin
Binary file not shown.
7 changes: 4 additions & 3 deletions mos.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
author: mark dornbach <[email protected]>
description: a minimal firmware for ota flashing tasmota from mongoose os
platform: esp8266
version: 0.4.3
version: 0.4.4

libs_version: ${mos.version}
modules_version: ${mos.version}
Expand Down Expand Up @@ -31,6 +31,7 @@ libs:
- origin: https://github.com/mongoose-os-libs/rpc-uart # RPC via serial console
- origin: https://github.com/mongoose-os-libs/rpc-service-config # manage device configuration remotely
- origin: https://github.com/mongoose-os-libs/ca-bundle # CA certificates
- origin: https://github.com/mongoose-os-libs/ota-http-server # local OTA update via HTTP POST

conds:
- when: build_vars.TARGETFW == "tasmota"
Expand Down Expand Up @@ -87,7 +88,7 @@ conds:
MGOS_ROOT_FS_TYPE: SPIFFS
- when: build_vars.MODEL == "ShellyRGBW2"
apply:
name: rgbw2
name: rgbw2-color
build_vars:
FS_SIZE: 262144
FLASH_SIZE: 2097152
Expand Down Expand Up @@ -149,7 +150,7 @@ conds:
FLASH_SIZE: 2097152
BOOT_CONFIG_ADDR: 0x7000
MGOS_ROOT_FS_TYPE: SPIFFS
- when: build_vars.MODEL == "ShellyBulbDuo"
- when: build_vars.MODEL == "ShellyDuo"
apply:
name: bulbduo
build_vars:
Expand Down
64 changes: 61 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ rboot_config *rboot_cfg;
/*
TODO
* hash verify download!
* if failed wait 60 sec and reboot
* disable wdt and interrupts during critical write operations
* move block for bootloader (0...4096) and its config (BOOT_CONFIG_ADDR ... BOOT_CONFIG_ADDR) last
* move to esp flash write lib:
#include "esp_flash_writer.h"
static struct esp_flash_write_ctx s_wctx;
Expand Down Expand Up @@ -110,6 +108,14 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data, void *ud) {
if ( state->next_blk > state->curr_blk ) {
memcpy(&state->data[BLOCK_SIZE - state->left_in_block], hm->body.p, state->left_in_block);

// check if the next write will overwrite the currently running program
if ( (state->next_blk * BLOCK_SIZE) > (*rboot_cfg).roms[(*rboot_cfg).current_rom] ) {
LOG(LL_ERROR, ("error! operation would overwrite the currently running program."));
c->flags |= MG_F_CLOSE_IMMEDIATELY;
state->status = 500;
break;
}

if ( spi_flash_erase_sector(state->curr_blk) != 0 ) {
LOG(LL_ERROR, ("flash delete error! abort at %d recieved bytes.", state->recieved));
c->flags |= MG_F_CLOSE_IMMEDIATELY;
Expand Down Expand Up @@ -167,7 +173,59 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data, void *ud) {
}
LOG(LL_DEBUG, ("last block dump done"));

block_copy( (*rboot_cfg).roms[TEMP_STORAGE], 0, state->recieved ); //TODO move me
// check if the next operation will overwrite the currently running program
if ( ((state->curr_blk + 3) * BLOCK_SIZE) > (*rboot_cfg).roms[(*rboot_cfg).current_rom] ) {
LOG(LL_ERROR, ("error! operation would overwrite the currently running program."));
break;
}

// we are going to overwrite the bootloader and boot config last
// in case something goes wrong. to do so, we first need to save
// respective blocks, so they don't get overwritten by the main
// copy process

// save bootloader block
block_copy(
(*rboot_cfg).roms[TEMP_STORAGE],
(state->curr_blk + 1) * BLOCK_SIZE,
BLOCK_SIZE
);

// save boot config block
block_copy(
(*rboot_cfg).roms[TEMP_STORAGE] + BOOT_CONFIG_ADDR,
(state->curr_blk + 2) * BLOCK_SIZE,
BLOCK_SIZE
);

// move everything between the bootloader and boot config
block_copy(
(*rboot_cfg).roms[TEMP_STORAGE] + BLOCK_SIZE,
BLOCK_SIZE,
BOOT_CONFIG_ADDR - BLOCK_SIZE
);

// move everything after boot config
block_copy(
(*rboot_cfg).roms[TEMP_STORAGE] + BOOT_CONFIG_ADDR + BLOCK_SIZE,
BOOT_CONFIG_ADDR + BLOCK_SIZE,
state->recieved - BOOT_CONFIG_ADDR - BLOCK_SIZE
);

// overwrite boot config
block_copy(
(state->curr_blk + 2) * BLOCK_SIZE,
BOOT_CONFIG_ADDR,
BLOCK_SIZE
);

// overwrite boot loader
block_copy(
(state->curr_blk + 1) * BLOCK_SIZE,
0,
BLOCK_SIZE
);

mgos_system_restart_after(200);
} else if (state->status == 0) {
LOG(LL_INFO, ("Following HTTP redirect..."));
Expand Down
Loading

0 comments on commit cbc7057

Please sign in to comment.