libpayload: Rename Config.in -> Kconfig
[coreboot.git] / Makefile.inc
blobb5acdd0b9740b1024590c9cafe0d14d1d2ef7b16
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.
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/acpi
56 subdirs-y += src/ec/acpi $(wildcard src/ec/*/*) $(wildcard src/southbridge/*/*)
57 subdirs-y += $(wildcard src/soc/*/*) $(wildcard src/northbridge/*/*)
58 subdirs-y += src/superio $(wildcard src/drivers/*) src/cpu src/vendorcode
59 subdirs-y += util/cbfstool util/sconfig util/nvramtool util/broadcom
60 subdirs-y += $(wildcard src/arch/*)
61 subdirs-y += src/mainboard/$(MAINBOARDDIR)
63 subdirs-y += site-local
65 #######################################################################
66 # Add source classes and their build options
67 classes-y := ramstage romstage bootblock smm smmstub cpu_microcode libverstage verstage secmon
69 # Add dynamic classes for rmodules
70 $(foreach supported_arch,$(ARCH_SUPPORTED), \
71             $(eval $(call define_class,rmodules_$(supported_arch),$(supported_arch))))
73 #######################################################################
74 # Helper functions for various file placement matters
76 # int-add: adds an arbitrary number of space-separated integers in
77 #          all formats understood by printf(1)
78 # int-align: align $1 to $2 units
79 # file-size: returns the filesize of the given file
80 _toint=$(shell printf "%d" $1)
81 _int-add2=$(shell expr $(call _toint,$1) + $(call _toint,$2))
82 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)))
83 int-align=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A + \( \( $$B - \( $$A % $$B \) \) % $$B \) )
84 file-size=$(shell cat $1 | wc -c)
86 #######################################################################
87 # Helper functions for ramstage postprocess
88 spc :=
89 spc +=
90 $(spc) :=
91 $(spc) +=
93 # files-in-dir-recursive,dir,files
94 files-in-dir-recursive=$(filter $(1)%,$(2))
96 # parent-dir,dir/
97 parent-dir=$(dir $(if $(patsubst /%,,$(1)),,/)$(subst $( ),/,$(strip $(subst /, ,$(1)))))
99 # filters out exactly the directory specified
100 # filter-out-dir,dir_to_keep,dirs
101 filter-out-dir=$(filter-out $(1),$(2))
103 # filters out dir_to_keep and all its parents
104 # filter-out-dirs,dir_to_keep,dirs
105 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)))
107 # dir-wildcards,dirs
108 dir-wildcards=$(addsuffix %,$(1))
110 # files-in-dir,dir,files
111 files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(sort $(dir $(2))))),$(call files-in-dir-recursive,$(1),$(2)))
113 #######################################################################
114 # reduce command line length by linking the objects of each
115 # directory into an intermediate file
116 ramstage-postprocess=$$(eval DEPENDENCIES+=$$(addsuffix .d,$$(basename $(1)))) \
117         $(foreach d,$(sort $(dir $(filter-out %.ld,$(1)))), \
118         $(eval $(d)ramstage.a: $(call files-in-dir,$(d),$(filter-out %.ld,$(1))); rm -f $$@ && $(AR_ramstage) rcsT $$@ $$^ ) \
119         $(eval ramstage-objs:=$(d)ramstage.a $(filter-out $(filter-out %.ld, $(call files-in-dir,$(d),$(1))),$(ramstage-objs))))
121 bootblock-generic-ccopts += -D__PRE_RAM__ -D__BOOTBLOCK__
122 romstage-generic-ccopts += -D__PRE_RAM__ -D__ROMSTAGE__
123 ramstage-generic-ccopts += -D__RAMSTAGE__
124 ifeq ($(CONFIG_TRACE),y)
125 ramstage-c-ccopts += -finstrument-functions
126 endif
127 ifeq ($(CONFIG_COVERAGE),y)
128 ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
129 endif
131 # try to fetch non-optional submodules if the source is under git
132 forgetthis:=$(if $(GIT),$(shell git submodule update --init))
133 ifeq ($(CONFIG_USE_BLOBS),y)
134 # this is necessary because 3rdparty/blobs is update=none, and so is ignored
135 # unless explicitly requested and enabled through --checkout
136 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/blobs))
137 endif
139 ramstage-c-deps:=$$(OPTION_TABLE_H)
140 romstage-c-deps:=$$(OPTION_TABLE_H)
141 libverstage-c-deps:=$$(OPTION_TABLE_H)
142 verstage-c-deps:=$$(OPTION_TABLE_H)
143 bootblock-c-deps:=$$(OPTION_TABLE_H)
145 # Add handler to copy linker scripts
146 define generic-objs_ld_template_gen
147 de$(EMPTY)fine $(1)-objs_ld_template
148 $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h
149         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
150         $$(CC_$(1)) $$(CPPFLAGS_$(1)) $($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h $$$$< > $$$$@.tmp
151         mv $$$$@.tmp $$$$@
152 en$(EMPTY)def
153 endef
155 # Add handler to deal with archives
156 define generic-objs_a_template_gen
157 de$(EMPTY)fine $(1)-objs_a_template
158 $$(call src-to-obj,$1,$$(1).a): $$(1).a
159         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
160         cp $$$$< $$$$@.tmp
161         mv $$$$@.tmp $$$$@
162 en$(EMPTY)def
163 endef
165 # Add handler to add no rules for manual files
166 define generic-objs_manual_template_gen
167 # do nothing
168 endef
170 #######################################################################
171 # Add handler to compile ACPI's ASL
172 define asl_template
173 $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml-file = $(obj)/$(1).aml
174 $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml-type = raw
175 $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml-compression = none
176 cbfs-files-y += $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml
177 $(obj)/$(1).aml: $(src)/mainboard/$(MAINBOARDDIR)/$(1).asl $(obj)/config.h
178         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
179         $(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 $$@
180         cd $$(dir $$@); $(IASL) -p $$(notdir $$@) $$(notdir $$@)
181 endef
183 #######################################################################
184 # Parse plaintext cmos defaults into binary format
185 # arg1: source file
186 # arg2: binary file name
187 cbfs-files-processor-nvramtool= \
188         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
189                 printf "    CREATE     $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
191 #######################################################################
192 # Link VSA binary to ELF-ish stage
193 # arg1: source file
194 # arg2: binary file name
195 cbfs-files-processor-vsa= \
196         $(eval $(2): $(1) ; \
197                 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))
199 #######################################################################
200 # Add handler for arbitrary files in CBFS
201 $(call add-special-class,cbfs-files)
202 cbfs-files-handler= \
203                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
204                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
205                 $(if $(wildcard $(1)$($(2)-file)), \
206                         $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
207                         $(eval tmp-cbfs-file:= $($(2)-file))) \
208                 $(if $(strip $($(2)-required)), \
209                         $(if $(wildcard $(tmp-cbfs-file)),, \
210                                 $(info This build configuration requires $($(2)-required)) \
211                                 $(eval FAILBUILD:=1) \
212                         )) \
213                 $(if $(strip $($(2)-align)), \
214                         $(if $(strip $($(2)-position)), \
215                                 $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
216                                 $(eval FAILBUILD:=1) \
217                         )) \
218                 $(if $(tmp-cbfs-method), \
219                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
220                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
221                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
222                 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align))\
223                 $(eval $(2)-name:=) \
224                 $(eval $(2)-type:=) \
225                 $(eval $(2)-compression:=) \
226                 $(eval $(2)-position:=) \
227                 $(eval $(2)-required:=) \
228                 $(eval $(2)-align:=)
230 #######################################################################
231 # a variety of flags for our build
232 CBFS_COMPRESS_FLAG:=none
233 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
234 CBFS_COMPRESS_FLAG:=LZMA
235 endif
237 CBFS_PAYLOAD_COMPRESS_FLAG:=none
238 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
239 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
240 endif
242 ifneq ($(CONFIG_LOCALVERSION),"")
243 export COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
244 endif
246 CPPFLAGS_common := -Isrc -Isrc/include -I$(obj)
247 CPPFLAGS_common += -Isrc/device/oprom/include
248 CPPFLAGS_common += -include $(src)/include/kconfig.h
250 CFLAGS_common += -pipe -g -nostdinc
251 CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
252 CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
253 CFLAGS_common += -Wstrict-aliasing -Wshadow
255 ifeq ($(CONFIG_COMPILER_GCC),y)
256 # cf. commit f69a99db (coreboot: x86: enable gc-sections)
257 CFLAGS_common += -Wno-unused-but-set-variable
258 endif
260 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
261 CFLAGS_common += -Werror
262 endif
263 CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
264 ifneq ($(GDB_DEBUG),)
265 CFLAGS_common += -Og
266 else
267 CFLAGS_common += -Os
268 endif
270 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
271                    $(objutil)/ifdfake $(objutil)/options $(objutil)/fletcher \
272                    $(objutil)/cbootimage $(objutil)/bimgtool
274 #######################################################################
275 # generate build support files
276 $(obj)/build.h: .xcompile
277         @printf "    GEN        build.h\n"
278         rm -f $(obj)/build.h
279         util/genbuild_h/genbuild_h.sh > $(obj)/build.ht
280         mv $(obj)/build.ht $(obj)/build.h
282 build-dirs:
283         mkdir -p $(objcbfs) $(objgenerated)
285 #######################################################################
286 # Build the tools
287 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
288 FMAPTOOL:=$(objutil)/cbfstool/fmaptool
289 RMODTOOL:=$(objutil)/cbfstool/rmodtool
291 $(obj)/cbfstool: $(CBFSTOOL)
292         cp $< $@
294 $(obj)/fmaptool: $(FMAPTOOL)
295         cp $< $@
297 $(obj)/rmodtool: $(RMODTOOL)
298         cp $< $@
300 _WINCHECK=$(shell uname -o 2> /dev/null)
301 STACK=
302 ifeq ($(_WINCHECK),Msys)
303         STACK=-Wl,--stack,16384000
304 endif
305 ifeq ($(_WINCHECK),Cygwin)
306         STACK=-Wl,--stack,16384000
307 endif
309 # this allows ccache to prepend itself
310 # (ccache handling happens first)
311 ROMCC_BIN= $(objutil)/romcc/romcc
312 ROMCC?=$(ROMCC_BIN)
313 $(ROMCC_BIN): $(top)/util/romcc/romcc.c
314         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
315         @# Note: Adding -O2 here might cause problems. For details see:
316         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
317         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
319 IFDTOOL:=$(objutil)/ifdtool/ifdtool
320 $(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
321         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
322         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
324 IFDFAKE:=$(objutil)/ifdfake/ifdfake
325 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
326         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
327         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
329 FLETCHER:=$(objutil)/fletcher/fletcher
330 $(FLETCHER): $(top)/util/fletcher/fletcher.c
331         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
332         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
334 CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
336 subdirs-y += util/nvidia
338 BIMGTOOL:=$(objutil)/bimgtool/bimgtool
339 $(BIMGTOOL): $(top)/util/bimgtool/bimgtool.c
340         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
341         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
343 #######################################################################
344 # needed objects that every mainboard uses
345 # Creation of these is architecture and mainboard independent
346 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
347         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
348         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
349         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
351 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
352 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
354 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
355         @printf "    CC         $(subst $(obj)/,,$(@))\n"
356         $(CC_ramstage) -MMD $(CFLAGS_ramstage) $(CPPFLAGS_ramstage) $(ramstage-c-ccopts) -c -o $@ $<
358 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
359         @printf "    CC         $(subst $(obj)/,,$(@))\n"
360         $(CC_romstage) -MMD $(CFLAGS_romstage) $(CPPFLAGS_romstage) $(romstage-c-ccopts) -c -o $@ $<
362 $(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
363         @printf "    CC         $(subst $(obj)/,,$(@))\n"
364         $(CC_bootblock) -MMD $(CFLAGS_bootblock) $(CPPFLAGS_bootblock) $(bootblock-c-ccopts) -c -o $@ $<
366 $(objgenerated)/libverstage.a: $$(libverstage-objs)
367         rm -f $@
368         $(AR_libverstage) rcsT $@ $^
370 #######################################################################
371 # Clean up rules
372 clean-abuild:
373         rm -rf coreboot-builds
375 clean-for-update-target:
376         rm -f $(obj)/ramstage* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
377         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
378         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
379         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
380         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
381         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
382         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
383         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
384         $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC_x86_32)" LD="$(LD_x86_32)"
386 clean-target:
387         rm -f $(obj)/coreboot*
389 #######################################################################
390 # Development utilities
391 printcrt0s:
392         @echo crt0s=$(crt0s)
393         @echo ldscripts=$(ldscripts)
395 update:
396         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
398 lint lint-stable:
399         FAILED=0; LINTLOG=`mktemp .tmpconfig.lintXXXXX`; \
400         for script in util/lint/$@-*; do \
401                 echo; echo `basename $$script`; \
402                 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
403                 echo ========; \
404                 $$script > $$LINTLOG; \
405                 if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \
406                         printf "success\n\n"; \
407                 else \
408                         echo test failed: ; \
409                         cat $$LINTLOG; \
410                         rm -f $$LINTLOG; \
411                         FAILED=$$(( $$FAILED + 1 )); \
412                 fi; \
413                 echo ========; \
414         done; \
415         test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed."; rm -f $$LINTLOG && exit 1; }; \
416         rm -f $$LINTLOG
418 gitconfig:
419         [ -d .git ]
420         mkdir -p .git/hooks
421         for hook in commit-msg pre-commit ; do                       \
422                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
423                 ! -x .git/hooks/$$hook ]; then                       \
424                         sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/$$hook > .git/hooks/$$hook;  \
425                         chmod +x .git/hooks/$$hook;                  \
426                 fi;                                                  \
427         done
428         git config remote.origin.push HEAD:refs/for/master
429         (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)
431 crossgcc: crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 crossgcc-mips crossgcc-riscv
433 .PHONY: crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 crossgcc-mips crossgcc-riscv
434 crossgcc-i386: clean-for-update
435         $(MAKE) -C util/crossgcc build-i386-without-gdb
437 crossgcc-x64: clean-for-update
438         $(MAKE) -C util/crossgcc build-x64-without-gdb
440 crossgcc-arm: clean-for-update
441         $(MAKE) -C util/crossgcc build-armv7a-without-gdb
443 crossgcc-aarch64: clean-for-update
444         $(MAKE) -C util/crossgcc build-aarch64-without-gdb
446 crossgcc-mips: clean-for-update
447         $(MAKE) -C util/crossgcc build-mips-without-gdb
449 crossgcc-riscv: clean-for-update
450         $(MAKE) -C util/crossgcc build-riscv-without-gdb
452 crosstools: crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 crosstools-mips crosstools-riscv
454 .PHONY: crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 crosstools-mips crosstools-riscv
455 crosstools-i386: clean-for-update
456         $(MAKE) -C util/crossgcc build-i386
458 crosstools-x64: clean-for-update
459         $(MAKE) -C util/crossgcc build-x64
461 crosstools-arm: clean-for-update
462         $(MAKE) -C util/crossgcc build-armv7a
464 crosstools-aarch64: clean-for-update
465         $(MAKE) -C util/crossgcc build-aarch64
467 crosstools-mips: clean-for-update
468         $(MAKE) -C util/crossgcc build-mips
470 crosstools-riscv: clean-for-update
471         $(MAKE) -C util/crossgcc build-riscv
473 crossgcc-clean: clean-for-update
474         $(MAKE) -C util/crossgcc clean
476 tools: $(objutil)/kconfig/conf $(CBFSTOOL) $(FMAPTOOL) $(RMODTOOL) $(objutil)/nvramtool/nvramtool $(ROMCC_BIN) $(objutil)/sconfig/sconfig $(IFDTOOL) $(IFDFAKE) $(CBOOTIMAGE)
478 ###########################################################################
479 # Common recipes for all stages
480 ###########################################################################
482 # loadaddr can determine the load address of a stage, which may be needed for
483 # platform-specific image headers (only works *after* the stage has been built)
484 loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
485              sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
487 # find-substr is required for stages like romstage_null and romstage_xip to
488 # eliminate the _* part of the string
489 find-substr = $(word 1,$(subst _, ,$(1)))
491 # find-class is used to identify the class from the name of the stage
492 # The input to this macro can be something like romstage.x or romstage.x.y
493 # find-class recursively strips off the suffixes to extract the exact class name
494 # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
495 # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
496 # and remove .x the next time and finally return romstage
497 find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
499 $(objcbfs)/%.bin: $(objcbfs)/%.elf
500         $(eval class := $(call find-class,$(@F)))
501         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
502         $(OBJCOPY_$(class)) -O binary $< $@
504 $(objcbfs)/%.elf: $(objcbfs)/%.debug
505         $(eval class := $(call find-class,$(@F)))
506         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
507         cp $< $@.tmp
508         $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
509         $(OBJCOPY_$(class)) --strip-debug $@.tmp
510         $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
511         mv $@.tmp $@
513 ###########################################################################
514 # Build the final rom image
515 ###########################################################################
517 COREBOOT_ROM_DEPENDENCIES:=
518 ifeq ($(CONFIG_PAYLOAD_ELF),y)
519 COREBOOT_ROM_DEPENDENCIES+=$(CONFIG_PAYLOAD_FILE)
520 endif
521 ifeq ($(CONFIG_PAYLOAD_SEABIOS),y)
522 COREBOOT_ROM_DEPENDENCIES+=seabios
523 endif
524 ifeq ($(CONFIG_PAYLOAD_FILO),y)
525 COREBOOT_ROM_DEPENDENCIES+=filo
526 endif
527 ifeq ($(CONFIG_PAYLOAD_GRUB2),y)
528 COREBOOT_ROM_DEPENDENCIES+=grub2
529 endif
531 extract_nth=$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-)))
533 cbfs-add-cmd = \
534                $(CBFSTOOL) $@.tmp \
535                add$(if $(filter stage,$(call extract_nth,3,$(file))),-stage)$(if $(filter payload,$(call extract_nth,3,$(file))),-payload) \
536                -f $(call extract_nth,1,$(file)) \
537                -n $(call extract_nth,2,$(file)) $(if $(filter-out stage,$(call extract_nth,3,$(file))),-t $(call extract_nth,3,$(file)))
539 ifneq ($(CONFIG_UPDATE_IMAGE),y)
540 prebuild-files = \
541                $(foreach file,$(cbfs-files), \
542                $(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 \
543                $(cbfs-add-cmd) -b {} &&,\
544                $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&))
545 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
547 $(obj)/coreboot.pre1: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(FMAPTOOL) $(CBFSTOOL) $$(cpu_ucode_cbfs_file)
548         $(CBFSTOOL) $@.tmp create \
549         -B $(objcbfs)/bootblock.bin -a 64 \
550         $(CBFSTOOL_PRE1_OPTS)
551         $(prebuild-files) true
552         $(call add-cpu-microcode-to-cbfs,$@.tmp)
553         mv $@.tmp $@
554 else
555 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
556 # Add all cbfs files to image of the form: CONFIG_CBFS_PREFIX/<filename>
557 prebuild-files = \
558         $(foreach file,$(cbfs-files), \
559                $(if $(filter $(call strip_quotes, $(CONFIG_CBFS_PREFIX))/%,\
560                    $(call extract_nth,2,$(file))), \
561                $(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 \
562                $(cbfs-add-cmd) -b {} &&,\
563                $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&)))
565 .PHONY: $(obj)/coreboot.pre1
566 $(obj)/coreboot.pre1: $$(prebuilt-files) $(CBFSTOOL)
567         mv $(obj)/coreboot.rom $@.tmp
568         $(prebuild-files) true
569         mv $@.tmp $@
570 endif
572 ifeq ($(CONFIG_PAYLOAD_LINUX),y)
573 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_COMMAND_LINE))),)
574       ADDITIONAL_PAYLOAD_CONFIG+=-C $(CONFIG_LINUX_COMMAND_LINE)
575 endif
576 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),)
577       ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)
578 endif
579 endif
581 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
582 REFCODE_BLOB=$(obj)/refcode.rmod
583 $(REFCODE_BLOB): $(RMODTOOL)
584         $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
585 endif
587 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/ramstage.elf $(CBFSTOOL) $(call strip_quotes,$(COREBOOT_ROM_DEPENDENCIES)) $$(INTERMEDIATE) $$(VBOOT_STUB) $(REFCODE_BLOB)
588         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
589 # The full ROM may be larger than the CBFS part, so create an empty
590 # file (filled with \377 = 0xff) and copy the CBFS image over it.
591         dd if=/dev/zero bs=$(call _toint,$(CONFIG_ROM_SIZE)) count=1 2> /dev/null | tr '\000' '\377' > $@.tmp
592         dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
593         $(CBFSTOOL) $@.tmp add-stage -f $(objcbfs)/ramstage.elf -n $(CONFIG_CBFS_PREFIX)/ramstage -c $(CBFS_COMPRESS_FLAG)
594 ifeq ($(CONFIG_PAYLOAD_NONE),y)
595         @printf "    PAYLOAD    none (as specified by user)\n"
596 endif
597 ifneq ($(CONFIG_PAYLOAD_FILE),)
598         @printf "    PAYLOAD    $(CONFIG_PAYLOAD_FILE) (compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
599         $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG) $(ADDITIONAL_PAYLOAD_CONFIG)
600 endif
601 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
602 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
603         @printf "    SeaBIOS    Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
604         $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
605 endif
606 endif
607 ifeq ($(CONFIG_SEABIOS_VGA_COREBOOT),y)
608         @printf "    SeaBIOS    Adding generated legacy VGA option rom.\n"
609         $(CBFSTOOL) $@.tmp add -f $(CONFIG_PAYLOAD_VGABIOS_FILE) -n vgaroms/seavgabios.bin -t raw
610 endif
611 ifeq ($(CONFIG_INCLUDE_CONFIG_FILE),y)
612         @printf "    CONFIG     $(DOTCONFIG)\n"
613         if [ -f $(DOTCONFIG) ]; then \
614         echo "# This image was built using git revision" `git rev-parse HEAD` > $(obj)/config.tmp ; \
615         sed -e '/^#/d' -e '/^ *$$/d' $(DOTCONFIG) >> $(obj)/config.tmp ; \
616         $(CBFSTOOL) $@.tmp add -f $(obj)/config.tmp -n config -t raw; rm -f $(obj)/config.tmp ; fi
617         @printf "    REVISION   build.h\n"
618         if [ -f $(obj)/build.h ]; then $(CBFSTOOL) $@.tmp add -f $(obj)/build.h -n revision -t raw; fi
619 endif
620 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
621         $(CBFSTOOL) $@.tmp add-stage -f $(REFCODE_BLOB) -n $(CONFIG_CBFS_PREFIX)/refcode -c $(CBFS_COMPRESS_FLAG)
622 endif
623 ifeq ($(CONFIG_PXE_ROM),y)
624         $(CBFSTOOL) $@.tmp add -f $(CONFIG_PXE_ROM_FILE) -n pci$(CONFIG_PXE_ROM_ID).rom -t raw
625 endif
626 ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
627 ifeq ($(CONFIG_CPU_MICROCODE_ADDED_DURING_BUILD),y)
628         @printf "    UPDATE-FIT \n"
629         $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
630 endif
631 endif
632         mv $@.tmp $@
633         @printf "    CBFSPRINT  $(subst $(obj)/,,$(@))\n\n"
634         $(CBFSTOOL) $@ print
636 cbfs-files-$(CONFIG_BOOTSPLASH) += bootsplash.jpg
637 bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
638 bootsplash.jpg-type := bootsplash
640 $(obj)/coreboot.pre: $(objcbfs)/romstage.elf $(obj)/coreboot.pre1 $(CBFSTOOL)
641         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
642         cp $(obj)/coreboot.pre1 $@.tmp
643         $(CBFSTOOL) $@.tmp add-stage \
644                 -f $(objcbfs)/romstage.elf \
645                 -n $(CONFIG_CBFS_PREFIX)/romstage -c none \
646                 $(CBFSTOOL_PRE_OPTS)
647         mv $@.tmp $@
649 cbfs-files-$(CONFIG_BOARD_ID_MANUAL) += board_id
650 board_id-file := $(obj)/board_id
651 board_id-type := raw
653 $(obj)/board_id:
654         printf $(CONFIG_BOARD_ID_STRING) > $@
656 JENKINS_PAYLOAD=none
657 what-jenkins-does:
658         util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c 4 -z -p $(JENKINS_PAYLOAD)
659         (cd payloads/libpayload; $(MAKE) $(if $(JENKINS_NOCCACHE),,CONFIG_CCACHE=y) V=$(V) Q=$(Q) junit.xml)
660         $(MAKE) V=$(V) Q=$(Q) -C util/cbmem junit.xml