Merge changes from topic "dynamic-toolchain" into integration

* changes:
  build: allow multiple toolchain defaults
  build: determine toolchain tools dynamically
This commit is contained in:
Manish V Badarkhe 2024-09-25 13:53:54 +02:00 committed by TrustedFirmware Code Review
commit 1297a45d6a
16 changed files with 233 additions and 168 deletions

View File

@ -37,17 +37,6 @@ include ${MAKE_HELPERS_DIRECTORY}defaults.mk
# Configure the toolchains used to build TF-A and its tools
################################################################################
#
# The clean and check targets do not behave correctly if the user's environment
# does not appropriately configure a toolchain. While we try to find a permanent
# solution to this, do not try to detect any toolchains if we are building
# exclusively with targets which do not use any toolchain tools.
#
ifeq ($(filter-out check% %clean doc %tool,$(or $(MAKECMDGOALS),all)),)
toolchains :=
endif
include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
# Assertions enabled for DEBUG builds by default

View File

@ -4,12 +4,6 @@
# SPDX-License-Identifier: BSD-3-Clause
#
ifeq ($(filter-out clean,$(or $(MAKECMDGOALS),all)),)
toolchains :=
else
toolchains := aarch64
endif
include ../../make_helpers/build-rules.mk
include ../../make_helpers/common.mk
include ../../make_helpers/toolchain.mk

View File

