@@ -154,14 +154,35 @@ int main() {
154
154
{
155
155
WiFiStorageFile update_file = WiFiStorage.open (UPDATE_FILE_NAME_LZSS);
156
156
157
+ union HeaderVersion
158
+ {
159
+ typedef struct __attribute__ ((packed))
160
+ {
161
+ uint32_t header_version : 6 ;
162
+ uint32_t compression : 1 ;
163
+ uint32_t signature : 1 ;
164
+ uint32_t spare : 4 ;
165
+ uint32_t payload_target : 4 ;
166
+ uint32_t payload_major : 8 ;
167
+ uint32_t payload_minor : 8 ;
168
+ uint32_t payload_patch : 8 ;
169
+ uint32_t payload_build_num : 24 ;
170
+ } field;
171
+ uint8_t buf[sizeof (field)];
172
+ static_assert (sizeof (buf) == 8 , " Error: sizeof(HEADER.VERSION) != 8" );
173
+ };
174
+
157
175
union
158
176
{
159
177
struct __attribute__ ((packed))
160
178
{
161
179
uint32_t len;
162
180
uint32_t crc32;
181
+ uint32_t magic_number;
182
+ HeaderVersion hdr_version;
163
183
} header;
164
184
uint8_t buf[sizeof (header)];
185
+ static_assert (sizeof (buf) == 20 , " Error: sizeof(HEADER) != 20" );
165
186
} ota_header;
166
187
uint32_t crc32, bytes_read;
167
188
uint8_t crc_buf[128 ];
@@ -170,12 +191,15 @@ int main() {
170
191
update_file.read (ota_header.buf , sizeof (ota_header.buf ));
171
192
172
193
/* ... and check first length ... */
173
- if (ota_header.header .len != (update_file.size () - sizeof (ota_header.buf ))) {
194
+ if (ota_header.header .len != (update_file.size () - sizeof (ota_header.header . len ) - sizeof (ota_header. header . crc32 ))) {
174
195
update_file.close ();
175
196
update_file.erase ();
176
197
goto boot;
177
198
}
178
- /* ... and the CRC second ... initialize CRC ... */
199
+
200
+ /* ... and the CRC second ... rewind to start of CRC verified header ... */
201
+ update_file.seek (sizeof (ota_header.header .len ) + sizeof (ota_header.header .crc32 ));
202
+ /* ... initialize CRC ... */
179
203
crc32 = 0xFFFFFFFF ;
180
204
/* ... and calculate over file ... */
181
205
for (bytes_read = 0 ;
0 commit comments