Skip to content

Commit f2a6146

Browse files
dpw13nordicjm
authored andcommitted
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 <[email protected]>
1 parent b778ad9 commit f2a6146

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

boot/bootutil/src/boot_record.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
237237
const uint8_t slot, const struct image_max_size *max_app_sizes)
238238
{
239239
int rc;
240+
#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
240241
uint8_t image = 0;
242+
#endif
241243

242244
#if defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
243245
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
322324
sizeof(recovery), &recovery);
323325
}
324326

327+
#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
325328
if (!rc) {
326329
rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO,
327330
BLINFO_RUNNING_SLOT,
328331
sizeof(slot), (void *)&slot);
329332
}
333+
#endif
330334

331335
#if defined(MCUBOOT_VERSION_AVAILABLE)
332336
if (!rc) {
@@ -337,6 +341,7 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
337341
}
338342
#endif
339343

344+
#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
340345
while (image < BOOT_IMAGE_NUMBER && !rc) {
341346
if (max_app_sizes[image].calculated == true) {
342347
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
348353

349354
++image;
350355
}
356+
#endif
351357

352358
if (!rc) {
353359
saved_bootinfo = true;

boot/zephyr/single_loader.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <assert.h>
99
#include "bootutil/image.h"
1010
#include "bootutil_priv.h"
11+
#include "bootutil/boot_record.h"
12+
#include "bootutil/bootutil.h"
1113
#include "bootutil/bootutil_log.h"
1214
#include "bootutil/bootutil_public.h"
1315
#include "bootutil/fault_injection_hardening.h"
@@ -140,6 +142,22 @@ boot_go(struct boot_rsp *rsp)
140142
fih_rc = FIH_SUCCESS;
141143
#endif /* MCUBOOT_VALIDATE_PRIMARY_SLOT */
142144

145+
#ifdef MCUBOOT_MEASURED_BOOT
146+
rc = boot_save_boot_status(0, &_hdr, _fa_p);
147+
if (rc != 0) {
148+
BOOT_LOG_ERR("Failed to add image data to shared area");
149+
return rc;
150+
}
151+
#endif /* MCUBOOT_MEASURED_BOOT */
152+
153+
#ifdef MCUBOOT_DATA_SHARING
154+
rc = boot_save_shared_data(&_hdr, _fa_p, 0, NULL);
155+
if (rc != 0) {
156+
BOOT_LOG_ERR("Failed to add data to shared memory area.");
157+
return rc;
158+
}
159+
#endif /* MCUBOOT_DATA_SHARING */
160+
143161
rsp->br_flash_dev_id = flash_area_get_device_id(_fa_p);
144162
rsp->br_image_off = flash_area_get_off(_fa_p);
145163
rsp->br_hdr = &_hdr;

0 commit comments

Comments
 (0)