Skip to content

Commit 8414450

Browse files
committed
[nrf noup] boot: bootutil: loader: Add error codes to log messages
Adds error codes to some messages, also formats others to fit more onto less lines for easier readability and searching using grep Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no> Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
1 parent 9ca3dd0 commit 8414450

2 files changed

Lines changed: 31 additions & 43 deletions

File tree

boot/bootutil/src/loader.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
791791
#endif
792792
!boot_check_header_erased(state, BOOT_SLOT_PRIMARY)
793793
) {
794-
BOOT_LOG_ERR("insufficient version in secondary slot");
794+
BOOT_LOG_ERR("Insufficient version in secondary slot");
795795
boot_scramble_slot(fap, slot);
796796
/* Image in the secondary slot does not satisfy version requirement.
797797
* Erase the image and continue booting from the primary slot.
@@ -1674,7 +1674,7 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
16741674
*/
16751675
rc = boot_update_security_counter(state, BOOT_SLOT_PRIMARY, BOOT_SLOT_SECONDARY);
16761676
if (rc != 0) {
1677-
BOOT_LOG_ERR("Security counter update failed after image upgrade.");
1677+
BOOT_LOG_ERR("Security counter update failed after image upgrade: %d", rc);
16781678
return rc;
16791679
}
16801680
#endif /* MCUBOOT_HW_ROLLBACK_PROT */
@@ -1932,8 +1932,7 @@ boot_perform_update(struct boot_loader_state *state, struct boot_status *bs)
19321932
*/
19331933
rc = boot_update_security_counter(state, BOOT_SLOT_PRIMARY, BOOT_SLOT_SECONDARY);
19341934
if (rc != 0) {
1935-
BOOT_LOG_ERR("Security counter update failed after "
1936-
"image upgrade.");
1935+
BOOT_LOG_ERR("Security counter update failed after image upgrade: %d", rc);
19371936
BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
19381937
}
19391938
}
@@ -2277,16 +2276,16 @@ boot_update_hw_rollback_protection(struct boot_loader_state *state)
22772276
if (swap_state.magic != BOOT_MAGIC_GOOD || swap_state.image_ok == BOOT_FLAG_SET) {
22782277
rc = boot_update_security_counter(state, BOOT_SLOT_PRIMARY, BOOT_SLOT_PRIMARY);
22792278
if (rc != 0) {
2280-
BOOT_LOG_ERR("Security counter update failed after image %d validation.",
2281-
BOOT_CURR_IMG(state));
2279+
BOOT_LOG_ERR("Security counter update failed after image %d validation: %d",
2280+
BOOT_CURR_IMG(state), rc);
22822281
return rc;
22832282
}
22842283

22852284
#ifdef MCUBOOT_HW_ROLLBACK_PROT_LOCK
22862285
rc = boot_nv_security_counter_lock(BOOT_CURR_IMG(state));
22872286
if (rc != 0) {
2288-
BOOT_LOG_ERR("Security counter lock failed after image %d validation.",
2289-
BOOT_CURR_IMG(state));
2287+
BOOT_LOG_ERR("Security counter lock failed after image %d validation: %d",
2288+
BOOT_CURR_IMG(state), rc);
22902289
return rc;
22912290
}
22922291
#endif /* MCUBOOT_HW_ROLLBACK_PROT_LOCK */
@@ -2425,8 +2424,8 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
24252424
/* Determine the sector layout of the image slots and scratch area. */
24262425
rc = boot_read_sectors(state, sectors);
24272426
if (rc != 0) {
2428-
BOOT_LOG_WRN("Failed reading sectors; BOOT_MAX_IMG_SECTORS=%d"
2429-
" - too small?", BOOT_MAX_IMG_SECTORS);
2427+
BOOT_LOG_WRN("Failed reading sectors; BOOT_MAX_IMG_SECTORS=%d - too small?",
2428+
BOOT_MAX_IMG_SECTORS);
24302429
BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE;
24312430
}
24322431

@@ -2611,7 +2610,7 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
26112610
* the magic number on the image is OK.
26122611
*/
26132612
if (BOOT_IMG(state, BOOT_SLOT_PRIMARY).hdr.ih_magic != IMAGE_MAGIC) {
2614-
BOOT_LOG_ERR("bad image magic 0x%lx; Image=%u", (unsigned long)
2613+
BOOT_LOG_ERR("Bad image magic 0x%lx; Image=%u", (unsigned long)
26152614
BOOT_IMG(state, BOOT_SLOT_PRIMARY).hdr.ih_magic,
26162615
BOOT_CURR_IMG(state));
26172616
rc = BOOT_EBADIMAGE;
@@ -2784,10 +2783,8 @@ boot_get_slot_usage(struct boot_loader_state *state)
27842783
BOOT_LOG_IMAGE_INFO(slot, hdr);
27852784
} else {
27862785
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2787-
BOOT_LOG_INF("Image %d %s slot: Image not found",
2788-
BOOT_CURR_IMG(state),
2789-
(slot == BOOT_SLOT_PRIMARY)
2790-
? "Primary" : "Secondary");
2786+
BOOT_LOG_INF("Image %d %s slot: image not found", BOOT_CURR_IMG(state),
2787+
(slot == BOOT_SLOT_PRIMARY) ? "primary" : "secondary");
27912788
}
27922789
}
27932790

@@ -2855,10 +2852,8 @@ print_loaded_images(struct boot_loader_state *state)
28552852
#endif
28562853
active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
28572854

2858-
BOOT_LOG_INF("Image %d loaded from the %s slot",
2859-
BOOT_CURR_IMG(state),
2860-
(active_slot == BOOT_SLOT_PRIMARY) ?
2861-
"primary" : "secondary");
2855+
BOOT_LOG_INF("Image %d loaded from the %s slot", BOOT_CURR_IMG(state),
2856+
(active_slot == BOOT_SLOT_PRIMARY) ? "primary" : "secondary");
28622857
}
28632858
}
28642859
#endif
@@ -2951,9 +2946,8 @@ boot_select_or_erase(struct boot_loader_state *state)
29512946
*/
29522947
rc = boot_write_copy_done(fap);
29532948
if (rc != 0) {
2954-
BOOT_LOG_WRN("Failed to set copy_done flag of the image in "
2955-
"the %s slot.", (active_slot == BOOT_SLOT_PRIMARY) ?
2956-
"primary" : "secondary");
2949+
BOOT_LOG_WRN("Failed to set copy_done flag of the image in the %s slot.",
2950+
(active_slot == BOOT_SLOT_PRIMARY) ? "primary" : "secondary");
29572951
rc = 0;
29582952
}
29592953
}
@@ -2997,8 +2991,7 @@ boot_load_and_validate_images(struct boot_loader_state *state)
29972991
}
29982992

