blob: cdcfcbd067ee6afbce72b931e72ac31f49947a9d [file] [log] [blame]
Tamas Bandb69d522018-03-01 10:04:41 +00001#-------------------------------------------------------------------------------
2# Copyright (c) 2018, Arm Limited. All rights reserved.
3#
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
32 #Find Python3.x interpreter
33 find_package(PythonInterp 3)
34 if (NOT PYTHONINTERP_FOUND)
35 message(FATAL_ERROR "Failed to find Python3.x interpreter. Pyhton3 must be installed and available on the PATH.")
36 endif()
37
38 if(NOT DEFINED FLASH_LAYOUT)
39 message(FATAL_ERROR "ERROR: Incomplete Configuration: FLASH_LAYOUT is not defined.")
40 endif()
41
42 add_custom_command(TARGET ${_MY_PARAMS_NS_BIN}
43 POST_BUILD
44
45 #Create concatenated binary image from the two binary file
46 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/assemble.py
47 ARGS -l ${FLASH_LAYOUT}
48 -s $<TARGET_FILE_DIR:${_MY_PARAMS_S_BIN}>/${_MY_PARAMS_S_BIN}.bin
49 -n $<TARGET_FILE_DIR:${_MY_PARAMS_NS_BIN}>/${_MY_PARAMS_NS_BIN}.bin
50 -o ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
51
52 #Sign concatenated binary image with default public key in mcuboot folder
53 COMMAND ${PYTHON_EXECUTABLE} ${MCUBOOT_DIR}/scripts/imgtool.py
54 ARGS sign
55 -k ${MCUBOOT_DIR}/root-rsa-2048.pem
56 --align 1
57 -v 1.0
58 -H 0x400
59 --pad ${SIGN_BIN_SIZE}
60 ${CMAKE_BINARY_DIR}/${_MY_PARAMS_FULL_BIN}.bin
61 ${CMAKE_BINARY_DIR}/${_MY_PARAMS_SIGN_BIN}.bin)
62endfunction()