3434#include " FlashIAPBlockDevice.h"
3535#include " utility/ota/FlashSHA256.h"
3636
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+
3762/* *****************************************************************************
3863 * FUNCTION DEFINITION
3964 ******************************************************************************/
@@ -92,7 +117,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
92117 if ((err = flash.init ()) < 0 )
93118 {
94119 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);
96121 }
97122
98123 watchdog_reset ();
@@ -105,7 +130,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
105130 if ((err = fs.reformat (&flash)) != 0 )
106131 {
107132 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);
109134 }
110135
111136 watchdog_reset ();
@@ -115,7 +140,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
115140 {
116141 DEBUG_ERROR (" %s: fopen() failed" , __FUNCTION__);
117142 fclose (file);
118- return static_cast <int >(OTAError ::RP2040_ErrorOpenUpdateFile);
143+ return static_cast <int >(rp2040OTAError ::RP2040_ErrorOpenUpdateFile);
119144 }
120145
121146 watchdog_reset ();
@@ -133,7 +158,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
133158 } else {
134159 DEBUG_ERROR (" %s: Failed to parse OTA URL %s" , __FUNCTION__, ota_url);
135160 fclose (file);
136- return static_cast <int >(OTAError ::RP2040_UrlParseError);
161+ return static_cast <int >(rp2040OTAError ::RP2040_UrlParseError);
137162 }
138163
139164 watchdog_reset ();
@@ -142,7 +167,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
142167 {
143168 DEBUG_ERROR (" %s: Connection failure with OTA storage server %s" , __FUNCTION__, url.host_ .c_str ());
144169 fclose (file);
145- return static_cast <int >(OTAError ::RP2040_ServerConnectError);
170+ return static_cast <int >(rp2040OTAError ::RP2040_ServerConnectError);
146171 }
147172
148173 watchdog_reset ();
@@ -179,7 +204,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
179204 {
180205 DEBUG_ERROR (" %s: Error receiving HTTP header %s" , __FUNCTION__, is_http_header_timeout ? " (timeout)" :" " );
181206 fclose (file);
182- return static_cast <int >(OTAError ::RP2040_HttpHeaderError);
207+ return static_cast <int >(rp2040OTAError ::RP2040_HttpHeaderError);
183208 }
184209
185210 /* Extract concent length from HTTP header. A typical entry looks like
@@ -190,7 +215,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
190215 {
191216 DEBUG_ERROR (" %s: Failure to extract content length from http header" , __FUNCTION__);
192217 fclose (file);
193- return static_cast <int >(OTAError ::RP2040_ErrorParseHttpHeader);
218+ return static_cast <int >(rp2040OTAError ::RP2040_ErrorParseHttpHeader);
194219 }
195220 /* Find start of numerical value. */
196221 char * ptr = const_cast <char *>(content_length_ptr);
@@ -219,7 +244,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
219244 {
220245 DEBUG_ERROR (" %s: Writing of firmware image to flash failed" , __FUNCTION__);
221246 fclose (file);
222- return static_cast <int >(OTAError ::RP2040_ErrorWriteUpdateFile);
247+ return static_cast <int >(rp2040OTAError ::RP2040_ErrorWriteUpdateFile);
223248 }
224249
225250 bytes_received++;
@@ -229,7 +254,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
229254 if (bytes_received != content_length_val) {
230255 DEBUG_ERROR (" %s: Error receiving HTTP data %s (%d bytes received, %d expected)" , __FUNCTION__, is_http_data_timeout ? " (timeout)" :" " , bytes_received, content_length_val);
231256 fclose (file);
232- return static_cast <int >(OTAError ::RP2040_HttpDataError);
257+ return static_cast <int >(rp2040OTAError ::RP2040_HttpDataError);
233258 }
234259
235260 DEBUG_INFO (" %s: %d bytes received" , __FUNCTION__, ftell (file));
@@ -239,15 +264,15 @@ int rp2040_connect_onOTARequest(char const * ota_url)
239264 if ((err = fs.unmount ()) != 0 )
240265 {
241266 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);
243268 }
244269
245270 /* Perform the reset to reboot to SFU. */
246271 mbed_watchdog_trigger_reset ();
247272 /* If watchdog is enabled we should not reach this point */
248273 NVIC_SystemReset ();
249274
250- return static_cast <int >(OTAError ::None);
275+ return static_cast <int >(rp2040OTAError ::None);
251276}
252277
253278String rp2040_connect_getOTAImageSHA256 ()
0 commit comments