@@ -201,6 +201,15 @@ int start_secure_application(void) {
201201 mbed_start_application (address);
202202}
203203
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+
204213int main (void ) {
205214 debug_init ();
206215
@@ -243,13 +252,8 @@ int main(void) {
243252 if (boot_empty_keys ()) {
244253 BOOT_LOG_INF (" Secure keys not configured" );
245254 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 ();
253257 if (ota_result == 0 ) {
254258 // clean reboot with success flag
255259 BOOT_LOG_INF (" Sketch updated" );
0 commit comments