MySensors Library & Examples  2.3.2
MyOTAFirmwareUpdate.h
Go to the documentation of this file.
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6  * network topology allowing messages to be routed to nodes.
7  *
8  * Created by Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2019 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  */
19 
57 #ifndef MyOTAFirmwareUpdate_h
58 #define MyOTAFirmwareUpdate_h
59 
60 #include "MySensorsCore.h"
61 #ifdef MCUBOOT_PRESENT
62 #include "generated_dts_board.h"
63 #define FIRMWARE_PROTOCOL_31
64 #endif
65 
66 #define LOCAL static
67 
68 #if MAX_PAYLOAD_SIZE >= 22
69 #define FIRMWARE_BLOCK_SIZE (16u)
70 #else
71 #define FIRMWARE_BLOCK_SIZE (8u)
72 #ifndef FIRMWARE_PROTOCOL_31
73 #define FIRMWARE_PROTOCOL_31
74 #endif
75 #endif
76 #ifndef MY_OTA_RETRY
77 #define MY_OTA_RETRY (5u)
78 #endif
79 #ifndef MY_OTA_RETRY_DELAY
80 #define MY_OTA_RETRY_DELAY (500u)
81 #endif
82 #ifndef MCUBOOT_PRESENT
83 #define FIRMWARE_START_OFFSET (10u)
84 #else
85 #define FIRMWARE_START_OFFSET (FLASH_AREA_IMAGE_1_OFFSET_0)
86 #endif
87 
88 #define MY_OTA_BOOTLOADER_MAJOR_VERSION (3u)
89 #ifdef FIRMWARE_PROTOCOL_31
90 #define MY_OTA_BOOTLOADER_MINOR_VERSION (1u)
91 #else
92 #define MY_OTA_BOOTLOADER_MINOR_VERSION (0u)
93 #endif
94 #define MY_OTA_BOOTLOADER_VERSION (MY_OTA_BOOTLOADER_MINOR_VERSION * 256 + MY_OTA_BOOTLOADER_MAJOR_VERSION)
95 
96 #if defined(MY_DEBUG_VERBOSE_OTA_UPDATE)
97 #define OTA_DEBUG(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__)
98 //#define OTA_EXTRA_FLASH_DEBUG
99 #else
100 #define OTA_DEBUG(x,...)
101 #endif
102 
103 #if defined(DOXYGEN) && !defined(FIRMWARE_PROTOCOL_31)
104 
111 #define FIRMWARE_PROTOCOL_31
112 #endif
113 
117 typedef struct {
118  uint16_t type;
119  uint16_t version;
120  uint16_t blocks;
121  uint16_t crc;
122 } __attribute__((packed)) nodeFirmwareConfig_t;
123 
127 typedef struct {
128  uint16_t type;
129  uint16_t version;
130  uint16_t blocks;
131  uint16_t crc;
132  uint16_t BLVersion;
133 #ifdef FIRMWARE_PROTOCOL_31
134  uint8_t blockSize;
135  uint8_t img_commited;
136  uint16_t img_revision;
137  uint32_t img_build_num;
138 #endif
139 } __attribute__((packed)) requestFirmwareConfig_t;
140 
144 typedef struct {
145  uint16_t type;
146  uint16_t version;
147  uint16_t block;
148 } __attribute__((packed)) requestFirmwareBlock_t;
149 
153 typedef struct {
154  uint16_t type;
155  uint16_t version;
156  uint16_t block;
158 } __attribute__((packed)) replyFirmwareBlock_t;
159 
163 typedef struct {
164  uint16_t type;
165  uint16_t version;
166  uint16_t block;
167  uint16_t number_of_blocks;
168  uint8_t data;
169 } __attribute__((packed)) replyFirmwareBlockRLE_t;
170 
176 LOCAL void readFirmwareSettings(void);
197 
198 #endif
199 
data
char data[MAX_PAYLOAD_SIZE+1]
Buffer for raw payload data.
Definition: MyMessage.h:653
type
uint8_t type
8 bit - Type varies depending on command
Definition: MyMessage.h:353
__attribute__::block
uint16_t block
Block index.
Definition: MyOTAFirmwareUpdate.h:147
__attribute__::img_build_num
uint32_t img_build_num
mcuboot build_num attribute, when protocol version >= 3.1 is reported
Definition: MyOTAFirmwareUpdate.h:137
__attribute__::number_of_blocks
uint16_t number_of_blocks
Number of blocks to fill with data.
Definition: MyOTAFirmwareUpdate.h:167
MySensorsCore.h
transportIsValidFirmware
LOCAL bool transportIsValidFirmware(void)
Validate uploaded FW CRC.
firmwareOTAUpdateRequest
LOCAL void firmwareOTAUpdateRequest(void)
Handle OTA FW update requests.
__attribute__::img_revision
uint16_t img_revision
mcuboot revision attribute, when protocol version >= 3.1 is reported
Definition: MyOTAFirmwareUpdate.h:136
presentBootloaderInformation
LOCAL void presentBootloaderInformation(void)
Present bootloader/FW information upon startup.
__attribute__::version
uint16_t version
Version of config.
Definition: MyOTAFirmwareUpdate.h:119
__attribute__::img_commited
uint8_t img_commited
mcuboot image_ok attribute commited firmware=0x01(mcuboot)|0x02(DualOptiboot), when protocol version ...
Definition: MyOTAFirmwareUpdate.h:135
LOCAL
#define LOCAL
static
Definition: MyOTAFirmwareUpdate.h:66
__attribute__::type
uint16_t type
Type of config.
Definition: MyOTAFirmwareUpdate.h:118
__attribute__
struct @4::@5 __attribute__
Doxygen will complain without this comment.
Definition: DigitalPin.h:65
firmwareOTAUpdateProcess
LOCAL bool firmwareOTAUpdateProcess(void)
Handle OTA FW update responses.
readFirmwareSettings
LOCAL void readFirmwareSettings(void)
Read firmware settings from EEPROM.
__attribute__::blocks
uint16_t blocks
Number of blocks.
Definition: MyOTAFirmwareUpdate.h:120
__attribute__::BLVersion
uint16_t BLVersion
Bootloader version.
Definition: MyOTAFirmwareUpdate.h:132
__attribute__::crc
uint16_t crc
CRC of block data.
Definition: MyOTAFirmwareUpdate.h:121
__attribute__::blockSize
uint8_t blockSize
Blocksize, when protocol version >= 3.1 is reported. Otherwhise the blocksize is 16.
Definition: MyOTAFirmwareUpdate.h:134
FIRMWARE_BLOCK_SIZE
#define FIRMWARE_BLOCK_SIZE
Size of each firmware block.
Definition: MyOTAFirmwareUpdate.h:69