blob: 31d3e21876f86250b555879051846359f2f0c2e4 [file] [log] [blame]
Patrick Georgi2faeb112020-05-08 18:32:38 +02001# SPDX-License-Identifier: GPL-2.0-only
Furquan Shaikh99ac98f2014-04-23 10:18:48 -07002
Patrick Georgie47477e2014-05-17 18:38:10 +02003# ccache integration
4ifeq ($(CONFIG_CCACHE),y)
5
6CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
7ifeq ($(CCACHE),)
8$(error ccache selected, but not found in PATH)
9endif
10
11export CCACHE_COMPILERCHECK=content
12export CCACHE_BASEDIR=$(top)
13
14$(foreach arch,$(ARCH_SUPPORTED), \
15 $(eval CC_$(arch):=$(CCACHE) $(CC_$(arch))))
16
17HOSTCC:=$(CCACHE) $(HOSTCC)
18HOSTCXX:=$(CCACHE) $(HOSTCXX)
Patrick Georgie47477e2014-05-17 18:38:10 +020019endif
Patrick Georgifadbe5f2014-05-17 18:26:38 +020020
21# scan-build integration
22ifneq ($(CCC_ANALYZER_OUTPUT_FORMAT),)
23
24ifeq ($(CCC_ANALYZER_ANALYSIS),)
25export CCC_ANALYZER_ANALYSIS := -analyzer-opt-analyze-headers
26endif
27
28$(foreach arch,$(ARCH_SUPPORTED), \
Patrick Georgie47477e2014-05-17 18:38:10 +020029 $(eval CC_$(arch):=CCC_CC="$(CC_$(arch))" $(CC) ))
Patrick Georgifadbe5f2014-05-17 18:26:38 +020030
31HOSTCC:=CCC_CC="$(HOSTCC)" $(CC)
32HOSTCXX:=CCC_CXX="$(HOSTCXX)" $(CXX)
Patrick Georgifadbe5f2014-05-17 18:26:38 +020033endif
34
Julius Werner99f46832018-05-16 14:14:04 -070035COREBOOT_STANDARD_STAGES := decompressor bootblock verstage romstage ramstage
36MAP-decompressor := bootblock
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070037
Patrick Georgi8688def2015-03-28 16:27:42 +010038ARCHDIR-i386 := x86
39ARCHDIR-x86_32 := x86
Martin Rothcf0f6b82016-01-11 10:30:24 -070040ARCHDIR-x86_64 := x86
Patrick Georgi8688def2015-03-28 16:27:42 +010041ARCHDIR-arm := arm
42ARCHDIR-arm64 := arm64
43ARCHDIR-riscv := riscv
Jonathan Neuschäferc22ad582018-11-30 00:06:50 +010044ARCHDIR-ppc64 := ppc64
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070045
Martin Rothcf0f6b82016-01-11 10:30:24 -070046CFLAGS_arm +=
47CFLAGS_arm64 += -mgeneral-regs-only
Stefan Reinauerd146ac62015-07-31 13:50:03 -070048CFLAGS_riscv +=
49CFLAGS_x86_32 +=
Martin Rothcf0f6b82016-01-11 10:30:24 -070050CFLAGS_x86_64 += -mcmodel=large -mno-red-zone
Jonathan Neuschäferc22ad582018-11-30 00:06:50 +010051CFLAGS_ppc64 +=
Stefan Reinauer46591132015-03-15 04:19:58 +010052
Julius Werner8d8799a2014-12-19 16:11:14 -080053# Some boards only provide 2K stacks, so storing lots of data there leads to
54# problems. Since C rules don't allow us to statically determine the maximum
55# stack use, we use 1.5K as heuristic, assuming that we typically have lots
56# of tiny stack frames and the odd large one.
57#
Kyösti Mälkki75396f62019-11-21 08:09:34 +020058# Store larger buffers in BSS, use MAYBE_STATIC_BSS to share data in cache-as-ram
Julius Werner8d8799a2014-12-19 16:11:14 -080059# on x86.
60# Since GCCs detection of dynamic array bounds unfortunately seems to be
61# very basic, you'll sometimes have to use a static upper bound for the
62# size and an assert() to make sure it's honored (see gpio_base3_value()
63# for an example).
64# (If you absolutely need a larger stack frame and are 100% sure it cannot
65# cause problems, you can whitelist it with #pragma diagnostic.)
Patrick Georgieef1e982017-05-10 22:02:55 +020066ifeq ($(CONFIG_COMPILER_GCC),y)
Julius Werner8d8799a2014-12-19 16:11:14 -080067CFLAGS_arm += -Wstack-usage=1536
68CFLAGS_arm64 += -Wstack-usage=1536
Julius Werner8d8799a2014-12-19 16:11:14 -080069CFLAGS_riscv += -Wstack-usage=1536
Jonathan Neuschäferc22ad582018-11-30 00:06:50 +010070CFLAGS_ppc64 += -Wstack-usage=1536
Patrick Georgieef1e982017-05-10 22:02:55 +020071endif
Julius Werner8d8799a2014-12-19 16:11:14 -080072
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070073toolchain_to_dir = \
74 $(foreach arch,$(ARCH_SUPPORTED),\
Patrick Georgib145b832014-05-17 15:08:47 +020075 $(eval CPPFLAGS_$(arch) += \
Patrick Georgi4ebd3d92014-05-17 14:02:08 +020076 -Isrc/arch/$(ARCHDIR-$(arch))/include))
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070077
78# set_stage_toolchain: Decides the toolchain to be used by every stage
79# E.g.: If bootblock is x86_32, it sets ARCH-BOOTBLOCK-y = x86_32, whereas
80# ARCH-BOOTBLOCK-n = armv7. Then, ARCH-BOOTBLOCK-y can be used anywhere to
81# decide the compiler toolchain for bootblock stage
82# This step is essential for initializing the toolchain for coreboot standard
83# stages i.e. bootblock, romstage and ramstage, since it acts as the second
84# parameter to create_class_compiler below in init_standard_toolchain
Patrick Georgi27ef6022015-04-30 14:25:14 +020085map_stage = $(strip $(if $(MAP-$(1)),$(MAP-$(1)),$(1)))
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070086set_stage_toolchain= \
Martin Rothcf0f6b82016-01-11 10:30:24 -070087 $(foreach arch,$(ARCH_SUPPORTED), \
88 $(eval ARCH-$(1)-$($(shell \
89 echo CONFIG_ARCH_$(call map_stage,$(1))_$(arch) | \
90 tr '[:lower:]' '[:upper:]')) := $(arch)))
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070091
Nico Huberbe5492a2015-09-29 16:41:19 +020092# standard-archs: Tell which architectures are used by the standard stages.
93standard-archs = $(sort $(foreach stagearch, \
94 $(patsubst %,ARCH-%-y,$(COREBOOT_STANDARD_STAGES)), \
95 $($(stagearch))))
96
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070097# create_class_compiler: Used to create compiler tool set for
98# special classes
99# @1: special class
100# @2: compiler set to be used
101# e.g.: smm special class uses i386 as compiler set
102define create_class_compiler
Martin Roth9a162d72016-08-01 19:57:02 -0600103$(if $(2),,$(warning *** The toolchain architecture for $(1) is unknown.) \
104 $(error Check your .config file for CONFIG_ARCH_$(1)_* settings))
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700105CC_$(1) := $(CC_$(2))
Nico Huber1850aa62017-09-03 23:42:58 +0200106GCC_$(1) := $(GCC_CC_$(2))
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700107LD_$(1) := $(LD_$(2))
108NM_$(1) := $(NM_$(2))
Daisuke Nojiri9b1cb582014-06-19 19:01:34 -0700109AR_$(1) := $(AR_$(2))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100110GNATBIND_$(1) := $(GNATBIND_$(2))
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700111OBJCOPY_$(1) := $(OBJCOPY_$(2))
112OBJDUMP_$(1) := $(OBJDUMP_$(2))
113STRIP_$(1) := $(STRIP_$(2))
114READELF_$(1) := $(READELF_$(2))
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700115CFLAGS_$(1) = $$(CFLAGS_common) $$(CFLAGS_$(2))
Nico Huber6d7564c2019-06-18 16:38:29 +0200116ADAFLAGS_$(1) = --RTS=$$(obj)/libgnat-$(2)/ $$(ADAFLAGS_common) $$(GCC_ADAFLAGS_$(2))
Julius Wernerd3634c12015-11-13 13:28:41 -0800117CPPFLAGS_$(1) = $$(CPPFLAGS_common) $$(CPPFLAGS_$(2)) -D__ARCH_$(2)__
Patrick Georgi527f3922015-06-04 13:31:38 +0200118COMPILER_RT_$(1) := $$(COMPILER_RT_$(2))
119COMPILER_RT_FLAGS_$(1) := $$(COMPILER_RT_FLAGS_$(2))
Aaron Durbind4dd44c2015-09-06 10:15:17 -0500120LDFLAGS_$(1) = $$(LDFLAGS_common) $$(LDFLAGS_$(2))
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700121endef
122
Furquan Shaikh133096b2014-07-31 09:28:55 -0700123# define_class: Allows defining any program as dynamic class and compiler tool
124# set for the same based on the architecture for which the program is to be
125# compiled
126# @1: program (class name)
127# @2: architecture for which the program needs to be compiled
128# IMP: Ensure that define_class is called before any .c or .S files are added to
129# the class of the program. Check subdirs-y for order of subdirectory inclusions
130define define_class
131classes-y += $(1)
132$(eval $(call create_class_compiler,$(1),$(2)))
133endef
134
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700135# initialize standard toolchain (CC,AS and others) for give stage
136# @1 : stage for which the toolchain is to be initialized
137init_standard_toolchain = \
Patrick Georgi4ebd3d92014-05-17 14:02:08 +0200138 $(eval $(call set_stage_toolchain,$(1))) \
Patrick Georgi262f31c2014-05-17 15:13:40 +0200139 $(eval $(call create_class_compiler,$(1),$(ARCH-$(1)-y)))
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700140
141init_stages = \
Martin Rothcf0f6b82016-01-11 10:30:24 -0700142 $(foreach stage,$(COREBOOT_STANDARD_STAGES), \
143 $(eval $(call init_standard_toolchain,$(stage))))
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700144
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700145$(eval $(call toolchain_to_dir))
146
147$(call init_stages)
Patrick Georgi1053f652015-03-26 21:39:12 +0100148
Martin Roth3fb73c22015-12-07 14:04:27 -0700149# Test for coreboot toolchain (except when explicitly not requested)
Patrick Georgi1053f652015-03-26 21:39:12 +0100150ifneq ($(NOCOMPILE),1)
Martin Rotha6563622016-01-15 14:56:06 -0700151# Only run if we're doing a build (not for tests, kconfig, ...)
Patrick Georgi1053f652015-03-26 21:39:12 +0100152# rationale: gcc versions by Linux distributions tend to be quite messed up
Martin Rotha23e2ce2015-12-07 14:07:10 -0700153# llvm/clang also needs patches supplied by the coreboot build
Patrick Georgi1053f652015-03-26 21:39:12 +0100154COMPILERFAIL:=0
Martin Rothd9c193d2015-11-26 22:34:42 -0700155IASLFAIL:=0
Martin Rotha23e2ce2015-12-07 14:07:10 -0700156
Patrick Georgi1053f652015-03-26 21:39:12 +0100157ifneq ($(CONFIG_ANY_TOOLCHAIN),y)
Martin Rotha6563622016-01-15 14:56:06 -0700158# Verify that the coreboot toolchain is being used.
Martin Rothcf0f6b82016-01-11 10:30:24 -0700159$(foreach arch,$(sort $(foreach stage,\
160 $(COREBOOT_STANDARD_STAGES),$(ARCH-$(stage)-y))), \
161 $(if $(shell if [ -n "$(CC_$(arch))" ]; then \
162 $(CC_$(arch)) -v 2>&1 | grep -q "coreboot toolchain" || \
163 echo not-coreboot; else echo not-coreboot; fi), \
164 $(eval COMPILERFAIL:=1)\
165 $(warning The coreboot toolchain for '$(arch)'\
166 architecture was not found.)))
Martin Rotha6563622016-01-15 14:56:06 -0700167# If iasl doesn't match the current coreboot version, fail the test
168# TODO: Figure out if iasl is even needed for the build.
Martin Rothcf0f6b82016-01-11 10:30:24 -0700169$(if $(shell if [ -n "$(IASL)" ]; then \
Martin Rothab8f9232016-01-05 16:14:12 -0700170 $(IASL) -v 2>&1 | grep -q "coreboot toolchain" || \
Martin Rothcf0f6b82016-01-11 10:30:24 -0700171 echo not-coreboot; else echo not-coreboot; fi), \
172 $(eval COMPILERFAIL:=1)$(eval IASLFAIL:=1)\
173 $(warning The coreboot toolchain version of iasl \
174 '$(shell util/crossgcc/buildgcc -s iasl)' was not found))
Martin Rothaf91b8b2015-12-07 14:33:44 -0700175else #$(CONFIG_ANY_TOOLCHAIN)
Martin Rotha6563622016-01-15 14:56:06 -0700176# If the coreboot toolchain isn't being used, verify that there is A toolchain
Martin Rothcf0f6b82016-01-11 10:30:24 -0700177$(foreach arch,$(sort \
178 $(foreach stage,$(COREBOOT_STANDARD_STAGES),$(ARCH-$(stage)-y))), \
Martin Rothaf91b8b2015-12-07 14:33:44 -0700179 $(if $(CC_$(arch)),, $(eval COMPILERFAIL:=1) \
Martin Rothcf0f6b82016-01-11 10:30:24 -0700180 $(warning No compiler found for '$(arch)' architecture. \
181 Install one or use the coreboot toolchain?)) )
Martin Rotha6563622016-01-15 14:56:06 -0700182# If iasl isn't present, fail
183# TODO: Figure out if iasl is even needed for the build.
Martin Rothaf91b8b2015-12-07 14:33:44 -0700184$(if $(IASL),, $(eval COMPILERFAIL:=1)$(eval IASLFAIL:=1) \
Martin Rothcf0f6b82016-01-11 10:30:24 -0700185 $(warning iasl not found. \
186 Please install it or use the coreboot toolchain.))
Patrick Georgi1053f652015-03-26 21:39:12 +0100187endif
Martin Rotha6563622016-01-15 14:56:06 -0700188
189# If the compiler check failed, print out warnings
Patrick Georgi1053f652015-03-26 21:39:12 +0100190ifeq ($(COMPILERFAIL),1)
Martin Roth019cdbf2015-12-07 14:13:40 -0700191ifneq ($(XGCCPATH),)
192$(warning )
193$(warning Path to your toolchain is currently set to '$(XGCCPATH)')
194endif
Martin Roth335a9b62015-11-25 12:44:15 -0700195$(warning )
Martin Rothada36d42015-12-07 14:27:34 -0700196$(warning To build the entire coreboot toolchain: run 'make crossgcc')
Martin Rothd9c193d2015-11-26 22:34:42 -0700197ifeq ($(IASLFAIL),1)
Martin Rothada36d42015-12-07 14:27:34 -0700198$(warning To build just IASL: run 'make iasl')
Martin Roth73b79972015-12-07 14:20:55 -0700199endif #($(IASLFAIL),1)
Martin Rothada36d42015-12-07 14:27:34 -0700200$(warning For more toolchain build targets: run 'make help_toolchain')
Martin Roth335a9b62015-11-25 12:44:15 -0700201$(warning )
Martin Roth5981a632015-12-07 14:24:57 -0700202ifneq ($(CONFIG_ANY_TOOLCHAIN),y)
Martin Rothcf0f6b82016-01-11 10:30:24 -0700203$(warning To try to use any toolchain in your path, \
204 run 'make menuconfig', then select)
205$(warning the config option: 'General setup', \
206 and 'Allow building with any toolchain')
207$(warning Note that this is NOT supported. \
208 Using it means you're on your own.)
Martin Roth5981a632015-12-07 14:24:57 -0700209$(warning )
210endif #($(CONFIG_ANY_TOOLCHAIN),y)
211$(error Halting the build)
Martin Roth73b79972015-12-07 14:20:55 -0700212endif #($(COMPILERFAIL),1)
213
214endif #($(NOCOMPILE),1)
Martin Rothaede3fc2016-01-05 16:07:42 -0700215
Martin Rotha6563622016-01-15 14:56:06 -0700216# Run the toolchain version checks if the requested target is 'test-toolchain'
217# Checks the versions of GCC, binutils, clang, and IASL
Martin Rothaede3fc2016-01-05 16:07:42 -0700218ifneq ($(MAKECMDGOALS),)
219ifneq ($(filter test-toolchain,$(MAKECMDGOALS)),)
220$(foreach arch, $(ARCH_SUPPORTED), \
Martin Rothcf0f6b82016-01-11 10:30:24 -0700221 $(if $(shell if [ -n "$(GCC_CC_$(arch))" ]; then \
222 $(GCC_CC_$(arch)) -v 2>&1 | \
223 grep -q "$(shell util/crossgcc/buildgcc -s gcc)" || \
224 echo not-current; fi), \
225 $(eval COMPILER_OUT_OF_DATE:=1) \
226 $(warning The coreboot toolchain version of gcc for '$(arch)' \
227 architecture is not the current version.)) \
228 $(if $(shell if [ -n "$(CLANG_CC_$(arch))" ]; then \
229 $(CLANG_CC_$(arch)) -v 2>&1 | \
230 grep -q "$(shell util/crossgcc/buildgcc -s clang)" || \
231 echo not-current; fi), \
232 $(eval COMPILER_OUT_OF_DATE:=1)\
233 $(warning The coreboot toolchain version of clang for \
234 '$(arch)' architecture is not the current version.)) \
235 $(if $(shell if [ "$(OBJDUMP_$(arch))" != "invalidobjdump" ]; then \
236 $(OBJDUMP_$(arch)) -v 2>&1 | \
237 grep -q "$(shell util/crossgcc/buildgcc -s binutils)" || \
238 echo not-current; fi), \
239 $(eval COMPILER_OUT_OF_DATE:=1)\
240 $(warning The coreboot toolchain version of binutils for \
241 '$(arch)' architecture is not the current version.)) \
Martin Rothaede3fc2016-01-05 16:07:42 -0700242)
Martin Rothcf0f6b82016-01-11 10:30:24 -0700243$(if $(shell if [ -n "$(IASL)" ]; then $(IASL) -v 2>&1 | \
244 grep -q "$(shell util/crossgcc/buildgcc -s iasl)" || \
245 echo not-coreboot; fi), \
246 $(eval COMPILER_OUT_OF_DATE:=1)\
247 $(warning The coreboot toolchain version of iasl \
248 is not the current version))
Martin Rotha6563622016-01-15 14:56:06 -0700249endif #($(filter crossgcc_check%,$(MAKECMDGOALS)),)
250endif #($(MAKECMDGOALS),)