soc/intel/skylake: Use Intel timer common code
[coreboot.git] / Makefile.inc
blob99110ed53814ad2f0c3d9ce64245a3143b285943
1 ##
2 ## This file is part of the coreboot project.
3 ##
4 ## Copyright (C) 2011 secunet Security Networks AG
5 ##
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; version 2 of the License.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
16 ifneq ($(NOCOMPILE),1)
17 GIT:=$(shell [ -e "$(top)/.git" ] && command -v git)
18 else
19 GIT:=
20 endif
22 #######################################################################
23 # normalize Kconfig variables in a central place
24 CONFIG_CBFS_PREFIX:=$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
25 CONFIG_FMDFILE:=$(call strip_quotes,$(CONFIG_FMDFILE))
26 CONFIG_DEVICETREE:=$(call strip_quotes, $(CONFIG_DEVICETREE))
28 #######################################################################
29 # misleadingly named, this is the coreboot version
30 ifeq ($(KERNELVERSION),)
31 ifeq ($(BUILD_TIMELESS),1)
32 export KERNELVERSION := TIMELESS
33 else
34 export KERNELVERSION := $(strip $(if $(GIT),\
35         $(shell git describe --dirty --always || git describe),\
36         $(if $(wildcard $(top)/.coreboot-version),\
37                 $(shell cat $(top)/.coreboot-version),\
38                 coreboot-unknown$(KERNELREVISION))))
39 endif
40 endif
42 #######################################################################
43 # Basic component discovery
44 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
45 VARIANT_DIR:=$(call strip_quotes,$(CONFIG_VARIANT_DIR))
46 export MAINBOARDDIR
47 export VARIANT_DIR
49 ## Final build results, which CBFSTOOL uses to create the final
50 ## rom image file, are placed under $(objcbfs).
51 ## These typically have suffixes .debug .elf .bin and .map
52 export objcbfs := $(obj)/cbfs/$(CONFIG_CBFS_PREFIX)
54 ## Based on the active configuration, Makefile conditionally collects
55 ## the required assembly includes and saves them in a file.
56 ## Such files that do not have a clear one-to-one relation to a source
57 ## file under src/ are placed and built under $(objgenerated)
58 export objgenerated := $(obj)/generated
60 #######################################################################
61 # root rule to resolve if in build mode (ie. configuration exists)
62 real-target: $(obj)/config.h coreboot files_added
63 coreboot: build-dirs $(obj)/coreboot.rom $(obj)/cbfstool $(obj)/rmodtool $(obj)/ifwitool
65 # This target can be used in site local to run scripts or additional
66 # targets after the build completes by creating a Makefile.inc in the
67 # site-local directory with a target named 'build_complete::'
68 build_complete:: coreboot
69         printf "\nBuilt %s (%s)\n" $(MAINBOARDDIR) \
70                 $(CONFIG_MAINBOARD_PART_NUMBER)
72 # This target can be used to run rules after all files were added to CBFS,
73 # for example to process FMAP regions or the entire image.
74 files_added:: build_complete
76 #######################################################################
77 # our phony targets
78 PHONY+= clean-abuild coreboot lint lint-stable build-dirs build_complete
80 #######################################################################
81 # root source directories of coreboot
82 subdirs-y := src/lib src/commonlib/ src/console src/device src/acpi
83 subdirs-y += src/ec/acpi $(wildcard src/ec/*/*) $(wildcard src/southbridge/*/*)
84 subdirs-y += $(wildcard src/soc/*/*) $(wildcard src/northbridge/*/*)
85 subdirs-y += src/superio
86 subdirs-y += $(wildcard src/drivers/*) $(wildcard src/drivers/*/*)
87 subdirs-y += src/cpu src/vendorcode
88 subdirs-y += util/cbfstool util/sconfig util/nvramtool util/broadcom
89 subdirs-y += util/futility util/marvell util/blobtool
90 subdirs-y += $(wildcard src/arch/*)
91 subdirs-y += src/mainboard/$(MAINBOARDDIR)
92 subdirs-y += src/vboot
93 subdirs-y += payloads payloads/external
95 subdirs-y += site-local
96 subdirs-y += util/checklist
98 #######################################################################
99 # Add source classes and their build options
100 classes-y := ramstage romstage bootblock postcar smm smmstub cpu_microcode verstage
102 # Add dynamic classes for rmodules
103 $(foreach supported_arch,$(ARCH_SUPPORTED), \
104             $(eval $(call define_class,rmodules_$(supported_arch),$(supported_arch))))
105 # Provide a macro to determine environment for free standing rmodules.
106 $(foreach supported_arch,$(ARCH_SUPPORTED), \
107         $(eval rmodules_$(supported_arch)-generic-ccopts += -D__RMODULE__))
109 #######################################################################
110 # Helper functions for math, strings, and various file placement matters.
111 # macros work on all formats understood by printf(1)
112 # values are space separated if using more than one value
114 # int-add:       adds an arbitrary length list of integers
115 # int-subtract:  subtracts the the second of two integers from the first
116 # int-multiply:  multiplies an arbitrary length list of integers
117 # int-divide:    divides the first integer by the second
118 # int-remainder: arithmetic remainder of the first number divided by the second
119 # int-lt:        1 if the first value is less than the second.  0 otherwise
120 # int-gt:        1 if the first values is greater than the second.  0 otherwise
121 # int-eq:        1 if the two values are equal.  0 otherwise
122 # int-align:     align $1 to $2 units
123 # file-size:     returns the filesize of the given file
124 # tolower:       returns the value in all lowercase
125 # toupper:       returns the value in all uppercase
126 # ws_to_under:   returns the value with any whitespace changed to underscores
127 _toint=$(shell printf "%d" $1)
128 _int-add2=$(shell expr $(call _toint,$1) + $(call _toint,$2))
129 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)))
130 int-subtract=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) - $(call _toint,$(word 2,$1))))
131 _int-multiply2=$(shell expr $(call _toint,$1) \* $(call _toint,$2))
132 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)))
133 int-divide=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) / $(call _toint,$(word 2,$1))))
134 int-remainder=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) % $(call _toint,$(word 2,$1))))
135 int-lt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \< $(call _toint,$(word 2,$1))))
136 int-gt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \> $(call _toint,$(word 2,$1))))
137 int-eq=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) = $(call _toint,$(word 2,$1))))
138 int-align=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A + \( \( $$B - \( $$A % $$B \) \) % $$B \) )
139 file-size=$(strip $(shell cat $1 | wc -c))
140 tolower=$(shell echo '$1' | tr '[:upper:]' '[:lower:]')
141 toupper=$(shell echo '$1' | tr '[:lower:]' '[:upper:]')
142 ws_to_under=$(shell echo '$1' | tr ' \t' '_')
144 #######################################################################
145 # Helper functions for ramstage postprocess
146 spc :=
147 spc +=
148 $(spc) :=
149 $(spc) +=
150 comma := ,
152 # files-in-dir-recursive,dir,files
153 files-in-dir-recursive=$(filter $(1)%,$(2))
155 # parent-dir,dir/
156 parent-dir=$(dir $(if $(patsubst /%,,$(1)),,/)$(subst $( ),/,$(strip $(subst /, ,$(1)))))
158 # filters out exactly the directory specified
159 # filter-out-dir,dir_to_keep,dirs
160 filter-out-dir=$(filter-out $(1),$(2))
162 # filters out dir_to_keep and all its parents
163 # filter-out-dirs,dir_to_keep,dirs
164 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)))
166 # dir-wildcards,dirs
167 dir-wildcards=$(addsuffix %,$(1))
169 # files-in-dir,dir,files
170 files-in-dir=$(filter-out $(call dir-wildcards,$(call filter-out-dirs,$(1),$(sort $(dir $(2))))),$(call files-in-dir-recursive,$(1),$(2)))
172 #######################################################################
173 # reduce command line length by linking the objects of each
174 # directory into an intermediate file
175 ramstage-postprocess=$$(eval DEPENDENCIES+=$$(addsuffix .d,$$(basename $(1)))) \
176         $(foreach d,$(sort $(dir $(filter-out %.ld,$(1)))), \
177         $(eval $(d)ramstage.a: $(call files-in-dir,$(d),$(filter-out %.ld,$(1))); rm -f $$@ && $(AR_ramstage) rcsT $$@ $$^ ) \
178         $(eval ramstage-objs:=$(d)ramstage.a $(filter-out $(filter-out %.ld, $(call files-in-dir,$(d),$(1))),$(ramstage-objs))))
180 bootblock-generic-ccopts += -D__PRE_RAM__ -D__BOOTBLOCK__
181 romstage-generic-ccopts += -D__PRE_RAM__ -D__ROMSTAGE__
182 ramstage-generic-ccopts += -D__RAMSTAGE__
183 ifeq ($(CONFIG_TRACE),y)
184 ramstage-c-ccopts += -finstrument-functions
185 endif
186 ifeq ($(CONFIG_COVERAGE),y)
187 ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
188 endif
190 ifneq ($(UPDATED_SUBMODULES),1)
191 # try to fetch non-optional submodules if the source is under git
192 forgetthis:=$(if $(GIT),$(shell git submodule update --init))
193 ifeq ($(CONFIG_USE_BLOBS),y)
194 # this is necessary because 3rdparty/blobs is update=none, and so is ignored
195 # unless explicitly requested and enabled through --checkout
196 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/blobs))
197 endif
198 export UPDATED_SUBMODULES:=1
199 endif
201 ramstage-c-deps:=$$(OPTION_TABLE_H)
202 romstage-c-deps:=$$(OPTION_TABLE_H)
203 verstage-c-deps:=$$(OPTION_TABLE_H)
204 bootblock-c-deps:=$$(OPTION_TABLE_H)
205 $(foreach type,ads adb, \
206   $(foreach stage,$(COREBOOT_STANDARD_STAGES), \
207     $(eval $(stage)-$(type)-deps := $(obj)/libgnat-$(ARCH-$(stage)-y)/libgnat.a)))
209 # Add handler to copy linker scripts
210 define generic-objs_ld_template_gen
211 de$(EMPTY)fine $(1)-objs_ld_template
212 $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h
213         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
214         $$(CC_$(1)) -MMD $$(CPPFLAGS_$(1)) $$($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h -MT $$$$@ -o $$$$@ $$$$<
215 en$(EMPTY)def
216 endef
218 # Add handler to deal with archives
219 define generic-objs_a_template_gen
220 de$(EMPTY)fine $(1)-objs_a_template
221 $$(call src-to-obj,$1,$$(1).a): $$(1).a
222         @printf "    AR         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
223         $$$$(AR_$(1)) rcsT $$$$@.tmp $$$$<
224         mv $$$$@.tmp $$$$@
225 en$(EMPTY)def
226 endef
228 # Add handler to add no rules for manual files
229 define generic-objs_manual_template_gen
230 # do nothing
231 endef
233 #######################################################################
234 # Add handler to compile ACPI's ASL
235 # arg1: base file name
236 # arg2: y or n for including in cbfs. defaults to y
237 define asl_template
238 $(CONFIG_CBFS_PREFIX)/$(1).aml-file = $(obj)/$(1).aml
239 $(CONFIG_CBFS_PREFIX)/$(1).aml-type = raw
240 $(CONFIG_CBFS_PREFIX)/$(1).aml-compression = none
241 cbfs-files-$(if $(2),$(2),y) += $(CONFIG_CBFS_PREFIX)/$(1).aml
242 -include $(obj)/$(1).d
243 $(obj)/$(1).aml: $(src)/mainboard/$(MAINBOARDDIR)/$(1).asl $(obj)/config.h
244         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
245         $(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 $$@
246         cd $$(dir $$@); $(IASL) -we -p $$(notdir $$@) $$(notdir $$@)
247         if [ -z "$$$$($(IASL) -d $$@ 2>&1 | grep 'ACPI Warning')" ]; then echo "    IASL       $$@ disassembled correctly."; true; else echo "Error: Could not correctly disassemble $$@"; $(IASL) -d $$@; false; fi
248 endef
250 #######################################################################
251 # Parse plaintext cmos defaults into binary format
252 # arg1: source file
253 # arg2: binary file name
254 cbfs-files-processor-nvramtool= \
255         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
256                 printf "    CREATE     $(2) (from $(1))\n"; \
257                 $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && \
258                 mv $(2).tmp $(2))
260 #######################################################################
261 # Link VSA binary to ELF-ish stage
262 # arg1: source file
263 # arg2: binary file name
264 cbfs-files-processor-vsa= \
265         $(eval $(2): $(1) ; \
266                 printf "    CREATE     $(2) (from $(1))\n"; \
267                 $(OBJCOPY_ramstage) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && \
268                 $(LD_ramstage) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
270 #######################################################################
271 # Reduce a .config file to its minimal representation
272 # arg1: input
273 # arg2: output
274 cbfs-files-processor-defconfig= \
275         $(eval $(2): $(1) $(obj)/build.h; \
276                 +printf "    CREATE     $(2) (from $(1))\n"; \
277                 printf "\# This image was built using coreboot " > $(2).tmp && \
278                 grep "\<COREBOOT_VERSION\>" $(obj)/build.h |cut -d\" -f2 >> $(2).tmp && \
279                 $(MAKE) DOTCONFIG=$(1) DEFCONFIG=$(2).tmp2 savedefconfig && \
280                 cat $(2).tmp2 >> $(2).tmp && \
281                 rm -f $(2).tmp2 && \
282                 \mv -f $(2).tmp $(2))
284 #######################################################################
285 # Compile a C file with a bare struct definition into binary
286 # arg1: C source file
287 # arg2: binary file
288 cbfs-files-processor-struct= \
289         $(eval $(2): $(1) $(obj)/build.h $(KCONFIG_AUTOHEADER); \
290                 printf "    CC+STRIP   $(@)\n"; \
291                 $(CC_ramstage) -MMD $(CPPFLAGS_ramstage) $(CFLAGS_ramstage) $$(ramstage-c-ccopts) -include $(KCONFIG_AUTOHEADER) -MT $(2) -o $(2).tmp -c $(1) && \
292                 $(OBJCOPY_ramstage) -O binary $(2).tmp $(2); \
293                 rm -f $(2).tmp) \
294         $(eval DEPENDENCIES += $(2).d)
296 #######################################################################
297 # Add handler for arbitrary files in CBFS
298 $(call add-special-class,cbfs-files)
299 cbfs-files-handler= \
300                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
301                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
302                 $(eval tmp-cbfs-file:= ) \
303                 $(if $($(2)-file), \
304                         $(if $(wildcard $(1)$($(2)-file)), \
305                                 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
306                                 $(eval tmp-cbfs-file:= $($(2)-file)))) \
307                 $(if $(strip $($(2)-required)), \
308                         $(if $(wildcard $(tmp-cbfs-file)),, \
309                                 $(info This build configuration requires $($(2)-required)) \
310                                 $(eval FAILBUILD:=1) \
311                         )) \
312                 $(if $(strip $($(2)-align)), \
313                         $(if $(strip $($(2)-position)), \
314                                 $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
315                                 $(eval FAILBUILD:=1) \
316                         )) \
317                 $(if $(tmp-cbfs-method), \
318                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
319                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
320                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
321                 $(if $(tmp-cbfs-file), \
322                         $(eval cbfs-files += $(subst $(spc),*,$(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align)|$($(2)-options)))) \
323                 $(eval $(2)-name:=) \
324                 $(eval $(2)-type:=) \
325                 $(eval $(2)-compression:=) \
326                 $(eval $(2)-position:=) \
327                 $(eval $(2)-required:=) \
328                 $(eval $(2)-options:=) \
329                 $(eval $(2)-align:=)
331 #######################################################################
332 # a variety of flags for our build
333 CBFS_COMPRESS_FLAG:=none
334 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
335 CBFS_COMPRESS_FLAG:=LZMA
336 endif
338 CBFS_PAYLOAD_COMPRESS_FLAG:=none
339 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
340 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
341 endif
343 CBFS_PRERAM_COMPRESS_FLAG:=none
344 ifeq ($(CONFIG_COMPRESS_PRERAM_STAGES),y)
345 CBFS_PRERAM_COMPRESS_FLAG:=LZ4
346 endif
348 ifneq ($(CONFIG_LOCALVERSION),"")
349 export COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
350 endif
352 CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -I$(obj)
353 CPPFLAGS_common += -Isrc/device/oprom/include
354 VBOOT_SOURCE ?= 3rdparty/vboot
355 CPPFLAGS_common += -I$(VBOOT_SOURCE)/firmware/include
356 CPPFLAGS_common += -include $(src)/include/kconfig.h
357 CPPFLAGS_common += -I3rdparty
359 CFLAGS_common += -pipe -g -nostdinc -std=gnu11
360 CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
361 CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
362 CFLAGS_common += -Wstrict-aliasing -Wshadow -Wdate-time
363 CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
364 CFLAGS_common += -ffunction-sections -fdata-sections -fno-pie
366 ADAFLAGS_common += -gnatg -gnatp
367 ADAFLAGS_common += -Wuninitialized -Wall -Werror
368 ADAFLAGS_common += -pipe -g -nostdinc
369 ADAFLAGS_common += -Wstrict-aliasing -Wshadow
370 ADAFLAGS_common += -fno-common -fomit-frame-pointer
371 ADAFLAGS_common += -ffunction-sections -fdata-sections
372 # Ada warning options:
374 #  a   Activate most optional warnings.
375 # .e   Activate every optional warnings.
376 #  e   Treat warnings and style checks as errors.
378 #  D   Suppress warnings on implicit dereferences:
379 #      As SPARK does not accept access types we have to map the
380 #      dynamically chosen register locations to a static SPARK
381 #      variable.
383 # .H   Suppress warnings on holes/gaps in records:
384 #      We are modelling hardware here!
386 #  H   Suppress warnings on hiding:
387 #      It's too annoying, you run out of ideas for identifiers fast.
389 #  T   Suppress warnings for tracking of deleted conditional code:
390 #      We use static options to select code paths at compile time.
392 #  U   Suppress warnings on unused entities:
393 #      Would have lots of warnings for unused register definitions,
394 #      `withs` for debugging etc.
396 # .U   Deactivate warnings on unordered enumeration types:
397 #      As SPARK doesn't support `pragma Ordered` by now, we don't
398 #      use that, yet.
400 # .W   Suppress warnings on unnecessary Warnings Off pragmas:
401 #      Things get really messy when you use different compiler
402 #      versions, otherwise.
403 # .Y   Disable information messages for why package spec needs body:
404 #      Those messages are annoying. But don't forget to enable those,
405 #      if you need the information.
406 ADAFLAGS_common += -gnatwa.eeD.HHTU.U.W.Y
407 # Disable style checks for now
408 ADAFLAGS_common += -gnatyN
410 LDFLAGS_common := --gc-sections -nostdlib -nostartfiles -static --emit-relocs
412 ifeq ($(CONFIG_COMPILER_GCC),y)
413 # cf. commit f69a99db (coreboot: x86: enable gc-sections)
414 CFLAGS_common += -Wno-unused-but-set-variable
415 endif
417 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
418 CFLAGS_common += -Werror
419 endif
420 ifneq ($(GDB_DEBUG),)
421 CFLAGS_common += -Og
422 ADAFLAGS_common += -Og
423 else
424 CFLAGS_common += -Os
425 ADAFLAGS_common += -Os
426 endif
428 ifeq ($(CONFIG_DEBUG_ADA_CODE),y)
429 ADAFLAGS_common += -gnata
430 endif
432 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
433                    $(objutil)/ifdfake $(objutil)/options $(objutil)/amdfwtool \
434                    $(objutil)/cbootimage $(objutil)/bimgtool
436 #######################################################################
437 # generate build support files
438 $(obj)/build.h: .xcompile
439         @printf "    GEN        build.h\n"
440         rm -f $(obj)/build.h
441         util/genbuild_h/genbuild_h.sh > $(obj)/build.ht
442         mv $(obj)/build.ht $(obj)/build.h
444 build-dirs:
445         mkdir -p $(objcbfs) $(objgenerated)
447 #######################################################################
448 # Build the tools
449 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
450 FMAPTOOL:=$(objutil)/cbfstool/fmaptool
451 RMODTOOL:=$(objutil)/cbfstool/rmodtool
452 IFWITOOL:=$(objutil)/cbfstool/ifwitool
454 $(obj)/cbfstool: $(CBFSTOOL)
455         cp $< $@
457 $(obj)/fmaptool: $(FMAPTOOL)
458         cp $< $@
460 $(obj)/rmodtool: $(RMODTOOL)
461         cp $< $@
463 $(obj)/ifwitool: $(IFWITOOL)
464         cp $< $@
466 _WINCHECK=$(shell uname -o 2> /dev/null)
467 STACK=
468 ifeq ($(_WINCHECK),Msys)
469         STACK=-Wl,--stack,16384000
470 endif
471 ifeq ($(_WINCHECK),Cygwin)
472         STACK=-Wl,--stack,16384000
473 endif
475 # this allows ccache to prepend itself
476 # (ccache handling happens first)
477 ROMCC_BIN= $(objutil)/romcc/romcc
478 ROMCC?=$(ROMCC_BIN)
479 $(ROMCC_BIN): $(top)/util/romcc/romcc.c
480         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
481         @# Note: Adding -O2 here might cause problems. For details see:
482         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
483         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
485 IFDTOOL:=$(objutil)/ifdtool/ifdtool
486 $(IFDTOOL):
487         @printf "    Compile IFDTOOL\n"
488         +$(MAKE) -C $(top)/util/ifdtool
489         cp -a $(top)/util/ifdtool/ifdtool $@
491 IFDFAKE:=$(objutil)/ifdfake/ifdfake
492 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
493         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
494         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
496 AMDFWTOOL:=$(objutil)/amdfwtool/amdfwtool
497 $(AMDFWTOOL): $(top)/util/amdfwtool/amdfwtool.c
498         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
499         $(HOSTCC) $(HOSTCFLAGS) -DCONFIG_ROM_SIZE=$(CONFIG_ROM_SIZE) -o $@ $<
501 CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
503 FUTILITY?=$(objutil)/futility/futility
505 subdirs-y += util/nvidia
507 BIMGTOOL:=$(objutil)/bimgtool/bimgtool
508 $(BIMGTOOL): $(top)/util/bimgtool/bimgtool.c
509         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
510         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
512 $(obj)/config.h: $(objutil)/kconfig/conf
514 #######################################################################
515 # needed objects that every mainboard uses
516 # Creation of these is architecture and mainboard independent
517 DEVICETREE_FILE := $(src)/mainboard/$(MAINBOARDDIR)/$(CONFIG_DEVICETREE)
518 DEVICETREE_STATIC_C := $(obj)/mainboard/$(MAINBOARDDIR)/static.c
520 $(DEVICETREE_STATIC_C): $(DEVICETREE_FILE) $(objutil)/sconfig/sconfig
521         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
522         mkdir -p $(dir $(DEVICETREE_STATIC_C))
523         $(objutil)/sconfig/sconfig $(DEVICETREE_FILE) $(DEVICETREE_STATIC_C)
525 ramstage-y+=$(DEVICETREE_STATIC_C)
526 romstage-y+=$(DEVICETREE_STATIC_C)
527 verstage-y+=$(DEVICETREE_STATIC_C)
528 bootblock-y+=$(DEVICETREE_STATIC_C)
529 postcar-y+=$(DEVICETREE_STATIC_C)
531 #######################################################################
532 # Clean up rules
533 clean-abuild:
534         rm -rf coreboot-builds
536 clean-for-update-target: clean-payloads
537         rm -f $(obj)/ramstage?* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
538         rm -rf $(obj)/bootblock?* $(obj)/romstage?* $(obj)/location.*
539         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
540         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
541         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
542         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
543         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/dsdt.*
544         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
546 clean-target:
547         rm -f $(obj)/coreboot*
549 #######################################################################
550 # Development utilities
551 printcrt0s:
552         @echo crt0s=$(crt0s)
553         @echo ldscripts=$(ldscripts)
555 update:
556         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
558 lint lint-stable:
559         util/lint/lint $@
561 gitconfig:
562         [ -d .git ]
563         mkdir -p .git/hooks
564         for hook in commit-msg pre-commit ; do                       \
565                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
566                 ! -x .git/hooks/$$hook ]; then                       \
567                         sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/$$hook > .git/hooks/$$hook;  \
568                         chmod +x .git/hooks/$$hook;                  \
569                 fi;                                                  \
570         done
571         # Now set up thehooks for 3rdparty/
572         for hooks in .git/modules/{3rdparty/blobs,libhwbase,libgfxinit}/hooks; do                       \
573                 if [ -d $$hooks -a                                                                      \
574                 \( util/gitconfig/commit-msg -nt $$hooks/commit-msg -o                                  \
575                         ! -x $$hooks/commit-msg \) ]; then                                              \
576                         sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/commit-msg > $$hooks/commit-msg;     \
577                         chmod +x $$hooks/commit-msg;                                                    \
578                 fi                                                                                      \
579         done
580         for d in 3rdparty/{blobs,libhwbase,libgfxinit}; do                      \
581                 if [ -d $$d ]; then                                             \
582                         (cd $$d;                                                \
583                          git config remote.origin.push HEAD:refs/for/master);   \
584                 fi;                                                             \
585         done
586         git config remote.origin.push HEAD:refs/for/master
587         git config alias.sup '!git submodule update --remote --rebase && git submodule update --init --checkout'
588         git config alias.sup-destroy '!git submodule deinit --force "$$(git rev-parse --show-toplevel)"; git submodule init && git submodule update --checkout'
589         (git config --global --includes user.name >/dev/null && git config --global --includes 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)
591 include util/crossgcc/Makefile.inc
593 .PHONY: tools
594 tools: $(objutil)/kconfig/conf $(CBFSTOOL) $(objutil)/cbfstool/cbfs-compression-tool $(FMAPTOOL) $(RMODTOOL) $(IFWITOOL) $(objutil)/nvramtool/nvramtool $(ROMCC_BIN) $(objutil)/sconfig/sconfig $(IFDTOOL) $(IFDFAKE) $(CBOOTIMAGE) $(AMDFWTOOL) $(FUTILITY) $(objutil)/blobtool/blobtool
596 ###########################################################################
597 # Common recipes for all stages
598 ###########################################################################
600 # loadaddr can determine the load address of a stage, which may be needed for
601 # platform-specific image headers (only works *after* the stage has been built)
602 loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
603              sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
605 # find-substr is required for stages like romstage_null and romstage_xip to
606 # eliminate the _* part of the string
607 find-substr = $(word 1,$(subst _, ,$(1)))
609 # find-class is used to identify the class from the name of the stage
610 # The input to this macro can be something like romstage.x or romstage.x.y
611 # find-class recursively strips off the suffixes to extract the exact class name
612 # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
613 # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
614 # and remove .x the next time and finally return romstage
615 find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
617 # Bootblocks are not CBFS stages. coreboot is currently expecting the bss to
618 # be cleared by the loader of the stage. For ARM SoCs that means one needs to
619 # include the bss section in the binary so the BootROM clears the bss on
620 # loading of the bootblock stage. Achieve this by marking the bss section
621 # loadable,allocatable, and data. Do the same for the .data section in case
622 # it's marked as NOBITS.
623 $(objcbfs)/bootblock.raw.bin: $(objcbfs)/bootblock.elf
624         @printf "    OBJCOPY    $(notdir $(@))\n"
625         $(OBJCOPY_bootblock) --set-section-flags .bss=load,alloc,data --set-section-flags .data=load,alloc,data $< $<.tmp
626         $(OBJCOPY_bootblock) -O binary $<.tmp $@
628 $(objcbfs)/%.bin: $(objcbfs)/%.raw.bin
629         cp $< $@
631 $(objcbfs)/%.elf: $(objcbfs)/%.debug
632         $(eval class := $(call find-class,$(@F)))
633         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
634         cp $< $@.tmp
635         $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
636         $(OBJCOPY_$(class)) --strip-debug $@.tmp
637         $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
638         mv $@.tmp $@
640 ###########################################################################
641 # Build the final rom image
642 ###########################################################################
644 # extract_nth - Return a subsection of the $file string
646 # the input string looks like this:
647 # ./build/cbfs/fallback/romstage.elf|fallback/romstage|stage|none||64|--xip*-S*.car.data*-P*0x10000
649 # Sections:
650 # 1 - Path and name of file [FILENAME: Added to cbfs-files-y list variable]
651 # 2 - Name of file in cbfs  [$(FILENAME)-file]
652 # 3 - File type:            [$(FILENAME)-type]
653 #                bootblock, cbfs header, stage, payload, optionrom, bootsplash, raw, vsa,
654 #                mbi, microcode, fsp, mrc, cmos_default, cmos_layout, spd, mrc_cache,
655 #                mma, efi, deleted, null
656 # 4 - Compression type      [$(FILENAME)-compression]
657 #                      none, LZMA
658 # 5 - Base address          [$(FILANAME)-position]
659 # 6 - Alignment             [$(FILENAME)-align]
660 # 7 - cbfstool flags        [$(FILENAME)-options]
662 # Input:
663 #  $(1) = Section to extract
664 #  $(2) = Input string
666 # Steps:
667 # 1) replace all '|' characters with the sequence '- -' within the full string, prepended and appended with the character '-'
668 # 2) extract the specified section from the string - this gets us the section surrounded by '-' characters
669 # 3) remove the leading and trailing '-' characters
670 # 4) replace all '*' characters with spaces
671 extract_nth=$(subst *,$(spc),$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-))))
673 # regions-for-file - Returns a cbfstool regions parameter
674 # $(call regions-for-file,$(filename))
675 # returns "REGION1,REGION2,..."
677 # This is the default implementation. When using a boot strategy employing
678 # multiple CBFSes in fmap regions, override it.
679 regions-for-file ?= COREBOOT
681 ifeq ($(CONFIG_CBFS_AUTOGEN_ATTRIBUTES),y)
682         cbfs-autogen-attributes=-g
683 endif
685 # cbfs-add-cmd-for-region
686 # $(call cbfs-add-cmd-for-region,file in extract_nth format,region name)
687 define cbfs-add-cmd-for-region
688         $(CBFSTOOL) $@.tmp \
689         add$(if $(filter stage,$(call extract_nth,3,$(1))),-stage)$(if \
690                 $(filter payload,$(call extract_nth,3,$(1))),-payload)$(if \
691                 $(filter flat-binary,$(call extract_nth,3,$(1))),-flat-binary) \
692         -f $(call extract_nth,1,$(1)) \
693         -n $(call extract_nth,2,$(1)) \
694         $(if $(filter-out flat-binary,$(filter-out stage,$(call \
695                 extract_nth,3,$(1)))),-t $(call extract_nth,3,$(1))) \
696         $(if $(call extract_nth,4,$(1)),-c $(call extract_nth,4,$(1))) \
697         $(cbfs-autogen-attributes) \
698         -r $(2) \
699         $(if $(call extract_nth,6,$(1)),-a $(call extract_nth,6,$(file)), \
700                 $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file)))) \
701                 $(call extract_nth,7,$(1))
704 endef
705 # Empty line before endef is necessary so cbfs-add-cmd-for-region ends in a
706 # newline
708 # cbfs-add-cmd
709 # $(call cbfs-add-cmd,
710 #          file in extract_nth format,
711 #          region name,
712 #          non-empty if file removal requested)
713 define cbfs-add-cmd
714         printf "    CBFS       $(call extract_nth,2,$(1))\n"
715         $(if $(3),-$(CBFSTOOL) $@.tmp remove -n $(call extract_nth,2,$(file)) 2>/dev/null)
716         $(call cbfs-add-cmd-for-region,$(1),$(2))
717 endef
719 # list of files to add (using their file system names, not CBFS names),
720 # for dependencies etc.
721 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
723 # $(all-regions)
724 # returns full list of fmap regions that we add files to
725 all-regions = $(sort $(subst $(comma),$(spc), \
726         $(foreach file,$(cbfs-files), \
727                 $(call regions-for-file,$(call extract_nth,2,$(file))))))
729 # $(call all-files-in-region,region name)
730 # returns elements in $(cbfs-files) that end up in that region, in the order
731 # they appear in $(cbfs-files)
732 all-files-in-region = $(foreach file,$(cbfs-files), \
733         $(if $(filter $(1), \
734                 $(subst $(comma),$(spc),$(call regions-for-file,$(call extract_nth,2,$(file))))), \
735                 $(file)))
737 # $(call update-file-for-region,file string from $(cbfs-files),region name)
738 # Update position and alignment according to overrides for region
739 # Doesn't check for invalid configurations (eg. resetting neither or both
740 # position and align)
741 # Returns the updated file string
742 update-file-for-region = \
743         $(subst $(spc),*,$(call extract_nth,1,$(1))|$(call extract_nth,2,$(1))|$(call extract_nth,3,$(1))|$(call extract_nth,4,$(1))|$($(call extract_nth,2,$(1))-$(2)-position)|$($(call extract_nth,2,$(1))-$(2)-align)|$(call extract_nth,7,$(1)))
745 # $(call placed-files-in-region,region name)
746 # like all-files-in-region, but updates the files to contain region overrides
747 # to position or alignment.
748 placed-files-in-region = $(foreach file,$(call all-files-in-region,$(1)), \
749         $(if $($(call extract_nth,2,$(file))-$(1)-position), \
750                 $(if $($(call extract_nth,2,$(file))-$(1)-align), \
751                         $(error It is not allowed to specify both alignment and position for $(call extract_nth,2,$(file))-$(1))) \
752                 $(call update-file-for-region,$(file),$(1)), \
753                 $(if $($(call extract_nth,2,$(file))-$(1)-align), \
754                         $(call update-file-for-region,$(file),$(1)), \
755                         $(file))))
757 # $(call sort-files,subset of $(cbfs-files))
758 # reorders the files in the given set to list files at fixed positions first,
759 # followed by aligned files and finally those with no constraints.
760 sort-files = \
761         $(eval _tmp_fixed:=) \
762         $(eval _tmp_aligned:=) \
763         $(eval _tmp_regular:=) \
764         $(foreach file,$(1), \
765                 $(if $(call extract_nth,5,$(file)),\
766                         $(eval _tmp_fixed += $(file)), \
767                 $(if $(call extract_nth,6,$(file)), \
768                         $(eval _tmp_aligned += $(file)), \
769                         $(eval _tmp_regular += $(file))))) \
770         $(_tmp_fixed) $(_tmp_aligned) $(_tmp_regular)
772 # command list to add files to CBFS
773 prebuild-files = $(foreach region,$(all-regions), \
774         $(foreach file, \
775                 $(call sort-files,$(call placed-files-in-region,$(region))), \
776                 $(call cbfs-add-cmd,$(file),$(region),$(CONFIG_UPDATE_IMAGE))))
778 ifeq ($(CONFIG_FMDFILE),)
779 # For a description of the flash layout described by these variables, check
780 # the $(DEFAULT_FLASHMAP) .fmd files.
781 ifeq ($(CONFIG_ARCH_X86),y)
782 DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default-x86.fmd
783 # entire flash
784 FMAP_ROM_ADDR := $(call int-subtract, 0x100000000 $(CONFIG_ROM_SIZE))
785 FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
786 # entire "BIOS" region (everything directly of concern to the host system)
787 # relative to ROM_BASE
788 FMAP_BIOS_BASE := $(call int-subtract, $(CONFIG_ROM_SIZE) $(CONFIG_CBFS_SIZE))
789 FMAP_BIOS_SIZE := $(shell echo $(CONFIG_CBFS_SIZE) | tr A-F a-f)
790 # position and size of flashmap, relative to BIOS_BASE
791 FMAP_FMAP_BASE := 0
792 FMAP_FMAP_SIZE := 0x100
793 # position, size and entry line of CONSOLE relative to BIOS_BASE, if enabled
794 ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
795 FMAP_CONSOLE_BASE := $(call int-add, $(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE))
796 FMAP_CONSOLE_SIZE := $(CONFIG_CONSOLE_SPI_FLASH_BUFFER_SIZE)
797 FMAP_CONSOLE_ENTRY := CONSOLE@$(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE)
798 else # ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
799 FMAP_CONSOLE_BASE := 0
800 FMAP_CONSOLE_SIZE := 0
801 FMAP_CONSOLE_ENTRY :=
802 endif # ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
803 # position and size of CBFS, relative to BIOS_BASE
804 FMAP_CBFS_BASE := $(call int-add, $(FMAP_CONSOLE_SIZE) $(FMAP_FMAP_SIZE))
805 FMAP_CBFS_SIZE := $(call int-subtract, $(FMAP_BIOS_SIZE) $(FMAP_CBFS_BASE))
806 else # ifeq ($(CONFIG_ARCH_X86),y)
807 DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default.fmd
808 # entire flash
809 FMAP_ROM_ADDR := 0
810 FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
811 # entire "BIOS" region (everything directly of concern to the host system)
812 # relative to ROM_BASE
813 FMAP_BIOS_BASE := 0
814 FMAP_BIOS_SIZE := $(CONFIG_CBFS_SIZE)
815 # position and size of flashmap, relative to BIOS_BASE
816 FMAP_FMAP_BASE := 0x20000
817 FMAP_FMAP_SIZE := 0x100
818 # position, size and entry line of CONSOLE relative to BIOS_BASE, if enabled
819 ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
820 FMAP_CONSOLE_BASE := $(call int-add, $(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE))
821 FMAP_CONSOLE_SIZE := $(CONFIG_CONSOLE_SPI_FLASH_BUFFER_SIZE)
822 FMAP_CONSOLE_ENTRY := CONSOLE@$(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE)
823 else # ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
824 FMAP_CONSOLE_BASE := 0
825 FMAP_CONSOLE_SIZE := 0
826 FMAP_CONSOLE_ENTRY :=
827 endif # ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
828 # position and size of CBFS, relative to BIOS_BASE
829 FMAP_CBFS_BASE := $(call int-add,$(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE) $(FMAP_CONSOLE_SIZE))
830 FMAP_CBFS_SIZE := $(call int-subtract,$(FMAP_BIOS_SIZE) $(FMAP_CBFS_BASE))
831 endif # ifeq ($(CONFIG_ARCH_X86),y)
833 $(obj)/fmap.fmd: $(top)/Makefile.inc $(DEFAULT_FLASHMAP) $(obj)/config.h
834         sed -e "s,##ROM_BASE##,$(FMAP_ROM_ADDR)," \
835             -e "s,##ROM_SIZE##,$(FMAP_ROM_SIZE)," \
836             -e "s,##BIOS_BASE##,$(FMAP_BIOS_BASE)," \
837             -e "s,##BIOS_SIZE##,$(FMAP_BIOS_SIZE)," \
838             -e "s,##FMAP_BASE##,$(FMAP_FMAP_BASE)," \
839             -e "s,##FMAP_SIZE##,$(FMAP_FMAP_SIZE)," \
840             -e "s,##CONSOLE_ENTRY##,$(FMAP_CONSOLE_ENTRY)," \
841             -e "s,##CBFS_BASE##,$(FMAP_CBFS_BASE)," \
842             -e "s,##CBFS_SIZE##,$(FMAP_CBFS_SIZE)," \
843                 $(DEFAULT_FLASHMAP) > $@.tmp
844         mv $@.tmp $@
845 else # ifeq ($(CONFIG_FMDFILE),)
846 $(obj)/fmap.fmd: $(CONFIG_FMDFILE) $(obj)/config.h
847         $(HOSTCC) $(PREPROCESS_ONLY) -include $(obj)/config.h $< -o $@.pre
848         mv $@.pre $@
849 endif # ifeq ($(CONFIG_FMDFILE),)
851 # generated at the same time as fmap.fmap
852 $(obj)/fmap_config.h: $(obj)/fmap.fmap
853 $(obj)/fmap.desc: $(obj)/fmap.fmap
855 $(obj)/fmap.fmap: $(obj)/fmap.fmd $(FMAPTOOL)
856         echo "    FMAP       $(FMAPTOOL) -h $(obj)/fmap_config.h $< $@"
857         $(FMAPTOOL) -h $(obj)/fmap_config.h -R $(obj)/fmap.desc $< $@
859 ifneq ($(CONFIG_UPDATE_IMAGE),y)
860 $(obj)/coreboot.pre: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL) $$(cpu_ucode_cbfs_file) $(obj)/fmap.fmap $(obj)/fmap.desc
861         $(CBFSTOOL) $@.tmp create -M $(obj)/fmap.fmap -r $(shell cat $(obj)/fmap.desc)
862 ifeq ($(CONFIG_ARCH_X86),y)
863         $(CBFSTOOL) $@.tmp add \
864                 -f $(objcbfs)/bootblock.bin \
865                 -n bootblock \
866                 -t bootblock \
867                 -b -$(call file-size,$(objcbfs)/bootblock.bin) $(cbfs-autogen-attributes)
868 else # ifeq ($(CONFIG_ARCH_X86),y)
869         $(CBFSTOOL) $@.tmp write -u \
870                 -r BOOTBLOCK \
871                 -f $(objcbfs)/bootblock.bin
872         # make space for the CBFS master header pointer. "ptr_" is just
873         # arbitrary 4 bytes that will be overwritten by add-master-header.
874         printf "ptr_" > $@.tmp.2
875         $(CBFSTOOL) $@.tmp add \
876                 -f $@.tmp.2 \
877                 -n "header pointer" \
878                 -t "cbfs header" \
879                 -b -4
880         rm -f $@.tmp.2
881 endif # ifeq ($(CONFIG_ARCH_X86),y)
882         $(CBFSTOOL) $@.tmp add-master-header
883         $(prebuild-files) true
884         mv $@.tmp $@
885 else # ifneq ($(CONFIG_UPDATE_IMAGE),y)
886 .PHONY: $(obj)/coreboot.pre
887 $(obj)/coreboot.pre: $$(prebuilt-files) $(CBFSTOOL)
888         mv $(obj)/coreboot.rom $@.tmp || \
889         (echo "Error: You have UPDATE_IMAGE set in Kconfig, but have no existing image to update." && \
890         echo "Exiting." && \
891         false)
892         $(prebuild-files) true
893         mv $@.tmp $@
894 endif # ifneq ($(CONFIG_UPDATE_IMAGE),y)
896 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
897 REFCODE_BLOB=$(obj)/refcode.rmod
898 $(REFCODE_BLOB): $(RMODTOOL)
899         $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
900 endif
902 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/ramstage.elf $(CBFSTOOL) $$(INTERMEDIATE)
903         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
904 # The full ROM may be larger than the CBFS part, so create an empty
905 # file (filled with \377 = 0xff) and copy the CBFS image over it.
906         dd if=/dev/zero bs=$(call _toint,$(CONFIG_ROM_SIZE)) count=1 2> /dev/null | tr '\000' '\377' > $@.tmp
907         dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
908 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
909 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
910 ifneq ($(CONFIG_UPDATE_IMAGE),y)
911         @printf "    SeaBIOS    Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
912         $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
913 endif
914 endif
915 endif
916 ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
917 ifeq ($(CONFIG_CPU_MICROCODE_CBFS_EXTERNAL_HEADER),y)
918         @printf "    UPDATE-FIT\n"
919         $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
920 endif
922 ifeq ($(CONFIG_CPU_MICROCODE_CBFS_GENERATE),y)
923         @printf "    UPDATE-FIT\n"
924         $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
925 endif
926 endif
927         mv $@.tmp $@
928         @printf "    CBFSPRINT  $(subst $(obj)/,,$(@))\n\n"
929         $(CBFSTOOL) $@ print -r $(subst $(spc),$(comma),$(all-regions))
931 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/romstage
932 $(CONFIG_CBFS_PREFIX)/romstage-file := $(objcbfs)/romstage.elf
933 $(CONFIG_CBFS_PREFIX)/romstage-type := stage
934 $(CONFIG_CBFS_PREFIX)/romstage-compression := $(CBFS_PRERAM_COMPRESS_FLAG)
935 ifeq ($(CONFIG_ARCH_ROMSTAGE_ARM),y)
936 $(CONFIG_CBFS_PREFIX)/romstage-options := -b 0
937 endif
938 ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32)$(CONFIG_ARCH_ROMSTAGE_X86_64),y)
939 # Use a 64 byte alignment to provide a minimum alignment
940 # requirement for the overall romstage. While the first object within
941 # romstage could have a 4 byte minimum alignment that doesn't mean the linker
942 # won't decide the entire section should be aligned to a larger value. In the
943 # future cbfstool should add XIP files proper and honor the alignment
944 # requirements of the program segment.
946 # Make sure that segment for .car.data is ignored while adding romstage.
947 $(CONFIG_CBFS_PREFIX)/romstage-align := 64
948 $(CONFIG_CBFS_PREFIX)/romstage-options := -S ".car.data"
950 # If CAR does not support execution of code, romstage on x86 is expected to be
951 # xip.
952 ifneq ($(CONFIG_NO_XIP_EARLY_STAGES),y)
953 $(CONFIG_CBFS_PREFIX)/romstage-options += --xip
955 # If XIP_ROM_SIZE isn't being used don't overly constrain romstage by passing
956 # -P with a default value.
957 ifneq ($(CONFIG_NO_FIXED_XIP_ROM_SIZE),y)
958 $(CONFIG_CBFS_PREFIX)/romstage-options += -P $(CONFIG_XIP_ROM_SIZE)
959 endif    # CONFIG_NO_FIXED_XIP_ROM_SIZE
961 endif   # CONFIG_NO_XIP_EARLY_STAGES
962 endif   # CONFIG_ARCH_ROMSTAGE_X86_32 / CONFIG_ARCH_ROMSTAGE_X86_64
964 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/ramstage
965 $(CONFIG_CBFS_PREFIX)/ramstage-file := $(objcbfs)/ramstage.elf
966 $(CONFIG_CBFS_PREFIX)/ramstage-type := stage
967 $(CONFIG_CBFS_PREFIX)/ramstage-compression := $(CBFS_COMPRESS_FLAG)
969 cbfs-files-$(CONFIG_HAVE_REFCODE_BLOB) += $(CONFIG_CBFS_PREFIX)/refcode
970 $(CONFIG_CBFS_PREFIX)/refcode-file := $(REFCODE_BLOB)
971 $(CONFIG_CBFS_PREFIX)/refcode-type := stage
972 $(CONFIG_CBFS_PREFIX)/refcode-compression := $(CBFS_COMPRESS_FLAG)
974 cbfs-files-$(CONFIG_SEABIOS_VGA_COREBOOT) += vgaroms/seavgabios.bin
975 vgaroms/seavgabios.bin-file := $(CONFIG_PAYLOAD_VGABIOS_FILE)
976 vgaroms/seavgabios.bin-type := raw
978 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += config
979 config-file := $(DOTCONFIG):defconfig
980 config-type := raw
982 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += revision
983 revision-file := $(obj)/build.h
984 revision-type := raw
986 BOOTSPLASH_SUFFIX=$(suffix $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE)))
987 cbfs-files-$(CONFIG_BOOTSPLASH_IMAGE) += bootsplash$(BOOTSPLASH_SUFFIX)
988 bootsplash$(BOOTSPLASH_SUFFIX)-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
989 bootsplash$(BOOTSPLASH_SUFFIX)-type := bootsplash
991 cbfs-files-$(CONFIG_BOARD_ID_MANUAL) += board_id
992 board_id-file := $(obj)/board_id
993 board_id-type := raw
995 $(obj)/board_id:
996         printf $(CONFIG_BOARD_ID_STRING) > $@
998 # Ensure that no payload segment overlaps with memory regions used by ramstage
999 # (not for x86 since it can relocate itself in that case)
1000 ifneq ($(CONFIG_ARCH_X86),y)
1001 check-ramstage-overlap-regions := ramstage
1002 check-ramstage-overlap-files :=
1003 ifneq ($(CONFIG_PAYLOAD_NONE),y)
1004 check-ramstage-overlap-files += $(CONFIG_CBFS_PREFIX)/payload
1005 endif
1007 # will output one or more lines of "<load address in hex> <memlen in decimal>"
1008 cbfs-get-segments-cmd = $(CBFSTOOL) $(obj)/coreboot.pre print -v | sed -n \
1009         '\%$(1)%,\%^[^ ]\{4\}%s%    .*load: \(0x[0-9a-fA-F]*\),.*length: [0-9]*/\([0-9]*\).*%\1 \2%p'
1011 ramstage-symbol-addr-cmd = $(OBJDUMP_ramstage) -t $(objcbfs)/ramstage.elf | \
1012         sed -n '/ $(1)$$/s/^\([0-9a-fA-F]*\) .*/0x\1/p'
1014 check-ramstage-overlaps: $(obj)/coreboot.pre
1015         programs=$$($(foreach file,$(check-ramstage-overlap-files), \
1016                 $(call cbfs-get-segments-cmd,$(file)) ; )) ; \
1017         regions=$$($(foreach region,$(check-ramstage-overlap-regions), \
1018                 echo $(region) ; \
1019                 $(call ramstage-symbol-addr-cmd,_$(region)) ; \
1020                 $(call ramstage-symbol-addr-cmd,_e$(region)) ; )) ; \
1021         pstart= ; pend= ; \
1022         for x in $$programs; do \
1023             if [ -z $$pstart ]; then pstart=$$(($$x)) ; continue ; fi ; \
1024             pend=$$(($$pstart + $$x)) ; \
1025             rname= ; rstart= ; rend= ; \
1026             for y in $$regions ; do \
1027                 if [ -z $$rname ]; then rname=$$y ; continue ; fi ; \
1028                 if [ -z $$rstart ]; then rstart=$$(($$y)) ; continue ; fi ; \
1029                 rend=$$(($$y)) ; \
1030                 if [ $$pstart -lt $$rend -a $$rstart -lt $$pend ]; then \
1031                     echo "ERROR: Ramstage region _$$rname overlapped by:" \
1032                          $(check-ramstage-overlap-files) ; \
1033                     exit 1 ; \
1034                 fi ; \
1035                 rname= ; rstart= ; rend= ; \
1036             done ; \
1037             pstart= ; pend= ; \
1038         done
1040 INTERMEDIATE+=check-ramstage-overlaps
1041 PHONY+=check-ramstage-overlaps
1042 endif
1044 junit.xml:
1045         echo "Building $(BLD)"
1046         echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp
1047         echo "<testcase classname='$(BLD)' name='$(BLD)'>" >> $@.tmp
1048         -$(MAKE) -j $(CPUS) -C "$(BLD_DIR)$(BLD)" clean distclean > $@.tmp.2 2>&1
1049         $(MAKE) -j $(CPUS) -C "$(BLD_DIR)$(BLD)" $(MAKETARGET) >> $@.tmp.2 2>&1 && type="system-out" || type="failure"; \
1050         cat $@.tmp.2; \
1051         if [ "$$type" = "failure" ]; then \
1052                 echo "<failure type='buildFailed'>" >> $@.tmp; \
1053                 echo "Building $(BLD) Failed"; \
1054         else \
1055                 echo "<$$type>" >> $@.tmp; \
1056                 echo "Building $(BLD) Succeeded"; \
1057         fi; \
1058         echo '<![CDATA[' >> $@.tmp; \
1059         cat $@.tmp.2 >> $@.tmp; \
1060         echo "]]></$$type>" >>$@.tmp
1061         rm -f $@.tmp.2
1062         echo "</testcase>" >> $@.tmp
1063         echo "</testsuite>" >> $@.tmp
1064         mv $@.tmp "$(BLD_DIR)$(BLD)/$@"
1065         echo
1067 TOOLLIST= \
1068         cbmem \
1069         ectool \
1070         futility \
1071         inteltool \
1072         intelvbttool \
1073         nvramtool \
1074         superiotool \
1075         viatool
1076 JENKINS_PAYLOAD?=none
1077 CPUS?=4
1078 what-jenkins-does:
1079         util/lint/lint lint-stable --junit
1080         util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD) -x -X $(top)/abuild-chromeos.xml
1081         util/abuild/abuild -B -J $(if $(JENKINS_NOCCACHE),,-y) -c $(CPUS) -z -p $(JENKINS_PAYLOAD)
1082         (cd payloads/libpayload; unset COREBOOT_BUILD_DIR; $(MAKE) $(if $(JENKINS_NOCCACHE),,CONFIG_LP_CCACHE=y) V=$(V) Q=$(Q) junit.xml)
1083         $(foreach tool, $(TOOLLIST), $(MAKE) CPUS=$(CPUS) V=$(V) Q=$(Q) BLD_DIR=util/ BLD="$(tool)" MFLAGS= MAKEFLAGS= MAKETARGET= junit.xml; )
1084         unset COREBOOT_BUILD_DIR;$(MAKE) CPUS=$(CPUS) V=$(V) Q=$(Q) BLD_DIR=payloads/ BLD=nvramcui MFLAGS= MAKEFLAGS= MAKETARGET=all junit.xml
1085         unset COREBOOT_BUILD_DIR;$(MAKE) CPUS=$(CPUS) V=$(V) Q=$(Q) BLD_DIR=payloads/ BLD=coreinfo MFLAGS= MAKEFLAGS= MAKETARGET=defaultbuild junit.xml
1086         $(MAKE) CPUS=$(CPUS) V=$(V) Q=$(Q) BLD_DIR=util/ BLD=romcc MFLAGS= MAKEFLAGS= MAKETARGET=test junit.xml