Skip to content

Commit 3b7c7fb

Browse files
MarekPietatejlmand
authored andcommitted
[nrf fromtree] boot: bootutil: loader: Let image version comparison
... use build number Change allows using build number in image version comparison. Signed-off-by: Marek Pieta <[email protected]> (cherry picked from commit a95a41b) Signed-off-by: Dominik Ermel <[email protected]>
1 parent ba0dc61 commit 3b7c7fb

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

boot/bootutil/src/loader.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,17 @@ boot_check_header_erased(struct boot_loader_state *state, int slot)
635635
defined(MCUBOOT_RAM_LOAD) || \
636636
defined(MCUBOOT_DOWNGRADE_PREVENTION)
637637
/**
638-
* Compare image version numbers not including the build number
638+
* Compare image version numbers
639+
*
640+
* By default, the comparison does not take build number into account.
641+
* Enable MCUBOOT_VERSION_CMP_USE_BUILD_NUMBER to take the build number into account.
639642
*
640643
* @param ver1 Pointer to the first image version to compare.
641644
* @param ver2 Pointer to the second image version to compare.
642645
*
643-
* @retval -1 If ver1 is strictly less than ver2.
644-
* @retval 0 If the image version numbers are equal,
645-
* (not including the build number).
646-
* @retval 1 If ver1 is strictly greater than ver2.
646+
* @retval -1 If ver1 is less than ver2.
647+
* @retval 0 If the image version numbers are equal.
648+
* @retval 1 If ver1 is greater than ver2.
647649
*/
648650
static int
649651
boot_version_cmp(const struct image_version *ver1,
@@ -670,6 +672,16 @@ boot_version_cmp(const struct image_version *ver1,
670672
return -1;
671673
}
672674

675+
#if defined(MCUBOOT_VERSION_CMP_USE_BUILD_NUMBER)
676+
/* The revisions are equal, continue comparison. */
677+
if (ver1->iv_build_num > ver2->iv_build_num) {
678+
return 1;
679+
}
680+
if (ver1->iv_build_num < ver2->iv_build_num) {
681+
return -1;
682+
}
683+
#endif
684+
673685
return 0;
674686
}
675687
#endif

boot/zephyr/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,15 @@ config UPDATEABLE_IMAGE_NUMBER
524524
help
525525
Enables support of multi image update.
526526

527+
config BOOT_VERSION_CMP_USE_BUILD_NUMBER
528+
bool "Use build number while comparing image version"
529+
depends on (UPDATEABLE_IMAGE_NUMBER > 1) || BOOT_DIRECT_XIP || \
530+
BOOT_RAM_LOAD || MCUBOOT_DOWNGRADE_PREVENTION
531+
help
532+
By default, the image version comparison relies only on version major,
533+
minor and revision. Enable this option to take into account the build
534+
number as well.
535+
527536
choice BOOT_DOWNGRADE_PREVENTION_CHOICE
528537
prompt "Downgrade prevention"
529538
optional

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
#define MCUBOOT_IMAGE_NUMBER 1
9393
#endif
9494

95+
#ifdef CONFIG_BOOT_VERSION_CMP_USE_BUILD_NUMBER
96+
#define MCUBOOT_VERSION_CMP_USE_BUILD_NUMBER
97+
#endif
98+
9599
#ifdef CONFIG_BOOT_SWAP_SAVE_ENCTLV
96100
#define MCUBOOT_SWAP_SAVE_ENCTLV 1
97101
#endif

0 commit comments

Comments
 (0)