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.
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))
21 CONFIG_FMDFILE:=$(call strip_quotes,$(CONFIG_FMDFILE))
23 #######################################################################
24 # misleadingly named, this is the coreboot version
25 export KERNELVERSION := $(strip $(if $(GIT),\
26 $(shell git describe --dirty --always || git describe),\
27 $(if $(wildcard $(top)/.coreboot-version),\
28 $(shell cat $(top)/.coreboot-version),\
29 coreboot-unknown$(KERNELREVISION))))
31 #######################################################################
32 # Basic component discovery
33 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
36 ## Final build results, which CBFSTOOL uses to create the final
37 ## rom image file, are placed under $(objcbfs).
38 ## These typically have suffixes .debug .elf .bin and .map
39 export objcbfs := $(obj)/cbfs/$(CONFIG_CBFS_PREFIX)
41 ## Based on the active configuration, Makefile conditionally collects
42 ## the required assembly includes and saves them in a file.
43 ## Such files that do not have a clear one-to-one relation to a source
44 ## file under src/ are placed and built under $(objgenerated)
45 export objgenerated := $(obj)/generated
47 #######################################################################
48 # root rule to resolve if in build mode (ie. configuration exists)
49 real-target: $(obj)/config.h coreboot
50 coreboot: build-dirs $(obj)/coreboot.rom $(obj)/cbfstool $(obj)/rmodtool
52 #######################################################################
54 PHONY+= clean-abuild coreboot lint lint-stable build-dirs
56 #######################################################################
57 # root source directories of coreboot
58 subdirs-y := src/lib src/commonlib/ src/console src/device src/acpi
59 subdirs-y += src/ec/acpi $(wildcard src/ec/*/*) $(wildcard src/southbridge/*/*)
60 subdirs-y += $(wildcard src/soc/*/*) $(wildcard src/northbridge/*/*)
61 subdirs-y += src/superio $(wildcard src/drivers/*) src/cpu src/vendorcode
62 subdirs-y += util/cbfstool util/sconfig util/nvramtool util/broadcom
63 subdirs-y += $(wildcard src/arch/*)
64 subdirs-y += src/mainboard/$(MAINBOARDDIR)
65 subdirs-y += payloads/external
67 subdirs-y += site-local
69 #######################################################################
70 # Add source classes and their build options
71 classes-y := ramstage romstage bootblock smm smmstub cpu_microcode libverstage verstage
73 # Add dynamic classes for rmodules
74 $(foreach supported_arch,$(ARCH_SUPPORTED), \
75 $(eval $(call define_class,rmodules_$(supported_arch),$(supported_arch))))
76 # Provide a macro to determine environment for free standing rmodules.
77 $(foreach supported_arch,$(ARCH_SUPPORTED), \
78 $(eval rmodules_$(supported_arch)-generic-ccopts += -D__RMODULE__))
80 #######################################################################
81 # Helper functions for math and various file placement matters.
82 # macros work on all formats understood by printf(1)
83 # values are space separated if using more than one value
85 # int-add: adds an arbitrary length list of integers
86 # int-subtract: subtracts the the second of two integers from the first
87 # int-multiply: multiplies an arbitrary length list of integers
88 # int-divide: divides the first integer by the second
89 # int-remainder: arithmetic remainder of the first number divided by the second
90 # int-lt: 1 if the first value is less than the second. 0 otherwise
91 # int-gt: 1 if the first values is greater than the second. 0 otherwise
92 # int-eq: 1 if the two values are equal. 0 otherwise
93 # int-align: align $1 to $2 units
94 # file-size: returns the filesize of the given file
95 _toint=$(shell printf "%d" $1)
96 _int-add2=$(shell expr $(call _toint,$1) + $(call _toint,$2))
97 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)))
98 int-subtract=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) - $(call _toint,$(word 2,$1))))
99 _int-multiply2=$(shell expr $(call _toint,$1) \* $(call _toint,$2))
100 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)))
101 int-divide=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) / $(call _toint,$(word 2,$1))))
102 int-remainder=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) % $(call _toint,$(word 2,$1))))
103 int-lt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \< $(call _toint,$(word 2,$1))))
104 int-gt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \> $(call _toint,$(word 2,$1))))
105 int-eq=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) = $(call _toint,$(word 2,$1))))
106 int-align=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A + \( \( $$B - \( $$A % $$B \) \) % $$B \) )
107 file-size=$(shell cat $1 | wc -c)
109 #######################################################################
110 # Helper functions for ramstage postprocess
116 # files-in-dir-recursive,dir,files
117 files-in-dir-recursive=$(filter $(1)%,$(2))
120 parent-dir=$(dir $(if $(patsubst /%,,$(1)),,/)$(subst $( ),/,$(strip $(subst /, ,$(1)))))
122 # filters out exactly the directory specified
123 # filter-out-dir,dir_to_keep,dirs
124 filter-out-dir=$(filter-out $(1),$(2))
126 # filters out dir_to_keep and all its parents
127 # filter-out-dirs,dir_to_keep,dirs
128 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)))
131 dir-wildcards=$(addsuffix %,$(1))
133 # files-in-dir,dir,files
134 files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(sort $(dir $(2))))),$(call files-in-dir-recursive,$(1),$(2)))
136 #######################################################################
137 # reduce command line length by linking the objects of each
138 # directory into an intermediate file
139 ramstage-postprocess=$$(eval DEPENDENCIES+=$$(addsuffix .d,$$(basename $(1)))) \
140 $(foreach d,$(sort $(dir $(filter-out %.ld,$(1)))), \
141 $(eval $(d)ramstage.a: $(call files-in-dir,$(d),$(filter-out %.ld,$(1))); rm -f $$@ && $(AR_ramstage) rcsT $$@ $$^ ) \
142 $(eval ramstage-objs:=$(d)ramstage.a $(filter-out $(filter-out %.ld, $(call files-in-dir,$(d),$(1))),$(ramstage-objs))))
144 bootblock-generic-ccopts += -D__PRE_RAM__ -D__BOOTBLOCK__
145 romstage-generic-ccopts += -D__PRE_RAM__ -D__ROMSTAGE__
146 ramstage-generic-ccopts += -D__RAMSTAGE__
147 ifeq ($(CONFIG_TRACE),y)
148 ramstage-c-ccopts += -finstrument-functions
150 ifeq ($(CONFIG_COVERAGE),y)
151 ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
154 # try to fetch non-optional submodules if the source is under git
155 forgetthis:=$(if $(GIT),$(shell git submodule update --init))
156 ifeq ($(CONFIG_USE_BLOBS),y)
157 # this is necessary because 3rdparty/blobs is update=none, and so is ignored
158 # unless explicitly requested and enabled through --checkout
159 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/blobs))
162 ramstage-c-deps:=$$(OPTION_TABLE_H)
163 romstage-c-deps:=$$(OPTION_TABLE_H)
164 libverstage-c-deps:=$$(OPTION_TABLE_H)
165 verstage-c-deps:=$$(OPTION_TABLE_H)
166 bootblock-c-deps:=$$(OPTION_TABLE_H)
168 # Add handler to copy linker scripts
169 define generic-objs_ld_template_gen
170 de$(EMPTY)fine $(1)-objs_ld_template
171 $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h
172 @printf " CP $$$$(subst $$$$(obj)/,,$$$$(@))\n"
173 $$(CC_$(1)) -MMD $$(CPPFLAGS_$(1)) $$($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h -MT $$$$@ -o $$$$@ $$$$<
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 $(CONFIG_CBFS_PREFIX)/$(1).aml-file = $(obj)/$(1).aml
198 $(CONFIG_CBFS_PREFIX)/$(1).aml-type = raw
199 $(CONFIG_CBFS_PREFIX)/$(1).aml-compression = none
200 cbfs-files-$(if $(2),$(2),y) += $(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 ifeq ($(CONFIG_IASL_WARNINGS_ARE_ERRORS),y)
205 cd $$(dir $$@); $(IASL) -we -p $$(notdir $$@) $$(notdir $$@)
207 cd $$(dir $$@); $(IASL) -p $$(notdir $$@) $$(notdir $$@)
211 #######################################################################
212 # Parse plaintext cmos defaults into binary format
214 # arg2: binary file name
215 cbfs-files-processor-nvramtool= \
216 $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
217 printf " CREATE $(2) (from $(1))\n"; \
218 $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && \
221 #######################################################################
222 # Link VSA binary to ELF-ish stage
224 # arg2: binary file name
225 cbfs-files-processor-vsa= \
226 $(eval $(2): $(1) ; \
227 printf " CREATE $(2) (from $(1))\n"; \
228 $(OBJCOPY_ramstage) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && \
229 $(LD_ramstage) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
231 #######################################################################
232 # Reduce a .config file to its minimal representation
235 cbfs-files-processor-defconfig= \
236 $(eval $(2): $(1) $(obj)/build.h; \
237 printf " CREATE $(2) (from $(1))\n"; \
238 printf "\# This image was built using coreboot " > $(2).tmp && \
239 grep "\<COREBOOT_VERSION\>" $(obj)/build.h |cut -d\" -f2 >> $(2).tmp && \
240 $(MAKE) DOTCONFIG=$(1) DEFCONFIG=$(2).tmp2 savedefconfig && \
241 cat $(2).tmp2 >> $(2).tmp && \
243 \mv -f $(2).tmp $(2))
245 #######################################################################
246 # Add handler for arbitrary files in CBFS
247 $(call add-special-class,cbfs-files)
248 cbfs-files-handler= \
249 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
250 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
251 $(eval tmp-cbfs-file:= ) \
253 $(if $(wildcard $(1)$($(2)-file)), \
254 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
255 $(eval tmp-cbfs-file:= $($(2)-file)))) \
256 $(if $(strip $($(2)-required)), \
257 $(if $(wildcard $(tmp-cbfs-file)),, \
258 $(info This build configuration requires $($(2)-required)) \
259 $(eval FAILBUILD:=1) \
261 $(if $(strip $($(2)-align)), \
262 $(if $(strip $($(2)-position)), \
263 $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
264 $(eval FAILBUILD:=1) \
266 $(eval _cbfs-bucket:=regular ) \
267 $(if $(strip $($(2)-position)), \
268 $(eval _cbfs-bucket:=fixed)) \
269 $(if $(strip $($(2)-align)), \
270 $(eval _cbfs-bucket:=aligned)) \
271 $(if $(tmp-cbfs-method), \
272 $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
273 $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
274 $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
275 $(if $(tmp-cbfs-file), \
276 $(eval cbfs-files-$(_cbfs-bucket) += $(subst $(spc),*,$(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align)|$($(2)-options)))) \
277 $(eval $(2)-name:=) \
278 $(eval $(2)-type:=) \
279 $(eval $(2)-compression:=) \
280 $(eval $(2)-position:=) \
281 $(eval $(2)-required:=) \
282 $(eval $(2)-options:=) \
285 #######################################################################
286 # a variety of flags for our build
287 CBFS_COMPRESS_FLAG:=none
288 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
289 CBFS_COMPRESS_FLAG:=LZMA
292 CBFS_PAYLOAD_COMPRESS_FLAG:=none
293 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
294 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
297 ifneq ($(CONFIG_LOCALVERSION),"")
298 export COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
301 CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -I$(obj)
302 CPPFLAGS_common += -Isrc/device/oprom/include
303 CPPFLAGS_common += -include $(src)/include/kconfig.h
305 CFLAGS_common += -pipe -g -nostdinc
306 CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
307 CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
308 CFLAGS_common += -Wstrict-aliasing -Wshadow
309 CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
310 CFLAGS_common += -ffunction-sections -fdata-sections
312 LDFLAGS_common := --gc-sections -nostdlib -nostartfiles -static --emit-relocs
314 ifeq ($(CONFIG_COMPILER_GCC),y)
315 # cf. commit f69a99db (coreboot: x86: enable gc-sections)
316 CFLAGS_common += -Wno-unused-but-set-variable
319 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
320 CFLAGS_common += -Werror
322 ifneq ($(GDB_DEBUG),)
328 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
329 $(objutil)/ifdfake $(objutil)/options $(objutil)/amdfwtool \
330 $(objutil)/cbootimage $(objutil)/bimgtool
332 #######################################################################
333 # generate build support files
334 $(obj)/build.h: .xcompile
335 @printf " GEN build.h\n"
337 util/genbuild_h/genbuild_h.sh > $(obj)/build.ht
338 mv $(obj)/build.ht $(obj)/build.h
341 mkdir -p $(objcbfs) $(objgenerated)
343 #######################################################################
345 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
346 FMAPTOOL:=$(objutil)/cbfstool/fmaptool
347 RMODTOOL:=$(objutil)/cbfstool/rmodtool
349 $(obj)/cbfstool: $(CBFSTOOL)
352 $(obj)/fmaptool: $(FMAPTOOL)
355 $(obj)/rmodtool: $(RMODTOOL)
358 _WINCHECK=$(shell uname -o 2> /dev/null)
360 ifeq ($(_WINCHECK),Msys)
361 STACK=-Wl,--stack,16384000
363 ifeq ($(_WINCHECK),Cygwin)
364 STACK=-Wl,--stack,16384000
367 # this allows ccache to prepend itself
368 # (ccache handling happens first)
369 ROMCC_BIN= $(objutil)/romcc/romcc
371 $(ROMCC_BIN): $(top)/util/romcc/romcc.c
372 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
373 @# Note: Adding -O2 here might cause problems. For details see:
374 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
375 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
377 IFDTOOL:=$(objutil)/ifdtool/ifdtool
378 $(IFDTOOL): $(top)/util/ifdtool/ifdtool.c
379 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
380 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
382 IFDFAKE:=$(objutil)/ifdfake/ifdfake
383 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
384 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
385 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
387 AMDFWTOOL:=$(objutil)/amdfwtool/amdfwtool
388 $(AMDFWTOOL): $(top)/util/amdfwtool/amdfwtool.c
389 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
390 $(HOSTCC) $(HOSTCFLAGS) -DCONFIG_ROM_SIZE=$(CONFIG_ROM_SIZE) -o $@ $<
392 CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
394 subdirs-y += util/nvidia
396 BIMGTOOL:=$(objutil)/bimgtool/bimgtool
397 $(BIMGTOOL): $(top)/util/bimgtool/bimgtool.c
398 @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
399 $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
401 #######################################################################
402 # needed objects that every mainboard uses
403 # Creation of these is architecture and mainboard independent
404 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
405 @printf " SCONFIG $(subst $(src)/,,$(<))\n"
406 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
407 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
409 ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
410 romstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
411 verstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
413 $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
414 @printf " CC $(subst $(obj)/,,$(@))\n"
415 $(CC_ramstage) -MMD $(CFLAGS_ramstage) $(CPPFLAGS_ramstage) $(ramstage-c-ccopts) -c -o $@ $<
417 $(obj)/%.romstage.o $(abspath $(obj))/%.romstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
418 @printf " CC $(subst $(obj)/,,$(@))\n"
419 $(CC_romstage) -MMD $(CFLAGS_romstage) $(CPPFLAGS_romstage) $(romstage-c-ccopts) -c -o $@ $<
421 $(obj)/%.bootblock.o $(abspath $(obj))/%.bootblock.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H)
422 @printf " CC $(subst $(obj)/,,$(@))\n"
423 $(CC_bootblock) -MMD $(CFLAGS_bootblock) $(CPPFLAGS_bootblock) $(bootblock-c-ccopts) -c -o $@ $<
425 $(objgenerated)/libverstage.a: $$(libverstage-objs)
427 $(AR_libverstage) rcsT $@ $^
429 #######################################################################
432 rm -rf coreboot-builds
434 clean-for-update-target:
435 rm -f $(obj)/ramstage* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
436 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
437 rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
438 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
439 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
440 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
441 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
442 rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
443 $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean
446 rm -f $(obj)/coreboot*
448 #######################################################################
449 # Development utilities
452 @echo ldscripts=$(ldscripts)
455 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
463 for hook in commit-msg pre-commit ; do \
464 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o \
465 ! -x .git/hooks/$$hook ]; then \
466 sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/$$hook > .git/hooks/$$hook; \
467 chmod +x .git/hooks/$$hook; \
470 # Now set up thehooks for 3rdparty/blobs
471 if [ -d .git/modules/3rdparty -a \
472 \( util/gitconfig/commit-msg -nt .git/modules/3rdparty/hooks/commit-msg -o \
473 ! -x .git/modules/3rdparty/hooks/commit-msg \) ]; then \
474 sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/commit-msg > .git/modules/3rdparty/hooks/commit-msg; \
475 chmod +x .git/modules/3rdparty/hooks/commit-msg; \
477 [ -d 3rdparty/blobs ] && cd 3rdparty/blobs && git config remote.origin.push HEAD:refs/for/master
478 git config remote.origin.push HEAD:refs/for/master
479 (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)
481 help_toolchain help::
482 @echo '*** Toolchain targets ***'
483 @echo ' crossgcc - Build coreboot cross-compilers for all platforms'
484 @echo ' crosstools - Build coreboot cross-compiler and GDB for all platforms'
485 @echo ' crossgcc-clean - Remove all built coreboot cross-compilers'
486 @echo ' iasl - Build coreboot IASL compiler (built by all cross targets)'
487 @echo ' clang - Build coreboot clang compiler'
488 @echo ' crossgcc-ARCH - Build cross-compiler for specific architecture'
489 @echo ' crosstools-ARCH - Build cross-compiler with GDB for specific architecture'
490 @echo ' ARCH can be "i386", "x64", "arm", "aarch64", "mips", or "riscv"'
491 @echo ' Use "make [target] CPUS=#" to build toolchain using multiple cores'
494 # For the toolchain builds, use CPUS=x to use multiple processors to build
495 # use BUILDGCC_OPTIONS= to set any crossgcc command line options
496 # Example: BUILDGCC_OPTIONS='-t' will keep temporary files after build
497 crossgcc: clean-for-update
498 $(MAKE) -C util/crossgcc all_without_gdb SKIP_CLANG=1
500 .PHONY: crossgcc crossgcc-i386 crossgcc-x64 crossgcc-arm crossgcc-aarch64 \
501 crossgcc-mips crossgcc-riscv crossgcc-clean iasl clang tools \
502 crosstools-i386 crosstools-x64 crosstools-arm crosstools-aarch64 \
503 crosstools-mips crosstools-riscv
505 crossgcc-i386: clean-for-update
506 $(MAKE) -C util/crossgcc build-i386 SKIP_GDB=1
508 crossgcc-x64: clean-for-update
509 $(MAKE) -C util/crossgcc build-x64 SKIP_GDB=1
511 crossgcc-arm: clean-for-update
512 $(MAKE) -C util/crossgcc build-armv7a SKIP_GDB=1
514 crossgcc-aarch64: clean-for-update
515 $(MAKE) -C util/crossgcc build-aarch64 SKIP_GDB=1
517 crossgcc-mips: clean-for-update
518 $(MAKE) -C util/crossgcc build-mips SKIP_GDB=1
520 crossgcc-riscv: clean-for-update
521 $(MAKE) -C util/crossgcc build-riscv SKIP_GDB=1
523 crosstools: clean-for-update
524 $(MAKE) -C util/crossgcc all_with_gdb SKIP_CLANG=1
526 iasl: clean-for-update
527 $(MAKE) -C util/crossgcc build_iasl
529 clang: clean-for-update
530 $(MAKE) -C util/crossgcc build_clang
532 crosstools-i386: clean-for-update
533 $(MAKE) -C util/crossgcc build-i386
535 crosstools-x64: clean-for-update
536 $(MAKE) -C util/crossgcc build-x64
538 crosstools-arm: clean-for-update
539 $(MAKE) -C util/crossgcc build-armv7a
541 crosstools-aarch64: clean-for-update
542 $(MAKE) -C util/crossgcc build-aarch64
544 crosstools-mips: clean-for-update
545 $(MAKE) -C util/crossgcc build-mips
547 crosstools-riscv: clean-for-update
548 $(MAKE) -C util/crossgcc build-riscv
550 crossgcc-clean: clean-for-update
551 $(MAKE) -C util/crossgcc clean
553 tools: $(objutil)/kconfig/conf $(CBFSTOOL) $(FMAPTOOL) $(RMODTOOL) $(objutil)/nvramtool/nvramtool $(ROMCC_BIN) $(objutil)/sconfig/sconfig $(IFDTOOL) $(IFDFAKE) $(CBOOTIMAGE) $(AMDFWTOOL)
555 ###########################################################################
556 # Common recipes for all stages
557 ###########################################################################
559 # loadaddr can determine the load address of a stage, which may be needed for
560 # platform-specific image headers (only works *after* the stage has been built)
561 loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
562 sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
564 # find-substr is required for stages like romstage_null and romstage_xip to
565 # eliminate the _* part of the string
566 find-substr = $(word 1,$(subst _, ,$(1)))
568 # find-class is used to identify the class from the name of the stage
569 # The input to this macro can be something like romstage.x or romstage.x.y
570 # find-class recursively strips off the suffixes to extract the exact class name
571 # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
572 # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
573 # and remove .x the next time and finally return romstage
574 find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
576 # Bootblocks are not CBFS stages. coreboot is currently expecting the bss to
577 # be cleared by the loader of the stage. For ARM SoCs that means one needs to
578 # include the bss section in the binary so the BootROM clears the bss on
579 # loading of the bootblock stage. Achieve this by marking the bss section
580 # loadable,allocatable, and data. Do the same for the .data section in case
581 # it's marked as NOBITS.
582 $(objcbfs)/bootblock.raw.bin: $(objcbfs)/bootblock.elf
583 @printf " OBJCOPY $(notdir $(@))\n"
584 $(OBJCOPY_bootblock) --set-section-flags .bss=load,alloc,data --set-section-flags .data=load,alloc,data $< $<.tmp
585 $(OBJCOPY_bootblock) -O binary $<.tmp $@
587 $(objcbfs)/%.bin: $(objcbfs)/%.raw.bin
590 $(objcbfs)/%.elf: $(objcbfs)/%.debug
591 $(eval class := $(call find-class,$(@F)))
592 @printf " OBJCOPY $(subst $(obj)/,,$(@))\n"
594 $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
595 $(OBJCOPY_$(class)) --strip-debug $@.tmp
596 $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
599 ###########################################################################
600 # Build the final rom image
601 ###########################################################################
603 extract_nth=$(subst *,$(spc),$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-))))
606 printf " CBFS $(call extract_nth,2,$(file))\n"; \
608 add$(if $(filter stage,$(call extract_nth,3,$(file))),-stage)$(if $(filter payload,$(call extract_nth,3,$(file))),-payload) \
609 -f $(call extract_nth,1,$(file)) \
610 -n $(call extract_nth,2,$(file)) \
611 $(if $(filter-out stage,$(call extract_nth,3,$(file))),-t $(call extract_nth,3,$(file))) \
612 $(if $(call extract_nth,4,$(file)),-c $(call extract_nth,4,$(file))) \
613 $(call extract_nth,7,$(file))
615 cbfs-files=$(cbfs-files-fixed) $(cbfs-files-aligned) $(cbfs-files-regular)
616 ifneq ($(CONFIG_UPDATE_IMAGE),y)
618 $(foreach file,$(cbfs-files), \
619 $(if $(call extract_nth,6,$(file)),$(cbfs-add-cmd) -a $(call extract_nth,6,$(file)) &&, \
620 $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&))
621 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
623 ifeq ($(CONFIG_FMDFILE),)
624 # For a description of the flash layout described by these variables, check
625 # the $(DEFAULT_FLASHMAP) .fmd files.
626 ifeq ($(CONFIG_ARCH_X86),y)
627 DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default-x86.fmd
629 FMAP_ROM_ADDR := $(call int-subtract, 0x100000000 $(CONFIG_ROM_SIZE))
630 FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
631 # entire "BIOS" region (everything directly of concern to the host system)
632 # relative to ROM_BASE
633 FMAP_BIOS_BASE := $(call int-subtract, $(CONFIG_ROM_SIZE) $(CONFIG_CBFS_SIZE))
634 FMAP_BIOS_SIZE := $(CONFIG_CBFS_SIZE)
635 # position and size of flashmap, relative to BIOS_BASE
637 FMAP_FMAP_SIZE := 0x100
638 # position and size of CBFS, relative to BIOS_BASE
639 FMAP_CBFS_BASE := $(FMAP_FMAP_SIZE)
640 FMAP_CBFS_SIZE := $(call int-subtract, $(FMAP_BIOS_SIZE) $(FMAP_FMAP_SIZE))
642 DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default.fmd
645 FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
646 # entire "BIOS" region (everything directly of concern to the host system)
647 # relative to ROM_BASE
649 FMAP_BIOS_SIZE := $(CONFIG_CBFS_SIZE)
650 # position and size of flashmap, relative to BIOS_BASE
651 FMAP_FMAP_BASE := 0x20000
652 FMAP_FMAP_SIZE := 0x100
653 # position and size of CBFS, relative to BIOS_BASE
654 FMAP_CBFS_BASE := $(call int-add,$(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE))
655 FMAP_CBFS_SIZE := $(call int-subtract,$(FMAP_BIOS_SIZE) $(FMAP_CBFS_BASE))
658 $(obj)/fmap.fmd: $(top)/Makefile.inc $(DEFAULT_FLASHMAP)
659 sed -e "s,##ROM_BASE##,$(FMAP_ROM_ADDR)," \
660 -e "s,##ROM_SIZE##,$(FMAP_ROM_SIZE)," \
661 -e "s,##BIOS_BASE##,$(FMAP_BIOS_BASE)," \
662 -e "s,##BIOS_SIZE##,$(FMAP_BIOS_SIZE)," \
663 -e "s,##FMAP_BASE##,$(FMAP_FMAP_BASE)," \
664 -e "s,##FMAP_SIZE##,$(FMAP_FMAP_SIZE)," \
665 -e "s,##CBFS_BASE##,$(FMAP_CBFS_BASE)," \
666 -e "s,##CBFS_SIZE##,$(FMAP_CBFS_SIZE)," \
667 $(DEFAULT_FLASHMAP) > $@.tmp
670 $(obj)/fmap.fmd: $(CONFIG_FMDFILE)
674 # generated at the same time as fmap.fmap
675 $(obj)/fmap.h: $(obj)/fmap.fmap
677 $(obj)/fmap.fmap: $(obj)/fmap.fmd $(FMAPTOOL)
678 $(FMAPTOOL) -h $(obj)/fmap.h $< $@
680 $(obj)/coreboot.pre: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL) $$(cpu_ucode_cbfs_file) $(obj)/fmap.fmap
681 $(CBFSTOOL) $@.tmp create -M $(obj)/fmap.fmap
682 ifeq ($(CONFIG_ARCH_X86),y)
683 $(CBFSTOOL) $@.tmp add \
684 -f $(objcbfs)/bootblock.bin \
687 -b -$(call file-size,$(objcbfs)/bootblock.bin)
689 # don't add bootblock to cbfs yet, it's just a waste of space
690 true $(CBFSTOOL) $@.tmp add \
691 -f $(objcbfs)/bootblock.bin \
695 $(CBFSTOOL) $@.tmp write -u \
697 -f $(objcbfs)/bootblock.bin
698 # make space for the CBFS master header pointer. "ptr_" is just
699 # arbitrary 4 bytes that will be overwritten by add-master-header.
700 printf "ptr_" > $@.tmp.2
701 $(CBFSTOOL) $@.tmp add \
703 -n "header pointer" \
708 $(CBFSTOOL) $@.tmp add-master-header
709 $(prebuild-files) true
712 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
713 # Add all cbfs files to image of the form: CONFIG_CBFS_PREFIX/<filename>
715 $(foreach file,$(cbfs-files), \
716 $(CBFSTOOL) $@.tmp remove -n $(call extract_nth,2,$(file)) 2>/dev/null ; \
717 $(if $(call extract_nth,6,$(file)),$(cbfs-add-cmd) -a $(call extract_nth,6,$(file)) &&,\
718 $(cbfs-add-cmd) $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file))) &&))
720 .PHONY: $(obj)/coreboot.pre
721 $(obj)/coreboot.pre: $$(prebuilt-files) $(CBFSTOOL)
722 mv $(obj)/coreboot.rom $@.tmp
723 $(prebuild-files) true
727 ifeq ($(CONFIG_PAYLOAD_LINUX),y)
728 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_COMMAND_LINE))),)
729 ADDITIONAL_PAYLOAD_CONFIG+=-C $(CONFIG_LINUX_COMMAND_LINE)
731 ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),)
732 ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)
736 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
737 REFCODE_BLOB=$(obj)/refcode.rmod
738 $(REFCODE_BLOB): $(RMODTOOL)
739 $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
742 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/ramstage.elf $(CBFSTOOL) $$(INTERMEDIATE)
743 @printf " CBFS $(subst $(obj)/,,$(@))\n"
744 # The full ROM may be larger than the CBFS part, so create an empty
745 # file (filled with \377 = 0xff) and copy the CBFS image over it.
746 dd if=/dev/zero bs=$(call _toint,$(CONFIG_ROM_SIZE)) count=1 2> /dev/null | tr '\000' '\377' > $@.tmp
747 dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
748 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
749 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
750 @printf " SeaBIOS Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
751 $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
754 ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
755 ifeq ($(CONFIG_CPU_MICROCODE_CBFS_GENERATE),y)
756 @printf " UPDATE-FIT \n"
757 $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
761 @printf " CBFSPRINT $(subst $(obj)/,,$(@))\n\n"
763 ifeq ($(CONFIG_IASL_WARNINGS_ARE_ERRORS),)
764 @printf "\n***** WARNING: IASL warnings as errors is disabled! *****\n"
765 @printf "***** Please fix the ASL for this platform. *****\n\n"
768 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/romstage
769 $(CONFIG_CBFS_PREFIX)/romstage-file := $(objcbfs)/romstage.elf
770 $(CONFIG_CBFS_PREFIX)/romstage-type := stage
771 $(CONFIG_CBFS_PREFIX)/romstage-compression := none
772 ifeq ($(CONFIG_ARCH_ROMSTAGE_ARM),y)
773 $(CONFIG_CBFS_PREFIX)/romstage-options := -b 0
775 ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32)$(CONFIG_ARCH_ROMSTAGE_X86_64),y)
776 # Use a 64 byte alignment to provide a minimum alignment
777 # requirement for the overall romstage. While the first object within
778 # romstage could have a 4 byte minimum alignment that doesn't mean the linker
779 # won't decide the entire section should be aligned to a larger value. In the
780 # future cbfstool should add XIP files proper and honor the alignment
781 # requirements of the program segment.
783 # Make sure that segment for .car.data is ignored while adding romstage.
784 $(CONFIG_CBFS_PREFIX)/romstage-align := 64
785 $(CONFIG_CBFS_PREFIX)/romstage-options := --xip -S .car.data -P $(CONFIG_XIP_ROM_SIZE)
788 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/ramstage
789 $(CONFIG_CBFS_PREFIX)/ramstage-file := $(objcbfs)/ramstage.elf
790 $(CONFIG_CBFS_PREFIX)/ramstage-type := stage
791 $(CONFIG_CBFS_PREFIX)/ramstage-compression := $(CBFS_COMPRESS_FLAG)
793 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/payload
794 $(CONFIG_CBFS_PREFIX)/payload-file := $(CONFIG_PAYLOAD_FILE)
795 $(CONFIG_CBFS_PREFIX)/payload-type := payload
796 $(CONFIG_CBFS_PREFIX)/payload-compression := $(CBFS_PAYLOAD_COMPRESS_FLAG)
797 $(CONFIG_CBFS_PREFIX)/payload-options := $(ADDITIONAL_PAYLOAD_CONFIG)
799 cbfs-files-$(CONFIG_HAVE_REFCODE_BLOB) += $(CONFIG_CBFS_PREFIX)/refcode
800 $(CONFIG_CBFS_PREFIX)/refcode-file := $(REFCODE_BLOB)
801 $(CONFIG_CBFS_PREFIX)/refcode-type := stage
802 $(CONFIG_CBFS_PREFIX)/refcode-compression := $(CBFS_COMPRESS_FLAG)
804 cbfs-files-$(CONFIG_SEABIOS_VGA_COREBOOT) += vgaroms/seavgabios.bin
805 vgaroms/seavgabios.bin-file := $(CONFIG_PAYLOAD_VGABIOS_FILE)
806 vgaroms/seavgabios.bin-type := raw
808 cbfs-files-$(CONFIG_PXE_ROM) += pci$(CONFIG_PXE_ROM_ID).rom
809 pci$(CONFIG_PXE_ROM_ID).rom-file := $(CONFIG_PXE_ROM_FILE)
810 pci$(CONFIG_PXE_ROM_ID).rom-type := raw
812 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += config
813 config-file := $(DOTCONFIG):defconfig
816 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += revision
817 revision-file := $(obj)/build.h
820 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += payload_config
821 payload_config-file := $(PAYLOAD_CONFIG)
822 payload_config-type := raw
824 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += payload_revision
825 payload_revision-file := $(PAYLOAD_VERSION)
826 payload_revision-type := raw
828 cbfs-files-$(CONFIG_BOOTSPLASH_IMAGE) += bootsplash.jpg
829 bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
830 bootsplash.jpg-type := bootsplash
832 cbfs-files-$(CONFIG_BOARD_ID_MANUAL) += board_id
833 board_id-file := $(obj)/board_id
837 printf $(CONFIG_BOARD_ID_STRING) > $@
840 echo "Building $(UTIL)"
841 echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp
842 echo "<testcase classname='$(UTIL)' name='$(UTIL)'>" >> $@.tmp
843 -$(MAKE) -j $(CPUS) -C "util/$(UTIL)" clean distclean > $@.tmp.2 2>&1
844 $(MAKE) -j $(CPUS) -C "util/$(UTIL)" >> $@.tmp.2 2>&1 && type="system-out" || type="failure"; \
846 if [ "$$type" = "failure" ]; then \
847 echo "<failure type='buildFailed'>" >> $@.tmp; \
848 echo "Building $(UTIL) Failed"; \
850 echo "<$$type>" >> $@.tmp; \
851 echo "Building $(UTIL) Succeeded"; \
853 echo '<![CDATA[' >> $@.tmp; \
854 cat $@.tmp.2 >> $@.tmp; \
855 echo "]]></$$type>" >>$@.tmp
857 echo "</testcase>" >> $@.tmp
858 echo "</testsuite>" >> $@.tmp
859 mv $@.tmp "util/$(UTIL)/$@"
870 JENKINS_PAYLOAD?=none
873 util/lint/lint lint-stable --junit
874 util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD) -x -X $(top)/abuild-chromeos.xml
875 util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD)
876 (cd payloads/libpayload; unset COREBOOT_BUILD_DIR; $(MAKE) $(if $(JENKINS_NOCCACHE),,CONFIG_LP_CCACHE=y) V=$(V) Q=$(Q) junit.xml)
877 $(foreach tool, $(TOOLLIST), $(MAKE) CPUS=$(CPUS) V=$(V) Q=$(Q) UTIL="$(tool)" MFLAGS= MAKEFLAGS= junit.xml; )