21
21
* INCLUDE
22
22
******************************************************************************/
23
23
24
- #include " OTA.h"
25
-
26
- #include " ../watchdog/Watchdog.h"
27
-
28
- #include < Arduino_DebugUtils.h>
29
-
30
24
#include < SFU.h>
31
25
32
26
#include " mbed.h"
33
27
#include " FATFileSystem.h"
34
28
#include " FlashIAPBlockDevice.h"
35
29
#include " utility/ota/FlashSHA256.h"
36
30
31
+ #include " ../watchdog/Watchdog.h"
32
+
33
+ #include < Arduino_DebugUtils.h>
34
+
35
+ /* *****************************************************************************
36
+ * DEFINES
37
+ ******************************************************************************/
38
+
39
+ #define RP2040_OTA_ERROR_BASE (-100 )
40
+
41
+ /* *****************************************************************************
42
+ * TYPEDEF
43
+ ******************************************************************************/
44
+
45
+ enum class rp2040OTAError : int
46
+ {
47
+ None = 0 ,
48
+ ErrorFlashInit = RP2040_OTA_ERROR_BASE - 3 ,
49
+ ErrorParseHttpHeader = RP2040_OTA_ERROR_BASE - 8 ,
50
+ UrlParseError = RP2040_OTA_ERROR_BASE - 9 ,
51
+ ServerConnectError = RP2040_OTA_ERROR_BASE - 10 ,
52
+ HttpHeaderError = RP2040_OTA_ERROR_BASE - 11 ,
53
+ HttpDataError = RP2040_OTA_ERROR_BASE - 12 ,
54
+ ErrorOpenUpdateFile = RP2040_OTA_ERROR_BASE - 19 ,
55
+ ErrorWriteUpdateFile = RP2040_OTA_ERROR_BASE - 20 ,
56
+ ErrorReformat = RP2040_OTA_ERROR_BASE - 21 ,
57
+ ErrorUnmount = RP2040_OTA_ERROR_BASE - 22 ,
58
+ };
59
+
37
60
/* *****************************************************************************
38
61
* FUNCTION DEFINITION
39
62
******************************************************************************/
@@ -92,7 +115,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
92
115
if ((err = flash.init ()) < 0 )
93
116
{
94
117
DEBUG_ERROR (" %s: flash.init() failed with %d" , __FUNCTION__, err);
95
- return static_cast <int >(OTAError::RP2040_ErrorFlashInit );
118
+ return static_cast <int >(rp2040OTAError::ErrorFlashInit );
96
119
}
97
120
98
121
watchdog_reset ();
@@ -105,7 +128,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
105
128
if ((err = fs.reformat (&flash)) != 0 )
106
129
{
107
130
DEBUG_ERROR (" %s: fs.reformat() failed with %d" , __FUNCTION__, err);
108
- return static_cast <int >(OTAError::RP2040_ErrorReformat );
131
+ return static_cast <int >(rp2040OTAError::ErrorReformat );
109
132
}
110
133
111
134
watchdog_reset ();
@@ -115,7 +138,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
115
138
{
116
139
DEBUG_ERROR (" %s: fopen() failed" , __FUNCTION__);
117
140
fclose (file);
118
- return static_cast <int >(OTAError::RP2040_ErrorOpenUpdateFile );
141
+ return static_cast <int >(rp2040OTAError::ErrorOpenUpdateFile );
119
142
}
120
143
121
144
watchdog_reset ();
@@ -133,7 +156,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
133
156
} else {
134
157
DEBUG_ERROR (" %s: Failed to parse OTA URL %s" , __FUNCTION__, ota_url);
135
158
fclose (file);
136
- return static_cast <int >(OTAError::RP2040_UrlParseError );
159
+ return static_cast <int >(rp2040OTAError::UrlParseError );
137
160
}
138
161
139
162
watchdog_reset ();
@@ -142,7 +165,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
142
165
{
143
166
DEBUG_ERROR (" %s: Connection failure with OTA storage server %s" , __FUNCTION__, url.host_ .c_str ());
144
167
fclose (file);
145
- return static_cast <int >(OTAError::RP2040_ServerConnectError );
168
+ return static_cast <int >(rp2040OTAError::ServerConnectError );
146
169
}
147
170
148
171
watchdog_reset ();
@@ -179,7 +202,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
179
202
{
180
203
DEBUG_ERROR (" %s: Error receiving HTTP header %s" , __FUNCTION__, is_http_header_timeout ? " (timeout)" :" " );
181
204
fclose (file);
182
- return static_cast <int >(OTAError::RP2040_HttpHeaderError );
205
+ return static_cast <int >(rp2040OTAError::HttpHeaderError );
183
206
}
184
207
185
208
/* Extract concent length from HTTP header. A typical entry looks like
@@ -190,7 +213,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
190
213
{
191
214
DEBUG_ERROR (" %s: Failure to extract content length from http header" , __FUNCTION__);
192
215
fclose (file);
193
- return static_cast <int >(OTAError::RP2040_ErrorParseHttpHeader );
216
+ return static_cast <int >(rp2040OTAError::ErrorParseHttpHeader );
194
217
}
195
218
/* Find start of numerical value. */
196
219
char * ptr = const_cast <char *>(content_length_ptr);
@@ -219,7 +242,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
219
242
{
220
243
DEBUG_ERROR (" %s: Writing of firmware image to flash failed" , __FUNCTION__);
221
244
fclose (file);
222
- return static_cast <int >(OTAError::RP2040_ErrorWriteUpdateFile );
245
+ return static_cast <int >(rp2040OTAError::ErrorWriteUpdateFile );
223
246
}
224
247
225
248
bytes_received++;
@@ -229,7 +252,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
229
252
if (bytes_received != content_length_val) {
230
253
DEBUG_ERROR (" %s: Error receiving HTTP data %s (%d bytes received, %d expected)" , __FUNCTION__, is_http_data_timeout ? " (timeout)" :" " , bytes_received, content_length_val);
231
254
fclose (file);
232
- return static_cast <int >(OTAError::RP2040_HttpDataError );
255
+ return static_cast <int >(rp2040OTAError::HttpDataError );
233
256
}
234
257
235
258
DEBUG_INFO (" %s: %d bytes received" , __FUNCTION__, ftell (file));
@@ -239,15 +262,15 @@ int rp2040_connect_onOTARequest(char const * ota_url)
239
262
if ((err = fs.unmount ()) != 0 )
240
263
{
241
264
DEBUG_ERROR (" %s: fs.unmount() failed with %d" , __FUNCTION__, err);
242
- return static_cast <int >(OTAError::RP2040_ErrorUnmount );
265
+ return static_cast <int >(rp2040OTAError::ErrorUnmount );
243
266
}
244
267
245
268
/* Perform the reset to reboot to SFU. */
246
269
mbed_watchdog_trigger_reset ();
247
270
/* If watchdog is enabled we should not reach this point */
248
271
NVIC_SystemReset ();
249
272
250
- return static_cast <int >(OTAError ::None);
273
+ return static_cast <int >(rp2040OTAError ::None);
251
274
}
252
275
253
276
String rp2040_connect_getOTAImageSHA256 ()
0 commit comments