1################################################################################
2# \file MCUBootApp.mk
3# \version 1.0
4#
5# \brief
6# Makefile for Cypress MCUBoot-based application.
7#
8################################################################################
9# \copyright
10# Copyright 2018-2019 Cypress Semiconductor Corporation
11# SPDX-License-Identifier: Apache-2.0
12#
13# Licensed under the Apache License, Version 2.0 (the "License");
14# you may not use this file except in compliance with the License.
15# You may obtain a copy of the License at
16#
17#     http://www.apache.org/licenses/LICENSE-2.0
18#
19# Unless required by applicable law or agreed to in writing, software
20# distributed under the License is distributed on an "AS IS" BASIS,
21# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22# See the License for the specific language governing permissions and
23# limitations under the License.
24################################################################################
25
26include host.mk
27
28# Cypress' MCUBoot Application supports GCC ARM only at this moment
29# Set default compiler to GCC if not specified from command line
30COMPILER ?= GCC_ARM
31
32USE_CRYPTO_HW ?= 0
33USE_EXTERNAL_FLASH ?= 0
34MCUBOOT_IMAGE_NUMBER ?= 1
35ENC_IMG ?= 0
36
37# For which core this application is built
38CORE ?= CM0P
39
40ifneq ($(COMPILER), GCC_ARM)
41$(error Only GCC ARM is supported at this moment)
42endif
43
44CUR_APP_PATH = $(PRJ_DIR)/$(APP_NAME)
45
46include $(PRJ_DIR)/platforms.mk
47include $(PRJ_DIR)/common_libs.mk
48include $(PRJ_DIR)/toolchains.mk
49
50# default slot size is 0x10000, 512bytes per row/sector, so 128 sectors
51MAX_IMG_SECTORS ?= 128
52
53# Application-specific DEFINES
54DEFINES_APP := -DMBEDTLS_CONFIG_FILE="\"mcuboot_crypto_config.h\""
55DEFINES_APP += -DECC256_KEY_FILE="\"keys/$(SIGN_KEY_FILE).pub\""
56DEFINES_APP += -DCORE=$(CORE)
57DEFINES_APP += -DMCUBOOT_IMAGE_NUMBER=$(MCUBOOT_IMAGE_NUMBER)
58ifeq ($(USE_EXTERNAL_FLASH), 1)
59DEFINES_APP += -DCY_BOOT_USE_EXTERNAL_FLASH
60endif
61DEFINES_APP += -DMCUBOOT_MAX_IMG_SECTORS=$(MAX_IMG_SECTORS)
62# Hardrware acceleration support
63ifeq ($(USE_CRYPTO_HW), 1)
64DEFINES_APP += -DMBEDTLS_USER_CONFIG_FILE="\"mcuboot_crypto_acc_config.h\""
65DEFINES_APP += -DCY_CRYPTO_HAL_DISABLE
66DEFINES_APP += -DCY_MBEDTLS_HW_ACCELERATION
67endif
68# Encrypted image support
69ifeq ($(ENC_IMG), 1)
70DEFINES_APP += -DENC_IMG=1
71endif
72
73# Collect MCUBoot sourses
74SOURCES_MCUBOOT := $(wildcard $(CURDIR)/../bootutil/src/*.c)
75# Collect MCUBoot Application sources
76SOURCES_APP_SRC := $(wildcard $(CUR_APP_PATH)/*.c)
77
78# Collect Flash Layer port sources
79SOURCES_FLASH_PORT := $(wildcard $(CURDIR)/cy_flash_pal/*.c)
80SOURCES_FLASH_PORT += $(wildcard $(CURDIR)/cy_flash_pal/flash_qspi/*.c)
81# Collect all the sources
82SOURCES_APP := $(SOURCES_MCUBOOT)
83SOURCES_APP += $(SOURCES_APP_SRC)
84SOURCES_APP += $(SOURCES_FLASH_PORT)
85
86INCLUDE_DIRS_MCUBOOT := $(addprefix -I, $(CURDIR)/../bootutil/include)
87INCLUDE_DIRS_MCUBOOT += $(addprefix -I, $(CURDIR)/../bootutil/src)
88INCLUDE_DIRS_MCUBOOT += $(addprefix -I, $(CURDIR)/..)
89
90INCLUDE_DIRS_APP := $(addprefix -I, $(CURDIR))
91INCLUDE_DIRS_APP += $(addprefix -I, $(CURDIR)/cy_flash_pal/flash_qspi)
92INCLUDE_DIRS_APP += $(addprefix -I, $(CURDIR)/cy_flash_pal/include)
93INCLUDE_DIRS_APP += $(addprefix -I, $(CURDIR)/cy_flash_pal/include/flash_map_backend)
94INCLUDE_DIRS_APP += $(addprefix -I, $(CUR_APP_PATH))
95INCLUDE_DIRS_APP += $(addprefix -I, $(CUR_APP_PATH)/config)
96INCLUDE_DIRS_APP += $(addprefix -I, $(CUR_APP_PATH)/os)
97
98ASM_FILES_APP :=
99ASM_FILES_APP += $(ASM_FILES_STARTUP)
100
101# Output folder
102OUT := $(APP_NAME)/out
103# Output folder to contain build artifacts
104OUT_TARGET := $(OUT)/$(PLATFORM)
105
106OUT_CFG := $(OUT_TARGET)/$(BUILDCFG)
107
108# Overwite path to linker script if custom is required
109ifeq ($(COMPILER), GCC_ARM)
110LINKER_SCRIPT := $(subst /cygdrive/c,c:,$(CUR_APP_PATH)/$(APP_NAME).ld)
111else
112$(error Only GCC ARM is supported at this moment)
113endif