OTA: Add incoming FW block check (#718)
This commit is contained in:
@@ -44,6 +44,7 @@ typedef enum {
|
|||||||
INDICATION_WAKEUP, //!< Node just woke from sleep.
|
INDICATION_WAKEUP, //!< Node just woke from sleep.
|
||||||
INDICATION_FW_UPDATE_START, //!< Start of OTA firmware update process.
|
INDICATION_FW_UPDATE_START, //!< Start of OTA firmware update process.
|
||||||
INDICATION_FW_UPDATE_RX, //!< Received a piece of firmware data.
|
INDICATION_FW_UPDATE_RX, //!< Received a piece of firmware data.
|
||||||
|
INDICATION_FW_UPDATE_RX_ERR, //!< Received wrong piece of firmware data.
|
||||||
|
|
||||||
INDICATION_ERR_START = 100,
|
INDICATION_ERR_START = 100,
|
||||||
INDICATION_ERR_TX, //!< Failed to transmit message.
|
INDICATION_ERR_TX, //!< Failed to transmit message.
|
||||||
|
|||||||
@@ -93,19 +93,26 @@ bool firmwareOTAUpdateProcess(void)
|
|||||||
OTA_DEBUG(PSTR("OTA:FWP:UPDATE SKIPPED\n")); // FW update skipped, no newer version available
|
OTA_DEBUG(PSTR("OTA:FWP:UPDATE SKIPPED\n")); // FW update skipped, no newer version available
|
||||||
} else if (_msg.type == ST_FIRMWARE_RESPONSE) {
|
} else if (_msg.type == ST_FIRMWARE_RESPONSE) {
|
||||||
if (_firmwareUpdateOngoing) {
|
if (_firmwareUpdateOngoing) {
|
||||||
// Save block to flash
|
|
||||||
setIndication(INDICATION_FW_UPDATE_RX);
|
|
||||||
OTA_DEBUG(PSTR("OTA:FWP:RECV B=%04X\n"), _firmwareBlock); // received FW block
|
|
||||||
// extract FW block
|
// extract FW block
|
||||||
replyFirmwareBlock_t *firmwareResponse = (replyFirmwareBlock_t *)_msg.data;
|
replyFirmwareBlock_t *firmwareResponse = (replyFirmwareBlock_t *)_msg.data;
|
||||||
// write to flash
|
|
||||||
|
OTA_DEBUG(PSTR("OTA:FWP:RECV B=%04X\n"), firmwareResponse->block); // received FW block
|
||||||
|
if (firmwareResponse->block != _firmwareBlock - 1) {
|
||||||
|
OTA_DEBUG(PSTR("!OTA:FWP:WRONG FWB\n")); // received FW block
|
||||||
|
// wrong firmware block received
|
||||||
|
setIndication(INDICATION_FW_UPDATE_RX_ERR);
|
||||||
|
// no further processing required
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
setIndication(INDICATION_FW_UPDATE_RX);
|
||||||
|
// Save block to flash
|
||||||
_flash.writeBytes( ((_firmwareBlock - 1) * FIRMWARE_BLOCK_SIZE) + FIRMWARE_START_OFFSET,
|
_flash.writeBytes( ((_firmwareBlock - 1) * FIRMWARE_BLOCK_SIZE) + FIRMWARE_START_OFFSET,
|
||||||
firmwareResponse->data, FIRMWARE_BLOCK_SIZE);
|
firmwareResponse->data, FIRMWARE_BLOCK_SIZE);
|
||||||
// wait until flash written
|
// wait until flash written
|
||||||
while (_flash.busy()) {}
|
while (_flash.busy()) {}
|
||||||
_firmwareBlock--;
|
_firmwareBlock--;
|
||||||
if (!_firmwareBlock) {
|
if (!_firmwareBlock) {
|
||||||
// We're finished! Do a checksum and reboot.
|
// We're done! Do a checksum and reboot.
|
||||||
OTA_DEBUG(PSTR("OTA:FWP:FW END\n")); // received FW block
|
OTA_DEBUG(PSTR("OTA:FWP:FW END\n")); // received FW block
|
||||||
_firmwareUpdateOngoing = false;
|
_firmwareUpdateOngoing = false;
|
||||||
if (transportIsValidFirmware()) {
|
if (transportIsValidFirmware()) {
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
* |!| OTA | FWP | FLASH INIT FAIL | Failed to initialise flash
|
* |!| OTA | FWP | FLASH INIT FAIL | Failed to initialise flash
|
||||||
* | | OTA | FWP | UPDATE SKIPPED | FW update skipped, no newer version available
|
* | | OTA | FWP | UPDATE SKIPPED | FW update skipped, no newer version available
|
||||||
* | | OTA | FWP | RECV B=%04X | Received FW block (B)
|
* | | OTA | FWP | RECV B=%04X | Received FW block (B)
|
||||||
|
* |!| OTA | FWP | WRONG FWB | Wrong FW block received
|
||||||
* | | OTA | FWP | FW END | FW received, proceed to CRC verification
|
* | | OTA | FWP | FW END | FW received, proceed to CRC verification
|
||||||
* | | OTA | FWP | CRC OK | FW CRC verification OK
|
* | | OTA | FWP | CRC OK | FW CRC verification OK
|
||||||
* |!| OTA | FWP | CRC FAIL | FW CRC verification failed
|
* |!| OTA | FWP | CRC FAIL | FW CRC verification failed
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void SPIFlash::select()
|
|||||||
#ifndef SPI_HAS_TRANSACTION
|
#ifndef SPI_HAS_TRANSACTION
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
#endif
|
#endif
|
||||||
#ifndef ESP8266
|
#if defined(SPCR) && defined(SPSR)
|
||||||
_SPCR = SPCR;
|
_SPCR = SPCR;
|
||||||
_SPSR = SPSR;
|
_SPSR = SPSR;
|
||||||
#endif
|
#endif
|
||||||
@@ -88,7 +88,7 @@ void SPIFlash::unselect()
|
|||||||
#else
|
#else
|
||||||
interrupts();
|
interrupts();
|
||||||
#endif
|
#endif
|
||||||
#ifndef ESP8266
|
#if defined(SPCR) && defined(SPSR)
|
||||||
SPCR = _SPCR;
|
SPCR = _SPCR;
|
||||||
SPSR = _SPSR;
|
SPSR = _SPSR;
|
||||||
#endif
|
#endif
|
||||||
@@ -97,7 +97,7 @@ void SPIFlash::unselect()
|
|||||||
/// setup SPI, read device ID etc...
|
/// setup SPI, read device ID etc...
|
||||||
boolean SPIFlash::initialize()
|
boolean SPIFlash::initialize()
|
||||||
{
|
{
|
||||||
#ifndef ESP8266
|
#if defined(SPCR) && defined(SPSR)
|
||||||
_SPCR = SPCR;
|
_SPCR = SPCR;
|
||||||
_SPSR = SPSR;
|
_SPSR = SPSR;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||||
|
* between your home built sensors/actuators and HA controller of choice.
|
||||||
|
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||||
|
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||||
|
* network topology allowing messages to be routed to nodes.
|
||||||
|
*
|
||||||
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
|
* Copyright (C) 2013-2015 Sensnology AB
|
||||||
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
|
*
|
||||||
|
* Documentation: http://www.mysensors.org
|
||||||
|
* Support Forum: http://forum.mysensors.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
*******************************
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <pins_arduino.h>
|
||||||
|
#define MY_DEBUG
|
||||||
|
#define MY_RADIO_NRF24
|
||||||
|
#define MY_OTA_FIRMWARE_FEATURE
|
||||||
|
#include <MySensors.h>
|
||||||
Reference in New Issue
Block a user