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