jetway/nf81-t56n-lf: Set OEM to Jetway in DSDT and mptables
[coreboot.git] / Makefile.inc
blob72f3951fa9bd10b4deb073ed77f23b44c6943e66
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`" ]; \
23        then git describe --dirty --always || git describe; \
24        else echo 4.0$(KERNELREVISION); fi)
26 #######################################################################
27 # Test for coreboot toolchain (except when explicitely not requested)
28 ifneq ($(NOCOMPILE),1)
29 # only run if we're doing a build (not for tests, kconfig, ...)
30 ifneq ($(CONFIG_ANY_TOOLCHAIN),y)
31 _toolchain=$(shell $(CC_i386) -v 2>&1 |grep -q "gcc version .*coreboot toolchain" && echo coreboot)
32 ifneq ($(_toolchain),coreboot)
33 $(error Please use the coreboot toolchain (or prove that your toolchain works))
34 endif
35 endif
36 endif
38 #######################################################################
39 # Basic component discovery
40 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
41 export MAINBOARDDIR
43 ## 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
46 export objcbfs := $(obj)/cbfs/$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
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)
52 export objgenerated := $(obj)/generated
54 #######################################################################
55 # root rule to resolve if in build mode (ie. configuration exists)
56 real-target: $(obj)/config.h coreboot
57 coreboot: build-dirs $(obj)/coreboot.rom
59 #######################################################################
60 # our phony targets
61 PHONY+= clean-abuild coreboot lint lint-stable build-dirs
63 #######################################################################
64 # root source directories of coreboot
65 subdirs-y := src/lib src/console src/device src/ec src/southbridge src/soc
66 subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode
67 subdirs-y += util/cbfstool util/sconfig util/nvramtool
68 subdirs-y += src/arch/$(ARCHDIR-y)
69 subdirs-y += src/mainboard/$(MAINBOARDDIR)
71 subdirs-y += site-local
73 #######################################################################
74 # Add source classes and their build options
75 classes-y := ramstage romstage bootblock smm smmstub cpu_microcode rmodules
77 #######################################################################
78 # Helper functions for ramstage postprocess
79 spc :=
80 spc +=
81 $(spc) :=
82 $(spc) +=
84 # files-in-dir-recursive,dir,files
85 files-in-dir-recursive=$(filter $(1)%,$(2))
87 # parent-dir,dir/
88 parent-dir=$(dir $(subst $( ),/,$(strip $(subst /, ,$(1)))))
90 # filters out exactly the directory specified
91 # filter-out-dir,dir_to_keep,dirs
92 filter-out-dir=$(filter-out $(1),$(2))
94 # filters out dir_to_keep and all its parents
95 # filter-out-dirs,dir_to_keep,dirs
96 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)))
98 # dir-wildcards,dirs
99 dir-wildcards=$(addsuffix %,$(1))
101 # files-in-dir,dir,files
102 files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(dir $(2)))),$(call files-in-dir-recursive,$(1),$(2)))
104 #######################################################################
105 # reduce command line length by linking the objects of each
106 # directory into an intermediate file
107 ramstage-postprocess=$(foreach d,$(sort $(dir $(1))), \
108         $(eval $(d)ramstage.o: $(call files-in-dir,$(d),$(1)); $$(LD) -o $$@ -r $$^ ) \
109         $(eval ramstage-objs:=$(d)ramstage.o $(filter-out $(call files-in-dir,$(d),$(1)),$(ramstage-objs))))
111 romstage-c-ccopts:=-D__PRE_RAM__
112 romstage-S-ccopts:=-D__PRE_RAM__
113 ifeq ($(CONFIG_TRACE),y)
114 ramstage-c-ccopts:= -finstrument-functions
115 endif
116 ifeq ($(CONFIG_COVERAGE),y)
117 ramstage-c-ccopts+=-fprofile-arcs -ftest-coverage
118 endif
120 ifeq ($(CONFIG_USE_BLOBS),y)
121 forgetthis:=$(shell git submodule update --init --checkout 3rdparty)
122 endif
124 bootblock-c-ccopts:=-D__BOOT_BLOCK__ -D__PRE_RAM__
125 bootblock-S-ccopts:=-D__BOOT_BLOCK__ -D__PRE_RAM__
127 smmstub-c-ccopts:=-D__SMM__
128 smmstub-S-ccopts:=-D__SMM__
129 smm-c-ccopts:=-D__SMM__
130 smm-S-ccopts:=-D__SMM__
132 # SMM TSEG base is dynamic
133 ifneq ($(CONFIG_SMM_MODULES),y)
134 ifeq ($(CONFIG_SMM_TSEG),y)
135 smm-c-ccopts += -fpic
136 endif
137 endif
139 ramstage-c-deps:=$$(OPTION_TABLE_H)
140 romstage-c-deps:=$$(OPTION_TABLE_H)
141 bootblock-c-deps:=$$(OPTION_TABLE_H)
142 smm-c-deps:=$$(OPTION_TABLE_H)
144 #######################################################################
145 # Add handler to compile ACPI's ASL
146 define ramstage-objs_asl_template
147 $(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h
148         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
149         $(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
150         cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl
151         mv $$(basename $$@).hex $$(basename $$@).c
152         $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
153         # keep %.o: %.c rule from catching the temporary .c file after a make clean
154         mv $$(basename $$@).c $$(basename $$@).hex
155 endef
157 #######################################################################
158 # Parse plaintext cmos defaults into binary format
159 # arg1: source file
160 # arg2: binary file name
161 cbfs-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))
165 #######################################################################
166 # Link VSA binary to ELF-ish stage
167 # arg1: source file
168 # arg2: binary file name
169 cbfs-files-processor-vsa= \
170         $(eval $(2): $(1) ; \
171                 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))
173 #######################################################################
174 # Add handler for arbitrary files in CBFS
175 $(call add-special-class,cbfs-files)
176 cbfs-files-handler= \
177                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
178                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
179                 $(if $(wildcard $(1)$($(2)-file)), \
180                         $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
181                         $(eval tmp-cbfs-file:= $($(2)-file))) \
182                 $(if $(strip $($(2)-required)), \
183                         $(if $(wildcard $(tmp-cbfs-file)),, \
184                                 $(info This build configuration requires $($(2)-required)) \
185                                 $(eval FAILBUILD:=1) \
186                         )) \
187                 $(if $(tmp-cbfs-method), \
188                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
189                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
190                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
191                 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$($(2)-position)) \
192                 $(eval $(2)-name:=) \
193                 $(eval $(2)-type:=) \
194                 $(eval $(2)-compression:=) \
195                 $(eval $(2)-position:=) \
196                 $(eval $(2)-required:=)
198 #######################################################################
199 # a variety of flags for our build
200 CBFS_COMPRESS_FLAG:=none
201 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
202 CBFS_COMPRESS_FLAG:=LZMA
203 endif
205 CBFS_PAYLOAD_COMPRESS_FLAG:=none
206 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
207 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
208 endif
210 ifneq ($(CONFIG_LOCALVERSION),"")
211 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
212 endif
214 INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
215 INCLUDES += -Isrc/device/oprom/include
216 # abspath is a workaround for romcc
217 INCLUDES += -include $(src)/include/kconfig.h
219 CFLAGS = $(INCLUDES) -Os -pipe -g -nostdinc
220 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
221 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
222 CFLAGS += -Wstrict-aliasing -Wshadow
223 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
224 CFLAGS += -Werror
225 endif
226 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
228 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
229                    $(objutil)/ifdfake $(objutil)/options
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
239         printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht
240         printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
241         printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
242         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
246         printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht
247         printf "\n" >> $(obj)/build.ht
248         printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
249         printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
250         printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
251         printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
252         printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
253         printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null || hostname 2>/dev/null)\"\n" >> $(obj)/build.ht
254         printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
255         printf "#endif\n" >> $(obj)/build.ht
256         mv $(obj)/build.ht $(obj)/build.h
258 $(obj)/ldoptions: $(obj)/config.h
259         awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
261 build-dirs:
262         mkdir -p $(objcbfs) $(objgenerated)
264 #######################################################################
265 # Build the tools
266 CBFSTOOL:=$(obj)/cbfstool
267 RMODTOOL:=$(obj)/rmodtool
269 $(CBFSTOOL): $(objutil)/cbfstool/cbfstool
270         cp $< $@
272 $(RMODTOOL): $(objutil)/cbfstool/rmodtool
273         cp $< $@
275 _WINCHECK=$(shell uname -o 2> /dev/null)
276 STACK=
277 ifeq ($(_WINCHECK),Msys)
278         STACK=-Wl,--stack,16384000
279 endif
280 ifeq ($(_WINCHECK),Cygwin)
281         STACK=-Wl,--stack,16384000
282 endif
284 ROMCC:= $(objutil)/romcc/romcc
285 $(ROMCC): $(top)/util/romcc/romcc.c
286         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
287         @# Note: Adding -O2 here might cause problems. For details see:
288         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
289         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
291 IFDTOOL:=$(objutil)/ifdtool/ifdtool
292 $(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
293         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
294         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
296 IFDFAKE:=$(objutil)/ifdfake/ifdfake
297 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
298         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
299         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
301 #######################################################################
302 # needed objects that every mainboard uses
303 # Creation of these is architecture and mainboard independent
304 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
305         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
306         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
307         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
309 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
310 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
312 $(objutil)/%.o: $(objutil)/%.c
313         @printf "    HOSTCC     $(subst $(objutil)/,,$(@))\n"
314         $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
316 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
317         @printf "    CC         $(subst $(obj)/,,$(@))\n"
318         $(CC) -MMD $(CFLAGS) -c -o $@ $<
320 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
321         @printf "    CC         $(subst $(obj)/,,$(@))\n"
322         $(CC) -MMD -D__PRE_RAM__ $(CFLAGS) -c -o $@ $<
324 $(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
325         @printf "    CC         $(subst $(obj)/,,$(@))\n"
326         $(CC) -MMD $(bootblock-c-ccopts) $(CFLAGS) -c -o $@ $<
328 #######################################################################
329 # Clean up rules
330 clean-abuild:
331         rm -rf coreboot-builds
333 clean-for-update-target:
334         rm -f $(obj)/ramstage* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
335         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
336         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
337         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
338         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
339         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
340         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
341         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
342         $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC)" LD="$(LD)"
344 clean-target:
345         rm -f $(obj)/coreboot*
347 #######################################################################
348 # Development utilities
349 printcrt0s:
350         @echo crt0s=$(crt0s)
351         @echo ldscripts=$(ldscripts)
353 update:
354         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
356 lint lint-stable:
357         FAILED=0; LINTLOG=`mktemp .tmpconfig.lintXXXXX`; \
358         for script in util/lint/$@-*; do \
359                 echo; echo `basename $$script`; \
360                 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
361                 echo ========; \
362                 $$script > $$LINTLOG; \
363                 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
364                         printf "success\n\n"; \
365                 else \
366                         echo test failed: ; \
367                         cat $$LINTLOG; \
368                         rm -f $$LINTLOG; \
369                         FAILED=$$(( $$FAILED + 1 )); \
370                 fi; \
371                 echo ========; \
372         done; \
373         test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." &&  exit 1; }; \
374         rm -f $$LINTLOG
376 gitconfig:
377         mkdir -p .git/hooks
378         for hook in commit-msg pre-commit ; do                       \
379                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
380                 ! -x .git/hooks/$$hook ]; then                       \
381                         cp util/gitconfig/$$hook .git/hooks/$$hook;  \
382                         chmod +x .git/hooks/$$hook;                  \
383                 fi;                                                  \
384         done
385         git config remote.origin.push HEAD:refs/for/master
386         (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)
388 crossgcc: crossgcc-i386 crossgcc-arm
390 .PHONY: crossgcc-i386 crossgcc-arm
391 crossgcc-i386: clean-for-update
392         $(MAKE) -C util/crossgcc build-i386-without-gdb
394 crossgcc-arm: clean-for-update
395         $(MAKE) -C util/crossgcc build-armv7a-without-gdb
397 crosstools: crosstools-i386
399 .PHONY: crosstools-i386 crosstools-arm
400 crosstools-i386: clean-for-update
401         $(MAKE) -C util/crossgcc build-i386
403 crosstools-arm: clean-for-update
404         $(MAKE) -C util/crossgcc build-armv7a
406 crossgcc-clean: clean-for-update
407         $(MAKE) -C util/crossgcc clean
409 tools: $(objutil)/kconfig/conf $(objutil)/cbfstool/cbfstool $(objutil)/cbfstool/rmodtool $(objutil)/nvramtool/nvramtool $(objutil)/romcc/romcc $(objutil)/sconfig/sconfig