@ -18,13 +18,74 @@
ifndef toolchain-mk
toolchain-mk := $(lastword $(MAKEFILE_LIST))
toolchains ?= host $(ARCH)
include $(dir $(toolchain-mk))build_env.mk
include $(dir $(toolchain-mk))utilities.mk
include $(dir $(lastword $(MAKEFILE_LIST)))build_env.mk
include $(dir $(lastword $(MAKEFILE_LIST)))utilities.mk
#
# Make assigns generic default values to `CC`, `CPP`, `AS`, etc. if they
# are not explicitly assigned values by the user. These are usually okay
# for very simple programs when building for the host system, but we
# need greater control over the toolchain flow.
#
# Therefore, we undefine these built-in variables if they have default
# values, so that we can provide our own default values later instead.
#
include $(addprefix $(dir $(lastword $(MAKEFILE_LIST)))toolchains/, \
$(addsuffix .mk,$(toolchains)))
ifeq ($(origin CC),default)
undefine CC
endif
ifeq ($(origin CPP),default)
undefine CPP
endif
ifeq ($(origin AS),default)
undefine AS
endif
ifeq ($(origin AR),default)
undefine AR
endif
ifeq ($(origin LD),default)
undefine LD
endif
#
# The full list of toolchains supported by TF-A.
#
# Each of these toolchains defines a file of the same name in the
# `toolchains` directory, which must configure the following variables:
#
# - <toolchain>-name
#
# A human-readable name for the toolchain,
#
# Additionally, for every tool class, it must also define:
#
# - <toolchain>-<tool-class>-parameter
#
# The command line or environment variable used to set the tool for
# for the given tool class.
#
# - <toolchain>-<tool-class>-default-id
#
# The default tool identifier used if the tool for the given tool
# class cannot be identified.
#
# - <toolchain>-<tool-class>-default
#
# The default commands to try, in the order defined, for the given
# tool class if the user does not explicitly provide one, and if the
# command could not be derived from the C compiler.
#
toolchains := host # Used for host targets
toolchains += aarch32 # Used for AArch32 targets
toolchains += aarch64 # Used for AArch64 targets
toolchains += rk3399-m0 # Used for RK3399 Cortex-M0 targets
include $(toolchains:%=$(dir $(toolchain-mk))toolchains/%.mk)
#
# Configure tool classes that we recognize.
@ -139,37 +200,6 @@ ifndef toolchain-mk
# Other tools
toolchain-tools-dtc := generic-dtc # Device tree compilers
#
# Default tools for each toolchain.
#
# Toolchains can specify a default path to any given tool with a tool
# class. These values are used in the absence of user-specified values,
# and are configured by the makefile for each toolchain using variables
# of the form:
#
# - $(toolchain)-$(tool-class)-default
#
# For example, the default C compiler for the AArch32 and AArch64
# toolchains could be configured with:
#
# - aarch32-cc-default
# - aarch64-cc-default
#
define toolchain-check-tool-class-default
ifndef $(1)-$(tool-class)-default
$$(error no default value specified for tool class `$(2)` of toolchain `$(1)`)
endif
endef
define toolchain-check-tool-class-defaults
$(foreach tool-class,$(toolchain-tool-classes), \
$(eval $(call toolchain-check-tool-class-default,$(1),$(tool-class))))
endef
$(foreach toolchain,$(toolchains), \
$(eval $(call toolchain-check-tool-class-defaults,$(toolchain))))
#
# Helper functions to identify toolchain tools.
#
@ -230,6 +260,39 @@ ifndef toolchain-mk
toolchain-guess-tool = $(firstword $(foreach candidate,$(1), \
$(if $(call toolchain-guess-tool-$(candidate),$(2)),$(candidate))))
#
# Warn the user that a tool could not be identified.
#
# Parameters:
#
# - $1: The toolchain that the tool belongs to.
# - $2: The tool class that the tool belongs to.
#
define toolchain-warn-unrecognized
$(warning )
$(warning The configured $($(1)-name) $(toolchain-tool-class-name-$(2)) could not be identified:)
$(warning )
$(warning $(space) $($(1)-$(2))$(if $($(1)-$(2)-parameter), (via `$($(1)-$(2)-parameter)`)))
$(warning )
$(warning The following tools were tried, but either did not exist or could not be identified:)
$(warning )
$(foreach default,$($(1)-$(2)-default), \
$(warning $(space) - $(default)))
$(warning )
$(warning The following tools are supported:)
$(warning )
$(foreach tool,$(toolchain-tools-$(2)), \
$(warning $(space) - $(toolchain-tool-name-$(tool))))
$(warning )
$(warning The build system will treat this $(toolchain-tool-class-name-$(2)) as $(toolchain-tool-name-$($(1)-$(2)-default-id)).)
$(warning )
endef
#
# Locate and identify tools belonging to each toolchain.
#
@ -271,56 +334,86 @@ ifndef toolchain-mk
toolchain-guess-gnu-gcc-od = $(shell $(1) --print-prog-name objdump 2>$(nul))
toolchain-guess-gnu-gcc-ar = $(shell $(1) --print-prog-name ar 2>$(nul))
define toolchain-warn-unrecognized
$$(warning )
$$(warning The configured $$($(1)-name) $$(toolchain-tool-class-name-$(2)) could not be identified and may not be supported:)
$$(warning )
$$(warning $$(space) $$($(1)-$(2)))
$$(warning )
$$(warning The default $$($(1)-name) $$(toolchain-tool-class-name-$(2)) is:)
$$(warning )
$$(warning $$(space) $$($(1)-$(2)-default))
$$(warning )
$$(warning The following tools are supported:)
$$(warning )
#
# Configure a toolchain.
#
# Parameters:
#
# - $1: The toolchain to configure.
#
# This function iterates over all tool classes and configures them for
# the provided toolchain. Toolchain tools are initialized lazily and
# on-demand based on the first read of the tool path or identifier
# variables.
#
$$(foreach tool,$$(toolchain-tools-$(2)), \
$$(warning $$(space) - $$(toolchain-tool-name-$$(tool))))
$$(warning )
$$(warning The build system will treat this $$(toolchain-tool-class-name-$(2)) as $$(toolchain-tool-name-$$($(1)-$(2)-id-default)).)
$$(warning )
define toolchain-configure
$$(foreach tool-class,$$(toolchain-tool-classes), \
$$(eval $$(call toolchain-configure-tool,$1,$$(tool-class))))
endef
#
# Configure a specific tool within a toolchain.
#
# Parameters:
#
# - $1: The toolchain to configure.
# - $2: The tool class to configure.
#
define toolchain-configure-tool
$1-$2-configure = $\
$$(eval $$(call toolchain-determine-tool,$1,$2))
#
# When either of the following variables are read for the first
# time, the appropriate tool is determined and *both* variables
# are overwritten with their final values.
#
$1-$2 = $$($1-$2-configure)$$($1-$2)
$1-$2-id = $$($1-$2-configure)$$($1-$2-id)
endef
#
# Determines and identifies a tool.
#
# Parameters:
#
# - $1: The toolchain identifier.
# - $2: The tool class.
#
# Tool identification happens by reading the designated tool parameter
# to get the user-specified command for the tool (e.g. `CC` or `LD`). If
# no tool parameter is defined then try to derive the tool from the C
# compiler.
#
# If all else fails, fall back to the default command defined by the
# toolchain makefile.
#
define toolchain-determine-tool
$(1)-$(2)-guess = $$(if $$(filter-out cc,$(2)),$\
$$(call toolchain-guess-$$($(1)-cc-id)-$(2),$$($(1)-cc)))
toolchain-$1-$2-guess-from-cc = $$(if $$(filter-out cc,$2),$\
$$(call toolchain-guess-$$($1-cc-id)-$2,$$($1-cc)))
$(1)-$(2) := $$(or $$($(1)-$(2)),$$($(1)-$(2)-guess))
$(1)-$(2) := $$(or $$($(1)-$(2)),$$($(1)-$(2)-default))
toolchain-$1-$2-shell = $$(or $$($$($1-$2-parameter)),$\
$$(toolchain-$1-$2-guess-from-cc),$\
$$(toolchain-$1-$2-default))
ifneq ($$(call which,$$($(1)-$(2))),)
# If we can resolve this tool to a program on the `PATH`
# then escape it for use in a shell, which allows us to
# preserve spaces.
toolchain-$1-$2-default = $$(firstword $\
$$(foreach default,$$($1-$2-default),$\
$$(if $$(call which,$$(default)),$$(default))) $\
$$($1-$2-default))
$(1)-$(2) := $$(call escape-shell,$$($(1)-$(2)))
endif
$1-$2 := $(if $(call which,$$(toolchain-$1-$2-shell)),$\
$$(call escape-shell,$$(toolchain-$1-$2-shell)),$\
$$(toolchain-$1-$2-shell))
$(1)-$(2)-id := $$(call toolchain-guess-tool,$$(toolchain-tools-$(2)),$$($(1)-$(2)))
ifndef $(1)-$(2)-id
$(1)-$(2)-id := $$($(1)-$(2)-id-default)
$$(eval $$(call toolchain-warn-unrecognized,$(1),$(2)))
endif
endef
define toolchain-determine
$$(foreach tool-class,$$(toolchain-tool-classes), \
$$(eval $$(call toolchain-determine-tool,$(1),$$(tool-class))))
$1-$2-id := $$(or \
$$(call toolchain-guess-tool,$$(toolchain-tools-$2),$$($1-$2)),$\
$$(strip $$(call toolchain-warn-unrecognized,$1,$2)$$($1-$2-default-id)))
endef
$(foreach toolchain,$(toolchains), \
$(eval $(call toolchain-determine,$(toolchain))))
$(eval $(call toolchain-configure,$(toolchain))))
endif

