Skip to content

Commit c493d3d

Browse files
moved header outside of decompress function
1 parent 9166de0 commit c493d3d

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

src/decompress/utility.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,37 @@ uint32_t crc_update(uint32_t crc, const void * data, size_t data_len)
8989
MAIN
9090
**************************************************************************************/
9191

92+
union HeaderVersion
93+
{
94+
struct __attribute__((packed))
95+
{
96+
uint32_t header_version : 6;
97+
uint32_t compression : 1;
98+
uint32_t signature : 1;
99+
uint32_t spare : 4;
100+
uint32_t payload_target : 4;
101+
uint32_t payload_major : 8;
102+
uint32_t payload_minor : 8;
103+
uint32_t payload_patch : 8;
104+
uint32_t payload_build_num : 24;
105+
} field;
106+
uint8_t buf[sizeof(field)];
107+
static_assert(sizeof(buf) == 8, "Error: sizeof(HEADER.VERSION) != 8");
108+
};
109+
110+
union OTAHeader
111+
{
112+
struct __attribute__((packed))
113+
{
114+
uint32_t len;
115+
uint32_t crc32;
116+
uint32_t magic_number;
117+
HeaderVersion hdr_version;
118+
} header;
119+
uint8_t buf[sizeof(header)];
120+
static_assert(sizeof(buf) == 20, "Error: sizeof(HEADER) != 20");
121+
};
122+
92123
int Arduino_Portenta_OTA::download(const char * url, bool const is_https, MbedSocketClass * socket)
93124
{
94125
return socket->download((char *)url, UPDATE_FILE_NAME_LZSS, is_https);
@@ -103,36 +134,7 @@ int Arduino_Portenta_OTA::decompress()
103134
/* For UPDATE.BIN.LZSS - LZSS compressed binary files. */
104135
FILE* update_file = fopen(UPDATE_FILE_NAME_LZSS, "rb");
105136

106-
union HeaderVersion
107-
{
108-
struct __attribute__((packed))
109-
{
110-
uint32_t header_version : 6;
111-
uint32_t compression : 1;
112-
uint32_t signature : 1;
113-
uint32_t spare : 4;
114-
uint32_t payload_target : 4;
115-
uint32_t payload_major : 8;
116-
uint32_t payload_minor : 8;
117-
uint32_t payload_patch : 8;
118-
uint32_t payload_build_num : 24;
119-
} field;
120-
uint8_t buf[sizeof(field)];
121-
static_assert(sizeof(buf) == 8, "Error: sizeof(HEADER.VERSION) != 8");
122-
};
123-
124-
union
125-
{
126-
struct __attribute__((packed))
127-
{
128-
uint32_t len;
129-
uint32_t crc32;
130-
uint32_t magic_number;
131-
HeaderVersion hdr_version;
132-
} header;
133-
uint8_t buf[sizeof(header)];
134-
static_assert(sizeof(buf) == 20, "Error: sizeof(HEADER) != 20");
135-
} ota_header;
137+
OTAHeader ota_header;
136138
uint32_t crc32, bytes_read;
137139
uint8_t crc_buf[128];
138140

0 commit comments

Comments
 (0)