From d5cca5adb138d9cdcdca1400146062c3362634fa Mon Sep 17 00:00:00 2001 From: Dane Wagner Date: Wed, 4 Dec 2024 10:46:40 -0600 Subject: [PATCH] boot: zephyr: boot_record: Save boot data with single image Ensure that bootloader info and measurements are saved to retained memory when using mcuboot in single-image mode. Signed-off-by: Dane Wagner --- boot/bootutil/src/boot_record.c | 6 ++++++ boot/zephyr/single_loader.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/boot/bootutil/src/boot_record.c b/boot/bootutil/src/boot_record.c index f6ed2a723..d6c235af9 100644 --- a/boot/bootutil/src/boot_record.c +++ b/boot/bootutil/src/boot_record.c @@ -237,7 +237,9 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are const uint8_t slot, const struct image_max_size *max_app_sizes) { int rc; +#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT) uint8_t image = 0; +#endif #if defined(MCUBOOT_SINGLE_APPLICATION_SLOT) uint8_t mode = MCUBOOT_MODE_SINGLE_SLOT; @@ -322,11 +324,13 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are sizeof(recovery), &recovery); } +#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT) if (!rc) { rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO, BLINFO_RUNNING_SLOT, sizeof(slot), (void *)&slot); } +#endif #if defined(MCUBOOT_VERSION_AVAILABLE) if (!rc) { @@ -337,6 +341,7 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are } #endif +#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT) while (image < BOOT_IMAGE_NUMBER && !rc) { if (max_app_sizes[image].calculated == true) { rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO, @@ -348,6 +353,7 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are ++image; } +#endif if (!rc) { saved_bootinfo = true; diff --git a/boot/zephyr/single_loader.c b/boot/zephyr/single_loader.c index 858f294ad..03b61d4bd 100644 --- a/boot/zephyr/single_loader.c +++ b/boot/zephyr/single_loader.c @@ -8,6 +8,8 @@ #include #include "bootutil/image.h" #include "bootutil_priv.h" +#include "bootutil/boot_record.h" +#include "bootutil/bootutil.h" #include "bootutil/bootutil_log.h" #include "bootutil/bootutil_public.h" #include "bootutil/fault_injection_hardening.h" @@ -140,6 +142,22 @@ boot_go(struct boot_rsp *rsp) fih_rc = FIH_SUCCESS; #endif /* MCUBOOT_VALIDATE_PRIMARY_SLOT */ +#ifdef MCUBOOT_MEASURED_BOOT + rc = boot_save_boot_status(0, &_hdr, _fa_p); + if (rc != 0) { + BOOT_LOG_ERR("Failed to add image data to shared area"); + return rc; + } +#endif /* MCUBOOT_MEASURED_BOOT */ + +#ifdef MCUBOOT_DATA_SHARING + rc = boot_save_shared_data(&_hdr, _fa_p, 0, NULL); + if (rc != 0) { + BOOT_LOG_ERR("Failed to add data to shared memory area."); + return rc; + } +#endif /* MCUBOOT_DATA_SHARING */ + rsp->br_flash_dev_id = flash_area_get_device_id(_fa_p); rsp->br_image_off = flash_area_get_off(_fa_p); rsp->br_hdr = &_hdr;