xref: /rk3399_ARM-atf/tools/encrypt_fw/Makefile (revision cf2dd17ddda2f44f5dedddcaf48300d16358597a)
190aa901fSSumit Garg#
29bc52d33SJuan Pablo Conde# Copyright (c) 2019-2022, Linaro Limited. All rights reserved.
390aa901fSSumit Garg#
490aa901fSSumit Garg# SPDX-License-Identifier: BSD-3-Clause
590aa901fSSumit Garg#
690aa901fSSumit Garg
790aa901fSSumit GargV		?= 0
890aa901fSSumit GargBUILD_INFO	?= 1
990aa901fSSumit GargDEBUG		:= 0
10b13e3f9fSManish V BadarkheENCTOOL		?= encrypt_fw${BIN_EXT}
11fafd3ec9SManish V BadarkheBINARY		:= $(notdir ${ENCTOOL})
1290aa901fSSumit GargOPENSSL_DIR	:= /usr
1390aa901fSSumit Garg
14*cf2dd17dSJuan Pablo Conde
15*cf2dd17dSJuan Pablo CondeMAKE_HELPERS_DIRECTORY := ../../make_helpers/
16*cf2dd17dSJuan Pablo Condeinclude ${MAKE_HELPERS_DIRECTORY}build_macros.mk
17*cf2dd17dSJuan Pablo Condeinclude ${MAKE_HELPERS_DIRECTORY}build_env.mk
18*cf2dd17dSJuan Pablo Condeinclude ${MAKE_HELPERS_DIRECTORY}defaults.mk
19*cf2dd17dSJuan Pablo Conde
2090aa901fSSumit GargOBJECTS := src/encrypt.o \
2190aa901fSSumit Garg           src/cmd_opt.o \
2290aa901fSSumit Garg           src/main.o
2390aa901fSSumit Garg
2490aa901fSSumit GargHOSTCCFLAGS := -Wall -std=c99
2590aa901fSSumit Garg
26*cf2dd17dSJuan Pablo Conde# Select OpenSSL version flag according to the OpenSSL build selected
27*cf2dd17dSJuan Pablo Conde# from setting the OPENSSL_DIR path.
28*cf2dd17dSJuan Pablo Conde$(eval $(call SELECT_OPENSSL_API_VERSION))
2990aa901fSSumit Garg
3090aa901fSSumit Gargifeq (${DEBUG},1)
3190aa901fSSumit Garg  HOSTCCFLAGS += -g -O0 -DDEBUG -DLOG_LEVEL=40
3290aa901fSSumit Gargelse
3390aa901fSSumit Gargifeq (${BUILD_INFO},1)
3490aa901fSSumit Garg  HOSTCCFLAGS += -O2 -DLOG_LEVEL=20
3590aa901fSSumit Gargelse
3690aa901fSSumit Garg  HOSTCCFLAGS += -O2 -DLOG_LEVEL=10
3790aa901fSSumit Gargendif
3890aa901fSSumit Gargendif
3990aa901fSSumit Gargifeq (${V},0)
4090aa901fSSumit Garg  Q := @
4190aa901fSSumit Gargelse
4290aa901fSSumit Garg  Q :=
4390aa901fSSumit Gargendif
4490aa901fSSumit Garg
45*cf2dd17dSJuan Pablo CondeHOSTCCFLAGS += ${DEFINES}
46*cf2dd17dSJuan Pablo Conde# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
47*cf2dd17dSJuan Pablo Conde# computed value.
48*cf2dd17dSJuan Pablo CondeHOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
49*cf2dd17dSJuan Pablo Conde
50*cf2dd17dSJuan Pablo Conde
5190aa901fSSumit Garg# Make soft links and include from local directory otherwise wrong headers
5290aa901fSSumit Garg# could get pulled in from firmware tree.
5390aa901fSSumit GargINC_DIR := -I ./include -I ../../include/tools_share -I ${OPENSSL_DIR}/include
549bc52d33SJuan Pablo Conde
559bc52d33SJuan Pablo Conde# Include library directories where OpenSSL library files are located.
569bc52d33SJuan Pablo Conde# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
579bc52d33SJuan Pablo Conde# /usr/local), binaries are located under the ${OPENSSL_DIR}/lib/
589bc52d33SJuan Pablo Conde# directory. However, for a local build of OpenSSL, the built binaries are
599bc52d33SJuan Pablo Conde# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
609bc52d33SJuan Pablo Conde# ${OPENSSL_DIR}/lib/).
619bc52d33SJuan Pablo CondeLIB_DIR := -L ${OPENSSL_DIR}/lib -L ${OPENSSL_DIR}
6290aa901fSSumit GargLIB := -lssl -lcrypto
6390aa901fSSumit Garg
6490aa901fSSumit GargHOSTCC ?= gcc
6590aa901fSSumit Garg
66*cf2dd17dSJuan Pablo Conde.PHONY: all clean realclean --openssl
6790aa901fSSumit Garg
6869a91659SRoss Burtonall: ${BINARY}
6990aa901fSSumit Garg
70*cf2dd17dSJuan Pablo Conde${BINARY}: --openssl ${OBJECTS} Makefile
7190aa901fSSumit Garg	@echo "  HOSTLD  $@"
7290aa901fSSumit Garg	@echo 'const char build_msg[] = "Built : "__TIME__", "__DATE__;' | \
7390aa901fSSumit Garg                ${HOSTCC} -c ${HOSTCCFLAGS} -xc - -o src/build_msg.o
7490aa901fSSumit Garg	${Q}${HOSTCC} src/build_msg.o ${OBJECTS} ${LIB_DIR} ${LIB} -o $@
7590aa901fSSumit Garg
7690aa901fSSumit Garg%.o: %.c
7790aa901fSSumit Garg	@echo "  HOSTCC  $<"
7890aa901fSSumit Garg	${Q}${HOSTCC} -c ${HOSTCCFLAGS} ${INC_DIR} $< -o $@
7990aa901fSSumit Garg
80*cf2dd17dSJuan Pablo Conde--openssl:
81*cf2dd17dSJuan Pablo Condeifeq ($(DEBUG),1)
82*cf2dd17dSJuan Pablo Conde	@echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
83*cf2dd17dSJuan Pablo Condeendif
84*cf2dd17dSJuan Pablo Conde
8590aa901fSSumit Gargclean:
8690aa901fSSumit Garg	$(call SHELL_DELETE_ALL, src/build_msg.o ${OBJECTS})
8790aa901fSSumit Garg
8890aa901fSSumit Gargrealclean: clean
8990aa901fSSumit Garg	$(call SHELL_DELETE,${BINARY})
90