blob: b5e8811370c5c66df39b0d9f8c168234b3a09ad7 [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
30#######################################################################
31# root rule to resolve if in build mode (ie. configuration exists)
32real-target: $(obj)/config.h coreboot
33coreboot: $(obj)/coreboot.rom
34
35#######################################################################
36# our phony targets
Patrick Georgicb02cb72012-02-25 19:42:59 +010037PHONY+= clean-abuild coreboot lint lint-stable
Patrick Georgi71b84802011-02-22 14:35:05 +000038
39#######################################################################
40# root source directories of coreboot
Kyösti Mälkki2a830d02011-12-01 17:49:43 +020041subdirs-y := src/lib src/boot src/console src/devices src/ec src/southbridge
42subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode
Patrick Georgi499fc922012-03-09 10:53:52 +010043subdirs-y += util/cbfstool util/sconfig util/nvramtool
Patrick Georgi71b84802011-02-22 14:35:05 +000044subdirs-y += src/arch/$(ARCHDIR-y)
45subdirs-y += src/mainboard/$(MAINBOARDDIR)
46
47subdirs-$(CONFIG_ARCH_X86) += src/pc80
48
Patrick Georgia25828d2011-09-02 09:57:01 +020049subdirs-y += site-local
50
Patrick Georgi71b84802011-02-22 14:35:05 +000051#######################################################################
52# Add source classes and their build options
53classes-y := ramstage romstage driver smm
54
Patrick Georgi71b84802011-02-22 14:35:05 +000055romstage-c-ccopts:=-D__PRE_RAM__
Stefan Reinauer61aee5f2011-04-10 04:15:23 +000056romstage-S-ccopts:=-D__PRE_RAM__
Rudolf Marek7f0e9302011-09-02 23:23:41 +020057ifeq ($(CONFIG_TRACE),y)
58ramstage-c-ccopts:= -finstrument-functions
59endif
60
Stefan Reinauer24ef1342011-04-14 22:28:00 +000061smm-c-ccopts:=-D__SMM__
62smm-S-ccopts:=-D__SMM__
Patrick Georgi71b84802011-02-22 14:35:05 +000063
Stefan Reinauer3aa067f2012-04-02 13:24:04 -070064# SMM TSEG base is dynamic
65ifeq ($(CONFIG_SMM_TSEG),y)
66smm-c-ccopts += -fpic
67endif
68
Patrick Georgi57205c72011-03-08 20:49:18 +000069ramstage-c-deps:=$$(OPTION_TABLE_H)
70romstage-c-deps:=$$(OPTION_TABLE_H)
71
Patrick Georgi71b84802011-02-22 14:35:05 +000072#######################################################################
73# Add handler to compile ACPI's ASL
74define ramstage-objs_asl_template
Sven Schnelled69438e2011-03-29 09:01:10 +000075$(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
Patrick Georgi71b84802011-02-22 14:35:05 +000076 @printf " IASL $$(subst $(top)/,,$$(@))\n"
Patrick Georgic8feedd2012-02-16 18:43:25 +010077 $(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 -060078 cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl
Patrick Georgib2a42642011-06-01 19:54:16 +000079 mv $$(basename $$@).hex $$(basename $$@).c
Patrick Georgi71b84802011-02-22 14:35:05 +000080 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
81 # keep %.o: %.c rule from catching the temporary .c file after a make clean
82 mv $$(basename $$@).c $$(basename $$@).hex
83endef
84
85#######################################################################
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +010086# Parse plaintext cmos defaults into binary format
87# arg1: source file
88# arg2: binary file name
89cbfs-files-processor-nvramtool= \
90 $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
91 printf " CREATE $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
92
93#######################################################################
Patrick Georgi71b84802011-02-22 14:35:05 +000094# Add handler for arbitrary files in CBFS
95$(call add-special-class,cbfs-files)
96cbfs-files-handler= \
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +010097 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
98 $(eval $(2)-file:=$(word 1, $(subst :, ,$($(2)-file)))) \
Patrick Georgi71b84802011-02-22 14:35:05 +000099 $(if $(wildcard $(1)$($(2)-file)), \
100 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
101 $(eval tmp-cbfs-file:= $($(2)-file))) \
Patrick Georgi3bbd2bf2012-03-09 12:30:07 +0100102 $(if $(tmp-cbfs-method), \
103 $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
104 $(eval tmp-cbfs-file:=$(shell mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
105 $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
Patrick Georgi71b84802011-02-22 14:35:05 +0000106 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-position)) \
107 $(eval $(2)-name:=) \
108 $(eval $(2)-type:=) \
109 $(eval $(2)-position:=)
110
111#######################################################################
112# a variety of flags for our build
Sven Schnelle8eee19d2011-05-02 19:53:04 +0000113CBFS_COMPRESS_FLAG:=
114ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
Patrick Georgi71b84802011-02-22 14:35:05 +0000115CBFS_COMPRESS_FLAG:=l
Sven Schnelle8eee19d2011-05-02 19:53:04 +0000116endif
117
Patrick Georgi71b84802011-02-22 14:35:05 +0000118CBFS_PAYLOAD_COMPRESS_FLAG:=
119CBFS_PAYLOAD_COMPRESS_NAME:=none
120ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
121CBFS_PAYLOAD_COMPRESS_FLAG:=l
122CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
123endif
124
125ifneq ($(CONFIG_LOCALVERSION),"")
126COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
127endif
128
129INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
130INCLUDES += -Isrc/devices/oprom/include
131# abspath is a workaround for romcc
132INCLUDES += -include $(abspath $(obj)/config.h)
133
Frank Vibransec402602011-05-05 16:45:36 +0000134CFLAGS = $(INCLUDES) -Os -pipe -g -nostdinc
Patrick Georgi71b84802011-02-22 14:35:05 +0000135CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
136CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
137CFLAGS += -Wstrict-aliasing -Wshadow
138ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
139CFLAGS += -Werror
140endif
Patrick Georgi71b84802011-02-22 14:35:05 +0000141CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
142
143additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options
144
145#######################################################################
146# generate build support files
147$(obj)/build.h: .xcompile
148 @printf " GEN build.h\n"
149 rm -f $(obj)/build.h
150 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
151 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
152 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
Patrick Georgib8e9ba92011-03-17 07:47:49 +0000153 printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
Patrick Georgi71b84802011-02-22 14:35:05 +0000154 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
155 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200156 printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht
Patrick Georgi71b84802011-02-22 14:35:05 +0000157 printf "\n" >> $(obj)/build.ht
158 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
159 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
160 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
161 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
162 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
163 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht
164 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
165 printf "#endif\n" >> $(obj)/build.ht
166 mv $(obj)/build.ht $(obj)/build.h
167
168$(obj)/ldoptions: $(obj)/config.h
169 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
170
171#######################################################################
172# Build the tools
173CBFSTOOL:=$(obj)/cbfstool
174
175$(CBFSTOOL): $(objutil)/cbfstool/cbfstool
176 cp $< $@
177
178_WINCHECK=$(shell uname -o 2> /dev/null)
179STACK=
180ifeq ($(_WINCHECK),Msys)
181 STACK=-Wl,--stack,16384000
182endif
183ifeq ($(_WINCHECK),Cygwin)
184 STACK=-Wl,--stack,16384000
185endif
186
187ROMCC:= $(objutil)/romcc/romcc
188$(ROMCC): $(top)/util/romcc/romcc.c
189 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
190 @# Note: Adding -O2 here might cause problems. For details see:
191 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
192 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
193
194#######################################################################
195# needed objects that every mainboard uses
196# Creation of these is architecture and mainboard independent
197$(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
198 @printf " SCONFIG $(subst $(src)/,,$(<))\n"
199 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
200 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
201
202ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
203
204$(objutil)/%.o: $(objutil)/%.c
205 @printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
206 $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
207
Patrick Georgi64ccc3b82011-05-20 23:08:12 +0000208$(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
Patrick Georgi71b84802011-02-22 14:35:05 +0000209 @printf " CC $(subst $(obj)/,,$(@))\n"
210 $(CC) -MMD $(CFLAGS) -c -o $@ $<
211
212#######################################################################
213# Clean up rules
214clean-abuild:
215 rm -rf coreboot-builds
216
217clean-for-update-target:
218 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
219 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
220 rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
221 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
222 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
223 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
224 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
225 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 -0600226 $(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 +0000227
228clean-target:
229 rm -f $(obj)/coreboot*
230
231#######################################################################
232# Development utilities
233printcrt0s:
234 @echo crt0s=$(crt0s)
235 @echo ldscripts=$(ldscripts)
236
237update:
238 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
239
Patrick Georgicb02cb72012-02-25 19:42:59 +0100240lint lint-stable:
Patrick Georgi71b84802011-02-22 14:35:05 +0000241 FAILED=0; LINTLOG=`mktemp`; \
Patrick Georgicb02cb72012-02-25 19:42:59 +0100242 for script in util/lint/$@-*; do \
Patrick Georgi71b84802011-02-22 14:35:05 +0000243 echo; echo `basename $$script`; \
244 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
245 echo ========; \
246 $$script > $$LINTLOG; \
Patrick Georgic040e4762012-03-09 23:02:09 +0100247 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
Patrick Georgi71b84802011-02-22 14:35:05 +0000248 printf "success\n\n"; \
249 else \
250 echo test failed: ; \
251 cat $$LINTLOG; \
252 rm -f $$LINTLOG; \
253 FAILED=$$(( $$FAILED + 1 )); \
254 fi; \
255 echo ========; \
256 done; \
257 test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." && exit 1; }; \
258 rm -f $$LINTLOG
Patrick Georgi6c445502011-05-16 15:32:28 +0000259
Patrick Georgibb605282011-06-05 15:15:49 +0200260gitconfig:
Patrick Georgi07408e62012-02-25 19:52:45 +0100261 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 +0200262 (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)
263
Patrick Georgi6c445502011-05-16 15:32:28 +0000264crossgcc: clean-for-update
Peter Stuge0b6b4d62011-06-09 05:06:25 +0200265 $(MAKE) -C util/crossgcc build-without-gdb
266
267crosstools: clean-for-update
Patrick Georgi6c445502011-05-16 15:32:28 +0000268 $(MAKE) -C util/crossgcc build
269
270crossgcc-clean: clean-for-update
271 $(MAKE) -C util/crossgcc clean
272