blob: e77728ea24c82cdcf035a9ae68f64554ae8ad651 [file] [log] [blame]
David Vincze54d05552019-08-05 12:58:47 +02001#-------------------------------------------------------------------------------
David Vinczec3e313a2020-01-06 17:31:11 +01002# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
David Vincze54d05552019-08-05 12:58:47 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
David Vincze63eda7a2019-08-09 17:42:51 +02008#Include BL2 bootloader related functions
9include("${CMAKE_CURRENT_LIST_DIR}/MCUBoot.cmake")
10
David Vincze54d05552019-08-05 12:58:47 +020011set(BL2 True CACHE BOOL "Configure TF-M to use BL2 and enable building BL2")
12
13if (BL2)
14 add_definitions(-DBL2)
15
Balint Matyif0873cd2020-06-09 14:03:47 +010016 set(MCUBOOT_REPO "UPSTREAM" CACHE STRING "Configure which repository use the MCUBoot from")
David Vinczec3e313a2020-01-06 17:31:11 +010017 set_property(CACHE MCUBOOT_REPO PROPERTY STRINGS "TF-M;UPSTREAM")
18 validate_cache_value(MCUBOOT_REPO)
19
David Vincze7384ee72019-07-23 17:00:42 +020020 set(MCUBOOT_IMAGE_NUMBER 2 CACHE STRING "Configure the number of separately updatable firmware images")
21 set_property(CACHE MCUBOOT_IMAGE_NUMBER PROPERTY STRINGS "1;2")
David Vincze63eda7a2019-08-09 17:42:51 +020022 validate_cache_value(MCUBOOT_IMAGE_NUMBER STRINGS)
23
David Vincze54d05552019-08-05 12:58:47 +020024 set(MCUBOOT_UPGRADE_STRATEGY "OVERWRITE_ONLY" CACHE STRING "Configure BL2 which upgrade strategy to use")
25 set_property(CACHE MCUBOOT_UPGRADE_STRATEGY PROPERTY STRINGS "OVERWRITE_ONLY;SWAP;NO_SWAP;RAM_LOADING")
26 validate_cache_value(MCUBOOT_UPGRADE_STRATEGY)
27
28 set(MCUBOOT_SIGNATURE_TYPE "RSA-3072" CACHE STRING "Algorithm used by MCUBoot to validate signatures.")
29 set_property(CACHE MCUBOOT_SIGNATURE_TYPE PROPERTY STRINGS "RSA-3072;RSA-2048")
30 validate_cache_value(MCUBOOT_SIGNATURE_TYPE)
31
Balint Matyif0873cd2020-06-09 14:03:47 +010032 #FixMe: These checks can be removed when the upgrade strategies in question are upstreamed to the original MCUBoot repo.
33 if (TARGET_PLATFORM STREQUAL "MUSCA_A" OR TARGET_PLATFORM STREQUAL "AN524")
34 if (MCUBOOT_REPO STREQUAL "UPSTREAM")
35 message(WARNING "The 'UPSTREAM' MCUBoot repository cannot be used when building for ${TARGET_PLATFORM}. Your choice was overridden.")
36 endif()
37 set(MCUBOOT_REPO "TF-M")
38 endif()
39
David Vinczef5c1e062020-03-31 17:05:34 +020040 set(MCUBOOT_HW_KEY On CACHE BOOL "Configure to use HW key for image verification. Otherwise key is embedded in MCUBoot image.")
Tamas Band0f4e1d2019-07-11 09:39:03 +010041
Balint Matyi5c476312020-03-31 13:15:39 +010042 set(MCUBOOT_ENCRYPT_RSA Off CACHE BOOL "Add encrypted image support to BL2. Also encrypts the signed images.")
43
David Vincze73dfbc52019-10-11 13:54:58 +020044 set(MCUBOOT_LOG_LEVEL "LOG_LEVEL_INFO" CACHE STRING "Configure the level of logging in MCUBoot.")
45 set_property(CACHE MCUBOOT_LOG_LEVEL PROPERTY STRINGS "LOG_LEVEL_OFF;LOG_LEVEL_ERROR;LOG_LEVEL_WARNING;LOG_LEVEL_INFO;LOG_LEVEL_DEBUG")
Raef Colesb321c0b2019-10-15 08:49:17 +010046 if (NOT CMAKE_BUILD_TYPE STREQUAL "debug")
David Vincze73dfbc52019-10-11 13:54:58 +020047 set(MCUBOOT_LOG_LEVEL "LOG_LEVEL_OFF")
48 endif()
Balint Matyi2fe04922020-02-18 12:27:38 +000049
David Vincze73dfbc52019-10-11 13:54:58 +020050 validate_cache_value(MCUBOOT_LOG_LEVEL)
51
David Vincze63eda7a2019-08-09 17:42:51 +020052 if ((${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "NO_SWAP" OR
53 ${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "RAM_LOADING") AND
54 NOT (MCUBOOT_IMAGE_NUMBER EQUAL 1))
55 message(WARNING "The number of separately updatable images with the NO_SWAP or the RAM_LOADING"
56 " upgrade strategy can be only '1'. Your choice was overriden.")
57 set(MCUBOOT_IMAGE_NUMBER 1)
58 endif()
59
David Vinczec3e313a2020-01-06 17:31:11 +010060 if (MCUBOOT_REPO STREQUAL "UPSTREAM")
Balint Matyi5c476312020-03-31 13:15:39 +010061 if(MCUBOOT_ENCRYPT_RSA)
62 set(MCUBOOT_ENC_IMAGES On)
63 endif()
64
David Vinczec3e313a2020-01-06 17:31:11 +010065 set_property(CACHE MCUBOOT_UPGRADE_STRATEGY PROPERTY STRINGS "OVERWRITE_ONLY;SWAP")
66 if (${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "NO_SWAP" OR
67 ${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "RAM_LOADING")
68 message(WARNING "The ${MCUBOOT_UPGRADE_STRATEGY} upgrade strategy cannot be used when building against"
69 " upstream MCUBoot. Your choice was overriden.")
70 mcuboot_override_upgrade_strategy("OVERWRITE_ONLY")
71 endif()
Balint Matyi5c476312020-03-31 13:15:39 +010072 elseif (MCUBOOT_REPO STREQUAL "TF-M")
73 if (MCUBOOT_ENCRYPT_RSA)
74 set(MCUBOOT_ENCRYPT_RSA Off)
75 message(WARNING "BL2 encryption cannot be used when building against the TF-M MCUBoot fork. Your choice was overridden.")
76 endif()
David Vinczec3e313a2020-01-06 17:31:11 +010077 endif()
78
David Vincze54d05552019-08-05 12:58:47 +020079else() #BL2 is turned off
David Vincze63eda7a2019-08-09 17:42:51 +020080
81 if (DEFINED MCUBOOT_IMAGE_NUMBER OR
82 DEFINED MCUBOOT_UPGRADE_STRATEGY OR
Tamas Band0f4e1d2019-07-11 09:39:03 +010083 DEFINED MCUBOOT_SIGNATURE_TYPE OR
David Vincze73dfbc52019-10-11 13:54:58 +020084 DEFINED MCUBOOT_HW_KEY OR
85 DEFINED MCUBOOT_LOG_LEVEL)
David Vinczec3e313a2020-01-06 17:31:11 +010086 message(WARNING "Ignoring the values of MCUBOOT_* variables as BL2 option is set to False.")
87 set(MCUBOOT_IMAGE_NUMBER "")
88 set(MCUBOOT_UPGRADE_STRATEGY "")
89 set(MCUBOOT_SIGNATURE_TYPE "")
90 set(MCUBOOT_HW_KEY "")
91 set(MCUBOOT_LOG_LEVEL "")
David Vincze54d05552019-08-05 12:58:47 +020092 endif()
93
David Vinczed8fbe0e2019-08-12 15:58:57 +020094 if (DEFINED SECURITY_COUNTER OR
95 DEFINED SECURITY_COUNTER_S OR
96 DEFINED SECURITY_COUNTER_NS)
David Vinczec3e313a2020-01-06 17:31:11 +010097 message(WARNING "Ignoring the values of SECURITY_COUNTER and/or SECURITY_COUNTER_* variables as BL2 option is set to False.")
98 set(SECURITY_COUNTER "")
99 set(SECURITY_COUNTER_S "")
100 set(SECURITY_COUNTER_NS "")
David Vinczed8fbe0e2019-08-12 15:58:57 +0200101 endif()
102
103 if (DEFINED IMAGE_VERSION OR
104 DEFINED IMAGE_VERSION_S OR
105 DEFINED IMAGE_VERSION_NS)
David Vinczec3e313a2020-01-06 17:31:11 +0100106 message(WARNING "Ignoring the values of IMAGE_VERSION and/or IMAGE_VERSION_* variables as BL2 option is set to False.")
107 set(IMAGE_VERSION "")
108 set(IMAGE_VERSION_S "")
109 set(IMAGE_VERSION_NS "")
David Vincze54d05552019-08-05 12:58:47 +0200110 endif()
David Vincze9ec0f542019-07-03 18:09:47 +0200111 if (DEFINED S_IMAGE_MIN_VER OR
112 DEFINED NS_IMAGE_MIN_VER)
David Vinczec3e313a2020-01-06 17:31:11 +0100113 message(WARNING "Ignoring the values of *_IMAGE_MIN_VER variables as BL2 option is set to False.")
114 set(S_IMAGE_MIN_VER "")
115 set(NS_IMAGE_MIN_VER "")
David Vincze9ec0f542019-07-03 18:09:47 +0200116 endif()
David Vincze54d05552019-08-05 12:58:47 +0200117endif()