Skip to content

Commit 60b6585

Browse files
committed
boot: bootutil: Fix pure image validation check with offset swap
Fixes an issue whereby the pure check did not set an offset to search for the TLVs Signed-off-by: Jamie McCrae <[email protected]>
1 parent bf5321b commit 60b6585

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

boot/bootutil/src/image_validate.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,22 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
125125
*
126126
* Value of TLV does not matter, presence decides.
127127
*/
128-
static int bootutil_check_for_pure(const struct image_header *hdr,
129-
const struct flash_area *fap)
128+
#if defined(MCUBOOT_SWAP_USING_OFFSET)
129+
static int bootutil_check_for_pure(const struct image_header *hdr, const struct flash_area *fap,
130+
uint32_t start_off)
131+
#else
132+
static int bootutil_check_for_pure(const struct image_header *hdr, const struct flash_area *fap)
133+
#endif
130134
{
131135
struct image_tlv_iter it;
132136
uint32_t off;
133137
uint16_t len;
134138
int32_t rc;
135139

140+
#if defined(MCUBOOT_SWAP_USING_OFFSET)
141+
it.start_off = start_off;
142+
#endif
143+
136144
rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_SIG_PURE, false);
137145
if (rc) {
138146
return -1;
@@ -246,19 +254,23 @@ bootutil_img_validate(struct boot_loader_state *state,
246254
}
247255
#endif
248256

257+
#if defined(MCUBOOT_SWAP_USING_OFFSET)
258+
it.start_off = boot_get_state_secondary_offset(state, fap);
259+
#endif
260+
249261
#if defined(MCUBOOT_SIGN_PURE)
250262
/* If Pure type signature is expected then it has to be there */
263+
#if defined(MCUBOOT_SWAP_USING_OFFSET)
264+
rc = bootutil_check_for_pure(hdr, fap, it.start_off);
265+
#else
251266
rc = bootutil_check_for_pure(hdr, fap);
267+
#endif
252268
if (rc != 0) {
253269
BOOT_LOG_DBG("bootutil_img_validate: pure expected");
254270
goto out;
255271
}
256272
#endif
257273

258-
#if defined(MCUBOOT_SWAP_USING_OFFSET)
259-
it.start_off = boot_get_state_secondary_offset(state, fap);
260-
#endif
261-
262274
rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_ANY, false);
263275
if (rc) {
264276
BOOT_LOG_DBG("bootutil_img_validate: TLV iteration failed %d", rc);

0 commit comments

Comments
 (0)