Skip to content

Commit aa2d71a

Browse files
committed
Add start_ota function to make code more readable
1 parent 7b12ae8 commit aa2d71a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

app/main.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
204213
int 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

Comments
 (0)