blob: e403b2d2091e39d5d72caab9be4f5616b4d3f1df [file] [log] [blame]
Juan Castillo6f971622014-10-21 11:30:42 +01001#
Chris Kayc3273702025-01-13 15:57:32 +00002# Copyright (c) 2015-2025, 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
Chris Kayc3273702025-01-13 15:57:32 +00009CRTTOOL ?= cert_create$(.exe)
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
Chris Kay7c4e1ee2024-05-02 17:52:37 +000015include ${MAKE_HELPERS_DIRECTORY}common.mk
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040016include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Chris Kaycc277de2023-10-20 09:17:33 +000017include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
Chris Kaya004ee82024-06-14 11:31:03 +000018include ${MAKE_HELPERS_DIRECTORY}utilities.mk
Evan Lloyd231c1472015-12-02 18:17:37 +000019
Pankaj Guptab94bf962020-12-09 14:02:38 +053020ifneq (${PLAT},none)
21TF_PLATFORM_ROOT := ../../plat/
22include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
23PLAT_CERT_CREATE_HELPER_MK := ${PLAT_DIR}/cert_create_tbbr.mk
24endif
25
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010026# Common source files.
27OBJECTS := src/cert.o \
28 src/cmd_opt.o \
29 src/ext.o \
30 src/key.o \
31 src/main.o \
32 src/sha.o
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090033
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010034# Chain of trust.
35ifeq (${COT},tbbr)
36 include src/tbbr/tbbr.mk
Sandrine Bailleuxa9d5c272020-01-10 14:32:30 +010037else ifeq (${COT},dualroot)
38 include src/dualroot/cot.mk
laurenw-arm0a6bf812022-04-21 16:21:53 -050039else ifeq (${COT},cca)
40 include src/cca/cot.mk
Sandrine Bailleux43743ea2020-01-15 10:11:07 +010041else
42 $(error Unknown chain of trust ${COT})
43endif
Evan Lloyd231c1472015-12-02 18:17:37 +000044
Pankaj Guptab94bf962020-12-09 14:02:38 +053045ifneq (,$(wildcard ${PLAT_CERT_CREATE_HELPER_MK}))
46include ${PLAT_CERT_CREATE_HELPER_MK}
47endif
48
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040049# Select OpenSSL version flag according to the OpenSSL build selected
50# from setting the OPENSSL_DIR path.
51$(eval $(call SELECT_OPENSSL_API_VERSION))
52
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010053HOSTCCFLAGS := -Wall -std=c99
Juan Castillo6f971622014-10-21 11:30:42 +010054
55ifeq (${DEBUG},1)
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010056 HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
Juan Castillo6f971622014-10-21 11:30:42 +010057else
Antonio Nino Diaz750e8d82018-10-04 14:35:38 +010058 HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
Juan Castillo6f971622014-10-21 11:30:42 +010059endif
Sandrine Bailleux3b24b662020-01-14 18:06:38 +010060
Chris Kaya004ee82024-06-14 11:31:03 +000061HOSTCCFLAGS += ${DEFINES} -DPLAT_MSG=$(call escape-shell,"$(PLAT_MSG)")
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040062# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
63# computed value.
64HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
Masahiro Yamadabb41eb72017-05-22 12:11:24 +090065
Juan Castillo6f971622014-10-21 11:30:42 +010066# Make soft links and include from local directory otherwise wrong headers
67# could get pulled in from firmware tree.
Pankaj Guptab94bf962020-12-09 14:02:38 +053068INC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
Juan Pablo Conde9bc52d32022-03-02 18:10:08 -050069
70# Include library directories where OpenSSL library files are located.
71# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
72# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
73# directory. However, for a local build of OpenSSL, the built binaries are
74# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
75# ${OPENSSL_DIR}/lib/).
76LIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
Juan Castillo6f971622014-10-21 11:30:42 +010077LIB := -lssl -lcrypto
78
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040079.PHONY: all clean realclean --openssl
Juan Castillo6f971622014-10-21 11:30:42 +010080
Vincent Stehléaa57ce62023-07-04 16:14:02 +020081all: --openssl ${BINARY}
Juan Castillo6f971622014-10-21 11:30:42 +010082
Vincent Stehléaa57ce62023-07-04 16:14:02 +020083${BINARY}: ${OBJECTS} Makefile
Chris Kay7c4e1ee2024-05-02 17:52:37 +000084 $(s)echo " HOSTLD $@"
Chris Kaya004ee82024-06-14 11:31:03 +000085 $(q)$(host-cc) ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
Juan Castillo6f971622014-10-21 11:30:42 +010086
87%.o: %.c
Chris Kay7c4e1ee2024-05-02 17:52:37 +000088 $(s)echo " HOSTCC $<"
89 $(q)$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
Juan Castillo6f971622014-10-21 11:30:42 +010090
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040091--openssl:
92ifeq ($(DEBUG),1)
Chris Kay7c4e1ee2024-05-02 17:52:37 +000093 $(s)echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
Juan Pablo Condecf2dd172022-10-25 19:41:02 -040094endif
95
Juan Castillo6f971622014-10-21 11:30:42 +010096clean:
Chris Kayc3273702025-01-13 15:57:32 +000097 $(q)rm -rf $(OBJECTS)
Juan Castillo6f971622014-10-21 11:30:42 +010098
99realclean: clean
Chris Kayc3273702025-01-13 15:57:32 +0000100 $(q)rm -f $(BINARY)