AMD boards: ACPI DSDT: Use COREBOOT for the OEM Table ID field
[coreboot.git] / Makefile.inc
blobad9736313961f09bbda8cc201623aca790f137f2
1 ##
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.
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
20 #######################################################################
21 # misleadingly named, this is the coreboot version
22 export KERNELVERSION := $(shell if [ -d "$(top)/.git" -a -f "`which git`" ]; then git describe --dirty 2>/dev/null || git describe; else echo unknown; fi)
24 #######################################################################
25 # Basic component discovery
26 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
27 export MAINBOARDDIR
29 ## Final build results, which CBFSTOOL uses to create the final
30 ## rom image file, are placed under $(objcbfs).
31 ## These typically have suffixes .debug .elf .bin and .map
32 export objcbfs := $(obj)/cbfs/$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
34 ## Based on the active configuration, Makefile conditionally collects
35 ## the required assembly includes and saves them in a file.
36 ## Such files that do not have a clear one-to-one relation to a source
37 ## file under src/ are placed and built under $(objgenerated)
38 export objgenerated := $(obj)/generated
40 #######################################################################
41 # root rule to resolve if in build mode (ie. configuration exists)
42 real-target: $(obj)/config.h coreboot
43 coreboot: build-dirs $(obj)/coreboot.rom
45 #######################################################################
46 # our phony targets
47 PHONY+= clean-abuild coreboot lint lint-stable build-dirs
49 #######################################################################
50 # root source directories of coreboot
51 subdirs-y := src/lib src/console src/device src/ec src/southbridge
52 subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode
53 subdirs-y += util/cbfstool util/sconfig util/nvramtool
54 subdirs-y += src/arch/$(ARCHDIR-y)
55 subdirs-y += src/mainboard/$(MAINBOARDDIR)
57 subdirs-y += site-local
59 #######################################################################
60 # Add source classes and their build options
61 classes-y := ramstage romstage bootblock smm cpu_microcode
63 #######################################################################
64 # Helper functions for ramstage postprocess
65 spc :=
66 spc +=
67 $(spc) :=
68 $(spc) +=
70 # files-in-dir-recursive,dir,files
71 files-in-dir-recursive=$(filter $(1)%,$(2))
73 # parent-dir,dir/
74 parent-dir=$(dir $(subst $( ),/,$(strip $(subst /, ,$(1)))))
76 # filters out exactly the directory specified
77 # filter-out-dir,dir_to_keep,dirs
78 filter-out-dir=$(filter-out $(1),$(2))
80 # filters out dir_to_keep and all its parents
81 # filter-out-dirs,dir_to_keep,dirs
82 filter-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)))
84 # dir-wildcards,dirs
85 dir-wildcards=$(addsuffix %,$(1))
87 # files-in-dir,dir,files
88 files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(dir $(2)))),$(call files-in-dir-recursive,$(1),$(2)))
90 #######################################################################
91 # reduce command line length by linking the objects of each
92 # directory into an intermediate file
93 ramstage-postprocess=$(foreach d,$(sort $(dir $(1))), \
94         $(eval $(d)ramstage.o: $(call files-in-dir,$(d),$(1)); $$(LD) -o $$@ -r $$^ ) \
95         $(eval ramstage-objs:=$(d)ramstage.o $(filter-out $(call files-in-dir,$(d),$(1)),$(ramstage-objs))))
97 romstage-c-ccopts:=-D__PRE_RAM__
98 romstage-S-ccopts:=-D__PRE_RAM__
99 ifeq ($(CONFIG_TRACE),y)
100 ramstage-c-ccopts:= -finstrument-functions
101 endif
102 ifeq ($(CONFIG_COVERAGE),y)
103 ramstage-c-ccopts+=-fprofile-arcs -ftest-coverage
104 endif
106 ifeq ($(CONFIG_USE_BLOBS),y)
107 forgetthis:=$(shell git submodule update --init --checkout 3rdparty)
108 endif
110 bootblock-c-ccopts:=-D__BOOT_BLOCK__ -D__PRE_RAM__
111 bootblock-S-ccopts:=-D__BOOT_BLOCK__ -D__PRE_RAM__
113 smm-c-ccopts:=-D__SMM__
114 smm-S-ccopts:=-D__SMM__
116 # SMM TSEG base is dynamic
117 ifeq ($(CONFIG_SMM_TSEG),y)
118 smm-c-ccopts += -fpic
119 endif
121 ramstage-c-deps:=$$(OPTION_TABLE_H)
122 romstage-c-deps:=$$(OPTION_TABLE_H)
123 bootblock-c-deps:=$$(OPTION_TABLE_H)
125 #######################################################################
126 # Add handler to compile ACPI's ASL
127 define ramstage-objs_asl_template
128 $(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
129         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
130         $(CC) -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-y)/include -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
131         cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl
132         mv $$(basename $$@).hex $$(basename $$@).c
133         $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
134         # keep %.o: %.c rule from catching the temporary .c file after a make clean
135         mv $$(basename $$@).c $$(basename $$@).hex
136 endef
138 #######################################################################
139 # Parse plaintext cmos defaults into binary format
140 # arg1: source file
141 # arg2: binary file name
142 cbfs-files-processor-nvramtool= \
143         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
144                 printf "    CREATE     $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
146 #######################################################################
147 # Link VSA binary to ELF-ish stage
148 # arg1: source file
149 # arg2: binary file name
150 cbfs-files-processor-vsa= \
151         $(eval $(2): $(1) ; \
152                 printf "    CREATE     $(2) (from $(1))\n";  $(OBJCOPY) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && $(LD) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
154 #######################################################################
155 # Add handler for arbitrary files in CBFS
156 $(call add-special-class,cbfs-files)
157 cbfs-files-handler= \
158                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
159                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
160                 $(if $(wildcard $(1)$($(2)-file)), \
161                         $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
162                         $(eval tmp-cbfs-file:= $($(2)-file))) \
163                 $(if $(strip $($(2)-required)), \
164                         $(if $(wildcard $(tmp-cbfs-file)),, \
165                                 $(info This build configuration requires $($(2)-required)) \
166                                 $(eval FAILBUILD:=1) \
167                         )) \
168                 $(if $(tmp-cbfs-method), \
169                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
170                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
171                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
172                 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$($(2)-position)) \
173                 $(eval $(2)-name:=) \
174                 $(eval $(2)-type:=) \
175                 $(eval $(2)-compression:=) \
176                 $(eval $(2)-position:=) \
177                 $(eval $(2)-required:=)
179 #######################################################################
180 # a variety of flags for our build
181 CBFS_COMPRESS_FLAG:=none
182 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
183 CBFS_COMPRESS_FLAG:=LZMA
184 endif
186 CBFS_PAYLOAD_COMPRESS_FLAG:=none
187 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
188 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
189 endif
191 ifneq ($(CONFIG_LOCALVERSION),"")
192 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
193 endif
195 INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
196 INCLUDES += -Isrc/device/oprom/include
197 # abspath is a workaround for romcc
198 INCLUDES += -include $(src)/include/kconfig.h
200 CFLAGS = $(INCLUDES) -Os -pipe -g -nostdinc
201 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
202 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
203 CFLAGS += -Wstrict-aliasing -Wshadow
204 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
205 CFLAGS += -Werror
206 endif
207 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
209 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool $(objutil)/options
211 #######################################################################
212 # generate build support files
213 $(obj)/build.h: .xcompile
214         @printf "    GEN        build.h\n"
215         rm -f $(obj)/build.h
216         printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
217         printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
218         printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
219         printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
220         printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
221         printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
222         printf "#define COREBOOT_BUILD_YEAR_BCD 0x`LANG= date +"%y"`\n" >> $(obj)/build.ht
223         printf "#define COREBOOT_BUILD_MONTH_BCD 0x`LANG= date +"%m"`\n" >> $(obj)/build.ht
224         printf "#define COREBOOT_BUILD_DAY_BCD 0x`LANG= date +"%d"`\n" >> $(obj)/build.ht
225         printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x`LANG= date +"%w"`\n" >> $(obj)/build.ht
226         printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht
227         printf "\n" >> $(obj)/build.ht
228         printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
229         printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
230         printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
231         printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
232         printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
233         printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null || hostname 2>/dev/null)\"\n" >> $(obj)/build.ht
234         printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
235         printf "#endif\n" >> $(obj)/build.ht
236         mv $(obj)/build.ht $(obj)/build.h
238 $(obj)/ldoptions: $(obj)/config.h
239         awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
241 build-dirs:
242         mkdir -p $(objcbfs) $(objgenerated)
244 #######################################################################
245 # Build the tools
246 CBFSTOOL:=$(obj)/cbfstool
248 $(CBFSTOOL): $(objutil)/cbfstool/cbfstool
249         cp $< $@
251 _WINCHECK=$(shell uname -o 2> /dev/null)
252 STACK=
253 ifeq ($(_WINCHECK),Msys)
254         STACK=-Wl,--stack,16384000
255 endif
256 ifeq ($(_WINCHECK),Cygwin)
257         STACK=-Wl,--stack,16384000
258 endif
260 ROMCC:= $(objutil)/romcc/romcc
261 $(ROMCC): $(top)/util/romcc/romcc.c
262         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
263         @# Note: Adding -O2 here might cause problems. For details see:
264         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
265         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
267 IFDTOOL:=$(objutil)/ifdtool/ifdtool
268 $(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
269         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
270         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
272 #######################################################################
273 # needed objects that every mainboard uses
274 # Creation of these is architecture and mainboard independent
275 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
276         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
277         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
278         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
280 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
281 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
283 $(objutil)/%.o: $(objutil)/%.c
284         @printf "    HOSTCC     $(subst $(objutil)/,,$(@))\n"
285         $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
287 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
288         @printf "    CC         $(subst $(obj)/,,$(@))\n"
289         $(CC) -MMD $(CFLAGS) -c -o $@ $<
291 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
292         @printf "    CC         $(subst $(obj)/,,$(@))\n"
293         $(CC) -MMD -D__PRE_RAM__ $(CFLAGS) -c -o $@ $<
295 $(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
296         @printf "    CC         $(subst $(obj)/,,$(@))\n"
297         $(CC) -MMD $(bootblock-c-ccopts) $(CFLAGS) -c -o $@ $<
299 #######################################################################
300 # Clean up rules
301 clean-abuild:
302         rm -rf coreboot-builds
304 clean-for-update-target:
305         rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
306         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
307         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
308         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
309         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
310         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
311         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
312         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
313         $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC)" LD="$(LD)"
315 clean-target:
316         rm -f $(obj)/coreboot*
318 #######################################################################
319 # Development utilities
320 printcrt0s:
321         @echo crt0s=$(crt0s)
322         @echo ldscripts=$(ldscripts)
324 update:
325         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
327 lint lint-stable:
328         FAILED=0; LINTLOG=`mktemp .tmpconfig.lintXXXXX`; \
329         for script in util/lint/$@-*; do \
330                 echo; echo `basename $$script`; \
331                 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
332                 echo ========; \
333                 $$script > $$LINTLOG; \
334                 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
335                         printf "success\n\n"; \
336                 else \
337                         echo test failed: ; \
338                         cat $$LINTLOG; \
339                         rm -f $$LINTLOG; \
340                         FAILED=$$(( $$FAILED + 1 )); \
341                 fi; \
342                 echo ========; \
343         done; \
344         test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." &&  exit 1; }; \
345         rm -f $$LINTLOG
347 gitconfig:
348         mkdir -p .git/hooks
349         for hook in commit-msg pre-commit ; do                       \
350                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
351                 ! -x .git/hooks/$$hook ]; then                       \
352                         cp util/gitconfig/$$hook .git/hooks/$$hook;  \
353                         chmod +x .git/hooks/$$hook;                  \
354                 fi;                                                  \
355         done
356         git config remote.origin.push HEAD:refs/for/master
357         (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)
359 crossgcc: clean-for-update
360         $(MAKE) -C util/crossgcc build-without-gdb
362 crosstools: clean-for-update
363         $(MAKE) -C util/crossgcc build
365 crossgcc-clean: clean-for-update
366         $(MAKE) -C util/crossgcc clean
368 tools: $(objutil)/kconfig/conf $(objutil)/cbfstool/cbfstool $(objutil)/nvramtool/nvramtool $(objutil)/romcc/romcc $(objutil)/sconfig/sconfig