Browse Source

feat(fiptool): add ability to build statically

Provide a STATIC command line build option for platforms willing to
build fiptool statically and remove dependency to toolchain and OpenSSL
libraries.

Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
Change-Id: I1d1b6676df50081828170e2b0ab7b71c4ec19d6e
pull/2003/head
Olivier Deprez 1 year ago
parent
commit
4d4fec2818
  1. 28
      tools/fiptool/Makefile
  2. 10
      tools/fiptool/fiptool.c

28
tools/fiptool/Makefile

@ -13,8 +13,7 @@ FIPTOOL ?= fiptool${BIN_EXT}
PROJECT := $(notdir ${FIPTOOL})
OBJECTS := fiptool.o tbbr_config.o
V ?= 0
OPENSSL_DIR := /usr
STATIC ?= 0
override CPPFLAGS += -D_GNU_SOURCE -D_XOPEN_SOURCE=700
HOSTCCFLAGS := -Wall -Werror -pedantic -std=c99
@ -24,14 +23,22 @@ else
HOSTCCFLAGS += -O2
endif
INCLUDE_PATHS := -I../../include/tools_share
DEFINES += -DSTATIC=$(STATIC)
ifeq (${STATIC},1)
LDOPTS := -static
else
OPENSSL_DIR := /usr
# Select OpenSSL version flag according to the OpenSSL build selected
# from setting the OPENSSL_DIR path.
$(eval $(call SELECT_OPENSSL_API_VERSION))
HOSTCCFLAGS += ${DEFINES}
# USING_OPENSSL3 flag will be added to the HOSTCCFLAGS variable with the proper
# computed value.
HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
DEFINES += -DUSING_OPENSSL3=$(USING_OPENSSL3)
# Include library directories where OpenSSL library files are located.
# For a normal installation (i.e.: when ${OPENSSL_DIR} = /usr or
@ -39,7 +46,11 @@ HOSTCCFLAGS += -DUSING_OPENSSL3=$(USING_OPENSSL3)
# directory. However, for a local build of OpenSSL, the built binaries are
# located under the main project directory (i.e.: ${OPENSSL_DIR}, not
# ${OPENSSL_DIR}/lib/).
LDLIBS := -L${OPENSSL_DIR}/lib -L${OPENSSL_DIR} -lcrypto
LDOPTS := -L${OPENSSL_DIR}/lib -L${OPENSSL_DIR} -lcrypto
INCLUDE_PATHS += -I${OPENSSL_DIR}/include
endif # STATIC
HOSTCCFLAGS += ${DEFINES}
ifeq (${V},0)
Q := @
@ -47,8 +58,6 @@ else
Q :=
endif
INCLUDE_PATHS := -I../../include/tools_share -I${OPENSSL_DIR}/include
HOSTCC ?= gcc
ifneq (${PLAT},)
@ -72,7 +81,7 @@ all: --openssl ${PROJECT}
${PROJECT}: ${OBJECTS} Makefile
@echo " HOSTLD $@"
${Q}${HOSTCC} ${OBJECTS} -o $@ ${LDLIBS}
${Q}${HOSTCC} ${OBJECTS} -o $@ $(LDOPTS)
@${ECHO_BLANK_LINE}
@echo "Built $@ successfully"
@${ECHO_BLANK_LINE}
@ -84,10 +93,11 @@ ${PROJECT}: ${OBJECTS} Makefile
-include $(DEPS)
--openssl:
ifeq ($(STATIC),0)
ifeq ($(DEBUG),1)
@echo "Selected OpenSSL version: ${OPENSSL_CURRENT_VER}"
endif
endif # STATIC
clean:
$(call SHELL_DELETE_ALL, ${PROJECT} ${OBJECTS} $(DEPS))

10
tools/fiptool/fiptool.c

@ -460,6 +460,7 @@ static struct option *fill_common_opts(struct option *opts, size_t *nr_opts,
return opts;
}
#if !STATIC
static void md_print(const unsigned char *md, size_t len)
{
size_t i;
@ -467,6 +468,7 @@ static void md_print(const unsigned char *md, size_t len)
for (i = 0; i < len; i++)
printf("%02x", md[i]);
}
#endif
static int info_cmd(int argc, char *argv[])
{
@ -498,7 +500,13 @@ static int info_cmd(int argc, char *argv[])
(unsigned long long)image->toc_e.offset_address,
(unsigned long long)image->toc_e.size,
desc->cmdline_name);
#ifndef _MSC_VER /* We don't have SHA256 for Visual Studio. */
/*
* Omit this informative code portion for:
* Visual Studio missing SHA256.
* Statically linked builds.
*/
#if !defined(_MSC_VER) && !STATIC
if (verbose) {
unsigned char md[SHA256_DIGEST_LENGTH];

Loading…
Cancel
Save