blob: 21523f6c3b587593053e89899794fb1b071e0585 [file] [log] [blame]
Juan Castillo11abdcd2014-10-21 11:30:42 +01001#
Chris Kayc8a47ba2023-10-20 09:17:33 +00002# Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
Juan Castillo11abdcd2014-10-21 11:30:42 +01003#
dp-armfa3cf0b2017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Juan Castillo11abdcd2014-10-21 11:30:42 +01005#
6
Juan Castillo11abdcd2014-10-21 11:30:42 +01007PLAT := none
dp-arm34c82012017-05-02 11:14:29 +01008V ?= 0
Juan Castillo11abdcd2014-10-21 11:30:42 +01009DEBUG := 0
Manish V Badarkheb9adb522020-09-05 04:40:41 +010010CRTTOOL ?= cert_create${BIN_EXT}
Manish V Badarkhe635482e2020-08-13 05:56:33 +010011BINARY := $(notdir ${CRTTOOL})
Sandrine Bailleux2f7f1442020-01-15 10:11:07 +010012COT := tbbr
Juan Castillo11abdcd2014-10-21 11:30:42 +010013
Chris Kayc8a47ba2023-10-20 09:17:33 +000014toolchains := host
15
Sandrine Bailleux3f9df3d2020-01-14 18:06:38 +010016MAKE_HELPERS_DIRECTORY := ../../make_helpers/
17include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
18include ${MAKE_HELPERS_DIRECTORY}build_env.mk
Juan Pablo Conde3539c742022-10-25 19:41:02 -040019include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Chris Kayc8a47ba2023-10-20 09:17:33 +000020include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
Sandrine Bailleux3f9df3d2020-01-14 18:06:38 +010021
Pankaj Guptadd906e62020-12-09 14:02:38 +053022ifneq (${PLAT},none)
23TF_PLATFORM_ROOT := ../../plat/
24include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
25PLAT_CERT_CREATE_HELPER_MK := ${PLAT_DIR}/cert_create_tbbr.mk
26endif
27
Sandrine Bailleux3f9df3d2020-01-14 18:06:38 +010028# Common source files.
Juan Castillo11abdcd2014-10-21 11:30:42 +010029OBJECTS := src/cert.o \
Juan Castillo1218dd52015-07-03 16:23:16 +010030 src/cmd_opt.o \
Juan Castillo11abdcd2014-10-21 11:30:42 +010031 src/ext.o \
32 src/key.o \
33 src/main.o \
Sandrine Bailleux3f9df3d2020-01-14 18:06:38 +010034 src/sha.o
Juan Castillo11abdcd2014-10-21 11:30:42 +010035
Sandrine Bailleux2f7f1442020-01-15 10:11:07 +010036# Chain of trust.
37ifeq (${COT},tbbr)
38 include src/tbbr/tbbr.mk
Sandrine Bailleux5d505082020-01-10 14:32:30 +010039else ifeq (${COT},dualroot)
40 include src/dualroot/cot.mk
laurenw-arm1c7c5762022-04-21 16:21:53 -050041else ifeq (${COT},cca)
42 include src/cca/cot.mk
Sandrine Bailleux2f7f1442020-01-15 10:11:07 +010043else
44 $(error Unknown chain of trust ${COT})
45endif
Juan Castillo11abdcd2014-10-21 11:30:42 +010046
Pankaj Guptadd906e62020-12-09 14:02:38 +053047ifneq (,$(wildcard ${PLAT_CERT_CREATE_HELPER_MK}))
48include ${PLAT_CERT_CREATE_HELPER_MK}
49endif
50
Juan Pablo Conde3539c742022-10-25 19:41:02 -040051# Select OpenSSL version flag according to the OpenSSL build selected
52# from setting the OPENSSL_DIR path.
53$(eval $(call SELECT_OPENSSL_API_VERSION))
54
Sandrine Bailleux3f9df3d2020-01-14 18:06:38 +010055HOSTCCFLAGS := -Wall -std=c99
Juan Castillo11abdcd2014-10-21 11:30:42 +010056
57ifeq (${DEBUG},1)
Antonio Nino Diaz1c4d3622018-10-04 14:35:38 +010058 HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
Juan Castillo11abdcd2014-10-21 11:30:42 +010059else
Antonio Nino Diaz1c4d3622018-10-04 14:35:38 +010060 HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
Juan Castillo11abdcd2014-10-21 11:30:42 +010061endif
Sandrine Bailleux3f9df3d2020-01-14 18:06:38 +010062
Juan Castillo11abdcd2014-10-21 11:30:42 +010063ifeq (${V},0)
dp-arm34c82012017-05-02 11:14:29 +010064 Q := @
Juan Castillo11abdcd2014-10-21 11:30:42 +010065else
dp-arm34c82012017-05-02 11:14:29 +010066 Q :=
Juan Castillo11abdcd2014-10-21 11:30:42 +010067endif
68
Antonio Nino Diaz1c4d3622018-10-04 14:35:38 +010069HOSTCCFLAGS += ${DEFINES}
Juan Pablo Conde3539c742022-10-25 19:41:02 -040070# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
71# computed value.
72HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
Masahiro Yamadaa27c1662017-05-22 12:11:24 +090073
Juan Castillo11abdcd2014-10-21 11:30:42 +010074# Make soft links and include from local directory otherwise wrong headers
75# could get pulled in from firmware tree.
Pankaj Guptadd906e62020-12-09 14:02:38 +053076INC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
Juan Pablo Conde7275a5a2022-03-02 18:10:08 -050077
78# Include library directories where OpenSSL library files are located.
79# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
80# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
81# directory. However, for a local build of OpenSSL, the built binaries are
82# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
83# ${OPENSSL_DIR}/lib/).
84LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
Juan Castillo11abdcd2014-10-21 11:30:42 +010085LIB := -lssl -lcrypto
86
Juan Pablo Conde3539c742022-10-25 19:41:02 -040087.PHONY: all clean realclean --openssl
Juan Castillo11abdcd2014-10-21 11:30:42 +010088
Vincent Stehléb75a0dd2023-07-04 16:14:02 +020089all: --openssl ${BINARY}
Juan Castillo11abdcd2014-10-21 11:30:42 +010090
Vincent Stehléb75a0dd2023-07-04 16:14:02 +020091${BINARY}: ${OBJECTS} Makefile
Antonio Nino Diaz1c4d3622018-10-04 14:35:38 +010092 @echo " HOSTLD $@"
Juan Castillo11abdcd2014-10-21 11:30:42 +010093 @echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__; \
Masahiro Yamadaa27c1662017-05-22 12:11:24 +090094 const char platform_msg[] = "${PLAT_MSG}";' | \
Chris Kay523e8642023-12-04 12:03:51 +000095 $(host-cc) -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
96 ${Q}$(host-cc) src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
Juan Castillo11abdcd2014-10-21 11:30:42 +010097
98%.o: %.c
Antonio Nino Diaz1c4d3622018-10-04 14:35:38 +010099 @echo " HOSTCC $<"
Chris Kay523e8642023-12-04 12:03:51 +0000100 ${Q}$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
Juan Castillo11abdcd2014-10-21 11:30:42 +0100101
Juan Pablo Conde3539c742022-10-25 19:41:02 -0400102--openssl:
103ifeq ($(DEBUG),1)
104 @echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
105endif
106
Juan Castillo11abdcd2014-10-21 11:30:42 +0100107clean:
Evan Lloyd26c6cb42015-12-02 18:33:55 +0000108 $(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS})
Juan Castillo11abdcd2014-10-21 11:30:42 +0100109
110realclean: clean
Jonathan Wright69da5f22018-04-30 15:04:02 +0100111 $(call SHELL_DELETE,${BINARY})