1################################################################################ 2# \file Makefile 3# \version 1.0 4# 5# \brief 6# Main Makefile for building MCUBoot application for Cypress target. 7# 8################################################################################ 9# \copyright 10# Copyright 2018-2021 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 26# minimum Python 3.7 is required 27# Python path definition 28ifeq ($(OS),Windows_NT) 29PYTHON_PATH?=python 30else 31PYTHON_PATH?=python3 32endif 33 34################################################################################ 35# Main settings 36################################################################################ 37 38# Defines whether or not show verbose build output 39MAKEINFO ?= 1 40# Application name by default 41APP_NAME ?= MCUBootApp 42# Weather or now execute post build script after build - set to 0 for CI 43POST_BUILD ?= 1 44 45SIGN_KEY_FILE ?= cypress-test-ec-p256 46ENC_KEY_FILE ?= enc-ec256-pub 47ENC_IMG ?= 0 48 49# set this variable to a path, where cysecuretools python package is installed 50# use command `python -m pip show cysecuretools` to find out this path 51# or rely on scripts that automates this action, bit not work for virtual envs 52CY_SEC_TOOLS_PATH ?= $(shell $(PYTHON_PATH) $(CURDIR)/scripts/find_cysectools.py) 53 54BUILDCFG ?= Debug 55 56# Set of supported applications 57APPS := MCUBootApp BlinkyApp 58 59HEADER_OFFSET ?= 0 60 61ifneq ($(filter $(APP_NAME), $(APPS)),) 62include ./$(APP_NAME)/$(APP_NAME).mk 63include ./$(APP_NAME)/libs.mk 64else 65$(error Not supported application: '$(APP_NAME)') 66endif 67 68ASM_FILES := $(ASM_FILES_APP) 69ASM_FILES += $(ASM_FILES_LIBS) 70 71C_FILES := $(SOURCES_APP) 72C_FILES += $(SOURCES_LIBS) 73 74INCLUDE_DIRS := $(INCLUDE_DIRS_APP) 75INCLUDE_DIRS += $(INCLUDE_DIRS_MCUBOOT) 76INCLUDE_DIRS += $(INCLUDE_DIRS_LIBS) 77 78#INCLUDE_FILES := $(INCLUDE_FILES_APP) 79 80#INCLUDES := $(addprefix -include , $(INCLUDE_FILES)) 81 82O_FILES := $(notdir $(C_FILES:.c=.o)) $(addsuffix .o, $(notdir $(basename $(ASM_FILES)))) 83 84DEFINES := $(DEFINES_APP) 85DEFINES += $(DEFINES_LIBS) 86AS_FLAGS += $(DEFINES) 87 88ifeq ($(MAKEINFO), 1) 89$(info ==============================================================================) 90$(info = Directories to look for header files: =) 91$(info ==============================================================================) 92$(info $(INCLUDE_DIRS)) 93 94$(info ==============================================================================) 95$(info = Collected Defines string: =) 96$(info ==============================================================================) 97$(info $(DEFINES)) 98endif 99 100# updating CFLAGS at this point as DEFINES are completed 101CFLAGS += $(DEFINES) 102 103VPATH = $(dir $(C_FILES) $(ASM_FILES)) 104 105# 106# STDE: For cygwin, adjust paths for compiler 107# 108MY_FILES := $(subst /cygdrive/c,c:,$(C_FILES)) 109#$(info MY_FILES $(MY_FILES)) 110C_FILES=$(MY_FILES) 111 112MY_DIRS := $(subst /cygdrive/c,c:,$(INCLUDE_DIRS)) 113#$(info MY_DIRS $(MY_DIRS)) 114INCLUDE_DIRS=$(MY_DIRS) 115 116MY_ASM_FILES := $(subst /cygdrive/c,c:,$(ASM_FILES)) 117#$(info MY_ASM_FILES $(MY_ASM_FILES)) 118ASM_FILES=$(MY_ASM_FILES) 119 120MY_LDFLAGS := $(subst /cygdrive/c,c:,$(LDFLAGS)) 121#$(info MY_LDFLAGS $(MY_LDFLAGS)) 122LDFLAGS=$(MY_LDFLAGS) 123 124# Default name pattern for output files 125# may be modified in %Application%.mk file 126OUT_FILE_NAME ?= $(OUT_APP)/$(APP_NAME) 127 128OUT_OBJ := $(OUT_CFG)/obj 129OUT_APP := $(OUT_CFG) 130 131.PHONY: all app build clean pre_build post_build 132 133all: clean app 134 135app: 136 @`mkdir -p ./$(OUT)` 137 @`mkdir -p ./$(OUT_TARGET)` 138 @`mkdir -p ./$(OUT_CFG)` 139 @`mkdir -p ./$(OUT_OBJ)` 140 $(MAKE) pre_build 141 $(MAKE) build -j8 142 $(MAKE) post_build 143 144build: $(OUT_APP)/$(APP_NAME).hex 145 $(GCC_PATH)/bin/arm-none-eabi-objdump $(OUT_APP)/$(APP_NAME).elf -S --disassemble > $(OUT_APP)/$(APP_NAME).lst 146 $(GCC_PATH)/bin/arm-none-eabi-objdump -h $(OUT_APP)/$(APP_NAME).elf 147 $(GCC_PATH)/bin/arm-none-eabi-size --format=SysV $(OUT_APP)/$(APP_NAME).elf 148 149$(OUT_APP)/$(APP_NAME).hex: $(OUT_APP)/$(APP_NAME).elf 150 $(GCC_PATH)/bin/arm-none-eabi-objcopy --change-addresses=$(HEADER_OFFSET) -O ihex $(OUT_APP)/$(APP_NAME).elf $(OUT_APP)/$(APP_NAME).hex 151 152$(OUT_APP)/$(APP_NAME).elf: $(addprefix $(OUT_OBJ)/, $(O_FILES)) 153 @echo "LD $@" 154ifeq ($(MAKEINFO), 1) 155 @echo $(LD) $(O_FILES) $(CC_DEPEND) $(@:.o=.d) -o $@ $(LDFLAGS) -T $(LINKER_SCRIPT) -Wl,-Map,$(OUT_FILE_NAME).map 156endif 157 @$(LD) $(addprefix $(OUT_OBJ)/, $(O_FILES)) $(CC_DEPEND) $(@:.o=.d) -o $@ $(LDFLAGS) -T $(LINKER_SCRIPT) -Wl,-Map,$(OUT_FILE_NAME).map 158 159 160$(OUT_OBJ)/%.o: %.c 161 @echo "CC $<" 162ifeq ($(MAKEINFO), 1) 163 @echo $(CC) $(CFLAGS) $(INCLUDE_DIRS) $(CC_DEPEND) $(@:.o=.d) -c $< -o $@ 164endif 165 @$(CC) $(CFLAGS) $(INCLUDE_DIRS) $(CC_DEPEND) $(@:.o=.d) -c $< -o $@ 166ifeq ($(MAKEINFO), 1) 167 @echo 168endif 169 170$(OUT_OBJ)/%.o: %.S 171 @echo "AS $<" 172ifeq ($(COMPILER), GCC_ARM) 173ifeq ($(MAKEINFO), 1) 174 @echo @$(CC) $(CFLAGS) $(INCLUDE_DIRS) $(CC_DEPEND) $(@:.o=.d) -c $< -o $@ 175endif 176 @$(CC) $(CFLAGS) $(INCLUDE_DIRS) $(CC_DEPEND) $(@:.o=.d) -c $< -o $@ 177else 178 @echo $(AS) $< -o $@ $(AS_FLAGS) 179 @$(AS) $< -o $@ $(AS_FLAGS) 180endif 181ifeq ($(MAKEINFO), 1) 182 @echo 183endif 184 185clean: 186 @echo "Cleanup out directory..." 187 rm -rf $(OUT_TARGET)/$(BUILDCFG) 188 189clean_boot: 190 @echo "Cleanup out BOOT directory of $(APP_NAME)..." 191 rm -rf $(OUT_TARGET)/$(BUILDCFG)/boot 192 193clean_upgrade: 194 @echo "Cleanup out UPGRADE directory of $(APP_NAME)..." 195 rm -rf $(OUT_TARGET)/$(BUILDCFG)/upgrade 196 197run_cppcheck: 198 @echo "Performing static code analysis with Cppcheck tool..." 199 cppcheck/cppcheck.sh $(APP_NAME) $(PLATFORM) "$(DEFINES)" "$(INCLUDE_DIRS)" "$(C_FILES)" $(CPP_CHECK_SCOPE) $(BUILDCFG) 200 201gen_key_ecc256: 202 @echo Generate ECC256 keys: $(SIGN_KEY_FILE).pem and $(SIGN_KEY_FILE).pub 203 ../../scripts/imgtool.py keygen -k keys/$(SIGN_KEY_FILE).pem -t ecdsa-p256 204 ../../scripts/imgtool.py getpub -k keys/$(SIGN_KEY_FILE).pem > keys/$(SIGN_KEY_FILE).pub 205 206ifeq ($(MAKEINFO) , 1) 207$(info ASM_FILES: $(ASM_FILES)) 208$(info C_FILES: $(C_FILES)) 209$(info INCLUDE_DIRS: $(INCLUDE_DIRS)) 210$(info DEFINES: $(DEFINES)) 211$(info CC: $(CC)) 212endif 213