blob: 4d25dd528bb8c117f40c00f762d4f38b772f868b [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
Sven Schnelle054849d2011-08-26 21:57:53 +020022export KERNELVERSION := $(shell if [ -d "$(top)/.git" -a -f "`which git`" ]; then git describe --dirty; else echo unknown; fi)
Patrick Georgi71b84802011-02-22 14:35:05 +000023
24#######################################################################
25# Basic component discovery
26ARCHDIR-$(CONFIG_ARCH_X86) := x86
27MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
28export MAINBOARDDIR
29
Kyösti Mälkki0db2ae3a2012-04-19 12:00:06 +030030## Final build results, which CBFSTOOL uses to create the final
31## rom image file, are placed under $(objcbfs).
32## These typically have suffixes .debug .elf .bin and .map
33export objcbfs := $(obj)/cbfs/$(CONFIG_CBFS_PREFIX)
34
35## Based on the active configuration, Makefile conditionally collects
36## the required assembly includes and saves them in a file.
37## Such files that do not have a clear one-to-one relation to a source
38## file under src/ are placed and built under $(objgenerated)
39export objgenerated := $(obj)/generated
40
Patrick Georgi71b84802011-02-22 14:35:05 +000041#######################################################################
42# root rule to resolve if in build mode (ie. configuration exists)
43real-target: $(obj)/config.h coreboot
Kyösti Mälkki0db2ae3a2012-04-19 12:00:06 +030044coreboot: build-dirs $(obj)/coreboot.rom
Patrick Georgi71b84802011-02-22 14:35:05 +000045
46#######################################################################
47# our phony targets
Kyösti Mälkki0db2ae3a2012-04-19 12:00:06 +030048PHONY+= clean-abuild coreboot lint lint-stable build-dirs
Patrick Georgi71b84802011-02-22 14:35:05 +000049
50#######################################################################
51# root source directories of coreboot
Kyösti Mälkki2a830d02011-12-01 17:49:43 +020052subdirs-y := src/lib src/boot src/console src/devices src/ec src/southbridge
53subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode
Patrick Georgi499fc922012-03-09 10:53:52 +010054subdirs-y += util/cbfstool util/sconfig util/nvramtool
Patrick Georgi71b84802011-02-22 14:35:05 +000055subdirs-y += src/arch/$(ARCHDIR-y)
56subdirs-y += src/mainboard/$(MAINBOARDDIR)
57
58subdirs-$(CONFIG_ARCH_X86) += src/pc80
59
Patrick Georgia25828d2011-09-02 09:57:01 +020060subdirs-y += site-local
61
Patrick Georgi71b84802011-02-22 14:35:05 +000062#######################################################################
63# Add source classes and their build options
64classes-y := ramstage romstage driver smm
65
Patrick Georgi71b84802011-02-22 14:35:05 +000066romstage-c-ccopts:=-D__PRE_RAM__
Stefan Reinauer61aee5f2011-04-10 04:15:23 +000067romstage-S-ccopts:=-D__PRE_RAM__
Rudolf Marek7f0e9302011-09-02 23:23:41 +020068ifeq ($(CONFIG_TRACE),y)
69ramstage-c-ccopts:= -finstrument-functions
70endif
71
Stefan Reinauer24ef1342011-04-14 22:28:00 +000072smm-c-ccopts:=-D__SMM__
73smm-S-ccopts:=-D__SMM__
Patrick Georgi71b84802011-02-22 14:35:05 +000074
Stefan Reinauer3aa067f2012-04-02 13:24:04 -070075# SMM TSEG base is dynamic
76ifeq ($(CONFIG_SMM_TSEG),y)
77smm-c-ccopts += -fpic
78endif
79
Patrick Georgi57205c72011-03-08 20:49:18 +000080ramstage-c-deps:=$$(OPTION_TABLE_H)
81romstage-c-deps:=$$(OPTION_TABLE_H)
82
Patrick Georgi71b84802011-02-22 14:35:05 +000083#######################################################################
84# Add handler to compile ACPI's ASL
85define ramstage-objs_asl_template
Sven Schnelled69438e2011-03-29 09:01:10 +000086$(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
Patrick Georgi71b84802011-02-22 14:35:05 +000087 @printf " IASL $$(subst $(top)/,,$$(@))\n"
Patrick Georgic8feedd2012-02-16 18:43:25 +010088 $(CC) -x assembler-with-cpp -E -MMD -MT $$(@) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/include -I$(src)/arch/$(ARCHDIR-y)/include -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
Marc Jones2aac3f62011-08-08 16:07:50 -060089 cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl
Patrick Georgib2a42642011-06-01 19:54:16 +000090 mv $$(basename $$@).hex $$(basename $$@).c
Patrick Georgi71b84802011-02-22 14:35:05 +000091 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
92 # keep %.o: %.c rule from catching the temporary .c file after a make clean
93 mv $$(basename $$@).c $$(basename $$@).hex
94endef
95
96#######################################################################
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +010097# Parse plaintext cmos defaults into binary format
98# arg1: source file
99# arg2: binary file name
100cbfs-files-processor-nvramtool= \
101 $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
102 printf " CREATE $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
103
104#######################################################################
Patrick Georgi71b84802011-02-22 14:35:05 +0000105# Add handler for arbitrary files in CBFS
106$(call add-special-class,cbfs-files)
107cbfs-files-handler= \
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +0100108 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
109 $(eval $(2)-file:=$(word 1, $(subst :, ,$($(2)-file)))) \
Patrick Georgi71b84802011-02-22 14:35:05 +0000110 $(if $(wildcard $(1)$($(2)-file)), \
111 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
112 $(eval tmp-cbfs-file:= $($(2)-file))) \
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +0100113 $(if $(tmp-cbfs-method), \
114 $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
115 $(eval tmp-cbfs-file:=$(shell mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
116 $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
Patrick Georgi71b84802011-02-22 14:35:05 +0000117 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-position)) \
118 $(eval $(2)-name:=) \
119 $(eval $(2)-type:=) \
120 $(eval $(2)-position:=)
121
122#######################################################################
123# a variety of flags for our build
Sven Schnelle8eee19d2011-05-02 19:53:04 +0000124CBFS_COMPRESS_FLAG:=
125ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
Patrick Georgi71b84802011-02-22 14:35:05 +0000126CBFS_COMPRESS_FLAG:=l
Sven Schnelle8eee19d2011-05-02 19:53:04 +0000127endif
128
Patrick Georgi71b84802011-02-22 14:35:05 +0000129CBFS_PAYLOAD_COMPRESS_FLAG:=
130CBFS_PAYLOAD_COMPRESS_NAME:=none
131ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
132CBFS_PAYLOAD_COMPRESS_FLAG:=l
133CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
134endif
135
136ifneq ($(CONFIG_LOCALVERSION),"")
137COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
138endif
139
140INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
141INCLUDES += -Isrc/devices/oprom/include
142# abspath is a workaround for romcc
143INCLUDES += -include $(abspath $(obj)/config.h)
144
Frank Vibransec402602011-05-05 16:45:36 +0000145CFLAGS = $(INCLUDES) -Os -pipe -g -nostdinc
Patrick Georgi71b84802011-02-22 14:35:05 +0000146CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
147CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
148CFLAGS += -Wstrict-aliasing -Wshadow
149ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
150CFLAGS += -Werror
151endif
Patrick Georgi71b84802011-02-22 14:35:05 +0000152CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
153
154additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options
155
156#######################################################################
157# generate build support files
158$(obj)/build.h: .xcompile
159 @printf " GEN build.h\n"
160 rm -f $(obj)/build.h
161 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
162 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
163 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
Patrick Georgib8e9ba92011-03-17 07:47:49 +0000164 printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
Patrick Georgi71b84802011-02-22 14:35:05 +0000165 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
166 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200167 printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht
Patrick Georgi71b84802011-02-22 14:35:05 +0000168 printf "\n" >> $(obj)/build.ht
169 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
170 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
171 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
172 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
173 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
174 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht
175 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
176 printf "#endif\n" >> $(obj)/build.ht
177 mv $(obj)/build.ht $(obj)/build.h
178
179$(obj)/ldoptions: $(obj)/config.h
180 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
181
Kyösti Mälkki0db2ae3a2012-04-19 12:00:06 +0300182build-dirs:
183 mkdir -p $(objcbfs) $(objgenerated)
184
Patrick Georgi71b84802011-02-22 14:35:05 +0000185#######################################################################
186# Build the tools
187CBFSTOOL:=$(obj)/cbfstool
188
189$(CBFSTOOL): $(objutil)/cbfstool/cbfstool
190 cp $< $@
191
192_WINCHECK=$(shell uname -o 2> /dev/null)
193STACK=
194ifeq ($(_WINCHECK),Msys)
195 STACK=-Wl,--stack,16384000
196endif
197ifeq ($(_WINCHECK),Cygwin)
198 STACK=-Wl,--stack,16384000
199endif
200
201ROMCC:= $(objutil)/romcc/romcc
202$(ROMCC): $(top)/util/romcc/romcc.c
203 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
204 @# Note: Adding -O2 here might cause problems. For details see:
205 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
206 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
207
208#######################################################################
209# needed objects that every mainboard uses
210# Creation of these is architecture and mainboard independent
211$(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
212 @printf " SCONFIG $(subst $(src)/,,$(<))\n"
213 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
214 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
215
216ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
217
218$(objutil)/%.o: $(objutil)/%.c
219 @printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
220 $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
221
Patrick Georgi64ccc3b82011-05-20 23:08:12 +0000222$(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
Patrick Georgi71b84802011-02-22 14:35:05 +0000223 @printf " CC $(subst $(obj)/,,$(@))\n"
224 $(CC) -MMD $(CFLAGS) -c -o $@ $<
225
226#######################################################################
227# Clean up rules
228clean-abuild:
229 rm -rf coreboot-builds
230
231clean-for-update-target:
232 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
233 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
234 rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
235 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
236 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
237 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
238 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
239 rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
Marc Jones1dd0dda2012-03-19 17:32:33 -0600240 $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC)" LD="$(LD)"
Patrick Georgi71b84802011-02-22 14:35:05 +0000241
242clean-target:
243 rm -f $(obj)/coreboot*
244
245#######################################################################
246# Development utilities
247printcrt0s:
248 @echo crt0s=$(crt0s)
249 @echo ldscripts=$(ldscripts)
250
251update:
252 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
253
Patrick Georgicb02cb72012-02-25 19:42:59 +0100254lint lint-stable:
Patrick Georgi71b84802011-02-22 14:35:05 +0000255 FAILED=0; LINTLOG=`mktemp`; \
Patrick Georgicb02cb72012-02-25 19:42:59 +0100256 for script in util/lint/$@-*; do \
Patrick Georgi71b84802011-02-22 14:35:05 +0000257 echo; echo `basename $$script`; \
258 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
259 echo ========; \
260 $$script > $$LINTLOG; \
Patrick Georgic040e4762012-03-09 23:02:09 +0100261 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
Patrick Georgi71b84802011-02-22 14:35:05 +0000262 printf "success\n\n"; \
263 else \
264 echo test failed: ; \
265 cat $$LINTLOG; \
266 rm -f $$LINTLOG; \
267 FAILED=$$(( $$FAILED + 1 )); \
268 fi; \
269 echo ========; \
270 done; \
271 test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." && exit 1; }; \
272 rm -f $$LINTLOG
Patrick Georgi6c445502011-05-16 15:32:28 +0000273
Patrick Georgibb605282011-06-05 15:15:49 +0200274gitconfig:
Patrick Georgi07408e62012-02-25 19:52:45 +0100275 for hook in commit-msg pre-commit; do if ! [ -x .git/hooks/$$hook ]; then cp util/gitconfig/$$hook .git/hooks/$$hook; chmod +x .git/hooks/$$hook; fi; done
Patrick Georgibb605282011-06-05 15:15:49 +0200276 (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)
277
Patrick Georgi6c445502011-05-16 15:32:28 +0000278crossgcc: clean-for-update
Peter Stuge0b6b4d62011-06-09 05:06:25 +0200279 $(MAKE) -C util/crossgcc build-without-gdb
280
281crosstools: clean-for-update
Patrick Georgi6c445502011-05-16 15:32:28 +0000282 $(MAKE) -C util/crossgcc build
283
284crossgcc-clean: clean-for-update
285 $(MAKE) -C util/crossgcc clean
286