Skip to content

Commit 82bd4a7

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 fe8f9fc commit 82bd4a7

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;
@@ -249,19 +257,23 @@ bootutil_img_validate(struct boot_loader_state *state,
249257
}
250258
#endif
251259

260+
#if defined(MCUBOOT_SWAP_USING_OFFSET)
261+
it.start_off = boot_get_state_secondary_offset(state, fap);
262+
#endif
263+
252264
#if defined(MCUBOOT_SIGN_PURE)
253265
/* If Pure type signature is expected then it has to be there */
266+
#if defined(MCUBOOT_SWAP_USING_OFFSET)
267+
rc = bootutil_check_for_pure(hdr, fap, it.start_off);
268+
#else
254269
rc = bootutil_check_for_pure(hdr, fap);
270+
#endif
255271
if (rc != 0) {
256272
BOOT_LOG_DBG("bootutil_img_validate: pure expected");
257273
goto out;
258274
}
259275
#endif
260276

261-
#if defined(MCUBOOT_SWAP_USING_OFFSET)
262-
it.start_off = boot_get_state_secondary_offset(state, fap);
263-
#endif
264-
265277
rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_ANY, false);
266278
if (rc) {
267279
BOOT_LOG_DBG("bootutil_img_validate: TLV iteration failed %d", rc);

0 commit comments

Comments
 (0)