29992993
if (active_slot == BOOT_SLOT_NONE) {
3000-
BOOT_LOG_INF("No slot to load for image %d",
3001-
BOOT_CURR_IMG(state));
2994+
BOOT_LOG_INF("No slot to load for image %d", BOOT_CURR_IMG(state));
30022995
FIH_RET(FIH_FAILURE);
30032996
}
30042997

@@ -3094,16 +3087,16 @@ boot_update_hw_rollback_protection(struct boot_loader_state *state)
30943087
state->slot_usage[BOOT_CURR_IMG(state)].active_slot,
30953088
state->slot_usage[BOOT_CURR_IMG(state)].active_slot);
30963089
if (rc != 0) {
3097-
BOOT_LOG_ERR("Security counter update failed after image %d validation.",
3098-
BOOT_CURR_IMG(state));
3090+
BOOT_LOG_ERR("Security counter update failed after image %d validation: %d",
3091+
BOOT_CURR_IMG(state), rc);
30993092
return rc;
31003093
}
31013094

31023095
#ifdef MCUBOOT_HW_ROLLBACK_PROT_LOCK
31033096
rc = boot_nv_security_counter_lock(BOOT_CURR_IMG(state));
31043097
if (rc != 0) {
3105-
BOOT_LOG_ERR("Security counter lock failed after image %d validation.",
3106-
BOOT_CURR_IMG(state));
3098+
BOOT_LOG_ERR("Security counter lock failed after image %d validation: %d",
3099+
BOOT_CURR_IMG(state), rc);
31073100
return rc;
31083101
}
31093102
#endif /* MCUBOOT_HW_ROLLBACK_PROT_LOCK */

