intel/kunimitsu: FAB 4 update for Rcomp Target table
[coreboot.git] / Makefile.inc
blob5d4017413e08ee4d86f7b208e6b78120bc55c2ff
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.
16 GIT:=$(shell [ -d "$(top)/.git" ] && command -v git)
18 #######################################################################
19 # normalize Kconfig variables in a central place
20 CONFIG_CBFS_PREFIX:=$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
22 #######################################################################
23 # misleadingly named, this is the coreboot version
24 export KERNELVERSION := $(strip $(if $(GIT),\
25         $(shell git describe --dirty --always || git describe),\
26         $(if $(wildcard $(top)/.coreboot-version),\
27                 $(shell cat $(top)/.coreboot-version),\
28                 coreboot-unknown$(KERNELREVISION))))
30 #######################################################################
31 # Basic component discovery
32 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
33 export MAINBOARDDIR
35 ## Final build results, which CBFSTOOL uses to create the final
36 ## rom image file, are placed under $(objcbfs).
37 ## These typically have suffixes .debug .elf .bin and .map
38 export objcbfs := $(obj)/cbfs/$(CONFIG_CBFS_PREFIX)
40 ## Based on the active configuration, Makefile conditionally collects
41 ## the required assembly includes and saves them in a file.
42 ## Such files that do not have a clear one-to-one relation to a source
43 ## file under src/ are placed and built under $(objgenerated)
44 export objgenerated := $(obj)/generated
46 #######################################################################
47 # root rule to resolve if in build mode (ie. configuration exists)
48 real-target: $(obj)/config.h coreboot
49 coreboot: build-dirs $(obj)/coreboot.rom $(obj)/cbfstool $(obj)/rmodtool
51 #######################################################################
52 # our phony targets
53 PHONY+= clean-abuild coreboot lint lint-stable build-dirs
55 #######################################################################
56 # root source directories of coreboot
57 subdirs-y := src/lib src/commonlib/ src/console src/device src/acpi
58 subdirs-y += src/ec/acpi $(wildcard src/ec/*/*) $(wildcard src/southbridge/*/*)
59 subdirs-y += $(wildcard src/soc/*/*) $(wildcard src/northbridge/*/*)
60 subdirs-y += src/superio $(wildcard src/drivers/*) src/cpu src/vendorcode
61 subdirs-y += util/cbfstool util/sconfig util/nvramtool util/broadcom
62 subdirs-y += $(wildcard src/arch/*)
63 subdirs-y += src/mainboard/$(MAINBOARDDIR)
64 subdirs-y += payloads/external
66 subdirs-y += site-local
68 #######################################################################
69 # Add source classes and their build options
70 classes-y := ramstage romstage bootblock smm smmstub cpu_microcode libverstage verstage
72 # Add dynamic classes for rmodules
73 $(foreach supported_arch,$(ARCH_SUPPORTED), \
74             $(eval $(call define_class,rmodules_$(supported_arch),$(supported_arch))))
75 # Provide a macro to determine environment for free standing rmodules.
76 $(foreach supported_arch,$(ARCH_SUPPORTED), \
77         $(eval rmodules_$(supported_arch)-generic-ccopts += -D__RMODULE__))
79 #######################################################################
80 # Helper functions for math and various file placement matters.
81 # macros work on all formats understood by printf(1)
82 # values are space separated if using more than one value
84 # int-add:       adds an arbitrary length list of integers
85 # int-subtract:  subtracts the the second of two integers from the first
86 # int-multiply:  multiplies an arbitrary length list of integers
87 # int-divide:    divides the first integer by the second
88 # int-remainder: arithmetic remainder of the first number divided by the second
89 # int-lt:        1 if the first value is less than the second.  0 otherwise
90 # int-gt:        1 if the first values is greater than the second.  0 otherwise
91 # int-eq:        1 if the two values are equal.  0 otherwise
92 # int-align:     align $1 to $2 units
93 # file-size:     returns the filesize of the given file
94 _toint=$(shell printf "%d" $1)
95 _int-add2=$(shell expr $(call _toint,$1) + $(call _toint,$2))
96 int-add=$(if $(filter 1,$(words $1)),$(strip $1),$(call int-add,$(call _int-add2,$(word 1,$1),$(word 2,$1)) $(wordlist 3,$(words $1),$1)))
97 int-subtract=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) - $(call _toint,$(word 2,$1))))
98 _int-multiply2=$(shell expr $(call _toint,$1) \* $(call _toint,$2))
99 int-multiply=$(if $(filter 1,$(words $1)),$(strip $1),$(call int-multiply,$(call _int-multiply2,$(word 1,$1),$(word 2,$1)) $(wordlist 3,$(words $1),$1)))
100 int-divide=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) / $(call _toint,$(word 2,$1))))
101 int-remainder=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) % $(call _toint,$(word 2,$1))))
102 int-lt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \< $(call _toint,$(word 2,$1))))
103 int-gt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \> $(call _toint,$(word 2,$1))))
104 int-eq=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) = $(call _toint,$(word 2,$1))))
105 int-align=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A + \( \( $$B - \( $$A % $$B \) \) % $$B \) )
106 file-size=$(shell cat $1 | wc -c)
108 #######################################################################
109 # Helper functions for ramstage postprocess
110 spc :=
111 spc +=
112 $(spc) :=
113 $(spc) +=
115 # files-in-dir-recursive,dir,files
116 files-in-dir-recursive=$(filter $(1)%,$(2))
118 # parent-dir,dir/
119 parent-dir=$(dir $(if $(patsubst /%,,$(1)),,/)$(subst $( ),/,$(strip $(subst /, ,$(1)))))
121 # filters out exactly the directory specified
122 # filter-out-dir,dir_to_keep,dirs
123 filter-out-dir=$(filter-out $(1),$(2))
125 # filters out dir_to_keep and all its parents
126 # filter-out-dirs,dir_to_keep,dirs
127 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)))
129 # dir-wildcards,dirs
130 dir-wildcards=$(addsuffix %,$(1))
132 # files-in-dir,dir,files
133 files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(sort $(dir $(2))))),$(call files-in-dir-recursive,$(1),$(2)))
135 #######################################################################
136 # reduce command line length by linking the objects of each
137 # directory into an intermediate file
138 ramstage-postprocess=$$(eval DEPENDENCIES+=$$(addsuffix .d,$$(basename $(1)))) \
139         $(foreach d,$(sort $(dir $(filter-out %.ld,$(1)))), \
140         $(eval $(d)ramstage.a: $(call files-in-dir,$(d),$(filter-out %.ld,$(1))); rm -f $$@ && $(AR_ramstage) rcsT $$@ $$^ ) \
141         $(eval ramstage-objs:=$(d)ramstage.a $(filter-out $(filter-out %.ld, $(call files-in-dir,$(d),$(1))),$(ramstage-objs))))
143 bootblock-generic-ccopts += -D__PRE_RAM__ -D__BOOTBLOCK__
144 romstage-generic-ccopts += -D__PRE_RAM__ -D__ROMSTAGE__
145 ramstage-generic-ccopts += -D__RAMSTAGE__
146 ifeq ($(CONFIG_TRACE),y)
147 ramstage-c-ccopts += -finstrument-functions
148 endif
149 ifeq ($(CONFIG_COVERAGE),y)
150 ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
151 endif
153 # try to fetch non-optional submodules if the source is under git
154 forgetthis:=$(if $(GIT),$(shell git submodule update --init))
155 ifeq ($(CONFIG_USE_BLOBS),y)
156 # this is necessary because 3rdparty/blobs is update=none, and so is ignored
157 # unless explicitly requested and enabled through --checkout
158 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/blobs))
159 endif
161 ramstage-c-deps:=$$(OPTION_TABLE_H)
162 romstage-c-deps:=$$(OPTION_TABLE_H)
163 libverstage-c-deps:=$$(OPTION_TABLE_H)
164 verstage-c-deps:=$$(OPTION_TABLE_H)
165 bootblock-c-deps:=$$(OPTION_TABLE_H)
167 # Add handler to copy linker scripts
168 define generic-objs_ld_template_gen
169 de$(EMPTY)fine $(1)-objs_ld_template
170 $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h
171         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
172         $$(CC_$(1)) -MMD $$(CPPFLAGS_$(1)) $$($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h -MT $$$$@ -o $$$$@ $$$$<
173 en$(EMPTY)def
174 endef
176 # Add handler to deal with archives
177 define generic-objs_a_template_gen
178 de$(EMPTY)fine $(1)-objs_a_template
179 $$(call src-to-obj,$1,$$(1).a): $$(1).a
180         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
181         cp $$$$< $$$$@.tmp
182         mv $$$$@.tmp $$$$@
183 en$(EMPTY)def
184 endef
186 # Add handler to add no rules for manual files
187 define generic-objs_manual_template_gen
188 # do nothing
189 endef
191 #######################################################################
192 # Add handler to compile ACPI's ASL
193 # arg1: base file name
194 # arg2: y or n for including in cbfs. defaults to y
195 define asl_template
196 $(CONFIG_CBFS_PREFIX)/$(1).aml-file = $(obj)/$(1).aml
197 $(CONFIG_CBFS_PREFIX)/$(1).aml-type = raw
198 $(CONFIG_CBFS_PREFIX)/$(1).aml-compression = none
199 cbfs-files-$(if $(2),$(2),y) += $(CONFIG_CBFS_PREFIX)/$(1).aml
200 $(obj)/$(1).aml: $(src)/mainboard/$(MAINBOARDDIR)/$(1).asl $(obj)/config.h
201         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
202         $(CC_ramstage) -x assembler-with-cpp -E -MMD -MT $$(@) $$(CPPFLAGS_ramstage) -D__ACPI__ -P -include $(src)/include/kconfig.h -I$(obj) -I$(src) -I$(src)/include -I$(src)/arch/$(ARCHDIR-$(ARCH-ramstage-y))/include -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$@
203 ifeq ($(CONFIG_IASL_WARNINGS_ARE_ERRORS),y)
204         cd $$(dir $$@); $(IASL) -we -p $$(notdir $$@) $$(notdir $$@)
205 else
206         cd $$(dir $$@); $(IASL) -p $$(notdir $$@) $$(notdir $$@)
207 endif
208 endef
210 #######################################################################
211 # Parse plaintext cmos defaults into binary format
212 # arg1: source file
213 # arg2: binary file name
214 cbfs-files-processor-nvramtool= \
215         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
216                 printf "    CREATE     $(2) (from $(1))\n"; \
217                 $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && \
218                 mv $(2).tmp $(2))
220 #######################################################################
221 # Link VSA binary to ELF-ish stage
222 # arg1: source file
223 # arg2: binary file name
224 cbfs-files-processor-vsa= \
225         $(eval $(2): $(1) ; \
226                 printf "    CREATE     $(2) (from $(1))\n"; \
227                 $(OBJCOPY_ramstage) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && \
228                 $(LD_ramstage) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
230 #######################################################################
231 # Reduce a .config file to its minimal representation
232 # arg1: input
233 # arg2: output
234 cbfs-files-processor-defconfig= \
235         $(eval $(2): $(1) ; \
236                 printf "    CREATE     $(2) (from $(1))\n"; \
237                 echo "\# This image was built using git revision" `git rev-parse HEAD` > $(2).tmp && \
238                 $(MAKE) DOTCONFIG=$(1) DEFCONFIG=$(2).tmp savedefconfig && \
239                 \mv -f $(2).tmp $(2))
241 #######################################################################
242 # Add handler for arbitrary files in CBFS
243 $(call add-special-class,cbfs-files)
244 cbfs-files-handler= \
245                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
246                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
247                 $(eval tmp-cbfs-file:= ) \
248                 $(if $($(2)-file), \
249                         $(if $(wildcard $(1)$($(2)-file)), \
250                                 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
251                                 $(eval tmp-cbfs-file:= $($(2)-file)))) \
252                 $(if $(strip $($(2)-required)), \
253                         $(if $(wildcard $(tmp-cbfs-file)),, \
254                                 $(info This build configuration requires $($(2)-required)) \
255                                 $(eval FAILBUILD:=1) \
256                         )) \
257                 $(if $(strip $($(2)-align)), \
258                         $(if $(strip $($(2)-position)), \
259                                 $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
260                                 $(eval FAILBUILD:=1) \
261                         )) \
262                 $(eval _cbfs-bucket:=regular ) \
263                 $(if $(strip $($(2)-position)), \
264                         $(eval _cbfs-bucket:=fixed)) \
265                 $(if $(strip $($(2)-align)), \
266                         $(eval _cbfs-bucket:=aligned)) \
267                 $(if $(tmp-cbfs-method), \
268                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
269                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
270                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
271                 $(if $(tmp-cbfs-file), \
272                         $(eval cbfs-files-$(_cbfs-bucket) += $(subst $(spc),*,$(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align)|$($(2)-options)))) \
273                 $(eval $(2)-name:=) \
274                 $(eval $(2)-type:=) \
275                 $(eval $(2)-compression:=) \
276                 $(eval $(2)-position:=) \
277                 $(eval $(2)-required:=) \
278                 $(eval $(2)-options:=) \
279                 $(eval $(2)-align:=)
281 #######################################################################
282 # a variety of flags for our build
283 CBFS_COMPRESS_FLAG:=none
284 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
285 CBFS_COMPRESS_FLAG:=LZMA
286 endif
288 CBFS_PAYLOAD_COMPRESS_FLAG:=none
289 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
290 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
291 endif
293 ifneq ($(CONFIG_LOCALVERSION),"")
294 export COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
295 endif
297 CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -I$(obj)
298 CPPFLAGS_common += -Isrc/device/oprom/include
299 CPPFLAGS_common += -include $(src)/include/kconfig.h
301 CFLAGS_common += -pipe -g -nostdinc
302 CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
303 CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
304 CFLAGS_common += -Wstrict-aliasing -Wshadow
305 CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
306 CFLAGS_common += -ffunction-sections -fdata-sections
308 LDFLAGS_common := --gc-sections -nostdlib -nostartfiles -static --emit-relocs
310 ifeq ($(CONFIG_COMPILER_GCC),y)
311 # cf. commit f69a99db (coreboot: x86: enable gc-sections)
312 CFLAGS_common += -Wno-unused-but-set-variable
313 endif
315 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
316 CFLAGS_common += -Werror
317 endif
318 ifneq ($(GDB_DEBUG),)
319 CFLAGS_common += -Og
320 else
321 CFLAGS_common += -Os
322 endif
324 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
325                    $(objutil)/ifdfake $(objutil)/options $(objutil)/amdfwtool \
326                    $(objutil)/cbootimage $(objutil)/bimgtool
328 #######################################################################
329 # generate build support files
330 $(obj)/build.h: .xcompile
331         @printf "    GEN        build.h\n"
332         rm -f $(obj)/build.h
333         util/genbuild_h/genbuild_h.sh > $(obj)/build.ht
334         mv $(obj)/build.ht $(obj)/build.h
336 build-dirs:
337         mkdir -p $(objcbfs) $(objgenerated)
339 #######################################################################
340 # Build the tools
341 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
342 FMAPTOOL:=$(objutil)/cbfstool/fmaptool
343 RMODTOOL:=$(objutil)/cbfstool/rmodtool
345 $(obj)/cbfstool: $(CBFSTOOL)
346         cp $< $@
348 $(obj)/fmaptool: $(FMAPTOOL)
349         cp $< $@
351 $(obj)/rmodtool: $(RMODTOOL)
352         cp $< $@
354 _WINCHECK=$(shell uname -o 2> /dev/null)
355 STACK=
356 ifeq ($(_WINCHECK),Msys)
357         STACK=-Wl,--stack,16384000
358 endif
359 ifeq ($(_WINCHECK),Cygwin)
360         STACK=-Wl,--stack,16384000
361 endif
363 # this allows ccache to prepend itself
364 # (ccache handling happens first)
365 ROMCC_BIN= $(objutil)/romcc/romcc
366 ROMCC?=$(ROMCC_BIN)
367 $(ROMCC_BIN): $(top)/util/romcc/romcc.c
368         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
369         @# Note: Adding -O2 here might cause problems. For details see:
370         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
371         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
373 IFDTOOL:=$(objutil)/ifdtool/ifdtool
374 $(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
375         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
376         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
378 IFDFAKE:=$(objutil)/ifdfake/ifdfake
379 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
380         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
381         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
383 AMDFWTOOL:=$(objutil)/amdfwtool/amdfwtool
384 $(AMDFWTOOL): $(top)/util/amdfwtool/amdfwtool.c
385         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
386         $(HOSTCC) $(HOSTCFLAGS) -DCONFIG_ROM_SIZE=$(CONFIG_ROM_SIZE) -o $@ $<
388 CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
390 subdirs-y += util/nvidia
392 BIMGTOOL:=$(objutil)/bimgtool/bimgtool
393 $(BIMGTOOL): $(top)/util/bimgtool/bimgtool.c
394         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
395         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
397 #######################################################################
398 # needed objects that every mainboard uses
399 # Creation of these is architecture and mainboard independent
400 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
401         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
402         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
403         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
405 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
406 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
407 verstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
409 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
410         @printf "    CC         $(subst $(obj)/,,$(@))\n"
411         $(CC_ramstage) -MMD $(CFLAGS_ramstage) $(CPPFLAGS_ramstage) $(ramstage-c-ccopts) -c -o $@ $<
413 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
414         @printf "    CC         $(subst $(obj)/,,$(@))\n"
415         $(CC_romstage) -MMD $(CFLAGS_romstage) $(CPPFLAGS_romstage) $(romstage-c-ccopts) -c -o $@ $<
417 $(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
418         @printf "    CC         $(subst $(obj)/,,$(@))\n"
419         $(CC_bootblock) -MMD $(CFLAGS_bootblock) $(CPPFLAGS_bootblock) $(bootblock-c-ccopts) -c -o $@ $<
421 $(objgenerated)/libverstage.a: $$(libverstage-objs)
422         rm -f $@
423         $(AR_libverstage) rcsT $@ $^
425 #######################################################################
426 # Clean up rules
427 clean-abuild:
428         rm -rf coreboot-builds
430 clean-for-update-target:
431         rm -f $(obj)/ramstage* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
432         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
433         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
434         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
435         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
436         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
437         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
438         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
439         $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean
441 clean-target:
442         rm -f $(obj)/coreboot*
444 #######################################################################
445 # Development utilities
446 printcrt0s:
447         @echo crt0s=$(crt0s)
448         @echo ldscripts=$(ldscripts)
450 update:
451         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
453 lint lint-stable:
454         util/lint/lint $@
456 gitconfig:
457         [ -d .git ]
458         mkdir -p .git/hooks
459         for hook in commit-msg pre-commit ; do                       \
460                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
461                 ! -x .git/hooks/$$hook ]; then                       \
462                         sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/$$hook > .git/hooks/$$hook;  \
463                         chmod +x .git/hooks/$$hook;                  \
464                 fi;                                                  \
465         done
466         # Now set up thehooks for 3rdparty/blobs
467         if [ -d .git/modules/3rdparty -a \
468         \( util/gitconfig/commit-msg -nt .git/modules/3rdparty/hooks/commit-msg -o \
469         ! -x .git/modules/3rdparty/hooks/commit-msg \) ]; then \
470                 sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/commit-msg > .git/modules/3rdparty/hooks/commit-msg; \
471                 chmod +x .git/modules/3rdparty/hooks/commit-msg; \
472         fi
473         [ -d 3rdparty/blobs ] && cd 3rdparty/blobs && git config remote.origin.push HEAD:refs/for/master
474         git config remote.origin.push HEAD:refs/for/master
475         (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)
477 help::
478         @echo  '*** Toolchain ***'
479         @echo  '  crossgcc        - Build coreboot cross-compilers for all platforms'
480         @echo  '  crosstools      - Build coreboot cross-compiler and GDB for all platforms'
481         @echo  '  crossgcc-clean  - Remove all built coreboot cross-compilers'
482         @echo  '  iasl            - Build coreboot IASL compiler (built by all cross targets)'
483         @echo  '  clang           - Build coreboot clang compiler'
484         @echo  '  crossgcc-ARCH   - Build cross-compiler for specific architecture'
485         @echo  '  crosstools-ARCH - Build cross-compiler with GDB for specific architecture'
486         @echo  '  ARCH can be "i386", "x64", "arm", "aarch64", "mips", or "riscv"'
487         @echo  '  Use "make [target] CPUS=#" to build toolchain using multiple cores'
488         @echo
490 # For the toolchain builds, use CPUS=x to use multiple processors to build
491 # use BUILDGCC_OPTIONS= to set any crossgcc command line options
492 # Example: BUILDGCC_OPTIONS='-t' will keep temporary files after build
493 crossgcc: clean-for-update
494         $(MAKE) -C util/crossgcc all_without_gdb SKIP_CLANG=1
496 .PHONY: crossgcc crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 \
497         crossgcc-mips crossgcc-riscv crossgcc-clean iasl clang tools \
498         crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 \
499         crosstools-mips crosstools-riscv
501 crossgcc-i386: clean-for-update
502         $(MAKE) -C util/crossgcc build-i386 SKIP_GDB=1
504 crossgcc-x64: clean-for-update
505         $(MAKE) -C util/crossgcc build-x64 SKIP_GDB=1
507 crossgcc-arm: clean-for-update
508         $(MAKE) -C util/crossgcc build-armv7a SKIP_GDB=1
510 crossgcc-aarch64: clean-for-update
511         $(MAKE) -C util/crossgcc build-aarch64 SKIP_GDB=1
513 crossgcc-mips: clean-for-update
514         $(MAKE) -C util/crossgcc build-mips SKIP_GDB=1
516 crossgcc-riscv: clean-for-update
517         $(MAKE) -C util/crossgcc build-riscv SKIP_GDB=1
519 crosstools: clean-for-update
520         $(MAKE) -C util/crossgcc all_with_gdb SKIP_CLANG=1
522 iasl: clean-for-update
523         $(MAKE) -C util/crossgcc build_iasl
525 clang: clean-for-update
526         $(MAKE) -C util/crossgcc build_clang
528 crosstools-i386: clean-for-update
529         $(MAKE) -C util/crossgcc build-i386
531 crosstools-x64: clean-for-update
532         $(MAKE) -C util/crossgcc build-x64
534 crosstools-arm: clean-for-update
535         $(MAKE) -C util/crossgcc build-armv7a
537 crosstools-aarch64: clean-for-update
538         $(MAKE) -C util/crossgcc build-aarch64
540 crosstools-mips: clean-for-update
541         $(MAKE) -C util/crossgcc build-mips
543 crosstools-riscv: clean-for-update
544         $(MAKE) -C util/crossgcc build-riscv
546 crossgcc-clean: clean-for-update
547         $(MAKE) -C util/crossgcc clean
549 tools: $(objutil)/kconfig/conf $(CBFSTOOL) $(FMAPTOOL) $(RMODTOOL) $(objutil)/nvramtool/nvramtool $(ROMCC_BIN) $(objutil)/sconfig/sconfig $(IFDTOOL) $(IFDFAKE) $(CBOOTIMAGE)
551 ###########################################################################
552 # Common recipes for all stages
553 ###########################################################################
555 # loadaddr can determine the load address of a stage, which may be needed for
556 # platform-specific image headers (only works *after* the stage has been built)
557 loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
558              sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
560 # find-substr is required for stages like romstage_null and romstage_xip to
561 # eliminate the _* part of the string
562 find-substr = $(word 1,$(subst _, ,$(1)))
564 # find-class is used to identify the class from the name of the stage
565 # The input to this macro can be something like romstage.x or romstage.x.y
566 # find-class recursively strips off the suffixes to extract the exact class name
567 # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
568 # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
569 # and remove .x the next time and finally return romstage
570 find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
572 # Bootblocks are not CBFS stages. coreboot is currently expecting the bss to
573 # be cleared by the loader of the stage. For ARM SoCs that means one needs to
574 # include the bss section in the binary so the BootROM clears the bss on
575 # loading of the bootblock stage. Achieve this by marking the bss section
576 # loadable,allocatable, and data. Do the same for the .data section in case
577 # it's marked as NOBITS.
578 $(objcbfs)/bootblock.raw.bin: $(objcbfs)/bootblock.elf
579         @printf "    OBJCOPY    $(notdir $(@))\n"
580         $(OBJCOPY_bootblock) --set-section-flags .bss=load,alloc,data --set-section-flags .data=load,alloc,data $< $<.tmp
581         $(OBJCOPY_bootblock) -O binary $<.tmp $@
583 $(objcbfs)/%.bin: $(objcbfs)/%.raw.bin
584         cp $< $@
586 $(objcbfs)/%.elf: $(objcbfs)/%.debug
587         $(eval class := $(call find-class,$(@F)))
588         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
589         cp $< $@.tmp
590         $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
591         $(OBJCOPY_$(class)) --strip-debug $@.tmp
592         $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
593         mv $@.tmp $@
595 ###########################################################################
596 # Build the final rom image
597 ###########################################################################
599 COREBOOT_ROM_DEPENDENCIES:=
601 extract_nth=$(subst *,$(spc),$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-))))
603 cbfs-add-cmd = \
604                printf "    CBFS       $(call extract_nth,2,$(file))\n"; \
605                $(CBFSTOOL) $@.tmp \
606                add$(if $(filter stage,$(call extract_nth,3,$(file))),-stage)$(if $(filter payload,$(call extract_nth,3,$(file))),-payload) \
607                -f $(call extract_nth,1,$(file)) \
608                -n $(call extract_nth,2,$(file)) \
609                $(if $(filter-out stage,$(call extract_nth,3,$(file))),-t $(call extract_nth,3,$(file))) \
610                $(if $(call extract_nth,4,$(file)),-c $(call extract_nth,4,$(file))) \
611                $(call extract_nth,7,$(file))
613 cbfs-files=$(cbfs-files-fixed) $(cbfs-files-aligned) $(cbfs-files-regular)
614 ifneq ($(CONFIG_UPDATE_IMAGE),y)
615 prebuild-files = \
616                $(foreach file,$(cbfs-files), \
617                $(if $(call extract_nth,6,$(file)),$(cbfs-add-cmd) -a $(call extract_nth,6,$(file)) &&, \
618                $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&))
619 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
621 $(obj)/coreboot.pre: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(FMAPTOOL) $(CBFSTOOL) $$(cpu_ucode_cbfs_file)
622         $(CBFSTOOL) $@.tmp create \
623         -B $(objcbfs)/bootblock.bin \
624         $(CBFSTOOL_PRE1_OPTS)
625         $(prebuild-files) true
626         mv $@.tmp $@
627 else
628 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
629 # Add all cbfs files to image of the form: CONFIG_CBFS_PREFIX/<filename>
630 prebuild-files = \
631         $(foreach file,$(cbfs-files), \
632         $(CBFSTOOL) $@.tmp remove -n $(call extract_nth,2,$(file)) 2>/dev/null ; \
633                $(if $(call extract_nth,6,$(file)),$(cbfs-add-cmd) -a $(call extract_nth,6,$(file)) &&,\
634                $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&))
636 .PHONY: $(obj)/coreboot.pre
637 $(obj)/coreboot.pre: $$(prebuilt-files) $(CBFSTOOL)
638         mv $(obj)/coreboot.rom $@.tmp
639         $(prebuild-files) true
640         mv $@.tmp $@
641 endif
643 ifeq ($(CONFIG_PAYLOAD_LINUX),y)
644 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_COMMAND_LINE))),)
645       ADDITIONAL_PAYLOAD_CONFIG+=-C $(CONFIG_LINUX_COMMAND_LINE)
646 endif
647 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),)
648       ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)
649 endif
650 endif
652 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
653 REFCODE_BLOB=$(obj)/refcode.rmod
654 $(REFCODE_BLOB): $(RMODTOOL)
655         $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
656 endif
658 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/ramstage.elf $(CBFSTOOL) $$(call strip_quotes,$$(COREBOOT_ROM_DEPENDENCIES)) $$(INTERMEDIATE) $(REFCODE_BLOB)
659         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
660 # The full ROM may be larger than the CBFS part, so create an empty
661 # file (filled with \377 = 0xff) and copy the CBFS image over it.
662         dd if=/dev/zero bs=$(call _toint,$(CONFIG_ROM_SIZE)) count=1 2> /dev/null | tr '\000' '\377' > $@.tmp
663         dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
664 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
665 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
666         @printf "    SeaBIOS    Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
667         $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
668 endif
669 endif
670 ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
671 ifeq ($(CONFIG_CPU_MICROCODE_CBFS_GENERATE),y)
672         @printf "    UPDATE-FIT \n"
673         $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
674 endif
675 endif
676         mv $@.tmp $@
677         @printf "    CBFSPRINT  $(subst $(obj)/,,$(@))\n\n"
678         $(CBFSTOOL) $@ print
679 ifeq ($(CONFIG_IASL_WARNINGS_ARE_ERRORS),)
680         @printf "\n***** WARNING: IASL warnings as errors is disabled!  *****\n"
681         @printf "*****          Please fix the ASL for this platform. *****\n\n"
682 endif
684 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/romstage
685 $(CONFIG_CBFS_PREFIX)/romstage-file := $(objcbfs)/romstage.elf
686 $(CONFIG_CBFS_PREFIX)/romstage-type := stage
687 $(CONFIG_CBFS_PREFIX)/romstage-compression := none
688 ifeq ($(CONFIG_ARCH_ROMSTAGE_ARM),y)
689 $(CONFIG_CBFS_PREFIX)/romstage-options := -b 0
690 endif
691 ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32)$(CONFIG_ARCH_ROMSTAGE_X86_64),y)
692 # Use a 64 byte alignment to provide a minimum alignment
693 # requirement for the overall romstage. While the first object within
694 # romstage could have a 4 byte minimum alignment that doesn't mean the linker
695 # won't decide the entire section should be aligned to a larger value. In the
696 # future cbfstool should add XIP files proper and honor the alignment
697 # requirements of the program segment.
699 # Make sure that segment for .car.data is ignored while adding romstage.
700 $(CONFIG_CBFS_PREFIX)/romstage-align := 64
701 $(CONFIG_CBFS_PREFIX)/romstage-options := --xip -S .car.data -P $(CONFIG_XIP_ROM_SIZE)
702 endif
704 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/ramstage
705 $(CONFIG_CBFS_PREFIX)/ramstage-file := $(objcbfs)/ramstage.elf
706 $(CONFIG_CBFS_PREFIX)/ramstage-type := stage
707 $(CONFIG_CBFS_PREFIX)/ramstage-compression := $(CBFS_COMPRESS_FLAG)
709 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/payload
710 $(CONFIG_CBFS_PREFIX)/payload-file := $(CONFIG_PAYLOAD_FILE)
711 $(CONFIG_CBFS_PREFIX)/payload-type := payload
712 $(CONFIG_CBFS_PREFIX)/payload-compression := $(CBFS_PAYLOAD_COMPRESS_FLAG)
713 $(CONFIG_CBFS_PREFIX)/payload-options := $(ADDITIONAL_PAYLOAD_CONFIG)
715 cbfs-files-$(CONFIG_HAVE_REFCODE_BLOB) += $(CONFIG_CBFS_PREFIX)/refcode
716 $(CONFIG_CBFS_PREFIX)/refcode-file := $(REFCODE_BLOB)
717 $(CONFIG_CBFS_PREFIX)/refcode-type := stage
718 $(CONFIG_CBFS_PREFIX)/refcode-compression := $(CBFS_COMPRESS_FLAG)
720 cbfs-files-$(CONFIG_SEABIOS_VGA_COREBOOT) += vgaroms/seavgabios.bin
721 vgaroms/seavgabios.bin-file := $(CONFIG_PAYLOAD_VGABIOS_FILE)
722 vgaroms/seavgabios.bin-type := raw
724 cbfs-files-$(CONFIG_PXE_ROM) += pci$(CONFIG_PXE_ROM_ID).rom
725 pci$(CONFIG_PXE_ROM_ID).rom-file := $(CONFIG_PXE_ROM_FILE)
726 pci$(CONFIG_PXE_ROM_ID).rom-type := raw
728 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += config
729 config-file := $(DOTCONFIG):defconfig
730 config-type := raw
732 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += revision
733 revision-file := $(obj)/build.h
734 revision-type := raw
736 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += payload_config
737 payload_config-file := $(PAYLOAD_CONFIG)
738 payload_config-type := raw
740 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += payload_revision
741 payload_revision-file := $(PAYLOAD_VERSION)
742 payload_revision-type := raw
744 cbfs-files-$(CONFIG_BOOTSPLASH_IMAGE) += bootsplash.jpg
745 bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
746 bootsplash.jpg-type := bootsplash
748 cbfs-files-$(CONFIG_BOARD_ID_MANUAL) += board_id
749 board_id-file := $(obj)/board_id
750 board_id-type := raw
752 $(obj)/board_id:
753         printf $(CONFIG_BOARD_ID_STRING) > $@
755 junit.xml:
756         echo "Building $(UTIL)"
757         echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp
758         echo "<testcase classname='$(UTIL)' name='$(UTIL)'>" >> $@.tmp
759         -$(MAKE) -j $(CPUS) -C "util/$(UTIL)" clean distclean > $@.tmp.2 2>&1
760         $(MAKE) -j $(CPUS) -C "util/$(UTIL)" >> $@.tmp.2 2>&1 && type="system-out" || type="failure"; \
761         cat $@.tmp.2; \
762         if [ "$$type" = "failure" ]; then \
763                 echo "<failure type='buildFailed'>" >> $@.tmp; \
764                 echo "Building $(UTIL) Failed"; \
765         else \
766                 echo "<$$type>" >> $@.tmp; \
767                 echo "Building $(UTIL) Succeeded"; \
768         fi; \
769         echo '<![CDATA[' >> $@.tmp; \
770         cat $@.tmp.2 >> $@.tmp; \
771         echo "]]></$$type>" >>$@.tmp
772         rm -f $@.tmp.2
773         echo "</testcase>" >> $@.tmp
774         echo "</testsuite>" >> $@.tmp
775         mv $@.tmp "util/$(UTIL)/$@"
776         echo
778 TOOLLIST= \
779         cbmem \
780         ectool \
781         inteltool \
782         intelvbttool \
783         nvramtool \
784         superiotool \
785         viatool
786 JENKINS_PAYLOAD?=none
787 CPUS?=4
788 what-jenkins-does:
789         util/lint/lint lint-stable --junit
790         util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD) -x -X $(top)/abuild-chromeos.xml
791         util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD)
792         (cd payloads/libpayload; unset COREBOOT_BUILD_DIR; $(MAKE) $(if $(JENKINS_NOCCACHE),,CONFIG_LP_CCACHE=y) V=$(V) Q=$(Q) junit.xml)
793         $(foreach tool, $(TOOLLIST), $(MAKE) CPUS=$(CPUS) V=$(V) Q=$(Q) UTIL="$(tool)" MFLAGS= MAKEFLAGS= junit.xml; )