Browse Source

modules: introduce MCUBOOT_BOOTUTIL module

Some parts of subsys/dfu/boot code are re-implementations of
what is implemented in the MCUBoot repository.

Mcuboot's repository already provide implementation of function
required for application for interact with the MCUboot.

This patch introduces new MCUBOOT_BOOTUTIL module which covers
common code which is used in the bootloader and the chainnloaded
application.

dfu/boot: use MCUBoot's source code

Module was reworked so it start using MCUBoot's
bootutil_public API instead of copied code.

Reworked boot_is_img_confirmed() used MCUBoot's API
for determine image_ok flag.

mcuboot_shell switchd to use MCUboot's boot_read_swap_state_by_id()
This is MCUBoot function, use it for avoid linking conflict.

test/subsys/mcuboot: fix `test_write_confirm`

dfu/boot library was reworked so it uses MCUboot's bootutil_public
library whenever it can.
The library required that image was marked as copy-done before it
can be pending.
This patch adds such mark which fixes the test.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
pull/31331/head
Andrzej Puzdrowski 5 years ago committed by Carles Cufí
parent
commit
049dac2a8a
  1. 32
      include/dfu/mcuboot.h
  2. 1
      modules/Kconfig
  3. 24
      modules/Kconfig.mcuboot_bootutil
  4. 1
      subsys/dfu/Kconfig
  5. 8
      subsys/dfu/boot/CMakeLists.txt
  6. 536
      subsys/dfu/boot/mcuboot.c
  7. 15
      subsys/dfu/boot/mcuboot_priv.h
  8. 1
      subsys/dfu/boot/mcuboot_shell.c
  9. 8
      tests/subsys/dfu/mcuboot/src/main.c
  10. 2
      west.yml

32
include/dfu/mcuboot.h

