blob: 767093918a76c06355545d2107339572e45c37ae [file] [log] [blame]
Juan Castillo6f971622014-10-21 11:30:42 +01001#
Chris Kaycc277de2023-10-20 09:17:33 +00002# Copyright (c) 2015-2024, 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
Juan Castillo6f971622014-10-21 11:30:42 +01008DEBUG := 0
Manish V Badarkheb13e3f92020-09-05 04:40:41 +01009CRTTOOL ?= cert_create${BIN_EXT}
Manish V Badarkhefafd3ec2020-08-13 05:56:33 +010010BINARY := $(notdir ${CRTTOOL})
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010011COT := tbbr
Juan Castillo6f971622014-10-21 11:30:42 +010012
Chris Kaycc277de2023-10-20 09:17:33 +000013toolchains := host
14
Evan Lloyd231c1472015-12-02 18:17:37 +000015MAKE_HELPERS_DIRECTORY := ../../make_helpers/
16include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
Evan Lloyde7f54db2015-12-02 18:56:06 +000017include ${MAKE_HELPERS_DIRECTORY}build_env.mk
Chris Kay7c4e1ee2024-05-02 17:52:37 +000018include ${MAKE_HELPERS_DIRECTORY}common.mk
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040019include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Chris Kaycc277de2023-10-20 09:17:33 +000020include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
Evan Lloyd231c1472015-12-02 18:17:37 +000021
Pankaj Guptab94bf962020-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 Bailleux3b24b662020-01-14 18:06:38 +010028# Common source files.
29OBJECTS := src/cert.o \
30 src/cmd_opt.o \
31 src/ext.o \
32 src/key.o \
33 src/main.o \
34 src/sha.o
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090035
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010036# Chain of trust.
37ifeq (${COT},tbbr)
38 include src/tbbr/tbbr.mk
Sandrine Bailleuxa9d5c272020-01-10 14:32:30 +010039else ifeq (${COT},dualroot)
40 include src/dualroot/cot.mk
laurenw-arm0a6bf812022-04-21 16:21:53 -050041else ifeq (${COT},cca)
42 include src/cca/cot.mk
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010043else
44 $(error Unknown chain of trust ${COT})
45endif
Evan Lloyd231c1472015-12-02 18:17:37 +000046
Pankaj Guptab94bf962020-12-09 14:02:38 +053047ifneq (,$(wildcard ${PLAT_CERT_CREATE_HELPER_MK}))
48include ${PLAT_CERT_CREATE_HELPER_MK}
49endif
50
Juan Pablo Condecf2dd172022-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 Bailleux3b24b662020-01-14 18:06:38 +010055HOSTCCFLAGS := -Wall -std=c99
Juan Castillo6f971622014-10-21 11:30:42 +010056
57ifeq (${DEBUG},1)
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010058 HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
Juan Castillo6f971622014-10-21 11:30:42 +010059else
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010060 HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
Juan Castillo6f971622014-10-21 11:30:42 +010061endif
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010062
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010063HOSTCCFLAGS += ${DEFINES}
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040064# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
65# computed value.
66HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090067
Juan Castillo6f971622014-10-21 11:30:42 +010068# Make soft links and include from local directory otherwise wrong headers
69# could get pulled in from firmware tree.
Pankaj Guptab94bf962020-12-09 14:02:38 +053070INC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
Juan Pablo Conde9bc52d32022-03-02 18:10:08 -050071
72# Include library directories where OpenSSL library files are located.
73# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
74# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
75# directory. However, for a local build of OpenSSL, the built binaries are
76# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
77# ${OPENSSL_DIR}/lib/).
78LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
Juan Castillo6f971622014-10-21 11:30:42 +010079LIB := -lssl -lcrypto
80
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040081.PHONY: all clean realclean --openssl
Juan Castillo6f971622014-10-21 11:30:42 +010082
Vincent Stehléaa57ce62023-07-04 16:14:02 +020083all: --openssl ${BINARY}
Juan Castillo6f971622014-10-21 11:30:42 +010084
Vincent Stehléaa57ce62023-07-04 16:14:02 +020085${BINARY}: ${OBJECTS} Makefile
Chris Kay7c4e1ee2024-05-02 17:52:37 +000086 $(s)echo " HOSTLD $@"
87 $(q)echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__; \
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090088 const char platform_msg[] = "${PLAT_MSG}";' | \
Chris Kayffb77422023-12-04 12:03:51 +000089 $(host-cc) -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
Chris Kay7c4e1ee2024-05-02 17:52:37 +000090 $(q)$(host-cc) src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
Juan Castillo6f971622014-10-21 11:30:42 +010091
92%.o: %.c
Chris Kay7c4e1ee2024-05-02 17:52:37 +000093 $(s)echo " HOSTCC $<"
94 $(q)$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
Juan Castillo6f971622014-10-21 11:30:42 +010095
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040096--openssl:
97ifeq ($(DEBUG),1)
Chris Kay7c4e1ee2024-05-02 17:52:37 +000098 $(s)echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040099endif
100
Juan Castillo6f971622014-10-21 11:30:42 +0100101clean:
Evan Lloydf1477d42015-12-02 18:33:55 +0000102 $(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS})
Juan Castillo6f971622014-10-21 11:30:42 +0100103
104realclean: clean
Jonathan Wright2f36e852018-04-30 15:04:02 +0100105 $(call SHELL_DELETE,${BINARY})