diff --git a/include/dfu/mcuboot.h b/include/dfu/mcuboot.h index 141e25336ba..e8a8641c389 100644 --- a/include/dfu/mcuboot.h +++ b/include/dfu/mcuboot.h @@ -8,11 +8,33 @@ #ifndef __MCUBOOT_H__ #define __MCUBOOT_H__ +#include + /** - * @brief Marks the image in slot 0 as confirmed. The system will continue - * booting into the image in slot 0 until told to boot from a different slot. + * @brief Check if the currently running image is confirmed as OK. * - * This call is expected to be used by the application running on trial. + * MCUboot can perform "test" upgrades. When these occur, a new + * firmware image is installed and booted, but the old version will be + * reverted at the next reset unless the new image explicitly marks + * itself OK. + * + * This routine can be used to check if the currently running image + * has been marked as OK. + * + * @return True if the image is confirmed as OK, false otherwise. + * @see boot_write_img_confirmed() + */ +bool boot_is_img_confirmed(void); + +/** + * @brief Marks the currently running image as confirmed. + * + * This routine attempts to mark the currently running firmware image + * as OK, which will install it permanently, preventing MCUboot from + * reverting it for an older image at the next reset. + * + * This routine is safe to call if the current image has already been + * confirmed. It will return a successful result in this case. * * @return 0 on success, negative errno code on fail. */ diff --git a/subsys/dfu/boot/mcuboot.c b/subsys/dfu/boot/mcuboot.c index 4fc3013024d..c418ac2217b 100644 --- a/subsys/dfu/boot/mcuboot.c +++ b/subsys/dfu/boot/mcuboot.c @@ -168,6 +168,11 @@ int boot_request_upgrade(int permanent) return rc; } +bool boot_is_img_confirmed(void) +{ + return boot_image_ok_read(FLASH_BANK0_OFFSET) == BOOT_FLAG_SET; +} + int boot_write_img_confirmed(void) { int rc;