Commit 904d0c46 authored by Dominik Ermel's avatar Dominik Ermel Committed by Dominik Ermel
Browse files

bootutil: Add DirectXIP version of boot_set_next

The commit adds DirectXIP version of bootutil boot_set_next
function.
The function is enabled by configuration option:
MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP.

Signed-off-by: default avatarDominik Ermel <dominik.ermel@nordicsemi.no>
parent d9a0074d
Loading
Loading
Loading
Loading
+0 −12
Changes for boot/bootutil/src/bootutil_misc.c: 0 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -294,18 +294,6 @@ boot_read_enc_key(const struct flash_area *fap, uint8_t slot, struct boot_status
}
#endif

int
boot_write_copy_done(const struct flash_area *fap)
{
    uint32_t off;

    off = boot_copy_done_off(fap);
    BOOT_LOG_DBG("writing copy_done; fa_id=%d off=0x%lx (0x%lx)",
                 flash_area_get_id(fap), (unsigned long)off,
                 (unsigned long)(flash_area_get_off(fap) + off));
    return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
}

int
boot_write_swap_size(const struct flash_area *fap, uint32_t swap_size)
{
+80 −0
Changes for boot/bootutil/src/bootutil_public.c: 80 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -476,6 +476,20 @@ static int flash_area_id_to_image(int id)
    return 0;
}

int
boot_write_copy_done(const struct flash_area *fap)
{
    uint32_t off;

    off = boot_copy_done_off(fap);
    BOOT_LOG_DBG("writing copy_done; fa_id=%d off=0x%lx (0x%lx)",
                 flash_area_get_id(fap), (unsigned long)off,
                 (unsigned long)(flash_area_get_off(fap) + off));
    return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
}


#ifndef MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP
int
boot_set_next(const struct flash_area *fa, bool active, bool confirm)
{
@@ -547,6 +561,72 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)

    return rc;
}
#else
int
boot_set_next(const struct flash_area *fa, bool active, bool confirm)
{
    struct boot_swap_state slot_state;
    int rc;

    if (active) {
        /* The only way to set active slot for next boot is to confirm it,
         * as DirectXIP will conclude that, since slot has not been confirmed
         * last boot, it is bad and will remove it.
         */
        confirm = true;
    }

    rc = boot_read_swap_state(fa, &slot_state);
    if (rc != 0) {
        return rc;
    }

    switch (slot_state.magic) {
    case BOOT_MAGIC_UNSET:
        /* Magic is needed for MCUboot to even consider booting an image */
        rc = boot_write_magic(fa);
        if (rc != 0) {
            break;
        }
        /* Pass */

    case BOOT_MAGIC_GOOD:
        if (confirm) {
            if (slot_state.copy_done == BOOT_FLAG_UNSET) {
                /* Magic is needed for DirectXIP to even try to boot application.
                 * DirectXIP will set copy-done flag before attempting to boot
                 * application. Next boot, application that has copy-done flag
                 * is expected to already have ok flag, otherwise it will be removed.
                 */
                rc = boot_write_copy_done(fa);
                if (rc != 0) {
                    break;
                }
            }

            if (slot_state.image_ok == BOOT_FLAG_UNSET) {
                rc = boot_write_image_ok(fa);
                if (rc != 0) {
                    break;
                }
            }
        }
        break;

    case BOOT_MAGIC_BAD:
        /* This image will not be boot next time anyway */
        rc = BOOT_EBADIMAGE;
        break;

    default:
        /* Something is not OK, this should never happen */
        assert(0);
        rc = BOOT_EBADSTATUS;
    }

    return rc;
}
#endif

/*
 * This function is not used by the bootloader itself, but its required API
+5 −0
Changes for boot/zephyr/include/mcuboot_config/mcuboot_config.h: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
 * Copyright (c) 2018 Open Source Foundries Limited
 * Copyright (c) 2019-2020 Arm Limited
 * Copyright (c) 2019-2020 Linaro Limited
 * Copyright (c) 2023 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */
@@ -273,6 +274,10 @@
    #endif
#endif

#ifdef CONFIG_MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP
#define MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP 1
#endif

#if CONFIG_BOOT_WATCHDOG_FEED
#if CONFIG_NRFX_WDT
#include <nrfx_wdt.h>