blob: 62675398841c8e96832ea7546bed876735d29917 [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
Patrick Georgib8e9ba92011-03-17 07:47:49 +000022REV=-r$(shell if [ -d $(top)/.svn -a -f "`which svnversion`" ]; then svnversion $(top); else if [ -d $(top)/.git -a -f "`which git`" ]; then git --git-dir=/$(top)/.git log|grep git-svn-id|cut -f 2 -d@|cut -f 1 -d' '|sort -g|tail -1; fi; fi)
23export KERNELVERSION := 4.0$(REV)
Patrick Georgi71b84802011-02-22 14:35:05 +000024
25#######################################################################
26# Basic component discovery
27ARCHDIR-$(CONFIG_ARCH_X86) := x86
28MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
29export MAINBOARDDIR
30
31#######################################################################
32# root rule to resolve if in build mode (ie. configuration exists)
33real-target: $(obj)/config.h coreboot
34coreboot: $(obj)/coreboot.rom
35
36#######################################################################
37# our phony targets
38PHONY+= clean-abuild coreboot
39
40#######################################################################
41# root source directories of coreboot
42subdirs-y := src/lib src/boot src/console src/devices src/ec src/southbridge src/northbridge src/superio src/drivers src/cpu
43subdirs-y += util/cbfstool util/sconfig
44subdirs-y += src/arch/$(ARCHDIR-y)
45subdirs-y += src/mainboard/$(MAINBOARDDIR)
46
47subdirs-$(CONFIG_ARCH_X86) += src/pc80
48
49#######################################################################
50# Add source classes and their build options
51classes-y := ramstage romstage driver smm
52
Patrick Georgi71b84802011-02-22 14:35:05 +000053romstage-c-ccopts:=-D__PRE_RAM__
Stefan Reinauer61aee5f2011-04-10 04:15:23 +000054romstage-S-ccopts:=-D__PRE_RAM__
Stefan Reinauer24ef1342011-04-14 22:28:00 +000055smm-c-ccopts:=-D__SMM__
56smm-S-ccopts:=-D__SMM__
Patrick Georgi71b84802011-02-22 14:35:05 +000057
Patrick Georgi57205c72011-03-08 20:49:18 +000058ramstage-c-deps:=$$(OPTION_TABLE_H)
59romstage-c-deps:=$$(OPTION_TABLE_H)
60
Patrick Georgi71b84802011-02-22 14:35:05 +000061#######################################################################
62# Add handler to compile ACPI's ASL
63define ramstage-objs_asl_template
Sven Schnelled69438e2011-03-29 09:01:10 +000064$(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
Patrick Georgi71b84802011-02-22 14:35:05 +000065 @printf " IASL $$(subst $(top)/,,$$(@))\n"
Stefan Reinauer61aee5f2011-04-10 04:15:23 +000066 $(CC) -x assembler-with-cpp -E -MMD -MT $$(@) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
Patrick Georgi71b84802011-02-22 14:35:05 +000067 iasl -p $$(obj)/$(1) -tc $$(basename $$@).asl
68 mv $$(obj)/$(1).hex $$(basename $$@).c
69 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
70 # keep %.o: %.c rule from catching the temporary .c file after a make clean
71 mv $$(basename $$@).c $$(basename $$@).hex
72endef
73
74#######################################################################
75# Add handler for arbitrary files in CBFS
76$(call add-special-class,cbfs-files)
77cbfs-files-handler= \
78 $(if $(wildcard $(1)$($(2)-file)), \
79 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
80 $(eval tmp-cbfs-file:= $($(2)-file))) \
81 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-position)) \
82 $(eval $(2)-name:=) \
83 $(eval $(2)-type:=) \
84 $(eval $(2)-position:=)
85
86#######################################################################
87# a variety of flags for our build
Sven Schnelle8eee19d2011-05-02 19:53:04 +000088CBFS_COMPRESS_FLAG:=
89ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
Patrick Georgi71b84802011-02-22 14:35:05 +000090CBFS_COMPRESS_FLAG:=l
Sven Schnelle8eee19d2011-05-02 19:53:04 +000091endif
92
Patrick Georgi71b84802011-02-22 14:35:05 +000093CBFS_PAYLOAD_COMPRESS_FLAG:=
94CBFS_PAYLOAD_COMPRESS_NAME:=none
95ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
96CBFS_PAYLOAD_COMPRESS_FLAG:=l
97CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
98endif
99
100ifneq ($(CONFIG_LOCALVERSION),"")
101COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
102endif
103
104INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
105INCLUDES += -Isrc/devices/oprom/include
106# abspath is a workaround for romcc
107INCLUDES += -include $(abspath $(obj)/config.h)
108
109CFLAGS = $(INCLUDES) -Os -pipe -g
110CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
111CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
112CFLAGS += -Wstrict-aliasing -Wshadow
113ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
114CFLAGS += -Werror
115endif
116ifneq ($(CONFIG_AMD_AGESA),y)
117CFLAGS += -nostdinc
118endif
119CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
120
121additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options
122
123#######################################################################
124# generate build support files
125$(obj)/build.h: .xcompile
126 @printf " GEN build.h\n"
127 rm -f $(obj)/build.h
128 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
129 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
130 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
Patrick Georgib8e9ba92011-03-17 07:47:49 +0000131 printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
Patrick Georgi71b84802011-02-22 14:35:05 +0000132 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
133 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
134 printf "\n" >> $(obj)/build.ht
135 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
136 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
137 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
138 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
139 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
140 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht
141 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
142 printf "#endif\n" >> $(obj)/build.ht
143 mv $(obj)/build.ht $(obj)/build.h
144
145$(obj)/ldoptions: $(obj)/config.h
146 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
147
148#######################################################################
149# Build the tools
150CBFSTOOL:=$(obj)/cbfstool
151
152$(CBFSTOOL): $(objutil)/cbfstool/cbfstool
153 cp $< $@
154
155_WINCHECK=$(shell uname -o 2> /dev/null)
156STACK=
157ifeq ($(_WINCHECK),Msys)
158 STACK=-Wl,--stack,16384000
159endif
160ifeq ($(_WINCHECK),Cygwin)
161 STACK=-Wl,--stack,16384000
162endif
163
164ROMCC:= $(objutil)/romcc/romcc
165$(ROMCC): $(top)/util/romcc/romcc.c
166 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
167 @# Note: Adding -O2 here might cause problems. For details see:
168 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
169 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
170
171#######################################################################
172# needed objects that every mainboard uses
173# Creation of these is architecture and mainboard independent
174$(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
175 @printf " SCONFIG $(subst $(src)/,,$(<))\n"
176 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
177 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
178
179ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
180
181$(objutil)/%.o: $(objutil)/%.c
182 @printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
183 $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
184
Patrick Georgi57205c72011-03-08 20:49:18 +0000185$(obj)/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
Patrick Georgi71b84802011-02-22 14:35:05 +0000186 @printf " CC $(subst $(obj)/,,$(@))\n"
187 $(CC) -MMD $(CFLAGS) -c -o $@ $<
188
189#######################################################################
190# Clean up rules
191clean-abuild:
192 rm -rf coreboot-builds
193
194clean-for-update-target:
195 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
196 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
197 rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
198 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
199 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
200 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
201 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
202 rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
203 $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean
204
205clean-target:
206 rm -f $(obj)/coreboot*
207
208#######################################################################
209# Development utilities
210printcrt0s:
211 @echo crt0s=$(crt0s)
212 @echo ldscripts=$(ldscripts)
213
214update:
215 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
216
217lint:
218 FAILED=0; LINTLOG=`mktemp`; \
219 for script in util/lint/lint-*; do \
220 echo; echo `basename $$script`; \
221 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
222 echo ========; \
223 $$script > $$LINTLOG; \
224 if [ `wc -l $$LINTLOG | cut -d' ' -f1` -eq 0 ]; then \
225 printf "success\n\n"; \
226 else \
227 echo test failed: ; \
228 cat $$LINTLOG; \
229 rm -f $$LINTLOG; \
230 FAILED=$$(( $$FAILED + 1 )); \
231 fi; \
232 echo ========; \
233 done; \
234 test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." && exit 1; }; \
235 rm -f $$LINTLOG