blob: 95f5ff088685b352fde0423e4f20acb26fd77419 [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
David Vinczedb32b212019-04-16 17:43:57 +020050 if (DEFINED SECURITY_COUNTER)
51 set (ADD_SECURITY_COUNTER "-s ${SECURITY_COUNTER}")
52 else()
53 set (ADD_SECURITY_COUNTER "")
54 endif()
55
Tamas Bandb69d522018-03-01 10:04:41 +000056 add_custom_command(TARGET ${_MY_PARAMS_NS_BIN}
57 POST_BUILD
Tamas Bandb69d522018-03-01 10:04:41 +000058 #Create concatenated binary image from the two binary file
59 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
60 ARGS -l ${FLASH_LAYOUT}
61 -s $<TARGET_FILE_DIR:${_MY_PARAMS_S_BIN}>/${_MY_PARAMS_S_BIN}.bin
62 -n $<TARGET_FILE_DIR:${_MY_PARAMS_NS_BIN}>/${_MY_PARAMS_NS_BIN}.bin
63 -o ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
64
65 #Sign concatenated binary image with default public key in mcuboot folder
66 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
67 ARGS sign
Oliver Swede05e5ded2018-07-19 16:40:49 +010068 --layout ${FLASH_LAYOUT}
Tamas Bandb69d522018-03-01 10:04:41 +000069 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
70 --align 1
Oliver Swede21440442018-07-10 09:31:32 +010071 -v ${IMAGE_VERSION}
David Vinczedb32b212019-04-16 17:43:57 +020072 ${ADD_SECURITY_COUNTER}
Tamas Bandb69d522018-03-01 10:04:41 +000073 -H 0x400
74 --pad ${SIGN_BIN_SIZE}
75 ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
76 ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin)
Tamas Ban57bfa432018-04-13 16:05:49 +010077
78 #Collect executables to common location: build/install/outputs/
79 set(TFM_FULL_NAME tfm_s_ns_concatenated)
80 set(TFM_SIGN_NAME tfm_s_ns_signed)
81
82 if (DEFINED MY_POSTFIX)
83 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin
84 RENAME tfm_sig${MY_POSTFIX}.bin
85 DESTINATION outputs/${TARGET_PLATFORM}/)
86 else()
87 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin
88 DESTINATION outputs/${TARGET_PLATFORM}/)
89 endif()
90
91 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
Oliver Swede05e5ded2018-07-19 16:40:49 +010092 DESTINATION outputs/${TARGET_PLATFORM}/)
Tamas Ban57bfa432018-04-13 16:05:49 +010093
94 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
95 RENAME ${TFM_FULL_NAME}${_MY_PARAMS_POSTFIX}.bin
96 DESTINATION outputs/fvp/)
97
98 install(FILES ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin
99 RENAME ${TFM_SIGN_NAME}${_MY_PARAMS_POSTFIX}.bin
100 DESTINATION outputs/fvp/)
David Vinczedb32b212019-04-16 17:43:57 +0200101endfunction()