|
24 | 24 |
|
25 | 25 | #include "mcuboot_config/mcuboot_config.h"
|
26 | 26 | #include "bootutil/crypto/sha.h"
|
| 27 | +#ifdef MCUBOOT_HW_ROLLBACK_PROT |
| 28 | +#include "bootutil/security_cnt.h" |
| 29 | +#endif |
27 | 30 |
|
28 | 31 | #if defined(MCUBOOT_MEASURED_BOOT) || defined(MCUBOOT_DATA_SHARING)
|
29 | 32 | #include "bootutil/boot_record.h"
|
@@ -242,6 +245,10 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
|
242 | 245 | int rc;
|
243 | 246 | #if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
|
244 | 247 | uint8_t image = 0;
|
| 248 | +#ifdef MCUBOOT_HW_ROLLBACK_PROT |
| 249 | + uint32_t security_cnt; |
| 250 | + FIH_DECLARE(fih_rc, FIH_FAILURE); |
| 251 | +#endif |
245 | 252 | #endif
|
246 | 253 |
|
247 | 254 | #if defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
|
@@ -346,14 +353,37 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
|
346 | 353 | }
|
347 | 354 | #endif
|
348 | 355 |
|
| 356 | +#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT) && defined(MCUBOOT_HW_ROLLBACK_PROT) |
| 357 | + image = 0; |
| 358 | + while (image < BOOT_IMAGE_NUMBER && !rc) { |
| 359 | + FIH_CALL(boot_nv_security_counter_get, fih_rc, image, &security_cnt); |
| 360 | + if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) { |
| 361 | + /* Some platforms support only a single security counter. */ |
| 362 | + continue; |
| 363 | + } |
| 364 | + |
| 365 | + rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO, |
| 366 | + BLINFO_SECURITY_COUNTER_IMAGE_0 + image, |
| 367 | + sizeof(security_cnt), |
| 368 | + (void *)&security_cnt); |
| 369 | + if (!rc) { |
| 370 | + break; |
| 371 | + } |
| 372 | + ++image; |
| 373 | + } |
| 374 | +#endif /* !defined(MCUBOOT_SINGLE_APPLICATION_SLOT) && defined(MCUBOOT_HW_ROLLBACK_PROT) */ |
| 375 | + |
349 | 376 | #if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
|
| 377 | + image = 0; |
350 | 378 | while (image < BOOT_IMAGE_NUMBER && !rc) {
|
351 | 379 | if (max_app_sizes[image].calculated == true) {
|
352 | 380 | rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO,
|
353 | 381 | (BLINFO_MAX_APPLICATION_SIZE + image),
|
354 | 382 | sizeof(max_app_sizes[image].max_size),
|
355 | 383 | (void *)&max_app_sizes[image].max_size);
|
356 |
| - |
| 384 | + if (!rc) { |
| 385 | + break; |
| 386 | + } |
357 | 387 | }
|
358 | 388 |
|
359 | 389 | ++image;
|
|
0 commit comments