soc/intel/cannonlake: Perform dram top calculation based on HW registers
[coreboot.git] / Makefile.inc
blob679e0ac39343ef576e73bad11cbb31eb92a513a4
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 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 util/testing
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 postcar-c-deps:=$$(OPTION_TABLE_H)
202 ramstage-c-deps:=$$(OPTION_TABLE_H)
203 romstage-c-deps:=$$(OPTION_TABLE_H)
204 verstage-c-deps:=$$(OPTION_TABLE_H)
205 bootblock-c-deps:=$$(OPTION_TABLE_H)
206 $(foreach type,ads adb, \
207   $(foreach stage,$(COREBOOT_STANDARD_STAGES), \
208     $(eval $(stage)-$(type)-deps := $(obj)/libgnat-$(ARCH-$(stage)-y)/libgnat.a)))
210 # Add handler to copy linker scripts
211 define generic-objs_ld_template_gen
212 de$(EMPTY)fine $(1)-objs_ld_template
213 $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h
214         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
215         $$(CC_$(1)) -MMD $$(CPPFLAGS_$(1)) $$($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h -MT $$$$@ -o $$$$@ $$$$<
216 en$(EMPTY)def
217 endef
219 # Add handler to deal with archives
220 define generic-objs_a_template_gen
221 de$(EMPTY)fine $(1)-objs_a_template
222 $$(call src-to-obj,$1,$$(1).a): $$(1).a
223         @printf "    AR         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
224         $$$$(AR_$(1)) rcsT $$$$@.tmp $$$$<
225         mv $$$$@.tmp $$$$@
226 en$(EMPTY)def
227 endef
229 # Add handler to add no rules for manual files
230 define generic-objs_manual_template_gen
231 # do nothing
232 endef
234 #######################################################################
235 # Add handler to compile ACPI's ASL
236 # arg1: base file name
237 # arg2: y or n for including in cbfs. defaults to y
238 define asl_template
239 $(CONFIG_CBFS_PREFIX)/$(1).aml-file = $(obj)/$(1).aml
240 $(CONFIG_CBFS_PREFIX)/$(1).aml-type = raw
241 $(CONFIG_CBFS_PREFIX)/$(1).aml-compression = none
242 cbfs-files-$(if $(2),$(2),y) += $(CONFIG_CBFS_PREFIX)/$(1).aml
243 -include $(obj)/$(1).d
244 $(obj)/$(1).aml: $(src)/mainboard/$(MAINBOARDDIR)/$(1).asl $(obj)/config.h
245         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
246         $(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 $$@
247         cd $$(dir $$@); $(IASL) -we -p $$(notdir $$@) $$(notdir $$@)
248         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
249 endef
251 #######################################################################
252 # Parse plaintext cmos defaults into binary format
253 # arg1: source file
254 # arg2: binary file name
255 cbfs-files-processor-nvramtool= \
256         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
257                 printf "    CREATE     $(2) (from $(1))\n"; \
258                 $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && \
259                 mv $(2).tmp $(2))
261 #######################################################################
262 # Link VSA binary to ELF-ish stage
263 # arg1: source file
264 # arg2: binary file name
265 cbfs-files-processor-vsa= \
266         $(eval $(2): $(1) ; \
267                 printf "    CREATE     $(2) (from $(1))\n"; \
268                 $(OBJCOPY_ramstage) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && \
269                 $(LD_ramstage) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
271 #######################################################################
272 # Reduce a .config file to its minimal representation
273 # arg1: input
274 # arg2: output
275 cbfs-files-processor-defconfig= \
276         $(eval $(2): $(1) $(obj)/build.h; \
277                 +printf "    CREATE     $(2) (from $(1))\n"; \
278                 printf "\# This image was built using coreboot " > $(2).tmp && \
279                 grep "\<COREBOOT_VERSION\>" $(obj)/build.h |cut -d\" -f2 >> $(2).tmp && \
280                 $(MAKE) DOTCONFIG=$(1) DEFCONFIG=$(2).tmp2 savedefconfig && \
281                 cat $(2).tmp2 >> $(2).tmp && \
282                 rm -f $(2).tmp2 && \
283                 \mv -f $(2).tmp $(2))
285 #######################################################################
286 # Compile a C file with a bare struct definition into binary
287 # arg1: C source file
288 # arg2: binary file
289 cbfs-files-processor-struct= \
290         $(eval $(2): $(1) $(obj)/build.h $(KCONFIG_AUTOHEADER); \
291                 printf "    CC+STRIP   $(@)\n"; \
292                 $(CC_ramstage) -MMD $(CPPFLAGS_ramstage) $(CFLAGS_ramstage) $$(ramstage-c-ccopts) -include $(KCONFIG_AUTOHEADER) -MT $(2) -o $(2).tmp -c $(1) && \
293                 $(OBJCOPY_ramstage) -O binary $(2).tmp $(2); \
294                 rm -f $(2).tmp) \
295         $(eval DEPENDENCIES += $(2).d)
297 #######################################################################
298 # Add handler for arbitrary files in CBFS
299 $(call add-special-class,cbfs-files)
300 cbfs-files-handler= \
301                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
302                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
303                 $(eval tmp-cbfs-file:= ) \
304                 $(if $($(2)-file), \
305                         $(if $(wildcard $(1)$($(2)-file)), \
306                                 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
307                                 $(eval tmp-cbfs-file:= $($(2)-file)))) \
308                 $(if $(strip $($(2)-required)), \
309                         $(if $(wildcard $(tmp-cbfs-file)),, \
310                                 $(info This build configuration requires $($(2)-required)) \
311                                 $(eval FAILBUILD:=1) \
312                         )) \
313                 $(if $(strip $($(2)-align)), \
314                         $(if $(strip $($(2)-position)), \
315                                 $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
316                                 $(eval FAILBUILD:=1) \
317                         )) \
318                 $(if $(tmp-cbfs-method), \
319                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
320                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
321                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
322                 $(if $(tmp-cbfs-file), \
323                         $(eval cbfs-files += $(subst $(spc),*,$(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align)|$($(2)-options)))) \
324                 $(eval $(2)-name:=) \
325                 $(eval $(2)-type:=) \
326                 $(eval $(2)-compression:=) \
327                 $(eval $(2)-position:=) \
328                 $(eval $(2)-required:=) \
329                 $(eval $(2)-options:=) \
330                 $(eval $(2)-align:=)
332 #######################################################################
333 # a variety of flags for our build
334 CBFS_COMPRESS_FLAG:=none
335 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
336 CBFS_COMPRESS_FLAG:=LZMA
337 endif
339 CBFS_PAYLOAD_COMPRESS_FLAG:=none
340 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
341 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
342 endif
344 CBFS_PRERAM_COMPRESS_FLAG:=none
345 ifeq ($(CONFIG_COMPRESS_PRERAM_STAGES),y)
346 CBFS_PRERAM_COMPRESS_FLAG:=LZ4
347 endif
349 ifneq ($(CONFIG_LOCALVERSION),"")
350 export COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
351 endif
353 CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -I$(obj)
354 CPPFLAGS_common += -Isrc/device/oprom/include
355 VBOOT_SOURCE ?= 3rdparty/vboot
356 CPPFLAGS_common += -I$(VBOOT_SOURCE)/firmware/include
357 CPPFLAGS_common += -include $(src)/include/kconfig.h
358 CPPFLAGS_common += -I3rdparty
360 CFLAGS_common += -pipe -g -nostdinc -std=gnu11
361 CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
362 CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
363 CFLAGS_common += -Wstrict-aliasing -Wshadow -Wdate-time
364 CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
365 CFLAGS_common += -ffunction-sections -fdata-sections -fno-pie
366 CFLAGS_common += -fno-delete-null-pointer-checks -fconserve-stack
368 ADAFLAGS_common += -gnatg -gnatp
369 ADAFLAGS_common += -Wuninitialized -Wall -Werror
370 ADAFLAGS_common += -pipe -g -nostdinc
371 ADAFLAGS_common += -Wstrict-aliasing -Wshadow
372 ADAFLAGS_common += -fno-common -fomit-frame-pointer
373 ADAFLAGS_common += -ffunction-sections -fdata-sections
374 # Ada warning options:
376 #  a   Activate most optional warnings.
377 # .e   Activate every optional warnings.
378 #  e   Treat warnings and style checks as errors.
380 #  D   Suppress warnings on implicit dereferences:
381 #      As SPARK does not accept access types we have to map the
382 #      dynamically chosen register locations to a static SPARK
383 #      variable.
385 # .H   Suppress warnings on holes/gaps in records:
386 #      We are modelling hardware here!
388 #  H   Suppress warnings on hiding:
389 #      It's too annoying, you run out of ideas for identifiers fast.
391 #  T   Suppress warnings for tracking of deleted conditional code:
392 #      We use static options to select code paths at compile time.
394 #  U   Suppress warnings on unused entities:
395 #      Would have lots of warnings for unused register definitions,
396 #      `withs` for debugging etc.
398 # .U   Deactivate warnings on unordered enumeration types:
399 #      As SPARK doesn't support `pragma Ordered` by now, we don't
400 #      use that, yet.
402 # .W   Suppress warnings on unnecessary Warnings Off pragmas:
403 #      Things get really messy when you use different compiler
404 #      versions, otherwise.
405 # .Y   Disable information messages for why package spec needs body:
406 #      Those messages are annoying. But don't forget to enable those,
407 #      if you need the information.
408 ADAFLAGS_common += -gnatwa.eeD.HHTU.U.W.Y
409 # Disable style checks for now
410 ADAFLAGS_common += -gnatyN
412 LDFLAGS_common := --gc-sections -nostdlib -nostartfiles -static --emit-relocs
414 ifeq ($(CONFIG_COMPILER_GCC),y)
415 # cf. commit f69a99db (coreboot: x86: enable gc-sections)
416 CFLAGS_common += -Wno-unused-but-set-variable
417 endif
419 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
420 CFLAGS_common += -Werror
421 endif
422 ifneq ($(GDB_DEBUG),)
423 CFLAGS_common += -Og
424 ADAFLAGS_common += -Og
425 else
426 CFLAGS_common += -Os
427 ADAFLAGS_common += -Os
428 endif
430 ifeq ($(CONFIG_DEBUG_ADA_CODE),y)
431 ADAFLAGS_common += -gnata
432 endif
434 additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/ifdtool \
435                    $(objutil)/ifdfake $(objutil)/options $(objutil)/amdfwtool \
436                    $(objutil)/cbootimage $(objutil)/bimgtool
438 #######################################################################
439 # generate build support files
440 $(obj)/build.h: .xcompile
441         @printf "    GEN        build.h\n"
442         rm -f $(obj)/build.h
443         util/genbuild_h/genbuild_h.sh > $(obj)/build.ht
444         mv $(obj)/build.ht $(obj)/build.h
446 build-dirs:
447         mkdir -p $(objcbfs) $(objgenerated)
449 #######################################################################
450 # Build the tools
451 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
452 FMAPTOOL:=$(objutil)/cbfstool/fmaptool
453 RMODTOOL:=$(objutil)/cbfstool/rmodtool
454 IFWITOOL:=$(objutil)/cbfstool/ifwitool
456 $(obj)/cbfstool: $(CBFSTOOL)
457         cp $< $@
459 $(obj)/fmaptool: $(FMAPTOOL)
460         cp $< $@
462 $(obj)/rmodtool: $(RMODTOOL)
463         cp $< $@
465 $(obj)/ifwitool: $(IFWITOOL)
466         cp $< $@
468 _WINCHECK=$(shell uname -o 2> /dev/null)
469 STACK=
470 ifeq ($(_WINCHECK),Msys)
471         STACK=-Wl,--stack,16384000
472 endif
473 ifeq ($(_WINCHECK),Cygwin)
474         STACK=-Wl,--stack,16384000
475 endif
477 # this allows ccache to prepend itself
478 # (ccache handling happens first)
479 ROMCC_BIN= $(objutil)/romcc/romcc
480 ROMCC?=$(ROMCC_BIN)
481 $(ROMCC_BIN): $(top)/util/romcc/romcc.c
482         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
483         @# Note: Adding -O2 here might cause problems. For details see:
484         @# https://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
485         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
487 IFDTOOL:=$(objutil)/ifdtool/ifdtool
488 $(IFDTOOL):
489         @printf "    Compile IFDTOOL\n"
490         +$(MAKE) -C $(top)/util/ifdtool
491         cp -a $(top)/util/ifdtool/ifdtool $@
493 IFDFAKE:=$(objutil)/ifdfake/ifdfake
494 $(IFDFAKE): $(top)/util/ifdfake/ifdfake.c
495         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
496         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
498 AMDFWTOOL:=$(objutil)/amdfwtool/amdfwtool
499 $(AMDFWTOOL): $(top)/util/amdfwtool/amdfwtool.c
500         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
501         $(HOSTCC) $(HOSTCFLAGS) -DCONFIG_ROM_SIZE=$(CONFIG_ROM_SIZE) -o $@ $<
503 CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
505 FUTILITY?=$(objutil)/futility/futility
507 subdirs-y += util/nvidia
509 BIMGTOOL:=$(objutil)/bimgtool/bimgtool
510 $(BIMGTOOL): $(top)/util/bimgtool/bimgtool.c
511         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
512         $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
514 $(obj)/config.h: $(objutil)/kconfig/conf
516 #######################################################################
517 # needed objects that every mainboard uses
518 # Creation of these is architecture and mainboard independent
519 DEVICETREE_FILE := $(src)/mainboard/$(MAINBOARDDIR)/$(CONFIG_DEVICETREE)
520 DEVICETREE_STATIC_C := $(obj)/mainboard/$(MAINBOARDDIR)/static.c
522 $(DEVICETREE_STATIC_C): $(DEVICETREE_FILE) $(objutil)/sconfig/sconfig
523         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
524         mkdir -p $(dir $(DEVICETREE_STATIC_C))
525         $(objutil)/sconfig/sconfig $(DEVICETREE_FILE) $(DEVICETREE_STATIC_C)
527 ramstage-y+=$(DEVICETREE_STATIC_C)
528 romstage-y+=$(DEVICETREE_STATIC_C)
529 verstage-y+=$(DEVICETREE_STATIC_C)
530 bootblock-y+=$(DEVICETREE_STATIC_C)
531 postcar-y+=$(DEVICETREE_STATIC_C)
533 #######################################################################
534 # Clean up rules
535 clean-abuild:
536         rm -rf coreboot-builds
538 clean-for-update-target: clean-payloads
539         rm -f $(obj)/ramstage?* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
540         rm -rf $(obj)/bootblock?* $(obj)/romstage?* $(obj)/location.*
541         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
542         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
543         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
544         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
545         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/dsdt.*
546         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
548 clean-target:
549         rm -f $(obj)/coreboot*
551 #######################################################################
552 # Development utilities
553 printcrt0s:
554         @echo crt0s=$(crt0s)
555         @echo ldscripts=$(ldscripts)
557 update:
558         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
560 gitconfig:
561         [ -d .git ]
562         mkdir -p .git/hooks
563         for hook in commit-msg pre-commit ; do                       \
564                 if [ util/gitconfig/$$hook -nt .git/hooks/$$hook -o  \
565                 ! -x .git/hooks/$$hook ]; then                       \
566                         sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/$$hook > .git/hooks/$$hook;  \
567                         chmod +x .git/hooks/$$hook;                  \
568                 fi;                                                  \
569         done
570         # Now set up thehooks for 3rdparty/
571         for hooks in .git/modules/{3rdparty/blobs,libhwbase,libgfxinit}/hooks; do                       \
572                 if [ -d $$hooks -a                                                                      \
573                 \( util/gitconfig/commit-msg -nt $$hooks/commit-msg -o                                  \
574                         ! -x $$hooks/commit-msg \) ]; then                                              \
575                         sed -e "s,%MAKE%,$(MAKE),g" util/gitconfig/commit-msg > $$hooks/commit-msg;     \
576                         chmod +x $$hooks/commit-msg;                                                    \
577                 fi                                                                                      \
578         done
579         for d in 3rdparty/{blobs,libhwbase,libgfxinit}; do                      \
580                 if [ -d $$d ]; then                                             \
581                         (cd $$d;                                                \
582                          git config remote.origin.push HEAD:refs/for/master);   \
583                 fi;                                                             \
584         done
585         git config remote.origin.push HEAD:refs/for/master
586         git config alias.sup '!git submodule update --remote --rebase && git submodule update --init --checkout'
587         git config alias.sup-destroy '!git submodule deinit --force "$$(git rev-parse --show-toplevel)"; git submodule init && git submodule update --checkout'
588         (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)
590 include util/crossgcc/Makefile.inc
592 .PHONY: tools
593 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
595 ###########################################################################
596 # Common recipes for all stages
597 ###########################################################################
599 # loadaddr can determine the load address of a stage, which may be needed for
600 # platform-specific image headers (only works *after* the stage has been built)
601 loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
602              sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
604 # find-substr is required for stages like romstage_null and romstage_xip to
605 # eliminate the _* part of the string
606 find-substr = $(word 1,$(subst _, ,$(1)))
608 # find-class is used to identify the class from the name of the stage
609 # The input to this macro can be something like romstage.x or romstage.x.y
610 # find-class recursively strips off the suffixes to extract the exact class name
611 # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
612 # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
613 # and remove .x the next time and finally return romstage
614 find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
616 # Bootblocks are not CBFS stages. coreboot is currently expecting the bss to
617 # be cleared by the loader of the stage. For ARM SoCs that means one needs to
618 # include the bss section in the binary so the BootROM clears the bss on
619 # loading of the bootblock stage. Achieve this by marking the bss section
620 # loadable,allocatable, and data. Do the same for the .data section in case
621 # it's marked as NOBITS.
622 $(objcbfs)/bootblock.raw.bin: $(objcbfs)/bootblock.elf
623         @printf "    OBJCOPY    $(notdir $(@))\n"
624         $(OBJCOPY_bootblock) --set-section-flags .bss=load,alloc,data --set-section-flags .data=load,alloc,data $< $<.tmp
625         $(OBJCOPY_bootblock) -O binary $<.tmp $@
627 $(objcbfs)/%.bin: $(objcbfs)/%.raw.bin
628         cp $< $@
630 $(objcbfs)/%.elf: $(objcbfs)/%.debug
631         $(eval class := $(call find-class,$(@F)))
632         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
633         cp $< $@.tmp
634         $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
635         $(OBJCOPY_$(class)) --strip-debug $@.tmp
636         $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
637         mv $@.tmp $@
639 ###########################################################################
640 # Build the final rom image
641 ###########################################################################
643 # extract_nth - Return a subsection of the $file string
645 # the input string looks like this:
646 # ./build/cbfs/fallback/romstage.elf|fallback/romstage|stage|none||64|--xip*-S*.car.data*-P*0x10000
648 # Sections:
649 # 1 - Path and name of file [FILENAME: Added to cbfs-files-y list variable]
650 # 2 - Name of file in cbfs  [$(FILENAME)-file]
651 # 3 - File type:            [$(FILENAME)-type]
652 #                bootblock, cbfs header, stage, payload, optionrom, bootsplash, raw, vsa,
653 #                mbi, microcode, fsp, mrc, cmos_default, cmos_layout, spd, mrc_cache,
654 #                mma, efi, deleted, null
655 # 4 - Compression type      [$(FILENAME)-compression]
656 #                      none, LZMA
657 # 5 - Base address          [$(FILANAME)-position]
658 # 6 - Alignment             [$(FILENAME)-align]
659 # 7 - cbfstool flags        [$(FILENAME)-options]
661 # Input:
662 #  $(1) = Section to extract
663 #  $(2) = Input string
665 # Steps:
666 # 1) replace all '|' characters with the sequence '- -' within the full string, prepended and appended with the character '-'
667 # 2) extract the specified section from the string - this gets us the section surrounded by '-' characters
668 # 3) remove the leading and trailing '-' characters
669 # 4) replace all '*' characters with spaces
670 extract_nth=$(subst *,$(spc),$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-))))
672 # regions-for-file - Returns a cbfstool regions parameter
673 # $(call regions-for-file,$(filename))
674 # returns "REGION1,REGION2,..."
676 # This is the default implementation. When using a boot strategy employing
677 # multiple CBFSes in fmap regions, override it.
678 regions-for-file ?= COREBOOT
680 ifeq ($(CONFIG_CBFS_AUTOGEN_ATTRIBUTES),y)
681         cbfs-autogen-attributes=-g
682 endif
684 # cbfs-add-cmd-for-region
685 # $(call cbfs-add-cmd-for-region,file in extract_nth format,region name)
686 define cbfs-add-cmd-for-region
687         $(CBFSTOOL) $@.tmp \
688         add$(if $(filter stage,$(call extract_nth,3,$(1))),-stage)$(if \
689                 $(filter payload,$(call extract_nth,3,$(1))),-payload)$(if \
690                 $(filter flat-binary,$(call extract_nth,3,$(1))),-flat-binary) \
691         -f $(call extract_nth,1,$(1)) \
692         -n $(call extract_nth,2,$(1)) \
693         $(if $(filter-out flat-binary,$(filter-out stage,$(call \
694                 extract_nth,3,$(1)))),-t $(call extract_nth,3,$(1))) \
695         $(if $(call extract_nth,4,$(1)),-c $(call extract_nth,4,$(1))) \
696         $(cbfs-autogen-attributes) \
697         -r $(2) \
698         $(if $(call extract_nth,6,$(1)),-a $(call extract_nth,6,$(file)), \
699                 $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file)))) \
700                 $(call extract_nth,7,$(1))
703 endef
704 # Empty line before endef is necessary so cbfs-add-cmd-for-region ends in a
705 # newline
707 # cbfs-add-cmd
708 # $(call cbfs-add-cmd,
709 #          file in extract_nth format,
710 #          region name,
711 #          non-empty if file removal requested)
712 define cbfs-add-cmd
713         printf "    CBFS       $(call extract_nth,2,$(1))\n"
714         $(if $(3),-$(CBFSTOOL) $@.tmp remove -n $(call extract_nth,2,$(file)) 2>/dev/null)
715         $(call cbfs-add-cmd-for-region,$(1),$(2))
716 endef
718 # list of files to add (using their file system names, not CBFS names),
719 # for dependencies etc.
720 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
722 # $(all-regions)
723 # returns full list of fmap regions that we add files to
724 all-regions = $(sort $(subst $(comma),$(spc), \
725         $(foreach file,$(cbfs-files), \
726                 $(call regions-for-file,$(call extract_nth,2,$(file))))))
728 # $(call all-files-in-region,region name)
729 # returns elements in $(cbfs-files) that end up in that region, in the order
730 # they appear in $(cbfs-files)
731 all-files-in-region = $(foreach file,$(cbfs-files), \
732         $(if $(filter $(1), \
733                 $(subst $(comma),$(spc),$(call regions-for-file,$(call extract_nth,2,$(file))))), \
734                 $(file)))
736 # $(call update-file-for-region,file string from $(cbfs-files),region name)
737 # Update position and alignment according to overrides for region
738 # Doesn't check for invalid configurations (eg. resetting neither or both
739 # position and align)
740 # Returns the updated file string
741 update-file-for-region = \
742         $(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)))
744 # $(call placed-files-in-region,region name)
745 # like all-files-in-region, but updates the files to contain region overrides
746 # to position or alignment.
747 placed-files-in-region = $(foreach file,$(call all-files-in-region,$(1)), \
748         $(if $($(call extract_nth,2,$(file))-$(1)-position), \
749                 $(if $($(call extract_nth,2,$(file))-$(1)-align), \
750                         $(error It is not allowed to specify both alignment and position for $(call extract_nth,2,$(file))-$(1))) \
751                 $(call update-file-for-region,$(file),$(1)), \
752                 $(if $($(call extract_nth,2,$(file))-$(1)-align), \
753                         $(call update-file-for-region,$(file),$(1)), \
754                         $(file))))
756 # $(call sort-files,subset of $(cbfs-files))
757 # reorders the files in the given set to list files at fixed positions first,
758 # followed by aligned files and finally those with no constraints.
759 sort-files = \
760         $(eval _tmp_fixed:=) \
761         $(eval _tmp_aligned:=) \
762         $(eval _tmp_regular:=) \
763         $(foreach file,$(1), \
764                 $(if $(call extract_nth,5,$(file)),\
765                         $(eval _tmp_fixed += $(file)), \
766                 $(if $(call extract_nth,6,$(file)), \
767                         $(eval _tmp_aligned += $(file)), \
768                         $(eval _tmp_regular += $(file))))) \
769         $(_tmp_fixed) $(_tmp_aligned) $(_tmp_regular)
771 # command list to add files to CBFS
772 prebuild-files = $(foreach region,$(all-regions), \
773         $(foreach file, \
774                 $(call sort-files,$(call placed-files-in-region,$(region))), \
775                 $(call cbfs-add-cmd,$(file),$(region),$(CONFIG_UPDATE_IMAGE))))
777 ifeq ($(CONFIG_FMDFILE),)
778 # For a description of the flash layout described by these variables, check
779 # the $(DEFAULT_FLASHMAP) .fmd files.
780 ifeq ($(CONFIG_ARCH_X86),y)
781 DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default-x86.fmd
782 # entire flash
783 FMAP_ROM_ADDR := $(call int-subtract, 0x100000000 $(CONFIG_ROM_SIZE))
784 FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
785 # entire "BIOS" region (everything directly of concern to the host system)
786 # relative to ROM_BASE
787 FMAP_BIOS_BASE := $(call int-subtract, $(CONFIG_ROM_SIZE) $(CONFIG_CBFS_SIZE))
788 FMAP_BIOS_SIZE := $(shell echo $(CONFIG_CBFS_SIZE) | tr A-F a-f)
789 # position and size of flashmap, relative to BIOS_BASE
790 FMAP_FMAP_BASE := 0
791 FMAP_FMAP_SIZE := 0x100
792 # position, size and entry line of CONSOLE relative to BIOS_BASE, if enabled
793 ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
794 FMAP_CONSOLE_BASE := $(call int-add, $(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE))
795 FMAP_CONSOLE_SIZE := $(CONFIG_CONSOLE_SPI_FLASH_BUFFER_SIZE)
796 FMAP_CONSOLE_ENTRY := CONSOLE@$(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE)
797 else # ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
798 FMAP_CONSOLE_BASE := 0
799 FMAP_CONSOLE_SIZE := 0
800 FMAP_CONSOLE_ENTRY :=
801 endif # ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
802 # position and size of CBFS, relative to BIOS_BASE
803 FMAP_CBFS_BASE := $(call int-add, $(FMAP_CONSOLE_SIZE) $(FMAP_FMAP_SIZE))
804 FMAP_CBFS_SIZE := $(call int-subtract, $(FMAP_BIOS_SIZE) $(FMAP_CBFS_BASE))
805 else # ifeq ($(CONFIG_ARCH_X86),y)
806 DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default.fmd
807 # entire flash
808 FMAP_ROM_ADDR := 0
809 FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
810 # entire "BIOS" region (everything directly of concern to the host system)
811 # relative to ROM_BASE
812 FMAP_BIOS_BASE := 0
813 FMAP_BIOS_SIZE := $(CONFIG_CBFS_SIZE)
814 # position and size of flashmap, relative to BIOS_BASE
815 FMAP_FMAP_BASE := 0x20000
816 FMAP_FMAP_SIZE := 0x100
817 # position, size and entry line of CONSOLE relative to BIOS_BASE, if enabled
818 ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
819 FMAP_CONSOLE_BASE := $(call int-add, $(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE))
820 FMAP_CONSOLE_SIZE := $(CONFIG_CONSOLE_SPI_FLASH_BUFFER_SIZE)
821 FMAP_CONSOLE_ENTRY := CONSOLE@$(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE)
822 else # ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
823 FMAP_CONSOLE_BASE := 0
824 FMAP_CONSOLE_SIZE := 0
825 FMAP_CONSOLE_ENTRY :=
826 endif # ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
827 # position and size of CBFS, relative to BIOS_BASE
828 FMAP_CBFS_BASE := $(call int-add,$(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE) $(FMAP_CONSOLE_SIZE))
829 FMAP_CBFS_SIZE := $(call int-subtract,$(FMAP_BIOS_SIZE) $(FMAP_CBFS_BASE))
830 endif # ifeq ($(CONFIG_ARCH_X86),y)
832 $(obj)/fmap.fmd: $(top)/Makefile.inc $(DEFAULT_FLASHMAP) $(obj)/config.h
833         sed -e "s,##ROM_BASE##,$(FMAP_ROM_ADDR)," \
834             -e "s,##ROM_SIZE##,$(FMAP_ROM_SIZE)," \
835             -e "s,##BIOS_BASE##,$(FMAP_BIOS_BASE)," \
836             -e "s,##BIOS_SIZE##,$(FMAP_BIOS_SIZE)," \
837             -e "s,##FMAP_BASE##,$(FMAP_FMAP_BASE)," \
838             -e "s,##FMAP_SIZE##,$(FMAP_FMAP_SIZE)," \
839             -e "s,##CONSOLE_ENTRY##,$(FMAP_CONSOLE_ENTRY)," \
840             -e "s,##CBFS_BASE##,$(FMAP_CBFS_BASE)," \
841             -e "s,##CBFS_SIZE##,$(FMAP_CBFS_SIZE)," \
842                 $(DEFAULT_FLASHMAP) > $@.tmp
843         mv $@.tmp $@
844 else # ifeq ($(CONFIG_FMDFILE),)
845 $(obj)/fmap.fmd: $(CONFIG_FMDFILE) $(obj)/config.h
846         $(HOSTCC) $(PREPROCESS_ONLY) -include $(obj)/config.h $< -o $@.pre
847         mv $@.pre $@
848 endif # ifeq ($(CONFIG_FMDFILE),)
850 # generated at the same time as fmap.fmap
851 $(obj)/fmap_config.h: $(obj)/fmap.fmap
852 $(obj)/fmap.desc: $(obj)/fmap.fmap
854 $(obj)/fmap.fmap: $(obj)/fmap.fmd $(FMAPTOOL)
855         echo "    FMAP       $(FMAPTOOL) -h $(obj)/fmap_config.h $< $@"
856         $(FMAPTOOL) -h $(obj)/fmap_config.h -R $(obj)/fmap.desc $< $@
858 ifneq ($(CONFIG_UPDATE_IMAGE),y)
859 $(obj)/coreboot.pre: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL) $$(cpu_ucode_cbfs_file) $(obj)/fmap.fmap $(obj)/fmap.desc
860         $(CBFSTOOL) $@.tmp create -M $(obj)/fmap.fmap -r $(shell cat $(obj)/fmap.desc)
861 ifeq ($(CONFIG_ARCH_X86),y)
862         $(CBFSTOOL) $@.tmp add \
863                 -f $(objcbfs)/bootblock.bin \
864                 -n bootblock \
865                 -t bootblock \
866                 -b -$(call file-size,$(objcbfs)/bootblock.bin) $(cbfs-autogen-attributes)
867 else # ifeq ($(CONFIG_ARCH_X86),y)
868         $(CBFSTOOL) $@.tmp write -u \
869                 -r BOOTBLOCK \
870                 -f $(objcbfs)/bootblock.bin
871         # make space for the CBFS master header pointer. "ptr_" is just
872         # arbitrary 4 bytes that will be overwritten by add-master-header.
873         printf "ptr_" > $@.tmp.2
874         $(CBFSTOOL) $@.tmp add \
875                 -f $@.tmp.2 \
876                 -n "header pointer" \
877                 -t "cbfs header" \
878                 -b -4
879         rm -f $@.tmp.2
880 endif # ifeq ($(CONFIG_ARCH_X86),y)
881         $(CBFSTOOL) $@.tmp add-master-header
882         $(prebuild-files) true
883         mv $@.tmp $@
884 else # ifneq ($(CONFIG_UPDATE_IMAGE),y)
885 .PHONY: $(obj)/coreboot.pre
886 $(obj)/coreboot.pre: $$(prebuilt-files) $(CBFSTOOL)
887         mv $(obj)/coreboot.rom $@.tmp || \
888         (echo "Error: You have UPDATE_IMAGE set in Kconfig, but have no existing image to update." && \
889         echo "Exiting." && \
890         false)
891         $(prebuild-files) true
892         mv $@.tmp $@
893 endif # ifneq ($(CONFIG_UPDATE_IMAGE),y)
895 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
896 REFCODE_BLOB=$(obj)/refcode.rmod
897 $(REFCODE_BLOB): $(RMODTOOL)
898         $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
899 endif
901 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(objcbfs)/ramstage.elf $(CBFSTOOL) $$(INTERMEDIATE)
902         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
903 # The full ROM may be larger than the CBFS part, so create an empty
904 # file (filled with \377 = 0xff) and copy the CBFS image over it.
905         dd if=/dev/zero bs=$(call _toint,$(CONFIG_ROM_SIZE)) count=1 2> /dev/null | tr '\000' '\377' > $@.tmp
906         dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
907 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
908 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
909 ifneq ($(CONFIG_UPDATE_IMAGE),y)
910         @printf "    SeaBIOS    Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
911         $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
912 endif
913 endif
914 endif
915 ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
916 ifeq ($(CONFIG_CPU_MICROCODE_CBFS_EXTERNAL_HEADER),y)
917         @printf "    UPDATE-FIT\n"
918         $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
919 endif
921 ifeq ($(CONFIG_CPU_MICROCODE_CBFS_GENERATE),y)
922         @printf "    UPDATE-FIT\n"
923         $(CBFSTOOL) $@.tmp update-fit -n cpu_microcode_blob.bin -x $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES)
924 endif
925 endif
926         mv $@.tmp $@
927         @printf "    CBFSPRINT  $(subst $(obj)/,,$(@))\n\n"
928         $(CBFSTOOL) $@ print -r $(subst $(spc),$(comma),$(all-regions))
930 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/romstage
931 $(CONFIG_CBFS_PREFIX)/romstage-file := $(objcbfs)/romstage.elf
932 $(CONFIG_CBFS_PREFIX)/romstage-type := stage
933 $(CONFIG_CBFS_PREFIX)/romstage-compression := $(CBFS_PRERAM_COMPRESS_FLAG)
934 ifeq ($(CONFIG_ARCH_ROMSTAGE_ARM),y)
935 $(CONFIG_CBFS_PREFIX)/romstage-options := -b 0
936 endif
937 ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32)$(CONFIG_ARCH_ROMSTAGE_X86_64),y)
938 # Use a 64 byte alignment to provide a minimum alignment
939 # requirement for the overall romstage. While the first object within
940 # romstage could have a 4 byte minimum alignment that doesn't mean the linker
941 # won't decide the entire section should be aligned to a larger value. In the
942 # future cbfstool should add XIP files proper and honor the alignment
943 # requirements of the program segment.
945 # Make sure that segment for .car.data is ignored while adding romstage.
946 $(CONFIG_CBFS_PREFIX)/romstage-align := 64
947 $(CONFIG_CBFS_PREFIX)/romstage-options := -S ".car.data"
949 # If CAR does not support execution of code, romstage on x86 is expected to be
950 # xip.
951 ifneq ($(CONFIG_NO_XIP_EARLY_STAGES),y)
952 $(CONFIG_CBFS_PREFIX)/romstage-options += --xip
954 # If XIP_ROM_SIZE isn't being used don't overly constrain romstage by passing
955 # -P with a default value.
956 ifneq ($(CONFIG_NO_FIXED_XIP_ROM_SIZE),y)
957 $(CONFIG_CBFS_PREFIX)/romstage-options += -P $(CONFIG_XIP_ROM_SIZE)
958 endif    # CONFIG_NO_FIXED_XIP_ROM_SIZE
960 endif   # CONFIG_NO_XIP_EARLY_STAGES
961 endif   # CONFIG_ARCH_ROMSTAGE_X86_32 / CONFIG_ARCH_ROMSTAGE_X86_64
963 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/ramstage
964 $(CONFIG_CBFS_PREFIX)/ramstage-file := $(objcbfs)/ramstage.elf
965 $(CONFIG_CBFS_PREFIX)/ramstage-type := stage
966 $(CONFIG_CBFS_PREFIX)/ramstage-compression := $(CBFS_COMPRESS_FLAG)
968 cbfs-files-$(CONFIG_HAVE_REFCODE_BLOB) += $(CONFIG_CBFS_PREFIX)/refcode
969 $(CONFIG_CBFS_PREFIX)/refcode-file := $(REFCODE_BLOB)
970 $(CONFIG_CBFS_PREFIX)/refcode-type := stage
971 $(CONFIG_CBFS_PREFIX)/refcode-compression := $(CBFS_COMPRESS_FLAG)
973 cbfs-files-$(CONFIG_SEABIOS_VGA_COREBOOT) += vgaroms/seavgabios.bin
974 vgaroms/seavgabios.bin-file := $(CONFIG_PAYLOAD_VGABIOS_FILE)
975 vgaroms/seavgabios.bin-type := raw
977 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += config
978 config-file := $(DOTCONFIG):defconfig
979 config-type := raw
981 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += revision
982 revision-file := $(obj)/build.h
983 revision-type := raw
985 BOOTSPLASH_SUFFIX=$(suffix $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE)))
986 cbfs-files-$(CONFIG_BOOTSPLASH_IMAGE) += bootsplash$(BOOTSPLASH_SUFFIX)
987 bootsplash$(BOOTSPLASH_SUFFIX)-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
988 bootsplash$(BOOTSPLASH_SUFFIX)-type := bootsplash
990 cbfs-files-$(CONFIG_BOARD_ID_MANUAL) += board_id
991 board_id-file := $(obj)/board_id
992 board_id-type := raw
994 $(obj)/board_id:
995         printf $(CONFIG_BOARD_ID_STRING) > $@
997 # Ensure that no payload segment overlaps with memory regions used by ramstage
998 # (not for x86 since it can relocate itself in that case)
999 ifneq ($(CONFIG_ARCH_X86),y)
1000 check-ramstage-overlap-regions := ramstage
1001 check-ramstage-overlap-files :=
1002 ifneq ($(CONFIG_PAYLOAD_NONE),y)
1003 check-ramstage-overlap-files += $(CONFIG_CBFS_PREFIX)/payload
1004 endif
1006 # will output one or more lines of "<load address in hex> <memlen in decimal>"
1007 cbfs-get-segments-cmd = $(CBFSTOOL) $(obj)/coreboot.pre print -v | sed -n \
1008         '\%$(1)%,\%^[^ ]\{4\}%s%    .*load: \(0x[0-9a-fA-F]*\),.*length: [0-9]*/\([0-9]*\).*%\1 \2%p'
1010 ramstage-symbol-addr-cmd = $(OBJDUMP_ramstage) -t $(objcbfs)/ramstage.elf | \
1011         sed -n '/ $(1)$$/s/^\([0-9a-fA-F]*\) .*/0x\1/p'
1013 check-ramstage-overlaps: $(obj)/coreboot.pre
1014         programs=$$($(foreach file,$(check-ramstage-overlap-files), \
1015                 $(call cbfs-get-segments-cmd,$(file)) ; )) ; \
1016         regions=$$($(foreach region,$(check-ramstage-overlap-regions), \
1017                 echo $(region) ; \
1018                 $(call ramstage-symbol-addr-cmd,_$(region)) ; \
1019                 $(call ramstage-symbol-addr-cmd,_e$(region)) ; )) ; \
1020         pstart= ; pend= ; \
1021         for x in $$programs; do \
1022             if [ -z $$pstart ]; then pstart=$$(($$x)) ; continue ; fi ; \
1023             pend=$$(($$pstart + $$x)) ; \
1024             rname= ; rstart= ; rend= ; \
1025             for y in $$regions ; do \
1026                 if [ -z $$rname ]; then rname=$$y ; continue ; fi ; \
1027                 if [ -z $$rstart ]; then rstart=$$(($$y)) ; continue ; fi ; \
1028                 rend=$$(($$y)) ; \
1029                 if [ $$pstart -lt $$rend -a $$rstart -lt $$pend ]; then \
1030                     echo "ERROR: Ramstage region _$$rname overlapped by:" \
1031                          $(check-ramstage-overlap-files) ; \
1032                     exit 1 ; \
1033                 fi ; \
1034                 rname= ; rstart= ; rend= ; \
1035             done ; \
1036             pstart= ; pend= ; \
1037         done
1039 INTERMEDIATE+=check-ramstage-overlaps
1040 PHONY+=check-ramstage-overlaps
1041 endif