@ -17,26 +17,58 @@ @@ -17,26 +17,58 @@
extern "C" {
#endif
#ifdef BOOT_SWAP_TYPE_NONE
#if BOOT_SWAP_TYPE_NONE != 1 /*ensure the same definition in MCUboot */
#error "definition incompatible"
#endif
#else
/** Attempt to boot the contents of slot 0. */
#define BOOT_SWAP_TYPE_NONE 1
#endif
#ifdef BOOT_SWAP_TYPE_TEST
#if BOOT_SWAP_TYPE_TEST != 2 /*ensure the same definition in MCUboot */
#error "definition incompatible"
#endif
#else
/** Swap to slot 1. Absent a confirm command, revert back on next boot. */
#define BOOT_SWAP_TYPE_TEST 2
#endif
#ifdef BOOT_SWAP_TYPE_PERM
#if BOOT_SWAP_TYPE_PERM != 3 /*ensure the same definition in MCUboot */
#error "definition incompatible"
#endif
#else
/** Swap to slot 1, and permanently switch to booting its contents. */
#define BOOT_SWAP_TYPE_PERM 3
#endif
#ifdef BOOT_SWAP_TYPE_REVERT
#if BOOT_SWAP_TYPE_REVERT != 4 /*ensure the same definition in MCUboot */
#error "definition incompatible"
#endif
#else
/** Swap back to alternate slot. A confirm changes this state to NONE. */
#define BOOT_SWAP_TYPE_REVERT 4
#endif
#ifdef BOOT_SWAP_TYPE_FAIL
#if BOOT_SWAP_TYPE_FAIL != 5 /*ensure the same definition in MCUboot */
#error "definition incompatible"
#endif
#else
/** Swap failed because image to be run is not valid */
#define BOOT_SWAP_TYPE_FAIL 5
#endif
#define BOOT_IMG_VER_STRLEN_MAX 25 /* 255.255.65535.4294967295\0 */
/* Trailer: */
#define BOOT_MAX_ALIGN 8
#ifndef BOOT_MAGIC_SZ
#define BOOT_MAGIC_SZ 16
#endif
#define BOOT_TRAILER_IMG_STATUS_OFFS(bank_area) ((bank_area)->fa_size -\
BOOT_MAGIC_SZ -\

1
modules/Kconfig

@ -31,3 +31,4 @@ source "modules/Kconfig.tinycbor" @@ -31,3 +31,4 @@ source "modules/Kconfig.tinycbor"
source "modules/Kconfig.tinycrypt"
source "modules/Kconfig.vega"
source "modules/Kconfig.xtensa"
source "modules/Kconfig.mcuboot_bootutil"

24
modules/Kconfig.mcuboot_bootutil

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
# Copyright (c) 2020 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
menuconfig MCUBOOT_BOOTUTIL_LIB
bool "MCUboot utility library"
help
Enable MCUboot utility library which implements functions
required by the chain-loaded application and the MCUboot.
if MCUBOOT_BOOTUTIL_LIB
# hiden option for disabling module-own log configuration
# while building MCUboot bootloader
config MCUBOOT_BOOTUTIL_LIB_OWN_LOG
bool
default y
if MCUBOOT_BOOTUTIL_LIB_OWN_LOG
module = MCUBOOT_UTIL
module-str = MCUboot bootutil
source "subsys/logging/Kconfig.template.log_config"
endif
endif # MCUBOOT_BOOTUTIL_LIB

1
subsys/dfu/Kconfig

@ -25,6 +25,7 @@ choice @@ -25,6 +25,7 @@ choice
config MCUBOOT_IMG_MANAGER
bool "Image manager for mcuboot"
select FLASH_MAP
select MCUBOOT_BOOTUTIL_LIB
help
Enable support for managing DFU image downloaded using mcuboot.

8
subsys/dfu/boot/CMakeLists.txt

@ -1,4 +1,8 @@ @@ -1,4 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
zephyr_sources_ifdef(CONFIG_MCUBOOT_IMG_MANAGER mcuboot.c)
zephyr_sources_ifdef(CONFIG_MCUBOOT_SHELL mcuboot_shell.c)
if(CONFIG_MCUBOOT_IMG_MANAGER)
zephyr_library()
zephyr_library_sources(mcuboot.c)
zephyr_library_sources_ifdef(CONFIG_MCUBOOT_SHELL mcuboot_shell.c)
zephyr_library_link_libraries(MCUBOOT_BOOTUTIL)
endif()

536
subsys/dfu/boot/mcuboot.c

@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
#include <sys/__assert.h>
#include <sys/byteorder.h>
#include "bootutil/bootutil_public.h"
#include <dfu/mcuboot.h>
#include "mcuboot_priv.h"
@ -55,333 +57,6 @@ struct mcuboot_v1_raw_header { @@ -55,333 +57,6 @@ struct mcuboot_v1_raw_header {
* End of strict defines
*/
#define BOOT_FLAG_IMAGE_OK 0
#define BOOT_FLAG_COPY_DONE 1
#define FLASH_MIN_WRITE_SIZE \
DT_PROP(DT_CHOSEN(zephyr_flash), write_block_size)
#ifdef CONFIG_MCUBOOT_TRAILER_SWAP_TYPE
#define SWAP_TYPE_OFFS(bank_area) ((bank_area)->fa_size -\
BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 3)
#endif
#define COPY_DONE_OFFS(bank_area) ((bank_area)->fa_size -\
BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 2)
#define IMAGE_OK_OFFS(bank_area) ((bank_area)->fa_size - BOOT_MAGIC_SZ -\
BOOT_MAX_ALIGN)
#define MAGIC_OFFS(bank_area) ((bank_area)->fa_size - BOOT_MAGIC_SZ)
#if defined(CONFIG_BOOTLOADER_MCUBOOT) || defined(CONFIG_ZTEST)
static const uint32_t boot_img_magic[4] = {
0xf395c277,
0x7fefd260,
0x0f505235,
0x8079b62c,
};
#define BOOT_MAGIC_ARR_SZ ARRAY_SIZE(boot_img_magic)
#endif
struct boot_swap_table {
/** For each field, a value of 0 means "any". */
uint8_t magic_primary_slot;
uint8_t magic_secondary_slot;
uint8_t image_ok_primary_slot;
uint8_t image_ok_secondary_slot;
uint8_t copy_done_primary_slot;
uint8_t swap_type;
};
#ifdef FLASH_AREA_IMAGE_SECONDARY
/**
* This set of tables maps image trailer contents to swap operation type.
* When searching for a match, these tables must be iterated sequentially.
*
* NOTE: the table order is very important. The settings in the secondary
* slot always are priority to the primary slot and should be located
* earlier in the table.
*
* The table lists only states where there is action needs to be taken by
* the bootloader, as in starting/finishing a swap operation.
*/
static const struct boot_swap_table boot_swap_tables[] = {
{
/* | slot-0 | slot-1 |
*----------+------------+------------|
* magic | Any | Good |
* image-ok | Any | Unset |
* ---------+------------+------------+
* swap: test |
* -----------------------------------'
*/
.magic_primary_slot = BOOT_MAGIC_ANY,
.magic_secondary_slot = BOOT_MAGIC_GOOD,
.image_ok_primary_slot = BOOT_FLAG_ANY,
.image_ok_secondary_slot = BOOT_FLAG_UNSET,
.copy_done_primary_slot = BOOT_FLAG_ANY,
.swap_type = BOOT_SWAP_TYPE_TEST,
},
{
/* | slot-0 | slot-1 |
*----------+------------+------------|
* magic | Any | Good |
* image-ok | Any | 0x01 |
* ---------+------------+------------+
* swap: permanent |
* -----------------------------------'
*/
.magic_primary_slot = BOOT_MAGIC_ANY,
.magic_secondary_slot = BOOT_MAGIC_GOOD,
.image_ok_primary_slot = BOOT_FLAG_ANY,
.image_ok_secondary_slot = BOOT_FLAG_SET,
.copy_done_primary_slot = BOOT_FLAG_ANY,
.swap_type = BOOT_SWAP_TYPE_PERM,
},
{
/* | slot-0 | slot-1 |
*----------+------------+------------|
* magic | Good | Unset |
* image-ok | Unset | Any |
* ---------+------------+------------+
* swap: revert (test image running) |
* -----------------------------------'
*/
.magic_primary_slot = BOOT_MAGIC_GOOD,
.magic_secondary_slot = BOOT_MAGIC_UNSET,
.image_ok_primary_slot = BOOT_FLAG_UNSET,
.image_ok_secondary_slot = BOOT_FLAG_ANY,
.copy_done_primary_slot = BOOT_FLAG_SET,
.swap_type = BOOT_SWAP_TYPE_REVERT,
},
};
#define BOOT_SWAP_TABLES_COUNT (ARRAY_SIZE(boot_swap_tables))
#endif
#if defined(CONFIG_BOOTLOADER_MCUBOOT) || defined(CONFIG_ZTEST)
static int boot_magic_decode(const uint32_t *magic)
{
if (memcmp(magic, boot_img_magic, BOOT_MAGIC_SZ) == 0) {
return BOOT_MAGIC_GOOD;
}
return BOOT_MAGIC_BAD;
}
static int boot_flag_decode(uint8_t flag)
{
if (flag != BOOT_FLAG_SET) {
return BOOT_FLAG_BAD;
}
return BOOT_FLAG_SET;
}
#endif
#if defined(CONFIG_BOOTLOADER_MCUBOOT) || defined(CONFIG_ZTEST)
int flash_area_read_is_empty(const struct flash_area *fa, uint32_t off,
void *dst, uint32_t len)
{
const uint8_t erase_val = flash_area_erased_val(fa);
uint8_t *u8dst;
uint8_t i;
int rc;
rc = flash_area_read(fa, off, dst, len);
if (rc) {
return rc;
}
for (i = 0, u8dst = (uint8_t *)dst; i < len; i++) {
if (u8dst[i] != erase_val) {
return 0;
}
}
return 1;
}
#endif
static int erased_flag_val(uint8_t bank_id)
{
const struct flash_area *fa;
int rc;
rc = flash_area_open(bank_id, &fa);
if (rc) {
return -EINVAL;
}
return flash_area_erased_val(fa);
}
#if !defined(CONFIG_BOOTLOADER_MCUBOOT) && !defined(CONFIG_ZTEST)
/* Provided by MCUBoot */
int boot_magic_compatible_check(uint8_t tbl_val, uint8_t val);
#else
/**
* Determines if a status source table is satisfied by the specified magic
* code.
*
* @param tbl_val A magic field from a status source table.
* @param val The magic value in a trailer, encoded as a
* BOOT_MAGIC_[...].
*
* @return 1 if the two values are compatible;
* 0 otherwise.
*/
int boot_magic_compatible_check(uint8_t tbl_val, uint8_t val)
{
switch (tbl_val) {
case BOOT_MAGIC_ANY:
return 1;
case BOOT_MAGIC_NOTGOOD:
return val != BOOT_MAGIC_GOOD;
default:
return tbl_val == val;
}
}
#endif
static int boot_flag_offs(int flag, const struct flash_area *fa, uint32_t *offs)
{
switch (flag) {
case BOOT_FLAG_COPY_DONE:
*offs = COPY_DONE_OFFS(fa);
return 0;
case BOOT_FLAG_IMAGE_OK:
*offs = IMAGE_OK_OFFS(fa);
return 0;
default:
return -ENOTSUP;
}
}
static int boot_write_trailer_byte(const struct flash_area *fa, uint32_t off,
uint8_t val)
{
uint8_t buf[BOOT_MAX_ALIGN];
uint8_t align;
uint8_t erased_val;
int rc;
align = flash_area_align(fa);
__ASSERT_NO_MSG(align <= BOOT_MAX_ALIGN);
erased_val = flash_area_erased_val(fa);
memset(buf, erased_val, BOOT_MAX_ALIGN);
buf[0] = val;
rc = flash_area_write(fa, off, buf, align);
if (rc != 0) {
return -EIO;
}
return 0;
}
static int boot_flag_write(int flag, uint8_t bank_id)
{
const struct flash_area *fa;
uint32_t offs;
int rc;
rc = flash_area_open(bank_id, &fa);
if (rc) {
return rc;
}
rc = boot_flag_offs(flag, fa, &offs);
if (rc != 0) {
flash_area_close(fa);
return rc;
}
rc = boot_write_trailer_byte(fa, offs, BOOT_FLAG_SET);
flash_area_close(fa);
return rc;
}
static int boot_flag_read(int flag, uint8_t bank_id)
{
const struct flash_area *fa;
uint32_t offs;
int rc;
uint8_t flag_val;
rc = flash_area_open(bank_id, &fa);
if (rc) {
return rc;
}
rc = boot_flag_offs(flag, fa, &offs);
if (rc != 0) {
flash_area_close(fa);
return rc;
}
rc = flash_area_read(fa, offs, &flag_val, sizeof(flag_val));
if (rc != 0) {
return rc;
}
return flag_val;
}
static int boot_image_ok_read(uint8_t bank_id)
{
return boot_flag_read(BOOT_FLAG_IMAGE_OK, bank_id);
}
static int boot_image_ok_write(uint8_t bank_id)
{
return boot_flag_write(BOOT_FLAG_IMAGE_OK, bank_id);
}
#ifdef FLASH_AREA_IMAGE_SECONDARY
static int boot_magic_write(uint8_t bank_id)
{
const struct flash_area *fa;
uint32_t offs;
int rc;
rc = flash_area_open(bank_id, &fa);
if (rc) {
return rc;
}
offs = MAGIC_OFFS(fa);
rc = flash_area_write(fa, offs, boot_img_magic, BOOT_MAGIC_SZ);
flash_area_close(fa);
return rc;
}
#ifdef CONFIG_MCUBOOT_TRAILER_SWAP_TYPE
static int boot_swap_type_write(uint8_t bank_id, uint8_t swap_type)
{
const struct flash_area *fa;
uint32_t offs;
int rc;
rc = flash_area_open(bank_id, &fa);
if (rc) {
return rc;
}
offs = SWAP_TYPE_OFFS(fa);
rc = boot_write_trailer_byte(fa, offs, swap_type);
flash_area_close(fa);
return rc;
}
#endif /* CONFIG_MCUBOOT_TRAILER_SWAP_TYPE */
#endif /* FLASH_AREA_IMAGE_SECONDARY */
static int boot_read_v1_header(uint8_t area_id,
struct mcuboot_v1_raw_header *v1_raw)
{
@ -469,221 +144,58 @@ int boot_read_bank_header(uint8_t area_id, @@ -469,221 +144,58 @@ int boot_read_bank_header(uint8_t area_id,
return 0;
}
#if defined(CONFIG_BOOTLOADER_MCUBOOT) || defined(CONFIG_ZTEST)
static int boot_read_swap_state(const struct flash_area *fa,
struct boot_swap_state *state)
int mcuboot_swap_type(void)
{
uint32_t magic[BOOT_MAGIC_ARR_SZ];
uint32_t off;
int rc;
off = MAGIC_OFFS(fa);
rc = flash_area_read_is_empty(fa, off, magic, BOOT_MAGIC_SZ);
if (rc < 0) {
return -EIO;
}
if (rc == 1) {
state->magic = BOOT_MAGIC_UNSET;
} else {
state->magic = boot_magic_decode(magic);
}
#ifdef CONFIG_MCUBOOT_TRAILER_SWAP_TYPE
off = SWAP_TYPE_OFFS(fa);
rc = flash_area_read_is_empty(fa, off, &state->swap_type,
sizeof(state->swap_type));
if (rc < 0) {
return -EIO;
}
if (rc == 1 || state->swap_type > BOOT_SWAP_TYPE_REVERT) {
state->swap_type = BOOT_SWAP_TYPE_NONE;
}
off = COPY_DONE_OFFS(fa);
rc = flash_area_read_is_empty(fa, off, &state->copy_done,
sizeof(state->copy_done));
if (rc < 0) {
return -EIO;
}
if (rc == 1) {
state->copy_done = BOOT_FLAG_UNSET;
} else {
state->copy_done = boot_flag_decode(state->copy_done);
}
#ifdef FLASH_AREA_IMAGE_SECONDARY
return boot_swap_type();
#else
#ifdef FLASH_AREA_IMAGE_SCRATCH
if (fa->fa_id != FLASH_AREA_IMAGE_SCRATCH) {
#endif
off = COPY_DONE_OFFS(fa);
rc = flash_area_read_is_empty(fa, off, &state->copy_done,
sizeof(state->copy_done));
if (rc < 0) {
return -EIO;
}
if (rc == 1) {
state->copy_done = BOOT_FLAG_UNSET;
} else {
state->copy_done = boot_flag_decode(state->copy_done);
}
#ifdef FLASH_AREA_IMAGE_SCRATCH
}
#endif
return BOOT_SWAP_TYPE_NONE;
#endif
off = IMAGE_OK_OFFS(fa);
rc = flash_area_read_is_empty(fa, off, &state->image_ok,
sizeof(state->image_ok));
if (rc < 0) {
return -EIO;
}
if (rc == 1) {
state->image_ok = BOOT_FLAG_UNSET;
} else {
state->image_ok = boot_flag_decode(state->image_ok);
}
return 0;
}
#endif
#if defined(CONFIG_BOOTLOADER_MCUBOOT) || defined(CONFIG_ZTEST)
/**
* Reads the image trailer from the scratch area.
*/
int
boot_read_swap_state_by_id(int flash_area_id, struct boot_swap_state *state)
{
const struct flash_area *fap;
int rc;
switch (flash_area_id) {
#ifdef FLASH_AREA_IMAGE_SCRATCH
case FLASH_AREA_IMAGE_SCRATCH:
#endif
case FLASH_AREA_IMAGE_PRIMARY:
#ifdef FLASH_AREA_IMAGE_SECONDARY
case FLASH_AREA_IMAGE_SECONDARY:
#endif
rc = flash_area_open(flash_area_id, &fap);
if (rc != 0) {
return -EIO;
}
break;
default:
return -EINVAL;
}
rc = boot_read_swap_state(fap, state);
flash_area_close(fap);
return rc;
}
#endif
/* equivalent of boot_swap_type() in mcuboot bootutil_misc.c */
int mcuboot_swap_type(void)
int boot_request_upgrade(int permanent)
{
#ifdef FLASH_AREA_IMAGE_SECONDARY
const struct boot_swap_table *table;
struct boot_swap_state primary_slot;
struct boot_swap_state secondary_slot;
int rc;
size_t i;
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_PRIMARY,
&primary_slot);
rc = boot_set_pending(permanent);
if (rc) {
return rc;
return -EFAULT;
}
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_SECONDARY,
&secondary_slot);
if (rc) {
return rc;
}
for (i = 0; i < BOOT_SWAP_TABLES_COUNT; i++) {
table = boot_swap_tables + i;
if (boot_magic_compatible_check(table->magic_primary_slot,
primary_slot.magic)
&&
boot_magic_compatible_check(table->magic_secondary_slot,
secondary_slot.magic)
&&
(table->image_ok_primary_slot == BOOT_FLAG_ANY ||
table->image_ok_primary_slot == primary_slot.image_ok)
&&
(table->image_ok_secondary_slot == BOOT_FLAG_ANY ||
table->image_ok_secondary_slot == secondary_slot.image_ok)
&&
(table->copy_done_primary_slot == BOOT_FLAG_ANY ||
table->copy_done_primary_slot == primary_slot.copy_done)) {
__ASSERT_NO_MSG(table->swap_type == BOOT_SWAP_TYPE_TEST ||
table->swap_type == BOOT_SWAP_TYPE_PERM ||
table->swap_type == BOOT_SWAP_TYPE_REVERT);
return table->swap_type;
}
}
#endif
return BOOT_SWAP_TYPE_NONE;
#endif /* FLASH_AREA_IMAGE_SECONDARY */
return 0;
}
int boot_request_upgrade(int permanent)
bool boot_is_img_confirmed(void)
{
#ifdef FLASH_AREA_IMAGE_SECONDARY
#ifdef CONFIG_MCUBOOT_TRAILER_SWAP_TYPE
uint8_t swap_type;
#endif
const struct flash_area *fa;
int rc;
uint8_t flag_val;
rc = boot_magic_write(FLASH_AREA_IMAGE_SECONDARY);
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY, &fa);
if (rc) {
goto op_end;
return false;
}
if (permanent) {
rc = boot_image_ok_write(FLASH_AREA_IMAGE_SECONDARY);
#ifdef CONFIG_MCUBOOT_TRAILER_SWAP_TYPE
if (rc) {
goto op_end;
}
swap_type = BOOT_SWAP_TYPE_PERM;
} else {
swap_type = BOOT_SWAP_TYPE_TEST;
rc = boot_read_image_ok(fa, &flag_val);
if (rc) {
return false;
}
rc = boot_swap_type_write(FLASH_AREA_IMAGE_SECONDARY, swap_type);
#else
}
#endif
op_end:
return rc;
#else
return 0;
#endif /* FLASH_AREA_IMAGE_SECONDARY */
}
bool boot_is_img_confirmed(void)
{
return boot_image_ok_read(FLASH_AREA_IMAGE_PRIMARY) == BOOT_FLAG_SET;
return flag_val == BOOT_FLAG_SET;
}
int boot_write_img_confirmed(void)
{
int rc;
if (boot_image_ok_read(FLASH_AREA_IMAGE_PRIMARY) !=
erased_flag_val(FLASH_AREA_IMAGE_PRIMARY)) {
/* Already confirmed. */
return 0;
rc = boot_set_confirmed();
if (rc) {
return -EIO;
}
rc = boot_image_ok_write(FLASH_AREA_IMAGE_PRIMARY);
return rc;
return 0;
}
int boot_erase_img_bank(uint8_t area_id)

15
subsys/dfu/boot/mcuboot_priv.h

@ -21,10 +21,6 @@ @@ -21,10 +21,6 @@
#endif
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE */
#if FLASH_AREA_LABEL_EXISTS(image_scratch)
#define FLASH_AREA_IMAGE_SCRATCH FLASH_AREA_ID(image_scratch)
#endif
#define BOOT_MAGIC_GOOD 1
#define BOOT_MAGIC_BAD 2
#define BOOT_MAGIC_UNSET 3
@ -36,15 +32,4 @@ @@ -36,15 +32,4 @@
#define BOOT_FLAG_UNSET 3
#define BOOT_FLAG_ANY 4 /* NOTE: control only, not dependent on sector */
/** Represents the management state of a single image slot. */
struct boot_swap_state {
uint8_t magic; /* One of the BOOT_MAGIC_[...] values. */
uint8_t swap_type; /* One of the BOOT_SWAP_TYPE_[...] values. */
uint8_t copy_done; /* One of the BOOT_FLAG_[...] values. */
uint8_t image_ok; /* One of the BOOT_FLAG_[...] values. */
};
int
boot_read_swap_state_by_id(int flash_area_id, struct boot_swap_state *state);
#endif /* ZEPHYR_DFU_BOOT_MCUBOOT_H_ */

1
subsys/dfu/boot/mcuboot_shell.c

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "bootutil/bootutil_public.h"
#include <dfu/mcuboot.h>
#include <init.h>
#include <shell/shell.h>

8
tests/subsys/dfu/mcuboot/src/main.c

@ -95,6 +95,7 @@ void test_write_confirm(void) @@ -95,6 +95,7 @@ void test_write_confirm(void)
{
const uint32_t img_magic[4] = BOOT_MAGIC_VALUES;
uint32_t readout[ARRAY_SIZE(img_magic)];
const uint32_t flag = 0xffffff01;
const struct flash_area *fa;
int ret;
@ -117,7 +118,12 @@ void test_write_confirm(void) @@ -117,7 +118,12 @@ void test_write_confirm(void)
zassert_true(ret == 0, "Write to flash");
}
zassert(boot_write_img_confirmed() == 0, "pass", "fail");
/* set copy-done flag */
ret = flash_area_write(fa, fa->fa_size - 32, &flag, sizeof(flag));
zassert_true(ret == 0, "Write to flash");
ret = boot_write_img_confirmed();
zassert(ret == 0, "pass", "fail (%d)", ret);
ret = flash_area_read(fa, fa->fa_size - 24, readout,
sizeof(readout[0]));

2
west.yml

@ -94,7 +94,7 @@ manifest: @@ -94,7 +94,7 @@ manifest:
revision: 13cf2e52024a144ecee9f37680681760a85febab
path: modules/crypto/mbedtls
- name: mcuboot
revision: c986a9059c55f21d1f6e87ca8c2ceed98bb76ad0
revision: 6f48e0abfd7c4284719dd7c25ef293d68ab528cf
path: bootloader/mcuboot
- name: mcumgr
revision: 697e145d5ee5e4b400e9d7bceaec79f6ac29df7c

Loading…
Cancel
Save