Skip to content

Commit 4c9883b

Browse files
committed
Add a capability query for image number
In addition to the binary capability flags, add a query function that returns the number of images MCUboot has been configured to support. Signed-off-by: David Brown <[email protected]>
1 parent 74b161e commit 4c9883b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

boot/bootutil/include/bootutil/caps.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ uint32_t bootutil_get_caps(void);
4141
#define BOOTUTIL_CAP_ENC_KW (1<<6)
4242
#define BOOTUTIL_CAP_VALIDATE_PRIMARY_SLOT (1<<7)
4343

44+
/*
45+
* Query the number of images this bootloader is configured for. This
46+
* is also primarily used for testing.
47+
*/
48+
uint32_t bootutil_get_num_images(void);
49+
4450
#ifdef __cplusplus
4551
}
4652
#endif

boot/bootutil/src/caps.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,12 @@ uint32_t bootutil_get_caps(void)
4747

4848
return res;
4949
}
50+
51+
uint32_t bootutil_get_num_images(void)
52+
{
53+
#if defined(MCUBOOT_IMAGE_NUMBER)
54+
return MCUBOOT_IMAGE_NUMBER;
55+
#else
56+
return 1;
57+
#endif
58+
}

sim/src/caps.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ impl Caps {
1919
let caps = unsafe { bootutil_get_caps() };
2020
(caps as u32) & (self as u32) != 0
2121
}
22+
23+
/// Query for the number of images that have been configured into this
24+
/// MCUboot build.
25+
pub fn get_num_images() -> usize {
26+
(unsafe { bootutil_get_num_images() }) as usize
27+
}
2228
}
2329

2430
extern "C" {
2531
fn bootutil_get_caps() -> Caps;
32+
fn bootutil_get_num_images() -> u32;
2633
}

0 commit comments

Comments
 (0)