Commit e575b0b8 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

Add macro to check if swap_type is an upgrade

This allows refactoring a check that was done in multiple places looking
for the same swap types.

Also fixes an issue where dependency checks would be run if a swap type
had a value that indicates fail.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent b1adb1ed
Loading
Loading
Loading
Loading
+5 −0
Changes for boot/bootutil/src/bootutil_priv.h: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -277,6 +277,11 @@ int boot_find_tlv_offs(const struct image_header *hdr,
#define BOOT_SWAP_TYPE(state) ((state)->swap_type[BOOT_CURR_IMG(state)])
#define BOOT_TLV_OFF(hdr) ((hdr)->ih_hdr_size + (hdr)->ih_img_size)

#define BOOT_IS_UPGRADE(swap_type)             \
    (((swap_type) == BOOT_SWAP_TYPE_TEST) ||   \
     ((swap_type) == BOOT_SWAP_TYPE_REVERT) || \
     ((swap_type) == BOOT_SWAP_TYPE_PERM))

static inline struct image_header*
boot_img_hdr(struct boot_loader_state *state, size_t slot)
{
+4 −11
Changes for boot/bootutil/src/loader.c: 4 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -958,10 +958,7 @@ boot_validated_swap_type(struct boot_loader_state *state,
    int rc;

    swap_type = boot_swap_type_multi(BOOT_CURR_IMG(state));
    switch (swap_type) {
    case BOOT_SWAP_TYPE_TEST:
    case BOOT_SWAP_TYPE_PERM:
    case BOOT_SWAP_TYPE_REVERT:
    if (BOOT_IS_UPGRADE(swap_type)) {
        /* Boot loader wants to switch to the secondary slot.
         * Ensure image is valid.
         */
@@ -2047,9 +2044,7 @@ boot_perform_update(struct boot_loader_state *state, struct boot_status *bs)
        }
    }

    if (swap_type == BOOT_SWAP_TYPE_TEST ||
            swap_type == BOOT_SWAP_TYPE_PERM ||
            swap_type == BOOT_SWAP_TYPE_REVERT) {
    if (BOOT_IS_UPGRADE(swap_type)) {
        rc = boot_set_copy_done(BOOT_CURR_IMG(state));
        if (rc != 0) {
            BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
@@ -2093,9 +2088,7 @@ boot_complete_partial_swap(struct boot_loader_state *state,
        }
    }

    if (bs->swap_type == BOOT_SWAP_TYPE_TEST ||
        bs->swap_type == BOOT_SWAP_TYPE_PERM ||
        bs->swap_type == BOOT_SWAP_TYPE_REVERT) {
    if (BOOT_IS_UPGRADE(bs->swap_type)) {
        rc = boot_set_copy_done(BOOT_CURR_IMG(state));
        if (rc != 0) {
            BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
@@ -2359,7 +2352,7 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
        /* Determine swap type and complete swap if it has been aborted. */
        boot_prepare_image_for_update(state, &bs);

        if (BOOT_SWAP_TYPE(state) != BOOT_SWAP_TYPE_NONE) {
        if (BOOT_IS_UPGRADE(BOOT_SWAP_TYPE(state))) {
            has_upgrade = true;
        }
    }