Skip to content

Commit

Permalink
dfu: mcuboot: Automatic primary/secondary image slot assignment
Browse files Browse the repository at this point in the history
The commit adds macros that allow automatic detection and definition
of FLASH_AREA_IMAGE_PRIMARY and FLASH_AREA_IMAGE_SECONDARY when
DTS uses chosen zephyr,code-partition to select partition for
application to run from.

Signed-off-by: Dominik Ermel <[email protected]>
  • Loading branch information
de-nordic committed Jan 27, 2021
1 parent 9e5ae8f commit 2875fca
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions subsys/dfu/boot/mcuboot_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@

#include <storage/flash_map.h>

#define DT_CODE_PARTITION_NODE DT_CHOSEN(zephyr_code_partition)
#define DT_IMAGE_0_NODE DT_NODE_BY_FIXED_PARTITION_LABEL(image_0)
#define DT_IMAGE_1_NODE DT_NODE_BY_FIXED_PARTITION_LABEL(image_1)
#define DT_IMAGE_0_NS_NODE DT_NODE_BY_FIXED_PARTITION_LABEL(image_0_nonsecure)
#define DT_IMAGE_1_NS_NODE DT_NODE_BY_FIXED_PARTITION_LABEL(image_1_nonsecure)

#define IS_IMAGE_CODE_PARTITION(image) \
DT_SAME_NODE(DT_CODE_PARTITION_NODE, image)

/*
* If code partition is selected via chosen zephyr,code-partition it should
* be possible to automatically detect primary and secondary partition.
*/
#if DT_NODE_EXISTS(DT_CODE_PARTITION_NODE)
/* Set PRIMARY to code-partition */
#define FLASH_AREA_IMAGE_PRIMARY DT_FIXED_PARTITION_ID(DT_CODE_PARTITION_NODE)

/* Secondary is the "other" partition in set */
#if DT_NODE_EXISTS(DT_IMAGE_1_NODE) && IS_IMAGE_CODE_PARTITION(DT_IMAGE_0_NODE)
#define FLASH_AREA_IMAGE_SECONDARY DT_FIXED_PARTITION_ID(DT_IMAGE_1_NODE)
#elif IS_IMAGE_CODE_PARTITION(DT_IMAGE_1_NODE)
#define FLASH_AREA_IMAGE_SECONDARY DT_FIXED_PARTITION_ID(DT_IMAGE_0_NODE)
#elif IS_IMAGE_CODE_PARTITION(DT_IMAGE_0_NS_NODE)
#define FLASH_AREA_IMAGE_SECONDARY DT_FIXED_PARTITION_ID(DT_IMAGE_1_NS_NODE)
#elif IS_IMAGE_CODE_PARTITION(DT_IMAGE_1_NS_NODE)
#define FLASH_AREA_IMAGE_SECONDARY DT_FIXED_PARTITION_ID(DT_IMAGE_0_NS_NODE)
#else
/* The naming of partitions is different than expected */
#error Could not determine image partitions for DFU
#endif

#else /* DT_NODE_EXISTS(DT_CODE_PARTITION_NODE), Non-automatic image setup */

/* FLASH_AREA_ID() values used below are auto-generated by DT */
#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE
#define FLASH_AREA_IMAGE_PRIMARY FLASH_AREA_ID(image_0_nonsecure)
Expand All @@ -21,6 +54,8 @@
#endif
#endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE */

#endif /* DT_NODE_EXISTS(DT_CODE_PARTITION_NODE) */

#define BOOT_MAGIC_GOOD 1
#define BOOT_MAGIC_BAD 2
#define BOOT_MAGIC_UNSET 3
Expand Down

0 comments on commit 2875fca

Please sign in to comment.