boot/bootutil/src/loader_manifest_xip.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,8 @@ boot_get_slot_usage(struct boot_loader_state *state)
255255
BOOT_LOG_IMAGE_INFO(slot, boot_img_hdr(state, slot));
256256
} else {
257257
state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
258-
BOOT_LOG_INF("Image %d %s slot: Image not found",
259-
BOOT_CURR_IMG(state),
260-
(slot == BOOT_SLOT_PRIMARY)
261-
? "Primary" : "Secondary");
258+
BOOT_LOG_INF("Image %d %s slot: image not found", BOOT_CURR_IMG(state),
259+
(slot == BOOT_SLOT_PRIMARY) ? "primary" : "secondary");
262260
}
263261
}
264262

@@ -319,10 +317,8 @@ print_loaded_images(struct boot_loader_state *state)
319317
IMAGES_ITER(BOOT_CURR_IMG(state)) {
320318
active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
321319

322-
BOOT_LOG_INF("Image %d loaded from the %s slot",
323-
BOOT_CURR_IMG(state),
324-
(active_slot == BOOT_SLOT_PRIMARY) ?
325-
"primary" : "secondary");
320+
BOOT_LOG_INF("Image %d loaded from the %s slot", BOOT_CURR_IMG(state),
321+
(active_slot == BOOT_SLOT_PRIMARY) ? "primary" : "secondary");
326322
}
327323
}
328324
#endif
@@ -418,9 +414,8 @@ boot_select_or_erase(struct boot_loader_state *state)
418414
*/
419415
rc = boot_write_copy_done(fap);
420416
if (rc != 0) {
421-
BOOT_LOG_WRN("Failed to set copy_done flag of the image in "
422-
"the %s slot.", (active_slot == BOOT_SLOT_PRIMARY) ?
423-
"primary" : "secondary");
417+
BOOT_LOG_WRN("Failed to set copy_done flag of the image in the %s slot.",
418+
(active_slot == BOOT_SLOT_PRIMARY) ? "primary" : "secondary");
424419
rc = 0;
425420
}
426421
}
@@ -595,16 +590,16 @@ boot_update_hw_rollback_protection(struct boot_loader_state *state)
595590
state->slot_usage[BOOT_CURR_IMG(state)].active_slot,
596591
state->slot_usage[BOOT_CURR_IMG(state)].active_slot);
597592
if (rc != 0) {
598-
BOOT_LOG_ERR("Security counter update failed after image %d validation.",
599-
BOOT_CURR_IMG(state));
593+
BOOT_LOG_ERR("Security counter update failed after image %d validation: %d",
594+
BOOT_CURR_IMG(state), rc);
600595
return rc;
601596
}
602597

603598
#ifdef MCUBOOT_HW_ROLLBACK_PROT_LOCK
604599
rc = boot_nv_security_counter_lock(BOOT_CURR_IMG(state));
605600
if (rc != 0) {
606-
BOOT_LOG_ERR("Security counter lock failed after image %d validation.",
607-
BOOT_CURR_IMG(state));
601+
BOOT_LOG_ERR("Security counter lock failed after image %d validation: %d",
602+
BOOT_CURR_IMG(state), rc);
608603
return rc;
609604
}
610605
#endif /* MCUBOOT_HW_ROLLBACK_PROT_LOCK */

0 commit comments

Comments
 (0)