@@ -82,16 +82,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
82
82
{
83
83
SFU::begin ();
84
84
85
- mbed_watchdog_reset ();
86
-
87
- #if 0
88
- /* Just to be safe delete any remains from previous updates. */
89
- struct stat st;
90
- int err = stat("/ota/UPDATE.BIN", &st);
91
- if (err == 0) {
92
- remove("/ota/UPDATE.BIN");
93
- }
94
- #endif
85
+ mbed_watchdog_reset ();
95
86
96
87
URI url (ota_url);
97
88
Client * client = nullptr ;
@@ -136,7 +127,6 @@ int rp2040_connect_onOTARequest(char const * ota_url)
136
127
137
128
/* Receive HTTP header. */
138
129
String http_header;
139
-
140
130
for (bool is_header_complete = false ; client->connected () && !is_header_complete; )
141
131
{
142
132
if (client->available ())
@@ -168,6 +158,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
168
158
else
169
159
{
170
160
DEBUG_ERROR (" %s: Failure to extract content length from http header" , __FUNCTION__);
161
+ fclose (file);
171
162
return static_cast <int >(OTAError::RP2040_ErrorParseHttpHeader);
172
163
}
173
164
@@ -183,19 +174,18 @@ int rp2040_connect_onOTARequest(char const * ota_url)
183
174
if (fwrite (&c, 1 , sizeof (c), file) != sizeof (c))
184
175
{
185
176
DEBUG_ERROR (" %s: Writing of firmware image to flash failed" , __FUNCTION__);
177
+ fclose (file);
186
178
return static_cast <int >(OTAError::RP2040_ErrorWriteUpdateFile);
187
179
}
188
180
189
181
bytes_received++;
190
182
}
191
183
}
192
184
185
+ /* Determine length. */
193
186
int const file_len = ftell (file);
194
- DEBUG_DEBUG (" %s: %d bytes received" , __FUNCTION__, file_len);
195
-
196
- mbed_watchdog_reset ();
197
-
198
187
fclose (file);
188
+ DEBUG_DEBUG (" %s: %d bytes received" , __FUNCTION__, file_len);
199
189
200
190
/* Perform the reset to reboot to SxU. */
201
191
NVIC_SystemReset ();
0 commit comments