blob: b911d19d2b4d639066f35edbbcdf33339b9f6543 [file] [log] [blame]
Juan Castillo6f971622014-10-21 11:30:42 +01001#
Juan Pablo Condecf2dd172022-10-25 19:41:02 -04002# Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved.
Juan Castillo6f971622014-10-21 11:30:42 +01003#
dp-arm82cb2c12017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Juan Castillo6f971622014-10-21 11:30:42 +01005#
6
Juan Castillo6f971622014-10-21 11:30:42 +01007PLAT := none
dp-arma9673902017-05-02 11:14:29 +01008V ?= 0
Juan Castillo6f971622014-10-21 11:30:42 +01009DEBUG := 0
Manish V Badarkheb13e3f92020-09-05 04:40:41 +010010CRTTOOL ?= cert_create${BIN_EXT}
Manish V Badarkhefafd3ec2020-08-13 05:56:33 +010011BINARY := $(notdir ${CRTTOOL})
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010012COT := tbbr
Juan Castillo6f971622014-10-21 11:30:42 +010013
Evan Lloyd231c1472015-12-02 18:17:37 +000014MAKE_HELPERS_DIRECTORY := ../../make_helpers/
15include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
Evan Lloyde7f54db2015-12-02 18:56:06 +000016include ${MAKE_HELPERS_DIRECTORY}build_env.mk
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040017include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Evan Lloyd231c1472015-12-02 18:17:37 +000018
Pankaj Guptab94bf962020-12-09 14:02:38 +053019ifneq (${PLAT},none)
20TF_PLATFORM_ROOT := ../../plat/
21include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
22PLAT_CERT_CREATE_HELPER_MK := ${PLAT_DIR}/cert_create_tbbr.mk
23endif
24
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010025# Common source files.
26OBJECTS := src/cert.o \
27 src/cmd_opt.o \
28 src/ext.o \
29 src/key.o \
30 src/main.o \
31 src/sha.o
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090032
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010033# Chain of trust.
34ifeq (${COT},tbbr)
35 include src/tbbr/tbbr.mk
Sandrine Bailleuxa9d5c272020-01-10 14:32:30 +010036else ifeq (${COT},dualroot)
37 include src/dualroot/cot.mk
laurenw-arm0a6bf812022-04-21 16:21:53 -050038else ifeq (${COT},cca)
39 include src/cca/cot.mk
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010040else
41 $(error Unknown chain of trust ${COT})
42endif
Evan Lloyd231c1472015-12-02 18:17:37 +000043
Pankaj Guptab94bf962020-12-09 14:02:38 +053044ifneq (,$(wildcard ${PLAT_CERT_CREATE_HELPER_MK}))
45include ${PLAT_CERT_CREATE_HELPER_MK}
46endif
47
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040048# Select OpenSSL version flag according to the OpenSSL build selected
49# from setting the OPENSSL_DIR path.
50$(eval $(call SELECT_OPENSSL_API_VERSION))
51
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010052HOSTCCFLAGS := -Wall -std=c99
Juan Castillo6f971622014-10-21 11:30:42 +010053
54ifeq (${DEBUG},1)
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010055 HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
Juan Castillo6f971622014-10-21 11:30:42 +010056else
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010057 HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
Juan Castillo6f971622014-10-21 11:30:42 +010058endif
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010059
Juan Castillo6f971622014-10-21 11:30:42 +010060ifeq (${V},0)
dp-arma9673902017-05-02 11:14:29 +010061 Q := @
Juan Castillo6f971622014-10-21 11:30:42 +010062else
dp-arma9673902017-05-02 11:14:29 +010063 Q :=
Juan Castillo6f971622014-10-21 11:30:42 +010064endif
65
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010066HOSTCCFLAGS += ${DEFINES}
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040067# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
68# computed value.
69HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090070
Juan Castillo6f971622014-10-21 11:30:42 +010071# Make soft links and include from local directory otherwise wrong headers
72# could get pulled in from firmware tree.
Pankaj Guptab94bf962020-12-09 14:02:38 +053073INC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
Juan Pablo Conde9bc52d32022-03-02 18:10:08 -050074
75# Include library directories where OpenSSL library files are located.
76# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
77# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
78# directory. However, for a local build of OpenSSL, the built binaries are
79# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
80# ${OPENSSL_DIR}/lib/).
81LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
Juan Castillo6f971622014-10-21 11:30:42 +010082LIB := -lssl -lcrypto
83
dp-arm72610c42017-05-02 11:09:11 +010084HOSTCC ?= gcc
Juan Castillo6f971622014-10-21 11:30:42 +010085
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040086.PHONY: all clean realclean --openssl
Juan Castillo6f971622014-10-21 11:30:42 +010087
Vincent Stehléaa57ce62023-07-04 16:14:02 +020088all: --openssl ${BINARY}
Juan Castillo6f971622014-10-21 11:30:42 +010089
Vincent Stehléaa57ce62023-07-04 16:14:02 +020090${BINARY}: ${OBJECTS} Makefile
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010091 @echo " HOSTLD $@"
Juan Castillo6f971622014-10-21 11:30:42 +010092 @echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__; \
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090093 const char platform_msg[] = "${PLAT_MSG}";' | \
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010094 ${HOSTCC} -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
dp-arm72610c42017-05-02 11:09:11 +010095 ${Q}${HOSTCC} src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
Juan Castillo6f971622014-10-21 11:30:42 +010096
97%.o: %.c
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010098 @echo " HOSTCC $<"
99 ${Q}${HOSTCC} -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
Juan Castillo6f971622014-10-21 11:30:42 +0100100
Juan Pablo Condecf2dd172022-10-25 19:41:02 -0400101--openssl:
102ifeq ($(DEBUG),1)
103 @echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
104endif
105
Juan Castillo6f971622014-10-21 11:30:42 +0100106clean:
Evan Lloydf1477d42015-12-02 18:33:55 +0000107 $(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS})
Juan Castillo6f971622014-10-21 11:30:42 +0100108
109realclean: clean
Jonathan Wright2f36e852018-04-30 15:04:02 +0100110 $(call SHELL_DELETE,${BINARY})
Evan Lloydf1477d42015-12-02 18:33:55 +0000111