From d9b3e491df9d995f5725f3db5cfbe753ddc6ca31 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 11 Nov 2024 09:53:36 +0000 Subject: [PATCH] boot: bootutil: boot_record: Fix issue with saving image data Fixes an issue with saving shared boot data when the number of images is more than 1. This is caused becuase the function is called once per image but the function itself saves common data plus data for all images, so prevent saving when it has already ran once Signed-off-by: Jamie McCrae --- boot/bootutil/src/boot_record.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/boot/bootutil/src/boot_record.c b/boot/bootutil/src/boot_record.c index fbfaf91f3..f6ed2a723 100644 --- a/boot/bootutil/src/boot_record.c +++ b/boot/bootutil/src/boot_record.c @@ -32,6 +32,10 @@ #include "bootutil/image.h" #include "flash_map_backend/flash_map_backend.h" +#if defined(MCUBOOT_DATA_SHARING_BOOTINFO) +static bool saved_bootinfo = false; +#endif + #if !defined(MCUBOOT_CUSTOM_DATA_SHARING_FUNCTION) /** * @var shared_memory_init_done @@ -296,6 +300,11 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are }; #endif + if (saved_bootinfo) { + /* Boot info has already been saved, nothing to do */ + return 0; + } + /* Write out all fields */ rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO, BLINFO_MODE, sizeof(mode), &mode); @@ -340,6 +349,10 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are ++image; } + if (!rc) { + saved_bootinfo = true; + } + return rc; } #endif /* MCUBOOT_DATA_SHARING_BOOTINFO */