Skip to content

Commit ab5e5a1

Browse files
committed
[nrf noup] Add routines for application
Adapt manifest headers, so they can be used by the main application. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent a9f7a21 commit ab5e5a1

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

boot/bootutil/include/bootutil/mcuboot_manifest.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,29 @@
1515

1616
#include <stdint.h>
1717
#include "bootutil/bootutil.h"
18+
#ifdef CONFIG_MCUBOOT
1819
#include "bootutil/crypto/sha.h"
20+
#elif defined(CONFIG_MCUBOOT_BOOTLOADER_USES_SHA512)
21+
#define IMAGE_HASH_SIZE (64)
22+
#else
23+
#define IMAGE_HASH_SIZE (32)
24+
#endif
25+
26+
#ifndef MCUBOOT_MANIFEST_IMAGE_NUMBER
27+
#ifdef CONFIG_NCS_MCUBOOT_MANIFEST_IMAGE_NUMBER
28+
#define MCUBOOT_MANIFEST_IMAGE_NUMBER CONFIG_NCS_MCUBOOT_MANIFEST_IMAGE_NUMBER
29+
#else
30+
#error "MCUBOOT_MANIFEST_IMAGE_NUMBER must be defined when MCUBOOT_MANIFEST_UPDATES is enabled"
31+
#endif
32+
#endif
33+
34+
#ifndef MCUBOOT_IMAGE_NUMBER
35+
#ifdef CONFIG_UPDATEABLE_IMAGE_NUMBER
36+
#define MCUBOOT_IMAGE_NUMBER CONFIG_UPDATEABLE_IMAGE_NUMBER
37+
#else
38+
#error "MCUBOOT_IMAGE_NUMBER must be defined when MCUBOOT_MANIFEST_UPDATES is enabled"
39+
#endif
40+
#endif
1941

2042
#ifndef __packed
2143
#define __packed __attribute__((__packed__))

boot/bootutil/src/bootutil_public.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
#define SEND_BOOT_REQUEST
5757
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST && !CONFIG_MCUBOOT */
5858

59+
#ifdef CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES
60+
#include <bootutil/mcuboot_manifest.h>
61+
#endif /* CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES */
62+
5963
#ifdef CONFIG_MCUBOOT
6064
BOOT_LOG_MODULE_DECLARE(mcuboot);
6165
#else
@@ -440,10 +444,31 @@ static int flash_area_to_image_slot(const struct flash_area *fa, uint32_t *slot)
440444
int
441445
boot_read_image_ok(const struct flash_area *fap, uint8_t *image_ok)
442446
{
443-
#ifdef SEND_BOOT_REQUEST
447+
#if defined(SEND_BOOT_REQUEST) || defined(CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES)
444448
enum boot_slot slot_id = BOOT_SLOT_NONE;
445449
int image_id = flash_area_to_image_slot(fap, &slot_id);
446-
bool confirm_pending = boot_request_check_confirmed_slot(image_id, slot_id);
450+
#endif
451+
#ifdef SEND_BOOT_REQUEST
452+
bool confirm_pending;
453+
#endif
454+
455+
#ifdef CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES
456+
/* If manifest-based updates are used, only the manifest image is considered. */
457+
image_id = CONFIG_NCS_MCUBOOT_MANIFEST_IMAGE_NUMBER;
458+
if (slot_id == BOOT_SLOT_PRIMARY) {
459+
int rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_id), &fap);
460+
if (rc != 0) {
461+
return rc;
462+
}
463+
} else if (slot_id == BOOT_SLOT_SECONDARY) {
464+
int rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_id), &fap);
465+
if (rc != 0) {
466+
return rc;
467+
}
468+
}
469+
#endif /* CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES */
470+
#ifdef SEND_BOOT_REQUEST
471+
confirm_pending = boot_request_check_confirmed_slot(image_id, slot_id);
447472

448473
if (confirm_pending) {
449474
BOOT_LOG_DBG("Image confirmation pending for image %d slot %d", image_id, slot_id);

0 commit comments

Comments
 (0)