Commit ccaf7f88 authored by Mark Horvath's avatar Mark Horvath Committed by Fabio Utzig
Browse files

boot: Multi-image boot for direct-xip and ram-load

Multiple image boot support is implemented for direct-xip and ram-load
strategies. Dependency checking is also added, and for ram-load more
executable ram regions can be set.
Wrapper functions are intoduced to all boot strategies.

Change-Id: I59b346277dcb2c17cef4800f1e556b4ea9144845
Signed-off-by: default avatarMark Horvath <mark.horvath@arm.com>
parent f04aa544
Loading
Loading
Loading
Loading
+35 −0
Changes for boot/bootutil/include/bootutil/ramload.h: 35 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 *  Copyright (c) 2021, Arm Limited. All rights reserved.
 *
 *  SPDX-License-Identifier: Apache-2.0
 */

#ifndef __RAMLOAD_H__
#define __RAMLOAD_H__

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef MULTIPLE_EXECUTABLE_RAM_REGIONS
/**
 * Provides information about the Executable RAM for a given image ID.
 *
 * @param image_id        Index of the image (from 0).
 * @param exec_ram_start  Pointer to store the start address of the exec RAM
 * @param exec_ram_size   Pointer to store the size of the exec RAM
 *
 * @return                0 on success; nonzero on failure.
 */
int boot_get_image_exec_ram_info(uint32_t image_id,
                                 uint32_t *exec_ram_start,
                                 uint32_t *exec_ram_size);
#endif

#ifdef __cplusplus
}
#endif

#endif /* __RAMLOAD_H__ */
 No newline at end of file
+1 −4
Changes for boot/bootutil/src/bootutil_priv.h: 1 added line, 4 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
 *
 * Copyright (c) 2017-2020 Linaro LTD
 * Copyright (c) 2017-2019 JUUL Labs
 * Copyright (c) 2019-2020 Arm Limited
 * Copyright (c) 2019-2021 Arm Limited
 *
 * Original license:
 *
@@ -143,9 +143,6 @@ _Static_assert(BOOT_IMAGE_NUMBER > 0, "Invalid value for BOOT_IMAGE_NUMBER");
#else
#define ARE_SLOTS_EQUIVALENT()    1

#if (BOOT_IMAGE_NUMBER != 1)
#error "The MCUBOOT_DIRECT_XIP and MCUBOOT_RAM_LOAD mode only supports single-image boot (MCUBOOT_IMAGE_NUMBER=1)."
#endif
#ifdef MCUBOOT_ENC_IMAGES
#error "Image encryption (MCUBOOT_ENC_IMAGES) is not supported when MCUBOOT_DIRECT_XIP or MCUBOOT_RAM_LOAD mode is selected."
#endif
+768 −256

File changed.

Preview size limit exceeded, changes collapsed.

+46 −2
Changes for docs/design.md: 46 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -272,13 +272,22 @@ ram-load is enabled then platform must define the following parameters:
#define IMAGE_EXECUTABLE_RAM_SIZE     <area_size_in_bytes>
```

For multiple image load if multiple ram regions are used platform must define
the `MULTIPLE_EXECUTABLE_RAM_REGIONS` flag instead and implement the following
function:

```c
int boot_get_image_exec_ram_info(uint32_t image_id,
                                 uint32_t *exec_ram_start,
                                 uint32_t *exec_ram_size)
```

When ram-load is enabled, the `--load-addr <addr>` option of the `imgtool`
script must also be used when signing the images. This option set the `RAM_LOAD`
flag in the image header which indicates that the image should be loaded to the
RAM and also set the load address in the image header.

The ram-load mode currently supports only the single image boot and the image
encryption feature is not supported.
The ram-load mode currently does not support the image encryption feature.

## [Boot Swap Types](#boot-swap-types)

@@ -692,6 +701,41 @@ process is presented below.
+ Boot into image in the primary slot of the 0th image position\
  (other image in the boot chain is started by another image).

### [Multiple Image Boot for RAM loading and direct-xip](#multiple-image-boot-for-ram-loading-and-direct-xip)

The operation of the boot loader is different when the ram-load or the
direct-xip strategy is chosen. The flash map is very similar to the swap
strategy but there is no need for Scratch area.

+  Loop 1. Until all images are loaded and all dependencies are satisfied
    1. Subloop 1. Iterate over all images
        + Does any of the slots contain an image?
            + Yes:
                + Choose the newer image.
                + Copy it to RAM in case of ram-load strategy.
                + Validate the image (integrity and security check).
                + If validation fails delete the image from flash and try the other
                  slot. (Image must be deleted from RAM too in case of ram-load
                  strategy.)
            + No: Return with failure.

    2. Subloop 2. Iterate over all images
        + Does the current image depend on other image(s)?
            + Yes: Are all the image dependencies satisfied?
                + Yes: Skip to next image.
                + No:
                    + Delete the image from RAM in case of ram-load strategy, but
                      do not delete it from flash.
                    + Try to load the image from the other slot.
                    + Restart dependency check from the first image.
            + No: Skip to next image.

+  Loop 2. Iterate over all images
    + Increase the security counter if needed.
    + Do the measured boot and the data sharing if needed.

+ Boot the loaded slot of image 0.

## [Image Swapping](#image-swapping)

The boot loader swaps the contents of the two image slots for two reasons: