Skip to content

Commit ccfe643

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 ccfe643

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
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: 30 additions & 4 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
@@ -398,7 +402,8 @@ boot_write_image_ok(const struct flash_area *fap)
398402
return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
399403
}
400404

401-
#if defined(SEND_BOOT_REQUEST) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP))
405+
#if defined(SEND_BOOT_REQUEST) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP)) || \
406+
defined(CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES)
402407
static int flash_area_to_image_slot(const struct flash_area *fa, uint32_t *slot)
403408
{
404409
int id = flash_area_get_id(fa);
@@ -435,15 +440,36 @@ static int flash_area_to_image_slot(const struct flash_area *fa, uint32_t *slot)
435440
#endif
436441
return 0;
437442
}
438-
#endif /* SEND_BOOT_REQUEST || !MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP */
443+
#endif /* SEND_BOOT_REQUEST || !MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP || CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES */
439444

440445
int
441446
boot_read_image_ok(const struct flash_area *fap, uint8_t *image_ok)
442447
{
443-
#ifdef SEND_BOOT_REQUEST
448+
#if defined(SEND_BOOT_REQUEST) || defined(CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES)
444449
enum boot_slot slot_id = BOOT_SLOT_NONE;
445450
int image_id = flash_area_to_image_slot(fap, &slot_id);
446-
bool confirm_pending = boot_request_check_confirmed_slot(image_id, slot_id);
451+
#endif
452+
#ifdef SEND_BOOT_REQUEST
453+
bool confirm_pending;
454+
#endif
455+
456+
#ifdef CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES
457+
/* If manifest-based updates are used, only the manifest image is considered. */
458+
image_id = CONFIG_NCS_MCUBOOT_MANIFEST_IMAGE_NUMBER;
459+
if (slot_id == BOOT_SLOT_PRIMARY) {
460+
int rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_id), &fap);
461+
if (rc != 0) {
462+
return rc;
463+
}
464+
} else if (slot_id == BOOT_SLOT_SECONDARY) {
465+
int rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_id), &fap);
466+
if (rc != 0) {
467+
return rc;
468+
}
469+
}
470+
#endif /* CONFIG_NCS_MCUBOOT_MANIFEST_UPDATES */
471+
#ifdef SEND_BOOT_REQUEST
472+
confirm_pending = boot_request_check_confirmed_slot(image_id, slot_id);
447473

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

0 commit comments

Comments
 (0)