xref: /rk3399_ARM-atf/tools/cert_create/Makefile (revision 7c4e1eea61a32291a6640070418e07ab98b42442)
16f971622SJuan Castillo#
2cc277de8SChris Kay# Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
36f971622SJuan Castillo#
482cb2c1aSdp-arm# SPDX-License-Identifier: BSD-3-Clause
56f971622SJuan Castillo#
66f971622SJuan Castillo
76f971622SJuan CastilloPLAT		:= none
86f971622SJuan CastilloDEBUG		:= 0
9b13e3f9fSManish V BadarkheCRTTOOL		?= cert_create${BIN_EXT}
10fafd3ec9SManish V BadarkheBINARY		:= $(notdir ${CRTTOOL})
1143743ea5SSandrine BailleuxCOT		:= tbbr
126f971622SJuan Castillo
13cc277de8SChris Kaytoolchains := host
14cc277de8SChris Kay
15231c1470SEvan LloydMAKE_HELPERS_DIRECTORY := ../../make_helpers/
16231c1470SEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_macros.mk
17e7f54dbdSEvan Lloydinclude ${MAKE_HELPERS_DIRECTORY}build_env.mk
18*7c4e1eeaSChris Kayinclude ${MAKE_HELPERS_DIRECTORY}common.mk
19cf2dd17dSJuan Pablo Condeinclude ${MAKE_HELPERS_DIRECTORY}defaults.mk
20cc277de8SChris Kayinclude ${MAKE_HELPERS_DIRECTORY}toolchain.mk
21231c1470SEvan Lloyd
22b94bf967SPankaj Guptaifneq (${PLAT},none)
23b94bf967SPankaj GuptaTF_PLATFORM_ROOT	:=	../../plat/
24b94bf967SPankaj Guptainclude ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
25b94bf967SPankaj GuptaPLAT_CERT_CREATE_HELPER_MK := ${PLAT_DIR}/cert_create_tbbr.mk
26b94bf967SPankaj Guptaendif
27b94bf967SPankaj Gupta
283b24b66eSSandrine Bailleux# Common source files.
293b24b66eSSandrine BailleuxOBJECTS := src/cert.o \
303b24b66eSSandrine Bailleux           src/cmd_opt.o \
313b24b66eSSandrine Bailleux           src/ext.o \
323b24b66eSSandrine Bailleux           src/key.o \
333b24b66eSSandrine Bailleux           src/main.o \
343b24b66eSSandrine Bailleux           src/sha.o
35bb41eb7aSMasahiro Yamada
3643743ea5SSandrine Bailleux# Chain of trust.
3743743ea5SSandrine Bailleuxifeq (${COT},tbbr)
383b24b66eSSandrine Bailleux  include src/tbbr/tbbr.mk
39a9d5c273SSandrine Bailleuxelse ifeq (${COT},dualroot)
40a9d5c273SSandrine Bailleux  include src/dualroot/cot.mk
410a6bf811Slaurenw-armelse ifeq (${COT},cca)
420a6bf811Slaurenw-arm  include src/cca/cot.mk
4343743ea5SSandrine Bailleuxelse
4443743ea5SSandrine Bailleux  $(error Unknown chain of trust ${COT})
4543743ea5SSandrine Bailleuxendif
46231c1470SEvan Lloyd
47b94bf967SPankaj Guptaifneq (,$(wildcard ${PLAT_CERT_CREATE_HELPER_MK}))
48b94bf967SPankaj Guptainclude ${PLAT_CERT_CREATE_HELPER_MK}
49b94bf967SPankaj Guptaendif
50b94bf967SPankaj Gupta
51cf2dd17dSJuan Pablo Conde# Select OpenSSL version flag according to the OpenSSL build selected
52cf2dd17dSJuan Pablo Conde# from setting the OPENSSL_DIR path.
53cf2dd17dSJuan Pablo Conde$(eval $(call SELECT_OPENSSL_API_VERSION))
54cf2dd17dSJuan Pablo Conde
553b24b66eSSandrine BailleuxHOSTCCFLAGS := -Wall -std=c99
566f971622SJuan Castillo
576f971622SJuan Castilloifeq (${DEBUG},1)
58750e8d80SAntonio Nino Diaz  HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
596f971622SJuan Castilloelse
60750e8d80SAntonio Nino Diaz  HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
616f971622SJuan Castilloendif
623b24b66eSSandrine Bailleux
63750e8d80SAntonio Nino DiazHOSTCCFLAGS += ${DEFINES}
64cf2dd17dSJuan Pablo Conde# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
65cf2dd17dSJuan Pablo Conde# computed value.
66cf2dd17dSJuan Pablo CondeHOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
67bb41eb7aSMasahiro Yamada
686f971622SJuan Castillo# Make soft links and include from local directory otherwise wrong headers
696f971622SJuan Castillo# could get pulled in from firmware tree.
70b94bf967SPankaj GuptaINC_DIR += -I ./include -I ${PLAT_INCLUDE} -I ${OPENSSL_DIR}/include
719bc52d33SJuan Pablo Conde
729bc52d33SJuan Pablo Conde# Include library directories where OpenSSL library files are located.
739bc52d33SJuan Pablo Conde# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
749bc52d33SJuan Pablo Conde# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
759bc52d33SJuan Pablo Conde# directory. However, for a local build of OpenSSL, the built binaries are
769bc52d33SJuan Pablo Conde# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
779bc52d33SJuan Pablo Conde# ${OPENSSL_DIR}/lib/).
789bc52d33SJuan Pablo CondeLIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
796f971622SJuan CastilloLIB := -lssl -lcrypto
806f971622SJuan Castillo
81cf2dd17dSJuan Pablo Conde.PHONY: all clean realclean --openssl
826f971622SJuan Castillo
83aa57ce63SVincent Stehléall: --openssl ${BINARY}
846f971622SJuan Castillo
85aa57ce63SVincent Stehlé${BINARY}: ${OBJECTS} Makefile
86*7c4e1eeaSChris Kay	$(s)echo "  HOSTLD  $@"
87*7c4e1eeaSChris Kay	$(q)echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__; \
88bb41eb7aSMasahiro Yamada                const char platform_msg[] = "${PLAT_MSG}";' | \
89ffb77421SChris Kay                $(host-cc) -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
90*7c4e1eeaSChris Kay	$(q)$(host-cc) src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
916f971622SJuan Castillo
926f971622SJuan Castillo%.o: %.c
93*7c4e1eeaSChris Kay	$(s)echo "  HOSTCC  $<"
94*7c4e1eeaSChris Kay	$(q)$(host-cc) -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
956f971622SJuan Castillo
96cf2dd17dSJuan Pablo Conde--openssl:
97cf2dd17dSJuan Pablo Condeifeq ($(DEBUG),1)
98*7c4e1eeaSChris Kay	$(s)echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
99cf2dd17dSJuan Pablo Condeendif
100cf2dd17dSJuan Pablo Conde
1016f971622SJuan Castilloclean:
102f1477d4aSEvan Lloyd	$(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS})
1036f971622SJuan Castillo
1046f971622SJuan Castillorealclean: clean
105f1477d4aSEvan Lloyd	$(call SHELL_DELETE,${BINARY})
106