View File

@ -6,34 +6,34 @@
aarch32-name := AArch32
aarch32-cc := $(if $(filter-out default,$(origin CC)),$(CC))
aarch32-cc-parameter := CC
aarch32-cc-default-id := gnu-gcc
aarch32-cc-default := $(or $(CROSS_COMPILE),arm-none-eabi-)gcc
aarch32-cc-id-default := gnu-gcc
aarch32-cpp := $(if $(filter-out default,$(origin CPP)),$(CPP))
aarch32-cpp-parameter := CPP
aarch32-cpp-default-id := gnu-gcc
aarch32-cpp-default := $(or $(CROSS_COMPILE),arm-none-eabi-)gcc
aarch32-cpp-id-default := gnu-gcc
aarch32-as := $(if $(filter-out default,$(origin AS)),$(AS))
aarch32-as-parameter := AS
aarch32-as-default-id := gnu-gcc
aarch32-as-default := $(or $(CROSS_COMPILE),arm-none-eabi-)gcc
aarch32-as-id-default := gnu-gcc
aarch32-ld := $(if $(filter-out default,$(origin LD)),$(LD))
aarch32-ld-parameter := LD
aarch32-ld-default-id := gnu-gcc
aarch32-ld-default := $(or $(CROSS_COMPILE),arm-none-eabi-)gcc
aarch32-ld-id-default := gnu-gcc
aarch32-oc := $(if $(filter-out default,$(origin OC)),$(OC))
aarch32-oc-parameter := OC
aarch32-oc-default-id := gnu-objcopy
aarch32-oc-default := $(or $(CROSS_COMPILE),arm-none-eabi-)objcopy
aarch32-oc-id-default := gnu-objcopy
aarch32-od := $(if $(filter-out default,$(origin OD)),$(OD))
aarch32-od-parameter := OD
aarch32-od-default-id := gnu-objdump
aarch32-od-default := $(or $(CROSS_COMPILE),arm-none-eabi-)objdump
aarch32-od-id-default := gnu-objdump
aarch32-ar := $(if $(filter-out default,$(origin AR)),$(AR))
aarch32-ar-parameter := AR
aarch32-ar-default-id := gnu-ar
aarch32-ar-default := $(or $(CROSS_COMPILE),arm-none-eabi-)gcc-ar
aarch32-ar-id-default := gnu-ar
aarch32-dtc := $(if $(filter-out default,$(origin DTC)),$(DTC))
aarch32-dtc-parameter := DTC
aarch32-dtc-default-id := generic-dtc
aarch32-dtc-default := dtc
aarch32-dtc-id-default := generic-dtc

