Unverified Commit 750678e3 authored by Dominik Ermel's avatar Dominik Ermel Committed by GitHub
Browse files

synchronized up to the mcu-tool/mcuboot 4427e4c9



Synchronized to:
mcu-tools@4427e4c

Changes included:
boot: zephyr: allow timeout based recovery with CDC ACM
boot: zephyr: Only call sys_clock_disable when supported
imgtool: fix getpriv format type for keys
mynewt: add flash sector requirement for swap move
ci: add Mynewt test target for swap move
ci: Fix compatibility with packaging==22
boot_serial: Add unaligned stack buffer writing
doc: espressif: Add warning note for Flash Encryption with Serial Recovery usage

Note: The following commits exists in both branches
boot: zephyr: boards: nrf52840dk: Fix overlay
espressif: add downgrade prevention feature
boot: Update Nordic's license identifier tag
docs: fix FIH example command in design.md
ci: fih: update TF-M version to 1.7.0 and adjust test suite

merged using GitHub web gui.

Signed-off-by: default avatarJoakim Andersson <joakim.andersson@nordicsemi.no>
parents dd59d907 4427e4c9
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -511,7 +511,38 @@ bs_upload(char *buf, int len)

    BOOT_LOG_INF("Writing at 0x%x until 0x%x", curr_off, curr_off + img_chunk_len);
    /* Write flash aligned chunk, note that img_chunk_len now holds aligned length */
#if defined(MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE) && MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE > 0
    if (flash_area_align(fap) > 1 &&
        (((size_t)img_chunk) & (flash_area_align(fap) - 1)) != 0) {
        /* Buffer address incompatible with write address, use buffer to write */
        uint8_t write_size = MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE;
        uint8_t wbs_aligned[MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE];

        while (img_chunk_len >= flash_area_align(fap)) {
            if (write_size > img_chunk_len) {
                write_size = img_chunk_len;
            }

            memset(wbs_aligned, flash_area_erased_val(fap), sizeof(wbs_aligned));
            memcpy(wbs_aligned, img_chunk, write_size);

            rc = flash_area_write(fap, curr_off, wbs_aligned, write_size);

            if (rc != 0) {
                goto out;
            }

            curr_off += write_size;
            img_chunk += write_size;
            img_chunk_len -= write_size;
        }
    } else {
        rc = flash_area_write(fap, curr_off, img_chunk, img_chunk_len);
    }
#else
    rc = flash_area_write(fap, curr_off, img_chunk, img_chunk_len);
#endif

    if (rc == 0 && rem_bytes) {
        /* Non-zero rem_bytes means that last chunk needs alignment; the aligned
         * part, in the img_chunk_len - rem_bytes count bytes, has already been
+13 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include <sysflash/sysflash.h>
#include <flash_map/flash_map.h>
#include <mcuboot_config/mcuboot_config.h>
#include <unistd.h>  /* off_t */

#if (MCUBOOT_IMAGE_NUMBER == 1)

@@ -40,6 +41,13 @@
int flash_area_id_from_multi_image_slot(int image_index, int slot);
int flash_area_id_to_multi_image_slot(int image_index, int area_id);

struct flash_sector {
    uint32_t fs_off;
    uint32_t fs_size;
};

int flash_area_sector_from_off(off_t off, struct flash_sector *sector);

static inline uint8_t flash_area_get_id(const struct flash_area *fa)
{
    return fa->fa_id;
@@ -60,4 +68,9 @@ static inline uint32_t flash_area_get_size(const struct flash_area *fa)
    return fa->fa_size;
}

static inline uint32_t flash_sector_get_off(const struct flash_sector *fs)
{
    return fs->fs_off;
}

#endif /* __FLASH_MAP_BACKEND_H__ */
+35 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@

#include <flash_map/flash_map.h>
#include <flash_map_backend/flash_map_backend.h>
#include <hal/hal_bsp.h>
#include <hal/hal_flash_int.h>

int flash_area_id_from_multi_image_slot(int image_index, int slot)
{
@@ -42,3 +44,36 @@ int flash_area_id_to_multi_image_slot(int image_index, int area_id)
    }
    return 255;
}

int flash_area_sector_from_off(off_t off, struct flash_sector *sector)
{
    const struct flash_area *fa;
    const struct hal_flash *hf;
    uint32_t start;
    uint32_t size;
    int rc;
    int i;

    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fa);
    if (rc != 0) {
        return -1;
    }

    rc = -1;
    hf = hal_bsp_flash_dev(fa->fa_device_id);
    for (i = 0; i < hf->hf_sector_cnt; i++) {
        hf->hf_itf->hff_sector_info(hf, i, &start, &size);
        if (start < fa->fa_off) {
            continue;
        }
        if (off >= start - fa->fa_off && off <= (start - fa->fa_off) + size) {
            sector->fs_off = start - fa->fa_off;
            sector->fs_size = size;
            rc = 0;
            break;
        }
    }

    flash_area_close(fa);
    return rc;
}
+9 −1
Original line number Diff line number Diff line
@@ -51,6 +51,14 @@ config MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD
	  Note that 0 is default upload target when no explicit
	  selection is done.

config BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
	int "Stack buffer for unaligned memory writes"
	default 64
	help
	  Specifies the stack usage for a buffer which is used for unaligned
	  memory access when data is written to a device with memory alignment
	  requirements. Set to 0 to disable.

config BOOT_MAX_LINE_INPUT_LEN
	int "Maximum input line length"
	default 512
@@ -148,7 +156,7 @@ config BOOT_SERIAL_ENCRYPT_EC256

config BOOT_SERIAL_WAIT_FOR_DFU
	bool "Wait for a prescribed duration to see if DFU is invoked by receiving a mcumgr comand"
	depends on BOOT_SERIAL_UART
	depends on BOOT_SERIAL_UART || BOOT_SERIAL_CDC_ACM
	help
	  If y, MCUboot waits for a prescribed duration of time to allow
	  for DFU to be invoked. The serial recovery can be entered by receiving any
+4 −0
Original line number Diff line number Diff line
@@ -245,6 +245,10 @@
#define MCUBOOT_SERIAL_MAX_RECEIVE_SIZE CONFIG_BOOT_SERIAL_MAX_RECEIVE_SIZE
#endif

#ifdef CONFIG_BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
#define MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE CONFIG_BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
#endif

/* Support 32-byte aligned flash sizes */
#if DT_HAS_CHOSEN(zephyr_flash)
    #if DT_PROP_OR(DT_CHOSEN(zephyr_flash), write_block_size, 0) > 8
Loading