diff --git a/cmake/dts.cmake b/cmake/dts.cmake index 12a522e69de..cb757b943ca 100644 --- a/cmake/dts.cmake +++ b/cmake/dts.cmake @@ -11,6 +11,7 @@ set(GENERATED_DTS_BOARD_H ${PROJECT_BINARY_DIR}/include/generated/generated_dts_board.h) set(GENERATED_DTS_BOARD_CONF ${PROJECT_BINARY_DIR}/include/generated/generated_dts_board.conf) set_ifndef(DTS_SOURCE ${PROJECT_SOURCE_DIR}/boards/${ARCH}/${BOARD_FAMILY}/${BOARD_FAMILY}.dts) +set_ifndef(DTS_COMMON_OVERLAYS ${PROJECT_SOURCE_DIR}/dts/common/common.dts) message(STATUS "Generating zephyr/include/generated/generated_dts_board.h") @@ -21,6 +22,9 @@ if(CONFIG_HAS_DTS) string(REPLACE " " ";" DTC_OVERLAY_FILE_AS_LIST ${DTC_OVERLAY_FILE}) endif() + # Prepend common overlays + set(DTC_OVERLAY_FILE_AS_LIST ${DTS_COMMON_OVERLAYS} ${DTC_OVERLAY_FILE_AS_LIST}) + set( dts_files ${DTS_SOURCE} diff --git a/doc/application/application.rst b/doc/application/application.rst index 0ce40243621..dfa802298b5 100644 --- a/doc/application/application.rst +++ b/doc/application/application.rst @@ -907,6 +907,8 @@ following available sources, in order: :makevar:`DTC_OVERLAY_FILE` variable, either as set explicitly by the user or using one of the default values detailed below. +#. Common overlays conditionally included by :file:`dts/common/common.dts`. + #. The board's default DT configuration for the current :makevar:`BOARD` setting (i.e. the :file:`boards/ARCHITECTURE/BOARD/BOARD.dts` file in the Zephyr base directory). @@ -928,6 +930,12 @@ checking the following until one is found, in order: If :makevar:`DTC_OVERLAY_FILE` specifies multiple files, they will be merged in order. +The build system will automatically prepend :file:`dts/common/common.dts` to +:makevar:`DTC_OVERLAY_FILE`, which conditionally includes certain overlays that +are considered common to all applications. This includes the required overlay +for MCUboot chain-loading (located in :file:`dts/comon/mcuboot.overlay`) +whenever the :option:`CONFIG_BOOTLOADER_MCUBOOT` is set using Kconfig. + Application-Specific Code ************************* diff --git a/dts/common/common.dts b/dts/common/common.dts new file mode 100644 index 00000000000..6bc308c8b32 --- /dev/null +++ b/dts/common/common.dts @@ -0,0 +1,9 @@ +/* + * Common Device Tree source, used for conditionally pulling in features and + * additions by the build system. + */ + +#ifdef CONFIG_BOOTLOADER_MCUBOOT +#include "mcuboot.overlay" +#endif + diff --git a/dts/common/mcuboot.overlay b/dts/common/mcuboot.overlay new file mode 100644 index 00000000000..795b0e26e97 --- /dev/null +++ b/dts/common/mcuboot.overlay @@ -0,0 +1,10 @@ +/* + * Basic Device Tree overlay file for chain-loading by MCUboot. + * Automatically pulled in when CONFIG_BOOTLOADER_MCUBOOT is set. + */ + +/ { + chosen { + zephyr,code-partition = &slot0_partition; + }; +}; diff --git a/misc/Kconfig b/misc/Kconfig index 2e67133e021..ba1a0901cb1 100644 --- a/misc/Kconfig +++ b/misc/Kconfig @@ -317,8 +317,16 @@ config BOOTLOADER_MCUBOOT help This option signifies that the target uses MCUboot as a bootloader, or in other words that the image is to be chain-loaded by MCUboot. - This sets several required options in order for the image generated - to be bootable using the MCUboot open source bootloader. + This sets several required build system and Device Tree options in + order for the image generated to be bootable using the MCUboot open + source bootloader. Currently this includes: + + * Setting TEXT_LOAD_OFFSET to a default value that allows space for + the MCUboot image header + * Activating SW_VECTOR_RELAY on Cortex-M0 targets with no built-in + vector relocation mechanisms + * Including dts/common/mcuboot.overlay when building the Device + Tree in order to place and link the image at the slot0 offset config BOOTLOADER_KEXEC bool