View File

@ -6,34 +6,41 @@
aarch64-name := AArch64
aarch64-cc := $(if $(filter-out default,$(origin CC)),$(CC))
aarch64-cc-parameter := CC
aarch64-cc-default-id := gnu-gcc
aarch64-cc-default := $(or $(CROSS_COMPILE),aarch64-none-elf-)gcc
aarch64-cc-id-default := gnu-gcc
aarch64-cc-default += $(if $(CROSS_COMPILE),,aarch64-linux-gnu-gcc)
aarch64-cpp := $(if $(filter-out default,$(origin CPP)),$(CPP))
aarch64-cpp-parameter := CPP
aarch64-cpp-default-id := gnu-gcc
aarch64-cpp-default := $(or $(CROSS_COMPILE),aarch64-none-elf-)gcc
aarch64-cpp-id-default := gnu-gcc
aarch64-cpp-default += $(if $(CROSS_COMPILE),,aarch64-linux-gnu-gcc)
aarch64-as := $(if $(filter-out default,$(origin AS)),$(AS))
aarch64-as-parameter := AS
aarch64-as-default-id := gnu-gcc
aarch64-as-default := $(or $(CROSS_COMPILE),aarch64-none-elf-)gcc
aarch64-as-id-default := gnu-gcc
aarch64-as-default += $(if $(CROSS_COMPILE),,aarch64-linux-gnu-gcc)
aarch64-ld := $(if $(filter-out default,$(origin LD)),$(LD))
aarch64-ld-parameter := LD
aarch64-ld-default-id := gnu-gcc
aarch64-ld-default := $(or $(CROSS_COMPILE),aarch64-none-elf-)gcc
aarch64-ld-id-default := gnu-gcc
aarch64-ld-default += $(if $(CROSS_COMPILE),,aarch64-linux-gnu-gcc)
aarch64-oc := $(if $(filter-out default,$(origin OC)),$(OC))
aarch64-oc-parameter := OC
aarch64-oc-default-id := gnu-objcopy
aarch64-oc-default := $(or $(CROSS_COMPILE),aarch64-none-elf-)objcopy
aarch64-oc-id-default := gnu-objcopy
aarch64-oc-default += $(if $(CROSS_COMPILE),,aarch64-linux-gnu-objcopy)
aarch64-od := $(if $(filter-out default,$(origin OD)),$(OD))
aarch64-od-parameter := OD
aarch64-od-default-id := gnu-objdump
aarch64-od-default := $(or $(CROSS_COMPILE),aarch64-none-elf-)objdump
aarch64-od-id-default := gnu-objdump
aarch64-od-default += $(if $(CROSS_COMPILE),,aarch64-linux-gnu-objdump)
aarch64-ar := $(if $(filter-out default,$(origin AR)),$(AR))
aarch64-ar-parameter := AR
aarch64-ar-default-id := gnu-ar
aarch64-ar-default := $(or $(CROSS_COMPILE),aarch64-none-elf-)gcc-ar
aarch64-ar-id-default := gnu-ar
aarch64-ar-default += $(if $(CROSS_COMPILE),,aarch64-linux-gnu-gcc-ar)
aarch64-dtc := $(if $(filter-out default,$(origin DTC)),$(DTC))
aarch64-dtc-parameter := DTC
aarch64-dtc-default-id := generic-dtc
aarch64-dtc-default := dtc
aarch64-dtc-id-default := generic-dtc

View File

@ -6,34 +6,34 @@
host-name := host
host-cc := $(HOSTCC)
host-cc-parameter := HOSTCC
host-cc-default-id := gnu-gcc
host-cc-default := gcc
host-cc-id-default := gnu-gcc
host-cpp := $(HOSTCPP)
host-cpp-parameter := HOSTCPP
host-cpp-default-id := gnu-gcc
host-cpp-default := gcc
host-cpp-id-default := gnu-gcc
host-as := $(HOSTAS)
host-as-parameter := HOSTAS
host-as-default-id := gnu-gcc
host-as-default := gcc
host-as-id-default := gnu-gcc
host-ld := $(HOSTLD)
host-ld-parameter := HOSTLD
host-ld-default-id := gnu-gcc
host-ld-default := gcc
host-ld-id-default := gnu-gcc
host-oc := $(HOSTOC)
host-oc-parameter := HOSTOC
host-oc-default-id := gnu-objcopy
host-oc-default := objcopy
host-oc-id-default := gnu-objcopy
host-od := $(HOSTOD)
host-od-parameter := HOSTOD
host-od-default-id := gnu-objdump
host-od-default := objdump
host-od-id-default := gnu-objdump
host-ar := $(HOSTAR)
host-ar-parameter := HOSTAR
host-ar-default-id := gnu-ar
host-ar-default := gcc-ar
host-ar-id-default := gnu-ar
host-dtc := $(HOSTDTC)
host-dtc-parameter := HOSTDTC
host-dtc-default-id := generic-dtc
host-dtc-default := dtc
host-dtc-id-default := generic-dtc

