@@ -201,6 +201,15 @@ int start_secure_application(void) {
201
201
mbed_start_application (address);
202
202
}
203
203
204
+ static int start_ota (void ) {
205
+ // DR1 contains the backing storage type, DR2 the offset in case of raw device / MBR
206
+ storageType storage_type = (storageType)RTCGetBKPRegister (RTC_BKP_DR1);
207
+ uint32_t offset = RTCGetBKPRegister (RTC_BKP_DR2);
208
+ uint32_t update_size = RTCGetBKPRegister (RTC_BKP_DR3);
209
+ BOOT_LOG_INF (" Start OTA 0x%X 0x%X 0x%X" , storage_type, offset, update_size);
210
+ return tryOTA (storage_type, offset, update_size);
211
+ }
212
+
204
213
int main (void ) {
205
214
debug_init ();
206
215
@@ -243,13 +252,8 @@ int main(void) {
243
252
if (boot_empty_keys ()) {
244
253
BOOT_LOG_INF (" Secure keys not configured" );
245
254
if ( magic == 0x07AA ) {
246
- /* Try unsecure OTA */
247
- // DR1 contains the backing storage type, DR2 the offset in case of raw device / MBR
248
- storageType storage_type = (storageType)RTCGetBKPRegister (RTC_BKP_DR1);
249
- uint32_t offset = RTCGetBKPRegister (RTC_BKP_DR2);
250
- uint32_t update_size = RTCGetBKPRegister (RTC_BKP_DR3);
251
- BOOT_LOG_INF (" Start OTA 0x%X 0x%X 0x%X" , storage_type, offset, update_size);
252
- int ota_result = tryOTA (storage_type, offset, update_size);
255
+ /* Start OTA */
256
+ int ota_result = start_ota ();
253
257
if (ota_result == 0 ) {
254
258
// clean reboot with success flag
255
259
BOOT_LOG_INF (" Sketch updated" );
0 commit comments