blob: 7c2caba11a3fd77038d9eade8e9bf3bf2beccc39 [file] [log] [blame]
Tamas Bandb69d522018-03-01 10:04:41 +00001#-------------------------------------------------------------------------------
David Vinczedb32b212019-04-16 17:43:57 +02002# Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Tamas Bandb69d522018-03-01 10:04:41 +00003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8cmake_minimum_required(VERSION 3.7)
9
10function(mcuboot_create_boot_payload)
11 set( _OPTIONS_ARGS) #Option (on/off) arguments (e.g. IGNORE_CASE)
12 set( _ONE_VALUE_ARGS S_BIN NS_BIN FULL_BIN SIGN_BIN POSTFIX) #Single option arguments (e.g. PATH "./foo/bar")
13 set( _MULTI_VALUE_ARGS) #List arguments (e.g. LANGUAGES C ASM CXX)
14 cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
15
16 if (NOT DEFINED _MY_PARAMS_S_BIN)
17 message(FATAL_ERROR "mcuboot_create_boot_payload(): mandatory parameter 'S_BIN' missing.")
18 endif()
19
20 if (NOT DEFINED _MY_PARAMS_NS_BIN)
21 message(FATAL_ERROR "mcuboot_create_boot_payload(): mandatory parameter 'NS_BIN' missing.")
22 endif()
23
24 if (NOT DEFINED _MY_PARAMS_FULL_BIN)
25 message(FATAL_ERROR "mcuboot_create_boot_payload(): mandatory parameter 'FULL_BIN' missing.")
26 endif()
27
28 if (NOT DEFINED _MY_PARAMS_SIGN_BIN)
29 message(FATAL_ERROR "mcuboot_create_boot_payload(): mandatory parameter 'SIGN_BIN' missing.")
30 endif()
31
Tamas Ban57bfa432018-04-13 16:05:49 +010032 if (DEFINED _MY_PARAMS_POSTFIX)
33 if (${_MY_PARAMS_POSTFIX} STREQUAL "_0")
34 set(MY_POSTFIX "0")
35 else()
36 set(MY_POSTFIX "1")
37 endif()
38 endif()
39
Tamas Bandb69d522018-03-01 10:04:41 +000040 #Find Python3.x interpreter
41 find_package(PythonInterp 3)
42 if (NOT PYTHONINTERP_FOUND)
43 message(FATAL_ERROR "Failed to find Python3.x interpreter. Pyhton3 must be installed and available on the PATH.")
44 endif()
45
46 if(NOT DEFINED FLASH_LAYOUT)
47 message(FATAL_ERROR "ERROR: Incomplete Configuration: FLASH_LAYOUT is not defined.")
48 endif()
49
Tamas Ban7801ed42019-05-20 13:21:53 +010050 if (MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-3072")
51 set(KEY_FILE "${MCUBOOT_DIR}/root-rsa-3072.pem")
52 elseif(MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-2048")
53 set(KEY_FILE "${MCUBOOT_DIR}/root-rsa-2048.pem")
54 else()
55 message(FATAL_ERROR "${MCUBOOT_SIGNATURE_TYPE} is not supported as firmware signing algorithm")
56 endif()
57
David Vinczedb32b212019-04-16 17:43:57 +020058 if (DEFINED SECURITY_COUNTER)
59 set (ADD_SECURITY_COUNTER "-s ${SECURITY_COUNTER}")
60 else()
61 set (ADD_SECURITY_COUNTER "")
62 endif()
63
Tamas Bandb69d522018-03-01 10:04:41 +000064 add_custom_command(TARGET ${_MY_PARAMS_NS_BIN}
65 POST_BUILD
Tamas Bandb69d522018-03-01 10:04:41 +000066 #Create concatenated binary image from the two binary file
67 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
68 ARGS -l ${FLASH_LAYOUT}
69 -s $<TARGET_FILE_DIR:${_MY_PARAMS_S_BIN}>/${_MY_PARAMS_S_BIN}.bin
70 -n $<TARGET_FILE_DIR:${_MY_PARAMS_NS_BIN}>/${_MY_PARAMS_NS_BIN}.bin
71 -o ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
72
73 #Sign concatenated binary image with default public key in mcuboot folder
74 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
75 ARGS sign
Oliver Swede05e5ded2018-07-19 16:40:49 +010076 --layout ${FLASH_LAYOUT}
Tamas Ban7801ed42019-05-20 13:21:53 +010077 -k ${KEY_FILE}
Tamas Bandb69d522018-03-01 10:04:41 +000078 --align 1
Oliver Swede21440442018-07-10 09:31:32 +010079 -v ${IMAGE_VERSION}
David Vinczedb32b212019-04-16 17:43:57 +020080 ${ADD_SECURITY_COUNTER}
Tamas Bandb69d522018-03-01 10:04:41 +000081 -H 0x400
82 --pad ${SIGN_BIN_SIZE}
83 ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
84 ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin)
Tamas Ban57bfa432018-04-13 16:05:49 +010085
86 #Collect executables to common location: build/install/outputs/
87 set(TFM_FULL_NAME tfm_s_ns_concatenated)
88 set(TFM_SIGN_NAME tfm_s_ns_signed)
89
90 if (DEFINED MY_POSTFIX)
91 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin
92 RENAME tfm_sig${MY_POSTFIX}.bin
93 DESTINATION outputs/${TARGET_PLATFORM}/)
94 else()
95 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin
96 DESTINATION outputs/${TARGET_PLATFORM}/)
97 endif()
98
99 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
Oliver Swede05e5ded2018-07-19 16:40:49 +0100100 DESTINATION outputs/${TARGET_PLATFORM}/)
Tamas Ban57bfa432018-04-13 16:05:49 +0100101
102 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
103 RENAME ${TFM_FULL_NAME}${_MY_PARAMS_POSTFIX}.bin
104 DESTINATION outputs/fvp/)
105
106 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin
107 RENAME ${TFM_SIGN_NAME}${_MY_PARAMS_POSTFIX}.bin
108 DESTINATION outputs/fvp/)
David Vinczedb32b212019-04-16 17:43:57 +0200109endfunction()