blob: bd1a58a39131eff7ef8884b694e6c01cae8c1329 [file] [log] [blame]
Patrick Georgi71b84802011-02-22 14:35:05 +00001##
2## This file is part of the coreboot project.
3##
4## Copyright (C) 2011 secunet Security Networks AG
5##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation; version 2 of the License.
9##
10## This program is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13## GNU General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with this program; if not, write to the Free Software
17## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18##
19
20#######################################################################
21# misleadingly named, this is the coreboot version
Vadim Bendebury6e7abcd2012-12-10 15:47:23 -080022export KERNELVERSION := $(shell if [ -d "$(top)/.git" -a -f "`which git`" ]; \
23 then git describe --dirty --always || git describe; \
24 else echo 4.0$(KERNELREVISION); fi)
Patrick Georgi71b84802011-02-22 14:35:05 +000025
26#######################################################################
Patrick Georgi9b0de712013-12-29 18:45:23 +010027# Test for coreboot toolchain (except when explicitely not requested)
28ifneq ($(NOCOMPILE),1)
29# only run if we're doing a build (not for tests, kconfig, ...)
30ifneq ($(CONFIG_ANY_TOOLCHAIN),y)
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070031_toolchain=$(shell $(CC_x86_32) -v 2>&1 |grep -q "gcc version .*coreboot toolchain" && echo coreboot)
Patrick Georgi9b0de712013-12-29 18:45:23 +010032ifneq ($(_toolchain),coreboot)
33$(error Please use the coreboot toolchain (or prove that your toolchain works))
34endif
35endif
36endif
37
38#######################################################################
Patrick Georgi71b84802011-02-22 14:35:05 +000039# Basic component discovery
Patrick Georgi71b84802011-02-22 14:35:05 +000040MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
41export MAINBOARDDIR
42
Kyösti Mälkki0db2ae3a2012-04-19 12:00:06 +030043## Final build results, which CBFSTOOL uses to create the final
44## rom image file, are placed under $(objcbfs).
45## These typically have suffixes .debug .elf .bin and .map
Stefan Reinauera60ca362012-08-09 11:09:44 -070046export objcbfs := $(obj)/cbfs/$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
Kyösti Mälkki0db2ae3a2012-04-19 12:00:06 +030047
48## Based on the active configuration, Makefile conditionally collects
49## the required assembly includes and saves them in a file.
50## Such files that do not have a clear one-to-one relation to a source
51## file under src/ are placed and built under $(objgenerated)
52export objgenerated := $(obj)/generated
53
Patrick Georgi71b84802011-02-22 14:35:05 +000054#######################################################################
55# root rule to resolve if in build mode (ie. configuration exists)
56real-target: $(obj)/config.h coreboot
Kyösti Mälkki0db2ae3a2012-04-19 12:00:06 +030057coreboot: build-dirs $(obj)/coreboot.rom
Patrick Georgi71b84802011-02-22 14:35:05 +000058
59#######################################################################
60# our phony targets
Kyösti Mälkki0db2ae3a2012-04-19 12:00:06 +030061PHONY+= clean-abuild coreboot lint lint-stable build-dirs
Patrick Georgi71b84802011-02-22 14:35:05 +000062
63#######################################################################
64# root source directories of coreboot
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050065subdirs-y := src/lib src/console src/device src/ec src/southbridge src/soc
Kyösti Mälkki2a830d02011-12-01 17:49:43 +020066subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode
Patrick Georgi499fc922012-03-09 10:53:52 +010067subdirs-y += util/cbfstool util/sconfig util/nvramtool
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070068subdirs-y += src/arch/armv7 src/arch/x86
Patrick Georgi71b84802011-02-22 14:35:05 +000069subdirs-y += src/mainboard/$(MAINBOARDDIR)
70
Patrick Georgia25828d2011-09-02 09:57:01 +020071subdirs-y += site-local
72
Patrick Georgi71b84802011-02-22 14:35:05 +000073#######################################################################
74# Add source classes and their build options
Aaron Durbin9be4c472013-01-12 00:41:44 -060075classes-y := ramstage romstage bootblock smm smmstub cpu_microcode rmodules
Patrick Georgi71b84802011-02-22 14:35:05 +000076
Patrick Georgif33e3952012-11-25 17:10:47 +010077#######################################################################
78# Helper functions for ramstage postprocess
79spc :=
80spc +=
81$(spc) :=
82$(spc) +=
83
84# files-in-dir-recursive,dir,files
85files-in-dir-recursive=$(filter $(1)%,$(2))
86
87# parent-dir,dir/
88parent-dir=$(dir $(subst $( ),/,$(strip $(subst /, ,$(1)))))
89
90# filters out exactly the directory specified
91# filter-out-dir,dir_to_keep,dirs
92filter-out-dir=$(filter-out $(1),$(2))
93
94# filters out dir_to_keep and all its parents
95# filter-out-dirs,dir_to_keep,dirs
96filter-out-dirs=$(if $(filter-out ./,$(1)),$(call filter-out-dirs,$(call parent-dir,$(1)),$(call filter-out-dir,$(1),$(2))),$(call filter-out-dir,$(1),$(2)))
97
98# dir-wildcards,dirs
99dir-wildcards=$(addsuffix %,$(1))
100
101# files-in-dir,dir,files
102files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(dir $(2)))),$(call files-in-dir-recursive,$(1),$(2)))
103
104#######################################################################
105# reduce command line length by linking the objects of each
106# directory into an intermediate file
107ramstage-postprocess=$(foreach d,$(sort $(dir $(1))), \
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700108 $(eval $(d)ramstage.o: $(call files-in-dir,$(d),$(1)); $$(LD_ramstage) -o $$@ -r $$^ ) \
Patrick Georgif33e3952012-11-25 17:10:47 +0100109 $(eval ramstage-objs:=$(d)ramstage.o $(filter-out $(call files-in-dir,$(d),$(1)),$(ramstage-objs))))
110
Patrick Georgi71b84802011-02-22 14:35:05 +0000111romstage-c-ccopts:=-D__PRE_RAM__
Stefan Reinauer61aee5f2011-04-10 04:15:23 +0000112romstage-S-ccopts:=-D__PRE_RAM__
Rudolf Marek7f0e9302011-09-02 23:23:41 +0200113ifeq ($(CONFIG_TRACE),y)
114ramstage-c-ccopts:= -finstrument-functions
115endif
Stefan Reinauerd37ab452012-12-18 16:23:28 -0800116ifeq ($(CONFIG_COVERAGE),y)
117ramstage-c-ccopts+=-fprofile-arcs -ftest-coverage
118endif
Rudolf Marek7f0e9302011-09-02 23:23:41 +0200119
Patrick Georgi7e9b9d82012-04-30 21:06:10 +0200120ifeq ($(CONFIG_USE_BLOBS),y)
121forgetthis:=$(shell git submodule update --init --checkout 3rdparty)
Patrick Georgi7e9b9d82012-04-30 21:06:10 +0200122endif
123
Hung-Te Lin5f83f6c2013-02-04 14:38:03 +0800124bootblock-c-ccopts:=-D__BOOT_BLOCK__ -D__PRE_RAM__
125bootblock-S-ccopts:=-D__BOOT_BLOCK__ -D__PRE_RAM__
Hung-Te Linfe187922013-02-01 01:09:24 +0800126
Aaron Durbin50a34642013-01-03 17:38:47 -0600127smmstub-c-ccopts:=-D__SMM__
128smmstub-S-ccopts:=-D__SMM__
Stefan Reinauer24ef1342011-04-14 22:28:00 +0000129smm-c-ccopts:=-D__SMM__
130smm-S-ccopts:=-D__SMM__
Patrick Georgi71b84802011-02-22 14:35:05 +0000131
Stefan Reinauer3aa067f2012-04-02 13:24:04 -0700132# SMM TSEG base is dynamic
Aaron Durbin50a34642013-01-03 17:38:47 -0600133ifneq ($(CONFIG_SMM_MODULES),y)
Stefan Reinauer3aa067f2012-04-02 13:24:04 -0700134ifeq ($(CONFIG_SMM_TSEG),y)
135smm-c-ccopts += -fpic
136endif
Aaron Durbin50a34642013-01-03 17:38:47 -0600137endif
Stefan Reinauer3aa067f2012-04-02 13:24:04 -0700138
Patrick Georgi57205c72011-03-08 20:49:18 +0000139ramstage-c-deps:=$$(OPTION_TABLE_H)
140romstage-c-deps:=$$(OPTION_TABLE_H)
Hung-Te Linfe187922013-02-01 01:09:24 +0800141bootblock-c-deps:=$$(OPTION_TABLE_H)
Kyösti Mälkkice22cd02013-11-30 21:06:18 +0200142smm-c-deps:=$$(OPTION_TABLE_H)
Patrick Georgi57205c72011-03-08 20:49:18 +0000143
Patrick Georgi71b84802011-02-22 14:35:05 +0000144#######################################################################
145# Add handler to compile ACPI's ASL
146define ramstage-objs_asl_template
Sven Schnelled69438e2011-03-29 09:01:10 +0000147$(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
Patrick Georgi71b84802011-02-22 14:35:05 +0000148 @printf " IASL $$(subst $(top)/,,$$(@))\n"
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700149 $(CC_ramstage) -x assembler-with-cpp -E -MMD -MT $$(@) -D__ACPI__ -P -include $(src)/include/kconfig.h -I$(obj) -I$(src) -I$(src)/include -I$(src)/arch/$(ARCHDIR-$(ARCH-RAMSTAGE-y))/include -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
Marc Jones2aac3f62011-08-08 16:07:50 -0600150 cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl
Patrick Georgib2a42642011-06-01 19:54:16 +0000151 mv $$(basename $$@).hex $$(basename $$@).c
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700152 $(CC_ramstage) $$(CFLAGS_ramstage) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
Patrick Georgi71b84802011-02-22 14:35:05 +0000153 # keep %.o: %.c rule from catching the temporary .c file after a make clean
154 mv $$(basename $$@).c $$(basename $$@).hex
155endef
156
157#######################################################################
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +0100158# Parse plaintext cmos defaults into binary format
159# arg1: source file
160# arg2: binary file name
161cbfs-files-processor-nvramtool= \
162 $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
163 printf " CREATE $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
164
165#######################################################################
Patrick Georgi843005c2012-04-30 23:15:17 +0200166# Link VSA binary to ELF-ish stage
167# arg1: source file
168# arg2: binary file name
169cbfs-files-processor-vsa= \
170 $(eval $(2): $(1) ; \
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700171 printf " CREATE $(2) (from $(1))\n"; $(OBJCOPY_ramstage) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && $(LD_ramstage) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
Patrick Georgi843005c2012-04-30 23:15:17 +0200172
173#######################################################################
Patrick Georgi71b84802011-02-22 14:35:05 +0000174# Add handler for arbitrary files in CBFS
175$(call add-special-class,cbfs-files)
176cbfs-files-handler= \
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +0100177 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
Patrick Georgi1fc2bda2012-11-15 14:51:54 +0100178 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
Patrick Georgi71b84802011-02-22 14:35:05 +0000179 $(if $(wildcard $(1)$($(2)-file)), \
180 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
181 $(eval tmp-cbfs-file:= $($(2)-file))) \
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100182 $(if $(strip $($(2)-required)), \
183 $(if $(wildcard $(tmp-cbfs-file)),, \
184 $(info This build configuration requires $($(2)-required)) \
185 $(eval FAILBUILD:=1) \
186 )) \
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +0100187 $(if $(tmp-cbfs-method), \
188 $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
Patrick Georgi16c7ad72012-09-21 18:11:59 +0200189 $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +0100190 $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
Dave Frodin0013bbf2012-08-14 11:01:53 -0600191 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$($(2)-position)) \
Patrick Georgi71b84802011-02-22 14:35:05 +0000192 $(eval $(2)-name:=) \
193 $(eval $(2)-type:=) \
Dave Frodin0013bbf2012-08-14 11:01:53 -0600194 $(eval $(2)-compression:=) \
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100195 $(eval $(2)-position:=) \
196 $(eval $(2)-required:=)
Patrick Georgi71b84802011-02-22 14:35:05 +0000197
198#######################################################################
199# a variety of flags for our build
Stefan Reinauer63217582012-10-29 16:52:36 -0700200CBFS_COMPRESS_FLAG:=none
Sven Schnelle8eee19d2011-05-02 19:53:04 +0000201ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
Stefan Reinauer63217582012-10-29 16:52:36 -0700202CBFS_COMPRESS_FLAG:=LZMA
Sven Schnelle8eee19d2011-05-02 19:53:04 +0000203endif
204
Stefan Reinauer63217582012-10-29 16:52:36 -0700205CBFS_PAYLOAD_COMPRESS_FLAG:=none
Patrick Georgi71b84802011-02-22 14:35:05 +0000206ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
Stefan Reinauer63217582012-10-29 16:52:36 -0700207CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
Patrick Georgi71b84802011-02-22 14:35:05 +0000208endif
209
210ifneq ($(CONFIG_LOCALVERSION),"")
211COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
212endif
213
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700214INCLUDES := -Isrc -Isrc/include -I$(obj)
Stefan Reinauer8d711552012-11-30 12:34:04 -0800215INCLUDES += -Isrc/device/oprom/include
Patrick Georgi71b84802011-02-22 14:35:05 +0000216# abspath is a workaround for romcc
Patrick Georgic0e16e72012-05-05 15:11:22 +0200217INCLUDES += -include $(src)/include/kconfig.h
Patrick Georgi71b84802011-02-22 14:35:05 +0000218
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700219CFLAGS_common = $(INCLUDES) -Os -pipe -g -nostdinc
220CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
221CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
222CFLAGS_common += -Wstrict-aliasing -Wshadow
Patrick Georgi71b84802011-02-22 14:35:05 +0000223ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700224CFLAGS_common += -Werror
Patrick Georgi71b84802011-02-22 14:35:05 +0000225endif
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700226CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
Patrick Georgi71b84802011-02-22 14:35:05 +0000227
Nico Hubera15cd662013-06-19 16:16:05 +0200228additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
229 $(objutil)/ifdfake $(objutil)/options
Patrick Georgi71b84802011-02-22 14:35:05 +0000230
231#######################################################################
232# generate build support files
233$(obj)/build.h: .xcompile
234 @printf " GEN build.h\n"
235 rm -f $(obj)/build.h
236 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
237 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
238 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
Patrick Georgib8e9ba92011-03-17 07:47:49 +0000239 printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
Patrick Georgi71b84802011-02-22 14:35:05 +0000240 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
241 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
Zheng Bao0e6d0ed2012-11-09 19:55:04 +0800242 printf "#define COREBOOT_BUILD_YEAR_BCD 0x`LANG= date +"%y"`\n" >> $(obj)/build.ht
243 printf "#define COREBOOT_BUILD_MONTH_BCD 0x`LANG= date +"%m"`\n" >> $(obj)/build.ht
244 printf "#define COREBOOT_BUILD_DAY_BCD 0x`LANG= date +"%d"`\n" >> $(obj)/build.ht
245 printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x`LANG= date +"%w"`\n" >> $(obj)/build.ht
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200246 printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht
Patrick Georgi71b84802011-02-22 14:35:05 +0000247 printf "\n" >> $(obj)/build.ht
Patrick Georgi71b84802011-02-22 14:35:05 +0000248 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
249 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
Zheng Bao86aa7c42012-09-28 16:06:44 +0800250 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null || hostname 2>/dev/null)\"\n" >> $(obj)/build.ht
Patrick Georgi71b84802011-02-22 14:35:05 +0000251 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
252 printf "#endif\n" >> $(obj)/build.ht
253 mv $(obj)/build.ht $(obj)/build.h
254
255$(obj)/ldoptions: $(obj)/config.h
256 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
257
Kyösti Mälkki0db2ae3a2012-04-19 12:00:06 +0300258build-dirs:
259 mkdir -p $(objcbfs) $(objgenerated)
260
Patrick Georgi71b84802011-02-22 14:35:05 +0000261#######################################################################
262# Build the tools
263CBFSTOOL:=$(obj)/cbfstool
Aaron Durbin3eb8eb72014-03-10 16:13:58 -0500264RMODTOOL:=$(obj)/rmodtool
Patrick Georgi71b84802011-02-22 14:35:05 +0000265
266$(CBFSTOOL): $(objutil)/cbfstool/cbfstool
267 cp $< $@
268
Aaron Durbin3eb8eb72014-03-10 16:13:58 -0500269$(RMODTOOL): $(objutil)/cbfstool/rmodtool
270 cp $< $@
271
Patrick Georgi71b84802011-02-22 14:35:05 +0000272_WINCHECK=$(shell uname -o 2> /dev/null)
273STACK=
274ifeq ($(_WINCHECK),Msys)
275 STACK=-Wl,--stack,16384000
276endif
277ifeq ($(_WINCHECK),Cygwin)
278 STACK=-Wl,--stack,16384000
279endif
280
281ROMCC:= $(objutil)/romcc/romcc
282$(ROMCC): $(top)/util/romcc/romcc.c
283 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
284 @# Note: Adding -O2 here might cause problems. For details see:
285 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
286 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
287
Stefan Reinauer5b635792012-08-16 14:05:42 -0700288IFDTOOL:=$(objutil)/ifdtool/ifdtool
289$(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
290 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
291 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
292
Nico Hubera15cd662013-06-19 16:16:05 +0200293IFDFAKE:=$(objutil)/ifdfake/ifdfake
294$(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
295 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
296 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
297
Patrick Georgi71b84802011-02-22 14:35:05 +0000298#######################################################################
299# needed objects that every mainboard uses
300# Creation of these is architecture and mainboard independent
301$(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
302 @printf " SCONFIG $(subst $(src)/,,$(<))\n"
303 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
304 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
305
306ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
Stefan Reinauer57879c92012-07-31 16:47:25 -0700307romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
Patrick Georgi71b84802011-02-22 14:35:05 +0000308
309$(objutil)/%.o: $(objutil)/%.c
310 @printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
311 $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
312
Patrick Georgi64ccc3b82011-05-20 23:08:12 +0000313$(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
Patrick Georgi71b84802011-02-22 14:35:05 +0000314 @printf " CC $(subst $(obj)/,,$(@))\n"
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700315 $(CC_ramstage) -MMD $(CFLAGS_ramstage) -c -o $@ $<
Patrick Georgi71b84802011-02-22 14:35:05 +0000316
Stefan Reinauer57879c92012-07-31 16:47:25 -0700317$(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
318 @printf " CC $(subst $(obj)/,,$(@))\n"
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700319 $(CC_romstage) -MMD -D__PRE_RAM__ $(CFLAGS_romstage) -c -o $@ $<
Stefan Reinauer57879c92012-07-31 16:47:25 -0700320
Hung-Te Linfe187922013-02-01 01:09:24 +0800321$(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
322 @printf " CC $(subst $(obj)/,,$(@))\n"
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700323 $(CC_bootblock) -MMD $(bootblock-c-ccopts) $(CFLAGS_bootblock) -c -o $@ $<
Hung-Te Linfe187922013-02-01 01:09:24 +0800324
Patrick Georgi71b84802011-02-22 14:35:05 +0000325#######################################################################
326# Clean up rules
327clean-abuild:
328 rm -rf coreboot-builds
329
330clean-for-update-target:
Furquan Shaikh20f25dd2014-04-22 10:41:05 -0700331 rm -f $(obj)/ramstage* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
Patrick Georgi71b84802011-02-22 14:35:05 +0000332 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
333 rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
334 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
335 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
336 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
337 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
338 rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700339 $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC_x86_32)" LD="$(LD_x86_32)"
Patrick Georgi71b84802011-02-22 14:35:05 +0000340
341clean-target:
342 rm -f $(obj)/coreboot*
343
344#######################################################################
345# Development utilities
346printcrt0s:
347 @echo crt0s=$(crt0s)
348 @echo ldscripts=$(ldscripts)
349
350update:
351 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
352
Patrick Georgicb02cb72012-02-25 19:42:59 +0100353lint lint-stable:
Zheng Bao533bca82012-09-28 19:38:37 +0800354 FAILED=0; LINTLOG=`mktemp .tmpconfig.lintXXXXX`; \
Patrick Georgicb02cb72012-02-25 19:42:59 +0100355 for script in util/lint/$@-*; do \
Patrick Georgi71b84802011-02-22 14:35:05 +0000356 echo; echo `basename $$script`; \
357 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
358 echo ========; \
359 $$script > $$LINTLOG; \
Patrick Georgic040e4762012-03-09 23:02:09 +0100360 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
Patrick Georgi71b84802011-02-22 14:35:05 +0000361 printf "success\n\n"; \
362 else \
363 echo test failed: ; \
364 cat $$LINTLOG; \
365 rm -f $$LINTLOG; \
366 FAILED=$$(( $$FAILED + 1 )); \
367 fi; \
368 echo ========; \
369 done; \
370 test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." && exit 1; }; \
371 rm -f $$LINTLOG
Patrick Georgi6c445502011-05-16 15:32:28 +0000372
Patrick Georgibb605282011-06-05 15:15:49 +0200373gitconfig:
Zheng Bao50ad0952012-10-22 16:29:37 +0800374 mkdir -p .git/hooks
zbaof2c32542012-08-10 15:44:02 +0800375 for hook in commit-msg pre-commit ; do \
376 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o \
377 ! -x .git/hooks/$$hook ]; then \
378 cp util/gitconfig/$$hook .git/hooks/$$hook; \
379 chmod +x .git/hooks/$$hook; \
380 fi; \
381 done
Ronald G. Minnich64b364d2013-01-03 08:26:09 -0800382 git config remote.origin.push HEAD:refs/for/master
Patrick Georgibb605282011-06-05 15:15:49 +0200383 (git config --global user.name >/dev/null && git config --global user.email >/dev/null) || (printf 'Please configure your name and email in git:\n\n git config --global user.name "Your Name Comes Here"\n git config --global user.email your.email@example.com\n'; exit 1)
384
Edward O'Callaghan3a722782013-11-02 03:40:39 +1100385crossgcc: crossgcc-i386 crossgcc-arm
Peter Stuge0b6b4d62011-06-09 05:06:25 +0200386
Edward O'Callaghan3a722782013-11-02 03:40:39 +1100387.PHONY: crossgcc-i386 crossgcc-arm
388crossgcc-i386: clean-for-update
389 $(MAKE) -C util/crossgcc build-i386-without-gdb
390
391crossgcc-arm: clean-for-update
392 $(MAKE) -C util/crossgcc build-armv7a-without-gdb
393
394crosstools: crosstools-i386
395
396.PHONY: crosstools-i386 crosstools-arm
397crosstools-i386: clean-for-update
398 $(MAKE) -C util/crossgcc build-i386
399
400crosstools-arm: clean-for-update
401 $(MAKE) -C util/crossgcc build-armv7a
Patrick Georgi6c445502011-05-16 15:32:28 +0000402
403crossgcc-clean: clean-for-update
404 $(MAKE) -C util/crossgcc clean
405
Aaron Durbin3eb8eb72014-03-10 16:13:58 -0500406tools: $(objutil)/kconfig/conf $(objutil)/cbfstool/cbfstool $(objutil)/cbfstool/rmodtool $(objutil)/nvramtool/nvramtool $(objutil)/romcc/romcc $(objutil)/sconfig/sconfig
Patrick Georgi43105d62011-11-05 14:44:41 +0100407
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700408###########################################################################
409# Common recipes for all stages
410###########################################################################
411
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700412# find-substr is required for stages like romstage_null and romstage_xip to
413# eliminate the _* part of the string
414find-substr = $(word 1,$(subst _, ,$(1)))
415
416# find-class is used to identify the class from the name of the stage
417# The input to this macro can be something like romstage.x or romstage.x.y
418# find-class recursively strips off the suffixes to extract the exact class name
419# e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
420# if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
421# and remove .x the next time and finally return romstage
422find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
423
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700424$(objcbfs)/%.bin: $(objcbfs)/%.elf
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700425 $(eval class := $(call find-class,$(@F)))
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700426 @printf " OBJCOPY $(subst $(obj)/,,$(@))\n"
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700427 $(OBJCOPY_$(class)) -O binary $< $@
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700428
429$(objcbfs)/%.elf: $(objcbfs)/%.debug
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700430 $(eval class := $(call find-class,$(@F)))
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700431 @printf " OBJCOPY $(subst $(obj)/,,$(@))\n"
432 cp $< $@.tmp
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700433 $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
434 $(OBJCOPY_$(class)) --strip-debug $@.tmp
435 $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700436 mv $@.tmp $@
437
438###########################################################################
439# Build the final rom image
440###########################################################################
441
442COREBOOT_ROM_DEPENDENCIES:=
443ifeq ($(CONFIG_PAYLOAD_ELF),y)
444COREBOOT_ROM_DEPENDENCIES+=$(CONFIG_PAYLOAD_FILE)
445endif
446ifeq ($(CONFIG_PAYLOAD_SEABIOS),y)
447COREBOOT_ROM_DEPENDENCIES+=seabios
448endif
449ifeq ($(CONFIG_PAYLOAD_FILO),y)
450COREBOOT_ROM_DEPENDENCIES+=filo
451endif
452ifeq ($(CONFIG_PAYLOAD_GRUB2),y)
453COREBOOT_ROM_DEPENDENCIES+=grub2
454endif
455
456extract_nth=$(word $(1), $(subst |, ,$(2)))
457
458ifneq ($(CONFIG_UPDATE_IMAGE),y)
459prebuild-files = \
460 $(foreach file,$(cbfs-files), \
461 $(CBFSTOOL) $@.tmp \
462 add$(if $(filter stage,$(call extract_nth,3,$(file))),-stage)$(if $(filter payload,$(call extract_nth,3,$(file))),-payload) \
463 -f $(call extract_nth,1,$(file)) \
464 -n $(call extract_nth,2,$(file)) $(if $(filter-out stage,$(call extract_nth,3,$(file))),-t $(call extract_nth,3,$(file))) \
465 $(if $(call extract_nth,4,$(file)),-b $(call extract_nth,4,$(file))) &&)
466prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
467
468$(obj)/coreboot.pre1: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL) $$(cpu_ucode_cbfs_file)
469 $(CBFSTOOL) $@.tmp create -s $(CONFIG_COREBOOT_ROMSIZE_KB)K \
470 -B $(objcbfs)/bootblock.bin -a 64 \
471 $(CBFSTOOL_PRE1_OPTS)
472 $(prebuild-files) true
473 $(call add-cpu-microcode-to-cbfs,$@.tmp)
474 mv $@.tmp $@
475else
476.PHONY: $(obj)/coreboot.pre1
477$(obj)/coreboot.pre1: $(CBFSTOOL)
478 mv $(obj)/coreboot.rom $@
479endif
480
481ifeq ($(CONFIG_PAYLOAD_LINUX),y)
482LINUX_ADDITIONAL_CONFIG:=
483ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_COMMAND_LINE))),)
484 LINUX_ADDITIONAL_CONFIG+=-C $(CONFIG_LINUX_COMMAND_LINE)
485endif
486ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),)
487 LINUX_ADDITIONAL_CONFIG+=-I $(CONFIG_LINUX_INITRD)
488endif
489endif
490
491ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
492REFCODE_BLOB=$(obj)/refcode.rmod
493$(REFCODE_BLOB): $(RMODTOOL)
494 $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
495endif
496
497$(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/ramstage.elf $(CBFSTOOL) $(call strip_quotes,$(COREBOOT_ROM_DEPENDENCIES)) $$(INTERMEDIATE) $$(VBOOT_STUB) $(REFCODE_BLOB)
498 @printf " CBFS $(subst $(obj)/,,$(@))\n"
499 cp $(obj)/coreboot.pre $@.tmp
500 $(CBFSTOOL) $@.tmp add-stage -f $(objcbfs)/ramstage.elf -n $(CONFIG_CBFS_PREFIX)/ramstage -c $(CBFS_COMPRESS_FLAG)
501ifeq ($(CONFIG_PAYLOAD_NONE),y)
502 @printf " PAYLOAD none (as specified by user)\n"
503endif
504ifeq ($(CONFIG_PAYLOAD_ELF),y)
505 @printf " PAYLOAD $(CONFIG_PAYLOAD_FILE) (compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
506 $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG)
507endif
508ifeq ($(CONFIG_PAYLOAD_LINUX),y)
509 @printf " PAYLOAD $(CONFIG_PAYLOAD_FILE) (compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
510 $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG) $(LINUX_ADDITIONAL_CONFIG)
511endif
512ifeq ($(CONFIG_PAYLOAD_SEABIOS),y)
513 @printf " PAYLOAD SeaBIOS (internal, compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
514 $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG)
515ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
516ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
517 @printf " SeaBIOS Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
518 $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
519endif
520endif
521endif
522ifeq ($(CONFIG_PAYLOAD_FILO),y)
523 @printf " PAYLOAD FILO (internal, compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
524 $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG)
525endif
526ifeq ($(CONFIG_PAYLOAD_GRUB2),y)
527 @printf " PAYLOAD GRUB2 (internal, compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
528 $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG)
529endif
530ifeq ($(CONFIG_PAYLOAD_TIANOCORE),y)
531 @printf " PAYLOAD Tiano Core (compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
532 $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG)
533endif
534ifeq ($(CONFIG_INCLUDE_CONFIG_FILE),y)
535 @printf " CONFIG $(DOTCONFIG)\n"
536 if [ -f $(DOTCONFIG) ]; then \
537 echo "# This image was built using git revision" `git rev-parse HEAD` > $(obj)/config.tmp ; \
538 sed -e '/^#/d' -e '/^ *$$/d' $(DOTCONFIG) >> $(obj)/config.tmp ; \
539 $(CBFSTOOL) $@.tmp add -f $(obj)/config.tmp -n config -t raw; rm -f $(obj)/config.tmp ; fi
540endif
541ifeq ($(CONFIG_VBOOT_VERIFY_FIRMWARE),y)
542 $(CBFSTOOL) $@.tmp add-stage -f $(VBOOT_STUB) -n $(CONFIG_CBFS_PREFIX)/vboot -c $(CBFS_COMPRESS_FLAG)
543endif
544ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
545 $(CBFSTOOL) $@.tmp add-stage -f $(REFCODE_BLOB) -n $(CONFIG_CBFS_PREFIX)/refcode -c $(CBFS_COMPRESS_FLAG)
546endif
547ifeq ($(CONFIG_PXE_ROM),y)
548 $(CBFSTOOL) $@.tmp add -f $(CONFIG_PXE_ROM_FILE) -n pci$(CONFIG_PXE_ROM_ID).rom -t raw
549endif
550ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
551ifeq ($(CONFIG_CPU_MICROCODE_IN_CBFS),y)
552 @printf " UPDATE-FIT \n"
553 $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
554endif
555endif
556 mv $@.tmp $@
557 @printf " CBFSPRINT $(subst $(obj)/,,$(@))\n\n"
558 $(CBFSTOOL) $@ print
559
560cbfs-files-$(CONFIG_BOOTSPLASH) += bootsplash.jpg
561bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
562bootsplash.jpg-type := bootsplash
563
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700564ifeq ($(CONFIG_ARCH_ROMSTAGE_ARMV7),y)
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700565ROMSTAGE_ELF := romstage.elf
566endif
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700567ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32),y)
Furquan Shaikh88ca81a2014-04-22 16:33:22 -0700568ROMSTAGE_ELF := romstage_xip.elf
569endif
570
571$(obj)/coreboot.pre: $(objcbfs)/$(ROMSTAGE_ELF) $(obj)/coreboot.pre1 $(CBFSTOOL)
572 @printf " CBFS $(subst $(obj)/,,$(@))\n"
573 cp $(obj)/coreboot.pre1 $@.tmp
574 $(CBFSTOOL) $@.tmp add-stage \
575 -f $(objcbfs)/$(ROMSTAGE_ELF) \
576 -n $(CONFIG_CBFS_PREFIX)/romstage -c none \
577 $(CBFSTOOL_PRE_OPTS)
578 mv $@.tmp $@