2 ## This file is part of the coreboot project.
4 ## Copyright (C) 2011 secunet Security Networks AG
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.
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
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 $(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))
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/$(call strip_quotes,$(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 #######################################################################
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 secmon
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
115 # files-in-dir-recursive,dir,files
116 files-in-dir-recursive=$(filter $(1)%,$(2))
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)))
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
149 ifeq ($(CONFIG_COVERAGE),y)
150 ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
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))
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)) $$(CPPFLAGS_$(1)) $($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h $$$$< > $$$$@.tmp
177 # Add handler to deal with archives
178 define generic-objs_a_template_gen
179 de$(EMPTY)fine $(1)-objs_a_template
180 $$(call src-to-obj,$1,$$(1).a): $$(1).a
181 @printf " CP $$$$(subst $$$$(obj)/,,$$$$(@))\n"
187 # Add handler to add no rules for manual files
188 define generic-objs_manual_template_gen
192 #######################################################################
193 # Add handler to compile ACPI's ASL
194 # arg1: base file name
195 # arg2: y or n for including in cbfs. defaults to y
197 $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml-file = $(obj)/$(1).aml
198 $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml-type = raw
199 $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml-compression = none
200 cbfs-files-$(if $(2),$(2),y) += $(call strip_quotes,$(CONFIG_CBFS_PREFIX))/$(1).aml
201 $(obj)/$(1).aml: $(src)/mainboard/$(MAINBOARDDIR)/$(1).asl $(obj)/config.h
202 @printf " IASL $$(subst $(top)/,,$$(@))\n"
203 $(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 $$@
204 cd $$(dir $$@); $(IASL) -p $$(notdir $$@) $$(notdir $$@)
207 #######################################################################
208 # Parse plaintext cmos defaults into binary format
210 # arg2: binary file name
211 cbfs-files-processor-nvramtool= \
212 $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
213 printf " CREATE $(2) (from $(1))\n"; $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && mv $(2).tmp $(2))
215 #######################################################################
216 # Link VSA binary to ELF-ish stage
218 # arg2: binary file name
219 cbfs-files-processor-vsa= \
220 $(eval $(2): $(1) ; \
221 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))
223 #######################################################################
224 # Add handler for arbitrary files in CBFS
225 $(call add-special-class,cbfs-files)
226 cbfs-files-handler= \
227 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
228 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
229 $(if $(wildcard $(1)$($(2)-file)), \
230 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
231 $(eval tmp-cbfs-file:= $($(2)-file))) \
232 $(if $(strip $($(2)-required)), \
233 $(if $(wildcard $(tmp-cbfs-file)),, \
234 $(info This build configuration requires $($(2)-required)) \
235 $(eval FAILBUILD:=1) \
237 $(if $(strip $($(2)-align)), \
238 $(if $(strip $($(2)-position)), \
239 $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
240 $(eval FAILBUILD:=1) \
242 $(if $(tmp-cbfs-method), \
243 $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
244 $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
245 $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
246 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align))\
247 $(eval $(2)-name:=) \
248 $(eval $(2)-type:=) \
249 $(eval $(2)-compression:=) \
250 $(eval $(2)-position:=) \
251 $(eval $(2)-required:=) \
254 #######################################################################
255 # a variety of flags for our build
256 CBFS_COMPRESS_FLAG:=none
257 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
258 CBFS_COMPRESS_FLAG:=LZMA
261 CBFS_PAYLOAD_COMPRESS_FLAG:=none
262 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
263 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
266 ifneq ($(CONFIG_LOCALVERSION),"")
267 export COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
270 CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -I$(obj)
271 CPPFLAGS_common += -Isrc/device/oprom/include
272 CPPFLAGS_common += -include $(src)/include/kconfig.h
274 CFLAGS_common += -pipe -g -nostdinc
275 CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
276 CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
277 CFLAGS_common += -Wstrict-aliasing -Wshadow
278 CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
279 CFLAGS_common += -ffunction-sections -fdata-sections
281 LDFLAGS_common := --gc-sections -nostdlib -nostartfiles -static --emit-relocs
283 ifeq ($(CONFIG_COMPILER_GCC),y)
284 # cf. commit f69a99db (coreboot: x86: enable gc-sections)
285 CFLAGS_common += -Wno-unused-but-set-variable
288 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
289 CFLAGS_common += -Werror
291 ifneq ($(GDB_DEBUG),)
297 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
298 $(objutil)/ifdfake $(objutil)/options $(objutil)/fletcher \
299 $(objutil)/cbootimage $(objutil)/bimgtool
301 #######################################################################
302 # generate build support files
303 $(obj)/build.h: .xcompile
304 @printf " GEN build.h\n"
306 util/genbuild_h/genbuild_h.sh > $(obj)/build.ht
307 mv $(obj)/build.ht $(obj)/build.h
310 mkdir -p $(objcbfs) $(objgenerated)
312 #######################################################################
314 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
315 FMAPTOOL:=$(objutil)/cbfstool/fmaptool
316 RMODTOOL:=$(objutil)/cbfstool/rmodtool
318 $(obj)/cbfstool: $(CBFSTOOL)
321 $(obj)/fmaptool: $(FMAPTOOL)
324 $(obj)/rmodtool: $(RMODTOOL)
327 _WINCHECK=$(shell uname -o 2> /dev/null)
329 ifeq ($(_WINCHECK),Msys)
330 STACK=-Wl,--stack,16384000
332 ifeq ($(_WINCHECK),Cygwin)
333 STACK=-Wl,--stack,16384000
336 # this allows ccache to prepend itself
337 # (ccache handling happens first)
338 ROMCC_BIN= $(objutil)/romcc/romcc
340 $(ROMCC_BIN): $(top)/util/romcc/romcc.c
341 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
342 @# Note: Adding -O2 here might cause problems. For details see:
343 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
344 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
346 IFDTOOL:=$(objutil)/ifdtool/ifdtool
347 $(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
348 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
349 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
351 IFDFAKE:=$(objutil)/ifdfake/ifdfake
352 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
353 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
354 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
356 FLETCHER:=$(objutil)/fletcher/fletcher
357 $(FLETCHER): $(top)/util/fletcher/fletcher.c
358 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
359 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
361 CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
363 subdirs-y += util/nvidia
365 BIMGTOOL:=$(objutil)/bimgtool/bimgtool
366 $(BIMGTOOL): $(top)/util/bimgtool/bimgtool.c
367 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
368 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
370 #######################################################################
371 # needed objects that every mainboard uses
372 # Creation of these is architecture and mainboard independent
373 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
374 @printf " SCONFIG $(subst $(src)/,,$(<))\n"
375 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
376 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
378 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
379 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
380 verstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
382 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
383 @printf " CC $(subst $(obj)/,,$(@))\n"
384 $(CC_ramstage) -MMD $(CFLAGS_ramstage) $(CPPFLAGS_ramstage) $(ramstage-c-ccopts) -c -o $@ $<
386 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
387 @printf " CC $(subst $(obj)/,,$(@))\n"
388 $(CC_romstage) -MMD $(CFLAGS_romstage) $(CPPFLAGS_romstage) $(romstage-c-ccopts) -c -o $@ $<
390 $(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
391 @printf " CC $(subst $(obj)/,,$(@))\n"
392 $(CC_bootblock) -MMD $(CFLAGS_bootblock) $(CPPFLAGS_bootblock) $(bootblock-c-ccopts) -c -o $@ $<
394 $(objgenerated)/libverstage.a: $$(libverstage-objs)
396 $(AR_libverstage) rcsT $@ $^
398 #######################################################################
401 rm -rf coreboot-builds
403 clean-for-update-target:
404 rm -f $(obj)/ramstage* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
405 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
406 rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
407 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
408 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
409 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
410 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
411 rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
412 $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean
415 rm -f $(obj)/coreboot*
417 #######################################################################
418 # Development utilities
421 @echo ldscripts=$(ldscripts)
424 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
432 for hook in commit-msg pre-commit ; do \
433 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o \
434 ! -x .git/hooks/$$hook ]; then \
435 sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/$$hook > .git/hooks/$$hook; \
436 chmod +x .git/hooks/$$hook; \
439 # Now set up thehooks for 3rdparty/blobs
440 if [ -d .git/modules/3rdparty -a \
441 \( util/gitconfig/commit-msg -nt .git/modules/3rdparty/hooks/commit-msg -o \
442 ! -x .git/modules/3rdparty/hooks/commit-msg \) ]; then \
443 sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/commit-msg > .git/modules/3rdparty/hooks/commit-msg; \
444 chmod +x .git/modules/3rdparty/hooks/commit-msg; \
446 [ -d 3rdparty/blobs ] && cd 3rdparty/blobs && git config remote.origin.push HEAD:refs/for/master
447 git config remote.origin.push HEAD:refs/for/master
448 (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)
450 crossgcc: crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 crossgcc-mips crossgcc-riscv
452 .PHONY: crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 crossgcc-mips crossgcc-riscv
453 crossgcc-i386: clean-for-update
454 $(MAKE) -C util/crossgcc build-i386-without-gdb
456 crossgcc-x64: clean-for-update
457 $(MAKE) -C util/crossgcc build-x64-without-gdb
459 crossgcc-arm: clean-for-update
460 $(MAKE) -C util/crossgcc build-armv7a-without-gdb
462 crossgcc-aarch64: clean-for-update
463 $(MAKE) -C util/crossgcc build-aarch64-without-gdb
465 crossgcc-mips: clean-for-update
466 $(MAKE) -C util/crossgcc build-mips-without-gdb
468 crossgcc-riscv: clean-for-update
469 $(MAKE) -C util/crossgcc build-riscv-without-gdb
471 crosstools: crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 crosstools-mips crosstools-riscv
473 .PHONY: crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 crosstools-mips crosstools-riscv
474 crosstools-i386: clean-for-update
475 $(MAKE) -C util/crossgcc build-i386
477 crosstools-x64: clean-for-update
478 $(MAKE) -C util/crossgcc build-x64
480 crosstools-arm: clean-for-update
481 $(MAKE) -C util/crossgcc build-armv7a
483 crosstools-aarch64: clean-for-update
484 $(MAKE) -C util/crossgcc build-aarch64
486 crosstools-mips: clean-for-update
487 $(MAKE) -C util/crossgcc build-mips
489 crosstools-riscv: clean-for-update
490 $(MAKE) -C util/crossgcc build-riscv
492 crossgcc-clean: clean-for-update
493 $(MAKE) -C util/crossgcc clean
495 tools: $(objutil)/kconfig/conf $(CBFSTOOL) $(FMAPTOOL) $(RMODTOOL) $(objutil)/nvramtool/nvramtool $(ROMCC_BIN) $(objutil)/sconfig/sconfig $(IFDTOOL) $(IFDFAKE) $(CBOOTIMAGE)
497 ###########################################################################
498 # Common recipes for all stages
499 ###########################################################################
501 # loadaddr can determine the load address of a stage, which may be needed for
502 # platform-specific image headers (only works *after* the stage has been built)
503 loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
504 sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
506 # find-substr is required for stages like romstage_null and romstage_xip to
507 # eliminate the _* part of the string
508 find-substr = $(word 1,$(subst _, ,$(1)))
510 # find-class is used to identify the class from the name of the stage
511 # The input to this macro can be something like romstage.x or romstage.x.y
512 # find-class recursively strips off the suffixes to extract the exact class name
513 # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
514 # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
515 # and remove .x the next time and finally return romstage
516 find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
518 # Bootblocks are not CBFS stages. coreboot is currently expecting the bss to
519 # be cleared by the loader of the stage. For ARM SoCs that means one needs to
520 # include the bss section in the binary so the BootROM clears the bss on
521 # loading of the bootblock stage. Achieve this by marking the bss section
522 # loadable,allocatable, and data. Do the same for the .data section in case
523 # it's marked as NOBITS.
524 $(objcbfs)/bootblock.raw.bin: $(objcbfs)/bootblock.elf
525 @printf " OBJCOPY $(notdir $(@))\n"
526 $(OBJCOPY_bootblock) --set-section-flags .bss=load,alloc,data --set-section-flags .data=load,alloc,data $< $<.tmp
527 $(OBJCOPY_bootblock) -O binary $<.tmp $@
529 $(objcbfs)/%.bin: $(objcbfs)/%.raw.bin
532 $(objcbfs)/%.elf: $(objcbfs)/%.debug
533 $(eval class := $(call find-class,$(@F)))
534 @printf " OBJCOPY $(subst $(obj)/,,$(@))\n"
536 $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
537 $(OBJCOPY_$(class)) --strip-debug $@.tmp
538 $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
541 ###########################################################################
542 # Build the final rom image
543 ###########################################################################
545 COREBOOT_ROM_DEPENDENCIES:=
547 extract_nth=$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-)))
551 add$(if $(filter stage,$(call extract_nth,3,$(file))),-stage)$(if $(filter payload,$(call extract_nth,3,$(file))),-payload) \
552 -f $(call extract_nth,1,$(file)) \
553 -n $(call extract_nth,2,$(file)) \
554 $(if $(filter-out stage,$(call extract_nth,3,$(file))),-t $(call extract_nth,3,$(file))) \
555 $(if $(call extract_nth,4,$(file)),-c $(call extract_nth,4,$(file)))
557 ifneq ($(CONFIG_UPDATE_IMAGE),y)
559 $(foreach file,$(cbfs-files), \
560 $(if $(call extract_nth,6,$(file)),$(cbfs-add-cmd) -a $(call extract_nth,6,$(file)) &&, \
561 $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&))
562 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
564 $(obj)/coreboot.pre1: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(FMAPTOOL) $(CBFSTOOL) $$(cpu_ucode_cbfs_file)
565 $(CBFSTOOL) $@.tmp create \
566 -B $(objcbfs)/bootblock.bin \
567 $(CBFSTOOL_PRE1_OPTS)
568 $(prebuild-files) true
571 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
572 # Add all cbfs files to image of the form: CONFIG_CBFS_PREFIX/<filename>
574 $(foreach file,$(cbfs-files), \
575 $(if $(filter $(call strip_quotes, $(CONFIG_CBFS_PREFIX))/%,\
576 $(call extract_nth,2,$(file))), \
577 $(if $(call extract_nth,6,$(file)),$(cbfs-add-cmd) -a $(call extract_nth,6,$(file)) &&,\
578 $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&)))
580 .PHONY: $(obj)/coreboot.pre1
581 $(obj)/coreboot.pre1: $$(prebuilt-files) $(CBFSTOOL)
582 mv $(obj)/coreboot.rom $@.tmp
583 $(prebuild-files) true
587 ifeq ($(CONFIG_PAYLOAD_LINUX),y)
588 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_COMMAND_LINE))),)
589 ADDITIONAL_PAYLOAD_CONFIG+=-C $(CONFIG_LINUX_COMMAND_LINE)
591 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),)
592 ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)
596 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
597 REFCODE_BLOB=$(obj)/refcode.rmod
598 $(REFCODE_BLOB): $(RMODTOOL)
599 $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
602 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/ramstage.elf $(CBFSTOOL) $$(call strip_quotes,$$(COREBOOT_ROM_DEPENDENCIES)) $$(INTERMEDIATE) $(REFCODE_BLOB) $$(VERSTAGE_FILE)
603 @printf " CBFS $(subst $(obj)/,,$(@))\n"
604 # The full ROM may be larger than the CBFS part, so create an empty
605 # file (filled with \377 = 0xff) and copy the CBFS image over it.
606 dd if=/dev/zero bs=$(call _toint,$(CONFIG_ROM_SIZE)) count=1 2> /dev/null | tr '\000' '\377' > $@.tmp
607 dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
608 $(CBFSTOOL) $@.tmp add-stage -f $(objcbfs)/ramstage.elf -n $(CONFIG_CBFS_PREFIX)/ramstage -c $(CBFS_COMPRESS_FLAG)
609 ifeq ($(CONFIG_PAYLOAD_NONE),y)
610 @printf " PAYLOAD none (as specified by user)\n"
612 ifneq ($(CONFIG_PAYLOAD_FILE),)
613 @printf " PAYLOAD $(CONFIG_PAYLOAD_FILE) (compression: $(CBFS_PAYLOAD_COMPRESS_FLAG))\n"
614 $(CBFSTOOL) $@.tmp add-payload -f $(CONFIG_PAYLOAD_FILE) -n $(CONFIG_CBFS_PREFIX)/payload -c $(CBFS_PAYLOAD_COMPRESS_FLAG) $(ADDITIONAL_PAYLOAD_CONFIG)
616 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
617 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
618 @printf " SeaBIOS Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
619 $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
622 ifeq ($(CONFIG_SEABIOS_VGA_COREBOOT),y)
623 @printf " SeaBIOS Adding generated legacy VGA option rom.\n"
624 $(CBFSTOOL) $@.tmp add -f $(CONFIG_PAYLOAD_VGABIOS_FILE) -n vgaroms/seavgabios.bin -t raw
626 ifeq ($(CONFIG_INCLUDE_CONFIG_FILE),y)
627 @printf " CONFIG $(DOTCONFIG)\n"
628 if [ -f $(DOTCONFIG) ]; then \
629 echo "# This image was built using git revision" `git rev-parse HEAD` > $(obj)/config.tmp && \
630 $(MAKE) DOTCONFIG=$(DOTCONFIG) DEFCONFIG=$(obj)/config.tmp savedefconfig && \
631 $(CBFSTOOL) $@.tmp add -f $(obj)/config.tmp -n config -t raw; rm -f $(obj)/config.tmp ; fi
632 @printf " REVISION build.h\n"
633 if [ -f $(obj)/build.h ]; then $(CBFSTOOL) $@.tmp add -f $(obj)/build.h -n revision -t raw; fi
635 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
636 $(CBFSTOOL) $@.tmp add-stage -f $(REFCODE_BLOB) -n $(CONFIG_CBFS_PREFIX)/refcode -c $(CBFS_COMPRESS_FLAG)
638 ifeq ($(CONFIG_PXE_ROM),y)
639 $(CBFSTOOL) $@.tmp add -f $(CONFIG_PXE_ROM_FILE) -n pci$(CONFIG_PXE_ROM_ID).rom -t raw
641 ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
642 ifeq ($(CONFIG_CPU_MICROCODE_ADDED_DURING_BUILD),y)
643 @printf " UPDATE-FIT \n"
644 $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
647 ifeq ($(CONFIG_INCLUDE_CONFIG_FILE),y)
648 @printf " CONFIG $(PAYLOAD_CONFIG)\n"
649 if [ -f "$(PAYLOAD_CONFIG)" ]; then \
650 $(CBFSTOOL) $@.tmp add -f "$(PAYLOAD_CONFIG)" -n payload_config -t raw; \
652 @printf " REVISION $(PAYLOAD_VERSION)\n"
653 if [ -f "$(PAYLOAD_VERSION)" ]; then \
654 $(CBFSTOOL) $@.tmp add -f "$(PAYLOAD_VERSION)" -n payload_revision -t raw; \
657 ifeq ($(CONFIG_SEPARATE_VERSTAGE),y)
658 $(CBFSTOOL) $@.tmp add-stage -f $(VERSTAGE_FILE) -n $(CONFIG_CBFS_PREFIX)/verstage $(CBFSTOOL_VERSTAGE_OPTS)
661 @printf " CBFSPRINT $(subst $(obj)/,,$(@))\n\n"
664 cbfs-files-$(CONFIG_BOOTSPLASH) += bootsplash.jpg
665 bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
666 bootsplash.jpg-type := bootsplash
668 $(obj)/coreboot.pre: $(objcbfs)/romstage.elf $(obj)/coreboot.pre1 $(CBFSTOOL)
669 @printf " CBFS $(subst $(obj)/,,$(@))\n"
670 cp $(obj)/coreboot.pre1 $@.tmp
671 $(CBFSTOOL) $@.tmp add-stage \
672 -f $(objcbfs)/romstage.elf \
673 -n $(CONFIG_CBFS_PREFIX)/romstage -c none \
677 cbfs-files-$(CONFIG_BOARD_ID_MANUAL) += board_id
678 board_id-file := $(obj)/board_id
682 printf $(CONFIG_BOARD_ID_STRING) > $@
685 echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp
686 $(MAKE) -C "util/$(UTIL)" distclean > /dev/null 2>&1
687 echo "<testcase classname='$(UTIL)' name='$(UTIL)'>" >> $@.tmp
688 $(MAKE) -C "util/$(UTIL)" >> $@.tmp.2 2>&1 && type="system-out" || type="failure"; \
689 if [ "$$type" = "failure" ]; then \
690 echo "<failure type='buildFailed'>" >> $@.tmp; \
692 echo "<$$type>" >> $@.tmp; \
694 echo '<![CDATA[' >> $@.tmp; \
695 cat $@.tmp.2 >> $@.tmp; \
696 echo "]]></$$type>" >>$@.tmp
698 echo "</testcase>" >> $@.tmp
699 echo "</testsuite>" >> $@.tmp
700 mv $@.tmp "util/$(UTIL)/$@"
706 JENKINS_PAYLOAD?=none
709 util/lint/lint lint-stable --junit
710 util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD) -x -X $(top)/abuild-chromeos.xml
711 util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD)
712 (cd payloads/libpayload; unset COREBOOT_BUILD_DIR; $(MAKE) $(if $(JENKINS_NOCCACHE),,CONFIG_LP_CCACHE=y) V=$(V) Q=$(Q) junit.xml)
713 $(foreach tool, $(TOOLLIST), $(MAKE) V=$(V) Q=$(Q) UTIL="$(tool)" MFLAGS= MAKEFLAGS= junit.xml; )