blob: 5ff2080d204f7eac7a1c08a3715d010b725ebf4d [file] [log] [blame]
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +02001################################################################################
2# \file BlinkyApp.mk
3# \version 1.0
4#
5# \brief
6# Makefile to describe demo application BlinkyApp for Cypress MCUBoot based applications.
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
Roman Okhrimenko4bc28102021-02-01 19:31:41 +020026include host.mk
27
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020028# Cypress' MCUBoot Application supports GCC ARM only at this moment
29# Set defaults to:
30# - compiler GCC
31# - build configuration to Debug
32# - image type to BOOT
33COMPILER ?= GCC_ARM
34IMG_TYPE ?= BOOT
35
Roman Okhrimenko4bc28102021-02-01 19:31:41 +020036# For which core this application is built
37CORE ?= CM4
38
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020039# image type can be BOOT or UPGRADE
40IMG_TYPES = BOOT UPGRADE
41
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050042# possible values are 0 and 0xff
43# internal Flash by default
44ERASED_VALUE ?= 0
45
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020046ifneq ($(COMPILER), GCC_ARM)
47$(error Only GCC ARM is supported at this moment)
48endif
49
Roman Okhrimenko4bc28102021-02-01 19:31:41 +020050CUR_APP_PATH = $(PRJ_DIR)/$(APP_NAME)
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020051
Roman Okhrimenko4bc28102021-02-01 19:31:41 +020052include $(PRJ_DIR)/platforms.mk
53include $(PRJ_DIR)/common_libs.mk
54include $(PRJ_DIR)/toolchains.mk
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020055
56# Application-specific DEFINES
57ifeq ($(IMG_TYPE), BOOT)
58 DEFINES_APP := -DBOOT_IMG
59else
60 DEFINES_APP := -DUPGRADE_IMG
61endif
62
63# Define start of application, RAM start and size, slot size
64ifeq ($(PLATFORM), PSOC_062_2M)
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050065 DEFINES_APP += -DRAM_START=0x08040000
66 DEFINES_APP += -DRAM_SIZE=0x10000
Roman Okhrimenko4bc28102021-02-01 19:31:41 +020067else ifeq ($(PLATFORM), PSOC_062_1M)
68 DEFINES_APP += -DRAM_START=0x08020000
69 DEFINES_APP += -DRAM_SIZE=0x10000
70else ifeq ($(PLATFORM), PSOC_062_512K)
71 DEFINES_APP += -DRAM_START=0x08020000
72 DEFINES_APP += -DRAM_SIZE=0x10000
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020073endif
74
Roman Okhrimenko4bc28102021-02-01 19:31:41 +020075
76DEFINES_APP += -DRAM_SIZE=0x10000
77DEFINES_APP += -DUSER_APP_START=0x10018000
78SLOT_SIZE ?= 0x10000
79
80
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020081# Collect Test Application sources
82SOURCES_APP_SRC := $(wildcard $(CUR_APP_PATH)/*.c)
83# Collect all the sources
84SOURCES_APP += $(SOURCES_APP_SRC)
85
86# Collect includes for BlinkyApp
87INCLUDE_DIRS_APP := $(addprefix -I, $(CURDIR))
88INCLUDE_DIRS_APP += $(addprefix -I, $(CUR_APP_PATH))
89
90# Overwite path to linker script if custom is required, otherwise default from BSP is used
91ifeq ($(COMPILER), GCC_ARM)
92LINKER_SCRIPT := $(subst /cygdrive/c,c:,$(CUR_APP_PATH)/linker/$(APP_NAME).ld)
93else
94$(error Only GCC ARM is supported at this moment)
95endif
96
97ASM_FILES_APP :=
Roman Okhrimenko4bc28102021-02-01 19:31:41 +020098ASM_FILES_APP += $(ASM_FILES_STARTUP)
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020099
100# We still need this for MCUBoot apps signing
101IMGTOOL_PATH ?= ../../scripts/imgtool.py
102
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -0500103SIGN_ARGS := sign --header-size 1024 --pad-header --align 8 -v "2.0" -S $(SLOT_SIZE) -M 512 --overwrite-only -R $(ERASED_VALUE) -k keys/$(SIGN_KEY_FILE).pem
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +0200104
105# Output folder
106OUT := $(APP_NAME)/out
107# Output folder to contain build artifacts
108OUT_TARGET := $(OUT)/$(PLATFORM)
109
110OUT_CFG := $(OUT_TARGET)/$(BUILDCFG)
111
112# Set build directory for BOOT and UPGRADE images
113ifeq ($(IMG_TYPE), UPGRADE)
Bohdan Kovalchukde518072020-11-30 22:10:48 +0200114 ifeq ($(ENC_IMG), 1)
115 SIGN_ARGS += --encrypt ../../$(ENC_KEY_FILE).pem
116 endif
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +0200117 SIGN_ARGS += --pad
118 UPGRADE_SUFFIX :=_upgrade
119 OUT_CFG := $(OUT_CFG)/upgrade
120else
121 OUT_CFG := $(OUT_CFG)/boot
122endif
123
124pre_build:
125 $(info [PRE_BUILD] - Generating linker script for application $(CUR_APP_PATH)/linker/$(APP_NAME).ld)
126 @$(CC) -E -x c $(CFLAGS) $(INCLUDE_DIRS) $(CUR_APP_PATH)/linker/$(APP_NAME)_template.ld | grep -v '^#' >$(CUR_APP_PATH)/linker/$(APP_NAME).ld
127
128# Post build action to execute after main build job
129post_build: $(OUT_CFG)/$(APP_NAME).hex
130 $(info [POST_BUILD] - Executing post build script for $(APP_NAME))
131 mv -f $(OUT_CFG)/$(APP_NAME).hex $(OUT_CFG)/$(APP_NAME)_unsigned.hex
132 $(PYTHON_PATH) $(IMGTOOL_PATH) $(SIGN_ARGS) $(OUT_CFG)/$(APP_NAME)_unsigned.hex $(OUT_CFG)/$(APP_NAME)$(UPGRADE_SUFFIX).hex