rush: Enable dp display
[coreboot.git] / Makefile.inc
blob9c043c482558492a1e4a96b27868f097c3b5456c
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 GIT:=$(shell [ -d "$(top)/.git" ] && command -v git)
22 #######################################################################
23 # misleadingly named, this is the coreboot version
24 export KERNELVERSION := $(strip $(if $(GIT),\
25         $(shell git describe --dirty --always || git describe),\
26         4.0$(KERNELREVISION)))
28 #######################################################################
29 # Basic component discovery
30 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
31 export MAINBOARDDIR
33 ## Final build results, which CBFSTOOL uses to create the final
34 ## rom image file, are placed under $(objcbfs).
35 ## These typically have suffixes .debug .elf .bin and .map
36 export objcbfs := $(obj)/cbfs/$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
38 ## Based on the active configuration, Makefile conditionally collects
39 ## the required assembly includes and saves them in a file.
40 ## Such files that do not have a clear one-to-one relation to a source
41 ## file under src/ are placed and built under $(objgenerated)
42 export objgenerated := $(obj)/generated
44 #######################################################################
45 # root rule to resolve if in build mode (ie. configuration exists)
46 real-target: $(obj)/config.h coreboot
47 coreboot: build-dirs $(obj)/coreboot.rom $(obj)/cbfstool $(obj)/rmodtool
49 #######################################################################
50 # our phony targets
51 PHONY+= clean-abuild coreboot lint lint-stable build-dirs
53 #######################################################################
54 # root source directories of coreboot
55 subdirs-y := src/lib src/console src/device src/ec src/southbridge src/soc
56 subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode
57 subdirs-y += util/cbfstool util/sconfig util/nvramtool
58 subdirs-y += src/arch/arm src/arch/arm64 src/arch/mips src/arch/riscv
59 subdirs-y += src/arch/x86
60 subdirs-y += src/mainboard/$(MAINBOARDDIR)
62 subdirs-y += site-local
64 #######################################################################
65 # Add source classes and their build options
66 classes-y := ramstage romstage bootblock smm smmstub cpu_microcode verstage secmon
68 # Add dynamic classes for rmodules
69 $(foreach supported_arch,$(ARCH_SUPPORTED), \
70             $(eval $(call define_class,rmodules_$(supported_arch),$(supported_arch))))
72 #######################################################################
73 # Helper functions for various file placement matters
75 # int-add: adds an arbitrary number of space-separated integers in
76 #          all formats understood by printf(1)
77 # int-align: align $1 to $2 units
78 # file-size: returns the filesize of the given file
79 _toint=$(shell printf "%d" $1)
80 _int-add2=$(shell expr $(call _toint,$1) + $(call _toint,$2))
81 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)))
82 int-align=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A + \( \( $$B - \( $$A % $$B \) \) % $$B \) )
83 file-size=$(shell cat $1 | wc -c)
85 #######################################################################
86 # Helper functions for ramstage postprocess
87 spc :=
88 spc +=
89 $(spc) :=
90 $(spc) +=
92 # files-in-dir-recursive,dir,files
93 files-in-dir-recursive=$(filter $(1)%,$(2))
95 # parent-dir,dir/
96 parent-dir=$(dir $(if $(patsubst /%,,$(1)),,/)$(subst $( ),/,$(strip $(subst /, ,$(1)))))
98 # filters out exactly the directory specified
99 # filter-out-dir,dir_to_keep,dirs
100 filter-out-dir=$(filter-out $(1),$(2))
102 # filters out dir_to_keep and all its parents
103 # filter-out-dirs,dir_to_keep,dirs
104 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)))
106 # dir-wildcards,dirs
107 dir-wildcards=$(addsuffix %,$(1))
109 # files-in-dir,dir,files
110 files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(sort $(dir $(2))))),$(call files-in-dir-recursive,$(1),$(2)))
112 #######################################################################
113 # reduce command line length by linking the objects of each
114 # directory into an intermediate file
115 ramstage-postprocess=$(foreach d,$(sort $(dir $(filter-out %.ld,$(1)))), \
116         $(eval $(d)ramstage.o: $(call files-in-dir,$(d),$(filter-out %.ld,$(1))); $$(LD_ramstage) -o $$@ -r $$^ ) \
117         $(eval ramstage-objs:=$(d)ramstage.o $(filter-out $(filter-out %.ld, $(call files-in-dir,$(d),$(1))),$(ramstage-objs))))
119 bootblock-generic-ccopts += -D__PRE_RAM__ -D__BOOTBLOCK__
120 romstage-generic-ccopts += -D__PRE_RAM__ -D__ROMSTAGE__
121 ramstage-generic-ccopts += -D__RAMSTAGE__
122 ifeq ($(CONFIG_TRACE),y)
123 ramstage-c-ccopts += -finstrument-functions
124 endif
125 ifeq ($(CONFIG_COVERAGE),y)
126 ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
127 endif
129 # try to fetch non-optional submodules if the source is under git
130 forgetthis:=$(if $(GIT),$(shell git submodule update --init))
131 ifeq ($(CONFIG_USE_BLOBS),y)
132 # this is necessary because 3rdparty is update=none, and so is ignored
133 # unless explicitly requested and enabled through --checkout
134 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty))
135 endif
137 ramstage-c-deps:=$$(OPTION_TABLE_H)
138 romstage-c-deps:=$$(OPTION_TABLE_H)
139 verstage-c-deps:=$$(OPTION_TABLE_H)
140 bootblock-c-deps:=$$(OPTION_TABLE_H)
142 # Add handler to copy linker scripts
143 define generic-objs_ld_template_gen
144 de$(EMPTY)fine $(1)-objs_ld_template
145 $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h
146         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
147         $$(CC_$(1)) $$(CPPFLAGS_$(1)) $($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h $$$$< > $$$$@.tmp
148         mv $$$$@.tmp $$$$@
149 en$(EMPTY)def
150 endef
152 # Add handler to add no rules for manual files
153 define generic-objs_manual_template_gen
154 # do nothing
155 endef
157 #######################################################################
158 # Add handler to compile ACPI's ASL
159 define ramstage-objs_asl_template
160 $$(call src-to-obj,ramstage,$(1).asl): $(1).asl $(obj)/config.h
161         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
162         $(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 $$@
163         cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$@)
164         mv $$(basename $$@).hex $$(basename $$@).c
165         $(CC_ramstage) $$(CFLAGS_ramstage) $$(CPPFLAGS_ramstage) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
166         # keep %.o: %.c rule from catching the temporary .c file after a make clean
167         mv $$(basename $$@).c $$(basename $$@).hex
168 endef
170 #######################################################################
171 # Parse plaintext cmos defaults into binary format
172 # arg1: source file
173 # arg2: binary file name
174 cbfs-files-processor-nvramtool= \
175         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
176                 printf "    CREATE     $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
178 #######################################################################
179 # Link VSA binary to ELF-ish stage
180 # arg1: source file
181 # arg2: binary file name
182 cbfs-files-processor-vsa= \
183         $(eval $(2): $(1) ; \
184                 printf "    CREATE     $(2) (from $(1))\n";  $(OBJCOPY_ramstage) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && $(LD_ramstage) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
186 #######################################################################
187 # Add handler for arbitrary files in CBFS
188 $(call add-special-class,cbfs-files)
189 cbfs-files-handler= \
190                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
191                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
192                 $(if $(wildcard $(1)$($(2)-file)), \
193                         $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
194                         $(eval tmp-cbfs-file:= $($(2)-file))) \
195                 $(if $(strip $($(2)-required)), \
196                         $(if $(wildcard $(tmp-cbfs-file)),, \
197                                 $(info This build configuration requires $($(2)-required)) \
198                                 $(eval FAILBUILD:=1) \
199                         )) \
200                 $(if $(strip $($(2)-align)), \
201                         $(if $(strip $($(2)-position)), \
202                                 $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
203                                 $(eval FAILBUILD:=1) \
204                         )) \
205                 $(if $(tmp-cbfs-method), \
206                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
207                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
208                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
209                 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align))\
210                 $(eval $(2)-name:=) \
211                 $(eval $(2)-type:=) \
212                 $(eval $(2)-compression:=) \
213                 $(eval $(2)-position:=) \
214                 $(eval $(2)-required:=) \
215                 $(eval $(2)-align:=)
217 #######################################################################
218 # a variety of flags for our build
219 CBFS_COMPRESS_FLAG:=none
220 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
221 CBFS_COMPRESS_FLAG:=LZMA
222 endif
224 CBFS_PAYLOAD_COMPRESS_FLAG:=none
225 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
226 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
227 endif
229 ifneq ($(CONFIG_LOCALVERSION),"")
230 export COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
231 endif
233 CPPFLAGS_common := -Isrc -Isrc/include -I$(obj)
234 CPPFLAGS_common += -Isrc/device/oprom/include
235 CPPFLAGS_common += -include $(src)/include/kconfig.h
237 CFLAGS_common += -pipe -g -nostdinc
238 CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
239 CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
240 CFLAGS_common += -Wstrict-aliasing -Wshadow
242 ifeq ($(CONFIG_COMPILER_GCC),y)
243 # cf. commit f69a99db (coreboot: x86: enable gc-sections)
244 CFLAGS_common += -Wno-unused-but-set-variable
245 endif
247 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
248 CFLAGS_common += -Werror
249 endif
250 CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
251 ifneq ($(GDB_DEBUG),)
252 CFLAGS_common += -Og
253 else
254 CFLAGS_common += -Os
255 endif
257 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
258                    $(objutil)/ifdfake $(objutil)/options $(objutil)/fletcher \
259                    $(objutil)/cbootimage $(objutil)/bimgtool
261 #######################################################################
262 # generate build support files
263 $(obj)/build.h: .xcompile
264         @printf "    GEN        build.h\n"
265         rm -f $(obj)/build.h
266         util/genbuild_h/genbuild_h.sh > $(obj)/build.ht
267         mv $(obj)/build.ht $(obj)/build.h
269 build-dirs:
270         mkdir -p $(objcbfs) $(objgenerated)
272 #######################################################################
273 # Build the tools
274 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
275 RMODTOOL:=$(objutil)/cbfstool/rmodtool
277 $(obj)/cbfstool: $(CBFSTOOL)
278         cp $< $@
280 $(obj)/rmodtool: $(RMODTOOL)
281         cp $< $@
283 _WINCHECK=$(shell uname -o 2> /dev/null)
284 STACK=
285 ifeq ($(_WINCHECK),Msys)
286         STACK=-Wl,--stack,16384000
287 endif
288 ifeq ($(_WINCHECK),Cygwin)
289         STACK=-Wl,--stack,16384000
290 endif
292 # this allows ccache to prepend itself
293 # (ccache handling happens first)
294 ROMCC_BIN= $(objutil)/romcc/romcc
295 ROMCC?=$(ROMCC_BIN)
296 $(ROMCC_BIN): $(top)/util/romcc/romcc.c
297         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
298         @# Note: Adding -O2 here might cause problems. For details see:
299         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
300         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
302 IFDTOOL:=$(objutil)/ifdtool/ifdtool
303 $(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
304         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
305         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
307 IFDFAKE:=$(objutil)/ifdfake/ifdfake
308 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
309         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
310         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
312 FLETCHER:=$(objutil)/fletcher/fletcher
313 $(FLETCHER): $(top)/util/fletcher/fletcher.c
314         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
315         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
317 CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
319 subdirs-y += util/nvidia
321 BIMGTOOL:=$(objutil)/bimgtool/bimgtool
322 $(BIMGTOOL): $(top)/util/bimgtool/bimgtool.c
323         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
324         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
326 #######################################################################
327 # needed objects that every mainboard uses
328 # Creation of these is architecture and mainboard independent
329 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
330         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
331         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
332         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
334 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
335 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
337 $(objutil)/%.o: $(objutil)/%.c
338         @printf "    HOSTCC     $(subst $(objutil)/,,$(@))\n"
339         $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
341 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
342         @printf "    CC         $(subst $(obj)/,,$(@))\n"
343         $(CC_ramstage) -MMD $(CFLAGS_ramstage) $(CPPFLAGS_ramstage) $(ramstage-c-ccopts) -c -o $@ $<
345 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
346         @printf "    CC         $(subst $(obj)/,,$(@))\n"
347         $(CC_romstage) -MMD $(CFLAGS_romstage) $(CPPFLAGS_romstage) $(romstage-c-ccopts) -c -o $@ $<
349 $(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
350         @printf "    CC         $(subst $(obj)/,,$(@))\n"
351         $(CC_bootblock) -MMD $(CFLAGS_bootblock) $(CPPFLAGS_bootblock) $(bootblock-c-ccopts) -c -o $@ $<
353 #######################################################################
354 # Clean up rules
355 clean-abuild:
356         rm -rf coreboot-builds
358 clean-for-update-target:
359         rm -f $(obj)/ramstage* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
360         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
361         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
362         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
363         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
364         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
365         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
366         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
367         $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC_x86_32)" LD="$(LD_x86_32)"
369 clean-target:
370         rm -f $(obj)/coreboot*
372 #######################################################################
373 # Development utilities
374 printcrt0s:
375         @echo crt0s=$(crt0s)
376         @echo ldscripts=$(ldscripts)
378 update:
379         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
381 lint lint-stable:
382         FAILED=0; LINTLOG=`mktemp .tmpconfig.lintXXXXX`; \
383         for script in util/lint/$@-*; do \
384                 echo; echo `basename $$script`; \
385                 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
386                 echo ========; \
387                 $$script > $$LINTLOG; \
388                 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
389                         printf "success\n\n"; \
390                 else \
391                         echo test failed: ; \
392                         cat $$LINTLOG; \
393                         rm -f $$LINTLOG; \
394                         FAILED=$$(( $$FAILED + 1 )); \
395                 fi; \
396                 echo ========; \
397         done; \
398         test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed."; rm -f $$LINTLOG && exit 1; }; \
399         rm -f $$LINTLOG
401 gitconfig:
402         [ -d .git ]
403         mkdir -p .git/hooks
404         for hook in commit-msg pre-commit ; do                       \
405                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
406                 ! -x .git/hooks/$$hook ]; then                       \
407                         cp util/gitconfig/$$hook .git/hooks/$$hook;  \
408                         chmod +x .git/hooks/$$hook;                  \
409                 fi;                                                  \
410         done
411         git config remote.origin.push HEAD:refs/for/master
412         (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)
414 crossgcc: crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 crossgcc-mips crossgcc-riscv
416 .PHONY: crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 crossgcc-mips crossgcc-riscv
417 crossgcc-i386: clean-for-update
418         $(MAKE) -C util/crossgcc build-i386-without-gdb
420 crossgcc-x64: clean-for-update
421         $(MAKE) -C util/crossgcc build-x64-without-gdb
423 crossgcc-arm: clean-for-update
424         $(MAKE) -C util/crossgcc build-armv7a-without-gdb
426 crossgcc-aarch64: clean-for-update
427         $(MAKE) -C util/crossgcc build-aarch64-without-gdb
429 crossgcc-mips: clean-for-update
430         $(MAKE) -C util/crossgcc build-mips-without-gdb
432 crossgcc-riscv: clean-for-update
433         $(MAKE) -C util/crossgcc build-riscv-without-gdb
435 crosstools: crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 crosstools-mips crosstools-riscv
437 .PHONY: crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 crosstools-mips crosstools-riscv
438 crosstools-i386: clean-for-update
439         $(MAKE) -C util/crossgcc build-i386
441 crosstools-x64: clean-for-update
442         $(MAKE) -C util/crossgcc build-x64
444 crosstools-arm: clean-for-update
445         $(MAKE) -C util/crossgcc build-armv7a
447 crosstools-aarch64: clean-for-update
448         $(MAKE) -C util/crossgcc build-aarch64
450 crosstools-mips: clean-for-update
451         $(MAKE) -C util/crossgcc build-mips
453 crosstools-riscv: clean-for-update
454         $(MAKE) -C util/crossgcc build-riscv
456 crossgcc-clean: clean-for-update
457         $(MAKE) -C util/crossgcc clean
459 tools: $(objutil)/kconfig/conf $(objutil)/cbfstool/cbfstool $(objutil)/cbfstool/rmodtool $(objutil)/nvramtool/nvramtool $(ROMCC_BIN) $(objutil)/sconfig/sconfig $(IFDTOOL) $(IFDFAKE) $(CBOOTIMAGE)
461 ###########################################################################
462 # Common recipes for all stages
463 ###########################################################################
465 # loadaddr can determine the load address of a stage, which may be needed for
466 # platform-specific image headers (only works *after* the stage has been built)
467 loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
468              sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
470 # find-substr is required for stages like romstage_null and romstage_xip to
471 # eliminate the _* part of the string
472 find-substr = $(word 1,$(subst _, ,$(1)))
474 # find-class is used to identify the class from the name of the stage
475 # The input to this macro can be something like romstage.x or romstage.x.y
476 # find-class recursively strips off the suffixes to extract the exact class name
477 # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
478 # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
479 # and remove .x the next time and finally return romstage
480 find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
482 $(objcbfs)/%.bin: $(objcbfs)/%.elf
483         $(eval class := $(call find-class,$(@F)))
484         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
485         $(OBJCOPY_$(class)) -O binary $< $@
487 $(objcbfs)/%.elf: $(objcbfs)/%.debug
488         $(eval class := $(call find-class,$(@F)))
489         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
490         cp $< $@.tmp
491         $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
492         $(OBJCOPY_$(class)) --strip-debug $@.tmp
493         $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
494         mv $@.tmp $@
496 ###########################################################################
497 # Build the final rom image
498 ###########################################################################
500 COREBOOT_ROM_DEPENDENCIES:=
501 ifeq ($(CONFIG_PAYLOAD_ELF),y)
502 COREBOOT_ROM_DEPENDENCIES+=$(CONFIG_PAYLOAD_FILE)
503 endif
504 ifeq ($(CONFIG_PAYLOAD_SEABIOS),y)
505 COREBOOT_ROM_DEPENDENCIES+=seabios
506 endif
507 ifeq ($(CONFIG_PAYLOAD_FILO),y)
508 COREBOOT_ROM_DEPENDENCIES+=filo
509 endif
510 ifeq ($(CONFIG_PAYLOAD_GRUB2),y)
511 COREBOOT_ROM_DEPENDENCIES+=grub2
512 endif
514 extract_nth=$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-)))
516 cbfs-add-cmd = \
517                $(CBFSTOOL) $@.tmp \
518                add$(if $(filter stage,$(call extract_nth,3,$(file))),-stage)$(if $(filter payload,$(call extract_nth,3,$(file))),-payload) \
519                -f $(call extract_nth,1,$(file)) \
520                -n $(call extract_nth,2,$(file)) $(if $(filter-out stage,$(call extract_nth,3,$(file))),-t $(call extract_nth,3,$(file)))
522 ifneq ($(CONFIG_UPDATE_IMAGE),y)
523 prebuild-files = \
524                $(foreach file,$(cbfs-files), \
525                $(if $(call extract_nth,6,$(file)),$(CBFSTOOL) $@.tmp locate -f $(call extract_nth,1,$(file)) -n $(call extract_nth,2,$(file)) -a $(call extract_nth,6,$(file))|xargs -i \
526                $(cbfs-add-cmd) -b {} &&,\
527                $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&))
528 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
530 $(obj)/coreboot.pre1: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL) $$(cpu_ucode_cbfs_file)
531         $(CBFSTOOL) $@.tmp create \
532         -B $(objcbfs)/bootblock.bin -a 64 \
533         $(CBFSTOOL_PRE1_OPTS)
534         $(prebuild-files) true
535         $(call add-cpu-microcode-to-cbfs,$@.tmp)
536         mv $@.tmp $@
537 else
538 .PHONY: $(obj)/coreboot.pre1
539 $(obj)/coreboot.pre1: $(CBFSTOOL)
540         mv $(obj)/coreboot.rom $@
541 endif
543 ifeq ($(CONFIG_PAYLOAD_LINUX),y)
544 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_COMMAND_LINE))),)
545       ADDITIONAL_PAYLOAD_CONFIG+=-C $(CONFIG_LINUX_COMMAND_LINE)
546 endif
547 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),)
548       ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)
549 endif
550 endif
552 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
553 REFCODE_BLOB=$(obj)/refcode.rmod
554 $(REFCODE_BLOB): $(RMODTOOL)
555         $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
556 endif
558 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/ramstage.elf $(CBFSTOOL) $(call strip_quotes,$(COREBOOT_ROM_DEPENDENCIES)) $$(INTERMEDIATE) $$(VBOOT_STUB) $(REFCODE_BLOB)
559         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
560 # The full ROM may be larger than the CBFS part, so create an empty
561 # file (filled with \377 = 0xff) and copy the CBFS image over it.
562         tr '\000' '\377' < /dev/zero 2> /dev/null | dd of=$@.tmp bs=8192 iflag=fullblock count=$$(($(CONFIG_ROM_SIZE) / 8192)) 2> /dev/null
563         dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
564         $(CBFSTOOL) $@.tmp add-stage -f $(objcbfs)/ramstage.elf -n $(CONFIG_CBFS_PREFIX)/ramstage -c $(CBFS_COMPRESS_FLAG)
565 ifeq ($(CONFIG_PAYLOAD_NONE),y)
566         @printf "    PAYLOAD    none (as specified by user)\n"
567 endif
568 ifneq ($(CONFIG_PAYLOAD_FILE),)
569         @printf "    PAYLOAD    $(CONFIG_PAYLOAD_FILE) (compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
570         $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG) $(ADDITIONAL_PAYLOAD_CONFIG)
571 endif
572 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
573 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
574         @printf "    SeaBIOS    Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
575         $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
576 endif
577 endif
578 ifeq ($(CONFIG_SEABIOS_VGA_COREBOOT),y)
579         @printf "    SeaBIOS    Adding generated legacy VGA option rom.\n"
580         $(CBFSTOOL) $@.tmp add -f $(CONFIG_PAYLOAD_VGABIOS_FILE) -n vgaroms/seavgabios.bin -t raw
581 endif
582 ifeq ($(CONFIG_INCLUDE_CONFIG_FILE),y)
583         @printf "    CONFIG     $(DOTCONFIG)\n"
584         if [ -f $(DOTCONFIG) ]; then \
585         echo "# This image was built using git revision" `git rev-parse HEAD` > $(obj)/config.tmp ; \
586         sed -e '/^#/d' -e '/^ *$$/d' $(DOTCONFIG) >> $(obj)/config.tmp ; \
587         $(CBFSTOOL) $@.tmp add -f $(obj)/config.tmp -n config -t raw; rm -f $(obj)/config.tmp ; fi
588         @printf "    REVISION   build.h\n"
589         if [ -f $(obj)/build.h ]; then $(CBFSTOOL) $@.tmp add -f $(obj)/build.h -n revision -t raw; fi
590 endif
591 ifeq ($(CONFIG_VBOOT_VERIFY_FIRMWARE),y)
592         $(CBFSTOOL) $@.tmp add-stage -f $(VBOOT_STUB) -n $(CONFIG_CBFS_PREFIX)/vboot -c $(CBFS_COMPRESS_FLAG)
593 endif
594 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
595         $(CBFSTOOL) $@.tmp add-stage -f $(REFCODE_BLOB) -n $(CONFIG_CBFS_PREFIX)/refcode -c $(CBFS_COMPRESS_FLAG)
596 endif
597 ifeq ($(CONFIG_PXE_ROM),y)
598         $(CBFSTOOL) $@.tmp add -f $(CONFIG_PXE_ROM_FILE) -n pci$(CONFIG_PXE_ROM_ID).rom -t raw
599 endif
600 ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
601 ifeq ($(CONFIG_CPU_MICROCODE_ADDED_DURING_BUILD),y)
602         @printf "    UPDATE-FIT \n"
603         $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
604 endif
605 endif
606         mv $@.tmp $@
607         @printf "    CBFSPRINT  $(subst $(obj)/,,$(@))\n\n"
608         $(CBFSTOOL) $@ print
610 cbfs-files-$(CONFIG_BOOTSPLASH) += bootsplash.jpg
611 bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
612 bootsplash.jpg-type := bootsplash
614 $(obj)/coreboot.pre: $(objcbfs)/romstage.elf $(obj)/coreboot.pre1 $(CBFSTOOL)
615         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
616         cp $(obj)/coreboot.pre1 $@.tmp
617         $(CBFSTOOL) $@.tmp add-stage \
618                 -f $(objcbfs)/romstage.elf \
619                 -n $(CONFIG_CBFS_PREFIX)/romstage -c none \
620                 $(CBFSTOOL_PRE_OPTS)
621         mv $@.tmp $@
623 JENKINS_PAYLOAD=none
624 what-jenkins-does:
625         util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c 4 -z -p $(JENKINS_PAYLOAD)
626         (cd payloads/libpayload; $(MAKE) $(if $(JENKINS_NOCCACHE),,CONFIG_CCACHE=y) V=$(V) Q=$(Q) junit.xml)
627         $(MAKE) V=$(V) Q=$(Q) -C util/cbmem junit.xml