blob: ce12a66058b38ed11a3bd9befbc212c99170365f [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
Evan Lloyd231c1472015-12-02 18:17:37 +000013MAKE_HELPERS_DIRECTORY := ../../make_helpers/
14include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
Evan Lloyde7f54db2015-12-02 18:56:06 +000015include ${MAKE_HELPERS_DIRECTORY}build_env.mk
Chris Kay7c4e1ee2024-05-02 17:52:37 +000016include ${MAKE_HELPERS_DIRECTORY}common.mk
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040017include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Chris Kaycc277de2023-10-20 09:17:33 +000018include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
Chris Kaya004ee82024-06-14 11:31:03 +000019include ${MAKE_HELPERS_DIRECTORY}utilities.mk
Evan Lloyd231c1472015-12-02 18:17:37 +000020
Pankaj Guptab94bf962020-12-09 14:02:38 +053021ifneq (${PLAT},none)
22TF_PLATFORM_ROOT := ../../plat/
23include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
24PLAT_CERT_CREATE_HELPER_MK := ${PLAT_DIR}/cert_create_tbbr.mk
25endif
26
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010027# Common source files.
28OBJECTS := src/cert.o \
29 src/cmd_opt.o \
30 src/ext.o \
31 src/key.o \
32 src/main.o \
33 src/sha.o
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090034
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010035# Chain of trust.
36ifeq (${COT},tbbr)
37 include src/tbbr/tbbr.mk
Sandrine Bailleuxa9d5c272020-01-10 14:32:30 +010038else ifeq (${COT},dualroot)
39 include src/dualroot/cot.mk
laurenw-arm0a6bf812022-04-21 16:21:53 -050040else ifeq (${COT},cca)
41 include src/cca/cot.mk
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010042else
43 $(error Unknown chain of trust ${COT})
44endif
Evan Lloyd231c1472015-12-02 18:17:37 +000045
Pankaj Guptab94bf962020-12-09 14:02:38 +053046ifneq (,$(wildcard ${PLAT_CERT_CREATE_HELPER_MK}))
47include ${PLAT_CERT_CREATE_HELPER_MK}
48endif
49
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040050# Select OpenSSL version flag according to the OpenSSL build selected
51# from setting the OPENSSL_DIR path.
52$(eval $(call SELECT_OPENSSL_API_VERSION))
53
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010054HOSTCCFLAGS := -Wall -std=c99
Juan Castillo6f971622014-10-21 11:30:42 +010055
56ifeq (${DEBUG},1)
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010057 HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
Juan Castillo6f971622014-10-21 11:30:42 +010058else
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010059 HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
Juan Castillo6f971622014-10-21 11:30:42 +010060endif
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010061
Chris Kaya004ee82024-06-14 11:31:03 +000062HOSTCCFLAGS += ${DEFINES} -DPLAT_MSG=$(call escape-shell,"$(PLAT_MSG)")
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040063# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
64# computed value.
65HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090066
Juan Castillo6f971622014-10-21 11:30:42 +010067# Make soft links and include from local directory otherwise wrong headers
68# could get pulled in from firmware tree.
Pankaj Guptab94bf962020-12-09 14:02:38 +053069INC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
Juan Pablo Conde9bc52d32022-03-02 18:10:08 -050070
71# Include library directories where OpenSSL library files are located.
72# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
73# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
74# directory. However, for a local build of OpenSSL, the built binaries are
75# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
76# ${OPENSSL_DIR}/lib/).
77LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
Juan Castillo6f971622014-10-21 11:30:42 +010078LIB := -lssl -lcrypto
79
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040080.PHONY: all clean realclean --openssl
Juan Castillo6f971622014-10-21 11:30:42 +010081
Vincent Stehléaa57ce62023-07-04 16:14:02 +020082all: --openssl ${BINARY}
Juan Castillo6f971622014-10-21 11:30:42 +010083
Vincent Stehléaa57ce62023-07-04 16:14:02 +020084${BINARY}: ${OBJECTS} Makefile
Chris Kay7c4e1ee2024-05-02 17:52:37 +000085 $(s)echo " HOSTLD $@"
Chris Kaya004ee82024-06-14 11:31:03 +000086 $(q)$(host-cc) ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
Juan Castillo6f971622014-10-21 11:30:42 +010087
88%.o: %.c
Chris Kay7c4e1ee2024-05-02 17:52:37 +000089 $(s)echo " HOSTCC $<"
90 $(q)$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
Juan Castillo6f971622014-10-21 11:30:42 +010091
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040092--openssl:
93ifeq ($(DEBUG),1)
Chris Kay7c4e1ee2024-05-02 17:52:37 +000094 $(s)echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040095endif
96
Juan Castillo6f971622014-10-21 11:30:42 +010097clean:
Chris Kaya004ee82024-06-14 11:31:03 +000098 $(call SHELL_DELETE_ALL,${OBJECTS})
Juan Castillo6f971622014-10-21 11:30:42 +010099
100realclean: clean
Jonathan Wright2f36e852018-04-30 15:04:02 +0100101 $(call SHELL_DELETE,${BINARY})