dfu/boot/mcuboot: made able to compile within MCUBoot

Use rather MCUBoot implementation of some function than
zephyr's implementations once avielabel.

Zephyr implementations are needed while compiling application
supposed to be chainloaded by the MCUBoot or when they are
tested.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
Andrzej Puzdrowski 2020-09-18 16:34:22 +02:00 committed by Carles Cufí
commit 5cfafb041b

View file

@ -98,6 +98,7 @@ struct mcuboot_v1_raw_header {
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,
@ -106,6 +107,7 @@ static const uint32_t boot_img_magic[4] = {
};
#define BOOT_MAGIC_ARR_SZ ARRAY_SIZE(boot_img_magic)
#endif
struct boot_swap_table {
/** For each field, a value of 0 means "any". */
@ -126,6 +128,7 @@ struct boot_swap_state {
uint8_t image_ok; /* One of the BOOT_FLAG_[...] values. */
};
#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.
@ -188,7 +191,9 @@ static const struct boot_swap_table boot_swap_tables[] = {
},
};
#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) {
@ -206,8 +211,9 @@ static int boot_flag_decode(uint8_t flag)
return BOOT_FLAG_SET;
}
#endif
/* TODO: this function should be moved to flash_area api in future */
#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)
{
@ -229,6 +235,7 @@ int flash_area_read_is_empty(const struct flash_area *fa, uint32_t off,
return 1;
}
#endif
static int erased_flag_val(uint8_t bank_id)
{
@ -242,6 +249,10 @@ static int erased_flag_val(uint8_t bank_id)
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.
@ -266,7 +277,7 @@ int boot_magic_compatible_check(uint8_t tbl_val, uint8_t val)
return tbl_val == val;
}
}
#endif
static int boot_flag_offs(int flag, const struct flash_area *fa, uint32_t *offs)
{
switch (flag) {
@ -362,6 +373,7 @@ 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;
@ -400,7 +412,8 @@ static int boot_swap_type_write(uint8_t bank_id, uint8_t swap_type)
return rc;
}
#endif
#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)
@ -489,6 +502,7 @@ 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)
{
@ -563,7 +577,13 @@ static int boot_read_swap_state(const struct flash_area *fa,
return 0;
}
#endif
#if !defined(CONFIG_BOOTLOADER_MCUBOOT) && !defined(CONFIG_ZTEST)
/* provided by MCUBoot */
int
boot_read_swap_state_by_id(int flash_area_id, struct boot_swap_state *state);
#else
/**
* Reads the image trailer from the scratch area.
*/
@ -594,7 +614,7 @@ boot_read_swap_state_by_id(int flash_area_id, struct boot_swap_state *state)
flash_area_close(fap);
return rc;
}
#endif
/* equivalent of boot_swap_type() in mcuboot bootutil_misc.c */
int mcuboot_swap_type(void)
{