View File

@ -6,26 +6,26 @@
rk3399-m0-name := RK3399 M0
rk3399-m0-cc-default-id := gnu-gcc
rk3399-m0-cc-default := $(or $(M0_CROSS_COMPILE),arm-none-eabi-)gcc
rk3399-m0-cc-id-default := gnu-gcc
rk3399-m0-cpp-default-id := gnu-gcc
rk3399-m0-cpp-default := $(or $(M0_CROSS_COMPILE),arm-none-eabi-)gcc
rk3399-m0-cpp-id-default := gnu-gcc
rk3399-m0-as-default-id := gnu-gcc
rk3399-m0-as-default := $(or $(M0_CROSS_COMPILE),arm-none-eabi-)gcc
rk3399-m0-as-id-default := gnu-gcc
rk3399-m0-ld-default-id := gnu-gcc
rk3399-m0-ld-default := $(or $(M0_CROSS_COMPILE),arm-none-eabi-)gcc
rk3399-m0-ld-id-default := gnu-gcc
rk3399-m0-oc-default-id := gnu-objcopy
rk3399-m0-oc-default := $(or $(M0_CROSS_COMPILE),arm-none-eabi-)objcopy
rk3399-m0-oc-id-default := gnu-objcopy
rk3399-m0-od-default-id := gnu-objdump
rk3399-m0-od-default := $(or $(M0_CROSS_COMPILE),arm-none-eabi-)objdump
rk3399-m0-od-id-default := gnu-objdump
rk3399-m0-ar-default-id := gnu-ar
rk3399-m0-ar-default := $(or $(M0_CROSS_COMPILE),arm-none-eabi-)gcc-ar
rk3399-m0-ar-id-default := gnu-ar
rk3399-m0-dtc-default-id := generic-dtc
rk3399-m0-dtc-default := dtc
rk3399-m0-dtc-id-default := generic-dtc

View File

@ -4,8 +4,6 @@
# SPDX-License-Identifier: BSD-3-Clause
#
toolchains := rk3399-m0
include ../../../../../make_helpers/common.mk
include ../../../../../make_helpers/toolchain.mk

View File

@ -5,8 +5,6 @@
# https://spdx.org/licenses
#
toolchains := host
MAKE_HELPERS_DIRECTORY := ../../make_helpers/
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}build_env.mk

View File

@ -10,8 +10,6 @@ CRTTOOL ?= cert_create${BIN_EXT}
BINARY := $(notdir ${CRTTOOL})
COT := tbbr
toolchains := host
MAKE_HELPERS_DIRECTORY := ../../make_helpers/
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}build_env.mk

View File

@ -11,8 +11,6 @@ ENCTOOL ?= encrypt_fw${BIN_EXT}
BINARY := $(notdir ${ENCTOOL})
OPENSSL_DIR := /usr
toolchains := host
MAKE_HELPERS_DIRECTORY := ../../make_helpers/
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}build_env.mk

View File

@ -4,8 +4,6 @@
# SPDX-License-Identifier: BSD-3-Clause
#
toolchains := host
MAKE_HELPERS_DIRECTORY := ../../make_helpers/
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}build_env.mk

View File

@ -4,8 +4,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# https://spdx.org/licenses
toolchains := host
include ../../../make_helpers/common.mk
include ../../../make_helpers/toolchain.mk

View File

@ -4,8 +4,6 @@
# SPDX-License-Identifier: BSD-3-Clause
#
toolchains := host
MAKE_HELPERS_DIRECTORY := ../../../make_helpers/
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}build_env.mk

View File

@ -4,8 +4,6 @@
# SPDX-License-Identifier: BSD-3-Clause
#
toolchains := host
MAKE_HELPERS_DIRECTORY := ../../make_helpers/
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}build_env.mk

View File

@ -4,8 +4,6 @@
# SPDX-License-Identifier: BSD-3-Clause
#
toolchains := host
MAKE_HELPERS_DIRECTORY := ../../make_helpers/
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}build_env.mk