Skip to content

Commit

Permalink
boot: zephyr: boot_record: Save boot data with single image
Browse files Browse the repository at this point in the history
Ensure that bootloader info and measurements are saved to retained
memory when using mcuboot in single-image mode.

Signed-off-by: Dane Wagner <[email protected]>
  • Loading branch information
dpw13 committed Dec 9, 2024
1 parent 5d6471b commit d5cca5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions boot/bootutil/src/boot_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions boot/zephyr/single_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <assert.h>
#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"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d5cca5a

Please sign in to comment.