mb/google/zork: Add support for fingerprint device
[coreboot.git] / Makefile.inc
blob86335d9a88757e8db7c9904739b2832d9006daf9
1 # SPDX-License-Identifier: GPL-2.0-only
3 ifneq ($(NOCOMPILE),1)
4 GIT:=$(shell git -C "$(top)" rev-parse --git-dir 1>/dev/null 2>&1 \
5         && command -v git)
6 else
7 GIT:=
8 endif
10 #######################################################################
11 # normalize Kconfig variables in a central place
12 CONFIG_CBFS_PREFIX:=$(call strip_quotes,$(CONFIG_CBFS_PREFIX))
13 CONFIG_FMDFILE:=$(call strip_quotes,$(CONFIG_FMDFILE))
14 CONFIG_DEVICETREE:=$(call strip_quotes, $(CONFIG_DEVICETREE))
15 CONFIG_OVERRIDE_DEVICETREE:=$(call strip_quotes, $(CONFIG_OVERRIDE_DEVICETREE))
16 CONFIG_MEMLAYOUT_LD_FILE:=$(call strip_quotes, $(CONFIG_MEMLAYOUT_LD_FILE))
18 #######################################################################
19 # misleadingly named, this is the coreboot version
20 ifeq ($(KERNELVERSION),)
21 ifeq ($(BUILD_TIMELESS),1)
22 KERNELVERSION := -TIMELESS--LESSTIME-
23 else
24 KERNELVERSION := $(strip $(if $(GIT),\
25         $(shell git describe --dirty --always || git describe),\
26         $(if $(wildcard $(top)/.coreboot-version),\
27                 $(shell cat $(top)/.coreboot-version),\
28                 coreboot-unknown$(KERNELREVISION))))
29 endif
30 endif
31 COREBOOT_EXPORTS += KERNELVERSION
33 #######################################################################
34 # Basic component discovery
35 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
36 VARIANT_DIR:=$(call strip_quotes,$(CONFIG_VARIANT_DIR))
37 COREBOOT_EXPORTS += MAINBOARDDIR VARIANT_DIR
39 ## Final build results, which CBFSTOOL uses to create the final
40 ## rom image file, are placed under $(objcbfs).
41 ## These typically have suffixes .debug .elf .bin and .map
42 objcbfs := $(obj)/cbfs/$(CONFIG_CBFS_PREFIX)
43 COREBOOT_EXPORTS += objcbfs
45 ## Based on the active configuration, Makefile conditionally collects
46 ## the required assembly includes and saves them in a file.
47 ## Such files that do not have a clear one-to-one relation to a source
48 ## file under src/ are placed and built under $(objgenerated)
49 objgenerated := $(obj)/generated
50 COREBOOT_EXPORTS += objgenerated
52 ## CCACHE_EXTRAFILES can be set by individual rules to help CCACHE
53 ## discover dependencies it might not notice on its own (e.g. asm (".incbin")).
54 COREBOOT_EXPORTS += CCACHE_EXTRAFILES
56 #######################################################################
57 # root rule to resolve if in build mode (ie. configuration exists)
58 real-target: $(obj)/config.h coreboot files_added
59 coreboot: build-dirs $(obj)/coreboot.rom $(obj)/cbfstool $(obj)/rmodtool $(obj)/ifwitool
61 # This target can be used in site local to run scripts or additional
62 # targets after the build completes by creating a Makefile.inc in the
63 # site-local directory with a target named 'build_complete::'
64 build_complete:: coreboot
65         printf "\nBuilt %s (%s)\n" $(MAINBOARDDIR) \
66                 $(CONFIG_MAINBOARD_PART_NUMBER)
68 # This target can be used to run rules after all files were added to CBFS,
69 # for example to process FMAP regions or the entire image.
70 files_added:: build_complete
72 #######################################################################
73 # our phony targets
74 PHONY+= clean-abuild coreboot check-style build-dirs build_complete
76 #######################################################################
77 # root source directories of coreboot
78 subdirs-y := src/lib src/commonlib/ src/console src/device src/acpi
79 subdirs-y += src/ec/acpi $(wildcard src/ec/*/*) $(wildcard src/southbridge/*/*)
80 subdirs-y += $(wildcard src/soc/*/*) $(wildcard src/northbridge/*/*)
81 subdirs-y += src/superio
82 subdirs-y += $(wildcard src/drivers/*) $(wildcard src/drivers/*/*)
83 subdirs-y += src/cpu src/vendorcode
84 subdirs-y += util/cbfstool util/sconfig util/nvramtool util/pgtblgen
85 subdirs-y += util/futility util/marvell util/bincfg util/supermicro
86 subdirs-y += $(wildcard src/arch/*)
87 subdirs-y += src/mainboard/$(MAINBOARDDIR)
88 subdirs-y += src/security
89 subdirs-y += payloads payloads/external
91 subdirs-y += site-local
92 subdirs-y += util/checklist util/testing
94 #######################################################################
95 # Add source classes and their build options
96 classes-y := ramstage romstage bootblock decompressor postcar smm smmstub cpu_microcode verstage
98 # Add a special 'all' class to add sources to all stages
99 $(call add-special-class,all)
100 all-handler = $(foreach class,bootblock verstage romstage postcar ramstage,$(eval $(class)-y += $(2)))
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 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-shift-left: Shift $1 left by $2 bits
120 # int-lt:         1 if the first value is less than the second.  0 otherwise
121 # int-gt:         1 if the first values is greater than the second.  0 otherwise
122 # int-eq:         1 if the two values are equal.  0 otherwise
123 # int-align:      align $1 to $2 units
124 # file-size:      returns the filesize of the given file
125 # tolower:        returns the value in all lowercase
126 # toupper:        returns the value in all uppercase
127 # ws_to_under:    returns the value with any whitespace changed to underscores
128 _toint=$(shell printf "%d" $1)
129 _int-add2=$(shell expr $(call _toint,$1) + $(call _toint,$2))
130 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)))
131 int-subtract=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) - $(call _toint,$(word 2,$1))))
132 _int-multiply2=$(shell expr $(call _toint,$1) \* $(call _toint,$2))
133 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)))
134 int-divide=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) / $(call _toint,$(word 2,$1))))
135 int-remainder=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) % $(call _toint,$(word 2,$1))))
136 int-shift-left=$(shell echo "$(call _toint,$(word 1, $1)) * (2 ^ $(call _toint,$(word 2, $1)))" | bc)
137 int-lt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \< $(call _toint,$(word 2,$1))))
138 int-gt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \> $(call _toint,$(word 2,$1))))
139 int-eq=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) = $(call _toint,$(word 2,$1))))
140 int-align=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A + \( \( $$B - \( $$A % $$B \) \) % $$B \) )
141 int-align-down=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A - \( $$A % $$B \) )
142 file-size=$(strip $(shell cat $1 | wc -c))
143 tolower=$(shell echo '$1' | tr '[:upper:]' '[:lower:]')
144 toupper=$(shell echo '$1' | tr '[:lower:]' '[:upper:]')
145 ws_to_under=$(shell echo '$1' | tr ' \t' '_')
147 #######################################################################
148 # Helper functions for ramstage postprocess
149 spc :=
150 spc := $(spc) $(spc)
151 comma := ,
153 # Returns all files and dirs below `dir` (recursively).
154 # files-below-dir,dir,files
155 files-below-dir=$(filter $(1)%,$(2))
157 # Returns all dirs below `dir` (recursively).
158 # dirs-below-dir,dir,files
159 dirs-below-dir=$(filter-out $(1),$(sort $(dir $(call files-below-dir,$(1),$(2)))))
161 # Returns all files directly in `dir` (non-recursively).
162 # files-in-dir,dir,files
163 files-in-dir=$(filter-out $(addsuffix %,$(call dirs-below-dir,$(1),$(2))),$(call files-below-dir,$(1),$(2)))
165 #######################################################################
166 # reduce command line length by linking the objects of each
167 # directory into an intermediate file
168 ramstage-postprocess=$$(eval DEPENDENCIES+=$$(addsuffix .d,$$(basename $(1)))) \
169         $(foreach d,$(sort $(dir $(filter-out %.ld,$(1)))), \
170         $(eval $(d)ramstage.a: $(call files-in-dir,$(d),$(filter-out %.ld,$(1))); rm -f $$@ && $(AR_ramstage) rcsT $$@ $$^ ) \
171         $(eval ramstage-objs:=$(d)ramstage.a $(filter-out $(filter-out %.ld, $(call files-in-dir,$(d),$(1))),$(ramstage-objs))))
173 decompressor-generic-ccopts += -D__DECOMPRESSOR__
174 bootblock-generic-ccopts += -D__BOOTBLOCK__
175 romstage-generic-ccopts += -D__ROMSTAGE__
176 ramstage-generic-ccopts += -D__RAMSTAGE__
177 ifeq ($(CONFIG_TRACE),y)
178 ramstage-c-ccopts += -finstrument-functions
179 endif
180 ifeq ($(CONFIG_COVERAGE),y)
181 ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
182 endif
184 ifneq ($(UPDATED_SUBMODULES),1)
185 # try to fetch non-optional submodules if the source is under git
186 forgetthis:=$(if $(GIT),$(shell git submodule update --init))
187 ifeq ($(CONFIG_USE_BLOBS),y)
188 # These items are necessary because each has update=none in .gitmodules.  They are ignored
189 # until expressly requested and enabled with --checkout
190 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/blobs))
191 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/intel-microcode))
192 ifeq ($(CONFIG_PLATFORM_USES_FSP1_0)$(CONFIG_PLATFORM_USES_FSP1_1)$(CONFIG_PLATFORM_USES_FSP2_0),y)
193 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/fsp))
194 endif
195 ifeq ($(CONFIG_USE_AMD_BLOBS),y)
196 forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/amd_blobs))
197 endif
198 endif
199 UPDATED_SUBMODULES:=1
200 COREBOOT_EXPORTS += UPDATED_SUBMODULES
201 endif
203 postcar-c-deps:=$$(OPTION_TABLE_H)
204 ramstage-c-deps:=$$(OPTION_TABLE_H)
205 romstage-c-deps:=$$(OPTION_TABLE_H)
206 verstage-c-deps:=$$(OPTION_TABLE_H)
207 bootblock-c-deps:=$$(OPTION_TABLE_H)
208 $(foreach type,ads adb, \
209   $(foreach stage,$(COREBOOT_STANDARD_STAGES), \
210     $(eval $(stage)-$(type)-deps := \
211         $(obj)/$(stage)/$(notdir $(KCONFIG_AUTOADS)) \
212         $(obj)/libgnat-$(ARCH-$(stage)-y)/libgnat.a)))
214 # Add handler to copy linker scripts
215 define generic-objs_ld_template_gen
216 de$(EMPTY)fine $(1)-objs_ld_template
217 $$(call src-to-obj,$1,$$(1).ld): $$(1).ld $(obj)/config.h $(obj)/fmap_config.h
218         @printf "    CP         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
219         $$(CC_$(1)) -MMD $$(CPPFLAGS_$(1)) $$($(1)-ld-ccopts) $(PREPROCESS_ONLY) -include $(obj)/config.h -MT $$$$@ -o $$$$@ $$$$<
220 en$(EMPTY)def
221 endef
223 # Add handler to deal with archives
224 define generic-objs_a_template_gen
225 de$(EMPTY)fine $(1)-objs_a_template
226 $$(call src-to-obj,$1,$$(1).a): $$(1).a
227         @printf "    AR         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
228         $$$$(AR_$(1)) rcsT $$$$@.tmp $$$$<
229         mv $$$$@.tmp $$$$@
230 en$(EMPTY)def
231 endef
233 # Add handler to add no rules for manual files
234 define generic-objs_manual_template_gen
235 # do nothing
236 endef
238 #######################################################################
239 # Add handler to compile ACPI's ASL
240 # arg1: base file name
241 # arg2: y or n for including in cbfs. defaults to y
243 # Empty resource templates were marked as a warning in IASL with the comment
244 # "This would appear to be worthless in real-world ASL code.", which is
245 # possibly true in many cases.  In other cases it seems that an empty
246 # ResourceTemplate is the correct code.
247 # As it's valid ASL, disable the warning.
248 EMPTY_RESOURCE_TEMPLATE_WARNING = 3150
249 # Redundant offset remarks are not useful in any way and are masking useful
250 # ones that might indicate an issue so it is better to hide them.
251 REDUNDANT_OFFSET_REMARK = 2158
252 # Ignore _HID & _ADR coexisting in Intel Lynxpoint and Broadwell ASL code.
253 # See cb:38803 & cb:38802
254 # "Multiple types (Device object requires either a _HID or _ADR, but not both)"
255 MULTIPLE_TYPES_WARNING = 3073
257 ifeq ($(CONFIG_SOUTHBRIDGE_INTEL_LYNXPOINT)$(CONFIG_SOC_INTEL_BROADWELL),y)
258 IGNORED_IASL_WARNINGS = -vw $(EMPTY_RESOURCE_TEMPLATE_WARNING) -vw $(REDUNDANT_OFFSET_REMARK) -vw $(MULTIPLE_TYPES_WARNING)
259 else
260 IGNORED_IASL_WARNINGS = -vw $(EMPTY_RESOURCE_TEMPLATE_WARNING) -vw $(REDUNDANT_OFFSET_REMARK)
261 endif
263 define asl_template
264 $(CONFIG_CBFS_PREFIX)/$(1).aml-file = $(obj)/$(1).aml
265 $(CONFIG_CBFS_PREFIX)/$(1).aml-type = raw
266 $(CONFIG_CBFS_PREFIX)/$(1).aml-compression = none
267 cbfs-files-$(if $(2),$(2),y) += $(CONFIG_CBFS_PREFIX)/$(1).aml
268 -include $(obj)/$(1).d
269 $(obj)/$(1).aml: $(src)/mainboard/$(MAINBOARDDIR)/$(1).asl $(obj)/config.h
270         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
271         $(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 $(obj)/$(1).asl
272         cd $$(dir $$@); $(IASL) $(IGNORED_IASL_WARNINGS) -we -p $$(notdir $$@) $(1).asl
273         if ! $(IASL) -d $$@ 2>&1 | grep -Eq 'ACPI (Warning|Error)'; then        \
274                 echo "    IASL       $$@ disassembled correctly.";              \
275                 true;                                                           \
276         else                                                                    \
277                 echo "Error: Could not correctly disassemble $$@";              \
278                 $(IASL) -d $$@;                                                 \
279                 false;                                                          \
280         fi
281 endef
283 #######################################################################
284 # Parse plaintext CMOS defaults into binary format
285 # arg1: source file
286 # arg2: binary file name
287 cbfs-files-processor-nvramtool= \
288         $(eval $(2): $(1) $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout | $(objutil)/nvramtool/nvramtool ; \
289                 printf "    CREATE     $(2) (from $(1))\n"; \
290                 $(objutil)/nvramtool/nvramtool -y $(src)/mainboard/$(MAINBOARDDIR)/cmos.layout -D $(2).tmp -p $(1) && \
291                 mv $(2).tmp $(2))
293 #######################################################################
294 # Link VSA binary to ELF-ish stage
295 # arg1: source file
296 # arg2: binary file name
297 cbfs-files-processor-vsa= \
298         $(eval $(2): $(1) ; \
299                 printf "    CREATE     $(2) (from $(1))\n"; \
300                 $(OBJCOPY_ramstage) --set-start 0x20 --adjust-vma 0x60000 -I binary -O elf32-i386 -B i386 $(1) $(2).tmp && \
301                 $(LD_ramstage) -m elf_i386 -e 0x60020 --section-start .data=0x60000 $(2).tmp -o $(2))
303 #######################################################################
304 # Reduce a .config file to its minimal representation
305 # arg1: input
306 # arg2: output
307 define cbfs-files-processor-defconfig
308         $(eval $(2): $(1) $(obj)/build.h $(objutil)/kconfig/conf; \
309                 +printf "    CREATE     $(2) (from $(1))\n"; \
310                 printf "# This image was built using coreboot " > $(2).tmp && \
311                 grep "\<COREBOOT_VERSION\>" $(obj)/build.h |cut -d\" -f2 >> $(2).tmp && \
312                 $(MAKE) DOTCONFIG=$(1) DEFCONFIG=$(2).tmp2 savedefconfig && \
313                 cat $(2).tmp2 >> $(2).tmp && \
314                 rm -f $(2).tmp2 && \
315                 \mv -f $(2).tmp $(2))
316 endef
318 #######################################################################
319 # Compile a C file with a bare struct definition into binary
320 # arg1: C source file
321 # arg2: binary file
322 cbfs-files-processor-struct= \
323         $(eval $(2): $(1) $(obj)/build.h $(KCONFIG_AUTOHEADER); \
324                 printf "    CC+STRIP   $(@)\n"; \
325                 $(CC_ramstage) -MMD $(CPPFLAGS_ramstage) $(CFLAGS_ramstage) $$(ramstage-c-ccopts) -include $(KCONFIG_AUTOHEADER) -MT $(2) -o $(2).tmp -c $(1) && \
326                 $(OBJCOPY_ramstage) -O binary $(2).tmp $(2); \
327                 rm -f $(2).tmp) \
328         $(eval DEPENDENCIES += $(2).d)
330 #######################################################################
331 # Add handler for arbitrary files in CBFS
332 $(call add-special-class,cbfs-files)
333 cbfs-files-handler= \
334                 $(eval tmp-cbfs-method:=$(word 2, $(subst :, ,$($(2)-file)))) \
335                 $(eval $(2)-file:=$(call strip_quotes,$(word 1, $(subst :, ,$($(2)-file))))) \
336                 $(eval tmp-cbfs-file:= ) \
337                 $(if $($(2)-file), \
338                         $(if $(wildcard $(1)$($(2)-file)), \
339                                 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
340                                 $(eval tmp-cbfs-file:= $($(2)-file)))) \
341                 $(if $(strip $($(2)-required)), \
342                         $(if $(wildcard $(tmp-cbfs-file)),, \
343                                 $(info This build configuration requires $($(2)-required)) \
344                                 $(eval FAILBUILD:=1) \
345                         )) \
346                 $(if $(strip $($(2)-align)), \
347                         $(if $(strip $($(2)-position)), \
348                                 $(info ERROR: It is not allowed to specify both alignment and position for $($(2)-file)) \
349                                 $(eval FAILBUILD:=1) \
350                         )) \
351                 $(if $(tmp-cbfs-method), \
352                         $(eval tmp-old-cbfs-file:=$(tmp-cbfs-file)) \
353                         $(eval tmp-cbfs-file:=$(shell mkdir -p $(obj)/mainboard/$(MAINBOARDDIR); mktemp $(obj)/mainboard/$(MAINBOARDDIR)/cbfs-file.XXXXXX).out) \
354                         $(call cbfs-files-processor-$(tmp-cbfs-method),$(tmp-old-cbfs-file),$(tmp-cbfs-file))) \
355                 $(if $(tmp-cbfs-file), \
356                         $(eval cbfs-files += $(subst $(spc),*,$(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-compression)|$(strip $($(2)-position))|$($(2)-align)|$($(2)-options)))) \
357                 $(eval $(2)-name:=) \
358                 $(eval $(2)-type:=) \
359                 $(eval $(2)-compression:=) \
360                 $(eval $(2)-position:=) \
361                 $(eval $(2)-required:=) \
362                 $(eval $(2)-options:=) \
363                 $(eval $(2)-align:=)
365 #######################################################################
366 # a variety of flags for our build
367 CBFS_COMPRESS_FLAG:=none
368 ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y)
369 CBFS_COMPRESS_FLAG:=LZMA
370 endif
372 CBFS_PAYLOAD_COMPRESS_FLAG:=none
373 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
374 CBFS_PAYLOAD_COMPRESS_FLAG:=LZMA
375 endif
376 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZ4),y)
377 CBFS_PAYLOAD_COMPRESS_FLAG:=LZ4
378 endif
380 CBFS_SECONDARY_PAYLOAD_COMPRESS_FLAG:=none
381 ifeq ($(CONFIG_COMPRESS_SECONDARY_PAYLOAD),y)
382 CBFS_SECONDARY_PAYLOAD_COMPRESS_FLAG:=LZMA
383 endif
385 CBFS_PRERAM_COMPRESS_FLAG:=none
386 ifeq ($(CONFIG_COMPRESS_PRERAM_STAGES),y)
387 CBFS_PRERAM_COMPRESS_FLAG:=LZ4
388 endif
390 ifneq ($(CONFIG_LOCALVERSION),"")
391 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
392 COREBOOT_EXPORTS += COREBOOT_EXTRA_VERSION
393 endif
395 CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -Isrc/commonlib/bsd/include -I$(obj)
396 VBOOT_SOURCE ?= 3rdparty/vboot
397 CPPFLAGS_common += -I$(VBOOT_SOURCE)/firmware/include
398 CPPFLAGS_common += -include $(src)/include/kconfig.h
399 CPPFLAGS_common += -include $(src)/include/rules.h
400 CPPFLAGS_common += -include $(src)/commonlib/bsd/include/commonlib/bsd/compiler.h
401 CPPFLAGS_common += -I3rdparty
402 CPPFLAGS_common += -D__BUILD_DIR__=\"$(obj)\"
404 ifeq ($(CONFIG_PCI_OPTION_ROM_RUN_YABEL)$(CONFIG_PCI_OPTION_ROM_RUN_REALMODE),y)
405 CPPFLAGS_ramstage += -Isrc/device/oprom/include
406 endif
408 CFLAGS_common += -pipe -g -nostdinc -std=gnu11
409 CFLAGS_common += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
410 CFLAGS_common += -Wwrite-strings -Wredundant-decls -Wno-trigraphs -Wimplicit-fallthrough
411 CFLAGS_common += -Wstrict-aliasing -Wshadow -Wdate-time -Wtype-limits -Wvla
412 CFLAGS_common += -Wlogical-op -Wduplicated-cond -Wdangling-else
413 CFLAGS_common += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
414 CFLAGS_common += -ffunction-sections -fdata-sections -fno-pie
415 ifeq ($(CONFIG_COMPILER_GCC),y)
416 # Don't add these GCC specific flags when running scan-build
417 ifeq ($(CCC_ANALYZER_OUTPUT_FORMAT),)
418 CFLAGS_common += -Wno-packed-not-aligned
419 CFLAGS_common += -fconserve-stack
420 CFLAGS_common += -Wnull-dereference -Wreturn-type
421 # cf. commit f69a99db (coreboot: x86: enable gc-sections)
422 CFLAGS_common += -Wno-unused-but-set-variable
423 endif
424 endif
426 ADAFLAGS_common += -gnatp
427 ADAFLAGS_common += -Wuninitialized -Wall -Werror
428 ADAFLAGS_common += -pipe -g -nostdinc
429 ADAFLAGS_common += -Wstrict-aliasing -Wshadow
430 ADAFLAGS_common += -fno-common -fomit-frame-pointer
431 ADAFLAGS_common += -ffunction-sections -fdata-sections
432 # Ada warning options:
434 #  a   Activate most optional warnings.
435 # .e   Activate every optional warnings.
436 #  e   Treat warnings and style checks as errors.
438 #  D   Suppress warnings on implicit dereferences:
439 #      As SPARK does not accept access types we have to map the
440 #      dynamically chosen register locations to a static SPARK
441 #      variable.
443 # .H   Suppress warnings on holes/gaps in records:
444 #      We are modelling hardware here!
446 #  H   Suppress warnings on hiding:
447 #      It's too annoying, you run out of ideas for identifiers fast.
449 #  T   Suppress warnings for tracking of deleted conditional code:
450 #      We use static options to select code paths at compile time.
452 #  U   Suppress warnings on unused entities:
453 #      Would have lots of warnings for unused register definitions,
454 #      `withs` for debugging etc.
456 # .U   Deactivate warnings on unordered enumeration types:
457 #      As SPARK doesn't support `pragma Ordered` by now, we don't
458 #      use that, yet.
460 # .W   Suppress warnings on unnecessary Warnings Off pragmas:
461 #      Things get really messy when you use different compiler
462 #      versions, otherwise.
463 # .Y   Disable information messages for why package spec needs body:
464 #      Those messages are annoying. But don't forget to enable those,
465 #      if you need the information.
466 ADAFLAGS_common += -gnatwa.eeD.HHTU.U.W.Y
467 # Disable style checks for now
468 ADAFLAGS_common += -gnatyN
470 LDFLAGS_common := --gc-sections -nostdlib -nostartfiles -static --emit-relocs
472 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
473 CFLAGS_common += -Werror
474 endif
475 ifneq ($(GDB_DEBUG),)
476 CFLAGS_common += -Og
477 ADAFLAGS_common += -Og
478 else
479 CFLAGS_common += -Os
480 ADAFLAGS_common += -Os
481 endif
483 ifeq ($(CONFIG_DEBUG_ADA_CODE),y)
484 ADAFLAGS_common += -gnata
485 endif
487 additional-dirs := $(objutil)/cbfstool $(objutil)/ifdtool \
488                    $(objutil)/options $(objutil)/amdfwtool \
489                    $(objutil)/cbootimage
491 export $(COREBOOT_EXPORTS)
493 #######################################################################
494 # generate build support files
496 build_h := $(obj)/build.h
498 # We have to manually export variables that `genbuild_h.sh` uses
499 # when we call it through the `$(shell)` function. This is fragile
500 # but as variables newly added to `genbuild_h.sh` would just not
501 # work, we'd notice that instantly at least.
502 build_h_exports := BUILD_TIMELESS KERNELVERSION COREBOOT_EXTRA_VERSION
504 # Report new `build.ht` as dependency if `build.h` differs.
505 build_h_check := \
506         export $(foreach exp,$(build_h_exports),$(exp)="$($(exp))"); \
507         util/genbuild_h/genbuild_h.sh .xcompile >$(build_h)t 2>/dev/null; \
508         cmp -s $(build_h)t $(build_h) >/dev/null 2>&1 || echo $(build_h)t
510 $(build_h): $$(shell $$(build_h_check))
511         @printf "    GEN        build.h\n"
512         mv $< $@
514 build-dirs $(objcbfs) $(objgenerated):
515         mkdir -p $(objcbfs) $(objgenerated)
517 #######################################################################
518 # Build the tools
519 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
520 FMAPTOOL:=$(objutil)/cbfstool/fmaptool
521 RMODTOOL:=$(objutil)/cbfstool/rmodtool
522 IFWITOOL:=$(objutil)/cbfstool/ifwitool
523 IFITTOOL:=$(objutil)/cbfstool/ifittool
524 AMDCOMPRESS:=$(objutil)/cbfstool/amdcompress
526 $(obj)/cbfstool: $(CBFSTOOL)
527         cp $< $@
529 $(obj)/fmaptool: $(FMAPTOOL)
530         cp $< $@
532 $(obj)/rmodtool: $(RMODTOOL)
533         cp $< $@
535 $(obj)/ifwitool: $(IFWITOOL)
536         cp $< $@
538 $(obj)/ifittool: $(IFITTOOL)
539         cp $< $@
541 $(obj)/amdcompress: $(AMDCOMPRESS)
542         cp $< $@
544 _WINCHECK=$(shell uname -o 2> /dev/null)
545 STACK=
546 ifeq ($(_WINCHECK),Msys)
547         STACK=-Wl,--stack,16384000
548 endif
549 ifeq ($(_WINCHECK),Cygwin)
550         STACK=-Wl,--stack,16384000
551 endif
553 BINCFG:=$(objutil)/bincfg/bincfg
555 IFDTOOL:=$(objutil)/ifdtool/ifdtool
556 $(IFDTOOL):
557         @printf "    Compile IFDTOOL\n"
558         +$(MAKE) -C $(top)/util/ifdtool
559         cp -a $(top)/util/ifdtool/ifdtool $@
561 AMDFWTOOL:=$(objutil)/amdfwtool/amdfwtool
562 $(AMDFWTOOL): $(top)/util/amdfwtool/amdfwtool.c
563         @printf "    HOSTCC     $(subst $(obj)/,,$(@))\n"
564         $(HOSTCC) $(HOSTCFLAGS) -DCONFIG_ROM_SIZE=$(CONFIG_ROM_SIZE) -o $@ $<
566 APCB_EDIT_TOOL:=$(top)/util/apcb/apcb_edit.py
568 CBOOTIMAGE:=$(objutil)/cbootimage/cbootimage
570 FUTILITY?=$(objutil)/futility/futility
572 subdirs-y += util/nvidia
574 $(obj)/config.h: $(objutil)/kconfig/conf
576 #######################################################################
577 # needed objects that every mainboard uses
578 # Creation of these is architecture and mainboard independent
579 DEVICETREE_FILE := $(src)/mainboard/$(MAINBOARDDIR)/$(CONFIG_DEVICETREE)
581 ifneq ($(CONFIG_OVERRIDE_DEVICETREE),)
583 OVERRIDE_DEVICETREE_FILE := $(src)/mainboard/$(MAINBOARDDIR)/$(CONFIG_OVERRIDE_DEVICETREE)
585 endif
587 DEVICETREE_STATIC_C := $(obj)/mainboard/$(MAINBOARDDIR)/static.c
588 DEVICETREE_STATIC_H := $(obj)/static.h
590 $(DEVICETREE_STATIC_C): $(DEVICETREE_FILE) $(OVERRIDE_DEVICETREE_FILE) $(objutil)/sconfig/sconfig
591         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
592         mkdir -p $(dir $(DEVICETREE_STATIC_C))
593         $(objutil)/sconfig/sconfig $(DEVICETREE_FILE) $(DEVICETREE_STATIC_C) $(DEVICETREE_STATIC_H) $(OVERRIDE_DEVICETREE_FILE)
595 ramstage-y+=$(DEVICETREE_STATIC_C)
596 romstage-y+=$(DEVICETREE_STATIC_C)
597 verstage-y+=$(DEVICETREE_STATIC_C)
598 bootblock-y+=$(DEVICETREE_STATIC_C)
599 postcar-y+=$(DEVICETREE_STATIC_C)
600 smm-y+=$(DEVICETREE_STATIC_C)
602 # Ensure static.c and static.h are created before any objects are compiled
603 ramstage-c-deps+=$(DEVICETREE_STATIC_C)
604 romstage-c-deps+=$(DEVICETREE_STATIC_C)
605 verstage-c-deps+=$(DEVICETREE_STATIC_C)
606 bootblock-c-deps+=$(DEVICETREE_STATIC_C)
607 postcar-c-deps+=$(DEVICETREE_STATIC_C)
608 smm-c-deps+=$(DEVICETREE_STATIC_C)
610 .PHONY: devicetree
611 devicetree: $(DEVICETREE_STATIC_C)
613 ramstage-y += $(CONFIG_MEMLAYOUT_LD_FILE)
614 romstage-y += $(CONFIG_MEMLAYOUT_LD_FILE)
615 bootblock-y += $(CONFIG_MEMLAYOUT_LD_FILE)
616 verstage-y += $(CONFIG_MEMLAYOUT_LD_FILE)
617 postcar-y += $(CONFIG_MEMLAYOUT_LD_FILE)
618 decompressor-y += $(CONFIG_MEMLAYOUT_LD_FILE)
620 #######################################################################
621 # Clean up rules
622 clean-abuild:
623         rm -rf coreboot-builds
625 clean-for-update-target: clean-payloads
626         rm -f $(obj)/ramstage?* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
627         rm -rf $(obj)/bootblock?* $(obj)/romstage?* $(obj)/location.*
628         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
629         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
630         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
631         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
632         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/dsdt.*
633         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
635 clean-target:
636         rm -f $(obj)/coreboot*
638 #######################################################################
639 # Development utilities
640 printcrt0s:
641         @echo crt0s=$(crt0s)
642         @echo ldscripts=$(ldscripts)
644 update:
645         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
647 check-style:
648         grep "^# DESCR:" util/lint/check-style | sed "s,.*DESCR: *,,"
649         echo "========"
650         util/lint/check-style
651         echo "========"
653 gitconfig:
654         util/gitconfig/gitconfig.sh "$(MAKE)"
656 install-git-commit-clangfmt:
657         cp util/scripts/prepare-commit-msg.clang-format .git/hooks/prepare-commit-msg
659 include util/crossgcc/Makefile.inc
661 .PHONY: tools
662 tools: $(objutil)/kconfig/conf $(objutil)/kconfig/toada $(CBFSTOOL) $(objutil)/cbfstool/cbfs-compression-tool $(FMAPTOOL) $(RMODTOOL) $(IFWITOOL) $(objutil)/nvramtool/nvramtool $(objutil)/sconfig/sconfig $(IFDTOOL) $(CBOOTIMAGE) $(AMDFWTOOL) $(AMDCOMPRESS) $(FUTILITY) $(BINCFG) $(IFITTOOL) $(objutil)/supermicro/smcbiosinfo
664 ###########################################################################
665 # Common recipes for all stages
666 ###########################################################################
668 # loadaddr can determine the load address of a stage, which may be needed for
669 # platform-specific image headers (only works *after* the stage has been built)
670 loadaddr = $(shell $(OBJDUMP_$(1)) -p $(objcbfs)/$(1).debug | \
671              sed -ne '/LOAD/s/^.*vaddr 0x\([0-9a-fA-F]\{8\}\).*$$/0x\1/p')
673 # find-substr is required for stages like romstage_null and romstage_xip to
674 # eliminate the _* part of the string
675 find-substr = $(word 1,$(subst _, ,$(1)))
677 # find-class is used to identify the class from the name of the stage
678 # The input to this macro can be something like romstage.x or romstage.x.y
679 # find-class recursively strips off the suffixes to extract the exact class name
680 # e.g.: if romstage.x is provided to find-class, it will remove .x and return romstage
681 # if romstage.x.y is provided, it will first remove .y, call find-class with romstage.x
682 # and remove .x the next time and finally return romstage
683 find-class = $(if $(filter $(1),$(basename $(1))),$(if $(CC_$(1)), $(1), $(call find-substr,$(1))),$(call find-class,$(basename $(1))))
685 # Bootblocks are not CBFS stages. coreboot is currently expecting the bss to
686 # be cleared by the loader of the stage. For ARM SoCs that means one needs to
687 # include the bss section in the binary so the BootROM clears the bss on
688 # loading of the bootblock stage. Achieve this by marking the bss section
689 # loadable,allocatable, and data. Do the same for the .data section in case
690 # the linker marked it NOBITS automatically because there are only zeroes in it.
691 preserve-bss-flags := --set-section-flags .bss=load,alloc,data --set-section-flags .data=load,alloc,data
693 # For Intel TXT files in the CBFS needs to be marked as 'Initial Boot Block'.
694 # As CBFS attributes aren't cheap, only mark them if TXT is enabled.
695 ifeq ($(CONFIG_INTEL_TXT),y)
697 TXTIBB := --ibb
699 else
701 TXTIBB :=
703 endif
705 ifeq ($(CONFIG_COMPRESS_BOOTBLOCK),y)
707 $(objcbfs)/bootblock.lz4: $(objcbfs)/bootblock.elf $(objutil)/cbfstool/cbfs-compression-tool
708         @printf "    LZ4        $(subst $(obj)/,,$(@))\n"
709         $(OBJCOPY_bootblock) $(preserve-bss-flags) $< $@.tmp
710         $(OBJCOPY_bootblock) -O binary $@.tmp
711         $(objutil)/cbfstool/cbfs-compression-tool rawcompress $@.tmp $@.tmp2 lz4
712         rm -f $@.tmp
713         mv $@.tmp2 $@
715 # Put assembled decompressor+bootblock into bootblock.raw.elf so that SoC
716 # Makefiles wrapping the bootblock in a header can always key off the same file.
717 $(objcbfs)/bootblock.raw.elf: $(objcbfs)/decompressor.elf
718         @printf "    OBJCOPY    $(notdir $(@))\n"
719         $(OBJCOPY_bootblock) $(preserve-bss-flags) $< $@
721 else    # CONFIG_COMPRESS_BOOTBLOCK
723 $(objcbfs)/bootblock.raw.elf: $(objcbfs)/bootblock.elf
724         @printf "    OBJCOPY    $(notdir $(@))\n"
725         $(OBJCOPY_bootblock) $(preserve-bss-flags) $< $@
727 endif   # CONFIG_COMPRESS_BOOTBLOCK
729 $(objcbfs)/bootblock.raw.bin: $(objcbfs)/bootblock.raw.elf
730         @printf "    OBJCOPY    $(notdir $(@))\n"
731         $(OBJCOPY_bootblock) -O binary $< $@
733 ifneq ($(CONFIG_HAVE_BOOTBLOCK),y)
734 $(objcbfs)/bootblock.bin: $(objcbfs)
735         dd if=/dev/zero of=$@ bs=64 count=1
736 endif
738 $(objcbfs)/%.bin: $(objcbfs)/%.raw.bin
739         cp $< $@
741 $(objcbfs)/%.elf: $(objcbfs)/%.debug
742         $(eval class := $(call find-class,$(@F)))
743         @printf "    OBJCOPY    $(subst $(obj)/,,$(@))\n"
744         cp $< $@.tmp
745         $(NM_$(class)) -n $@.tmp | sort > $(basename $@).map
746         $(OBJCOPY_$(class)) --strip-debug $@.tmp
747         $(OBJCOPY_$(class)) --add-gnu-debuglink=$< $@.tmp
748         mv $@.tmp $@
751 ###########################################################################
752 # Build the final rom image
753 ###########################################################################
755 # extract_nth - Return a subsection of the $file string
757 # the input string looks like this:
758 # ./build/cbfs/fallback/romstage.elf|fallback/romstage|stage|none||64|--xip*-S*.car.data*-P*0x10000
760 # Sections:
761 # 1 - Path and name of file [FILENAME: Added to cbfs-files-y list variable]
762 # 2 - Name of file in cbfs  [$(FILENAME)-file]
763 # 3 - File type:            [$(FILENAME)-type]
764 #                bootblock, cbfs header, stage, payload, optionrom, bootsplash, raw, vsa,
765 #                mbi, microcode, fsp, mrc, cmos_default, cmos_layout, spd, mrc_cache,
766 #                mma, efi, deleted, null
767 # 4 - Compression type      [$(FILENAME)-compression]
768 #                      none, LZMA
769 # 5 - Base address          [$(FILANAME)-position]
770 # 6 - Alignment             [$(FILENAME)-align]
771 # 7 - cbfstool flags        [$(FILENAME)-options]
773 # Input:
774 #  $(1) = Section to extract
775 #  $(2) = Input string
777 # Steps:
778 # 1) replace all '|' characters with the sequence '- -' within the full string, prepended and appended with the character '-'
779 # 2) extract the specified section from the string - this gets us the section surrounded by '-' characters
780 # 3) remove the leading and trailing '-' characters
781 # 4) replace all '*' characters with spaces
782 extract_nth=$(subst *,$(spc),$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-))))
784 # regions-for-file - Returns a cbfstool regions parameter
785 # $(call regions-for-file,$(filename))
786 # returns "REGION1,REGION2,..."
788 # This is the default implementation. When using a boot strategy employing
789 # multiple CBFSes in fmap regions, override it.
790 regions-for-file ?= COREBOOT
792 ifeq ($(CONFIG_CBFS_AUTOGEN_ATTRIBUTES),y)
793         cbfs-autogen-attributes=-g
794 endif
796 # cbfs-add-cmd-for-region
797 # $(call cbfs-add-cmd-for-region,file in extract_nth format,region name)
798 define cbfs-add-cmd-for-region
799         $(CBFSTOOL) $@.tmp \
800         add$(if $(filter stage,$(call extract_nth,3,$(1))),-stage)$(if \
801                 $(filter payload,$(call extract_nth,3,$(1))),-payload)$(if \
802                 $(filter flat-binary,$(call extract_nth,3,$(1))),-flat-binary) \
803         -f $(call extract_nth,1,$(1)) \
804         -n $(call extract_nth,2,$(1)) \
805         $(if $(filter-out flat-binary payload stage,$(call \
806                 extract_nth,3,$(1))),-t $(call extract_nth,3,$(1))) \
807         $(if $(call extract_nth,4,$(1)),-c $(call extract_nth,4,$(1))) \
808         $(cbfs-autogen-attributes) \
809         -r $(2) \
810         $(if $(call extract_nth,6,$(1)),-a $(call extract_nth,6,$(file)), \
811                 $(if $(call extract_nth,5,$(file)),-b $(call extract_nth,5,$(file)))) \
812                 $(call extract_nth,7,$(1))
815 endef
816 # Empty line before endef is necessary so cbfs-add-cmd-for-region ends in a
817 # newline
819 # cbfs-add-cmd
820 # $(call cbfs-add-cmd,
821 #          file in extract_nth format,
822 #          region name,
823 #          non-empty if file removal requested)
824 define cbfs-add-cmd
825         printf "    CBFS       $(call extract_nth,2,$(1))\n"
826         $(if $(3),-$(CBFSTOOL) $@.tmp remove -n $(call extract_nth,2,$(file)) 2>/dev/null)
827         $(call cbfs-add-cmd-for-region,$(1),$(2))
828 endef
830 # list of files to add (using their file system names, not CBFS names),
831 # for dependencies etc.
832 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
834 # $(all-regions)
835 # returns full list of fmap regions that we add files to
836 all-regions = $(sort $(subst $(comma),$(spc), \
837         $(foreach file,$(cbfs-files), \
838                 $(call regions-for-file,$(call extract_nth,2,$(file))))))
840 # $(call all-files-in-region,region name)
841 # returns elements in $(cbfs-files) that end up in that region, in the order
842 # they appear in $(cbfs-files)
843 all-files-in-region = $(foreach file,$(cbfs-files), \
844         $(if $(filter $(1), \
845                 $(subst $(comma),$(spc),$(call regions-for-file,$(call extract_nth,2,$(file))))), \
846                 $(file)))
848 # $(call update-file-for-region,file string from $(cbfs-files),region name)
849 # Update position and alignment according to overrides for region
850 # Doesn't check for invalid configurations (eg. resetting neither or both
851 # position and align)
852 # Returns the updated file string
853 update-file-for-region = \
854         $(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)))
856 # $(call placed-files-in-region,region name)
857 # like all-files-in-region, but updates the files to contain region overrides
858 # to position or alignment.
859 placed-files-in-region = $(foreach file,$(call all-files-in-region,$(1)), \
860         $(if $($(call extract_nth,2,$(file))-$(1)-position), \
861                 $(if $($(call extract_nth,2,$(file))-$(1)-align), \
862                         $(error It is not allowed to specify both alignment and position for $(call extract_nth,2,$(file))-$(1))) \
863                 $(call update-file-for-region,$(file),$(1)), \
864                 $(if $($(call extract_nth,2,$(file))-$(1)-align), \
865                         $(call update-file-for-region,$(file),$(1)), \
866                         $(file))))
868 # $(call sort-files,subset of $(cbfs-files))
869 # reorders the files in the given set to list files at fixed positions first,
870 # followed by aligned files and finally those with no constraints.
871 sort-files = \
872         $(eval _tmp_fixed:=) \
873         $(eval _tmp_aligned:=) \
874         $(eval _tmp_regular:=) \
875         $(foreach file,$(1), \
876                 $(if $(call extract_nth,5,$(file)),\
877                         $(eval _tmp_fixed += $(file)), \
878                 $(if $(call extract_nth,6,$(file)), \
879                         $(eval _tmp_aligned += $(file)), \
880                         $(eval _tmp_regular += $(file))))) \
881         $(_tmp_fixed) $(_tmp_aligned) $(_tmp_regular)
883 # command list to add files to CBFS
884 prebuild-files = $(foreach region,$(all-regions), \
885         $(foreach file, \
886                 $(call sort-files,$(call placed-files-in-region,$(region))), \
887                 $(call cbfs-add-cmd,$(file),$(region),$(CONFIG_UPDATE_IMAGE))))
889 ifeq ($(CONFIG_FMDFILE),)
890 # For a description of the flash layout described by these variables, check
891 # the $(DEFAULT_FLASHMAP) .fmd files.
892 ifeq ($(CONFIG_ARCH_X86),y)
893 DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default-x86.fmd
894 # entire flash
895 FMAP_ROM_ADDR := $(call int-subtract, 0x100000000 $(CONFIG_ROM_SIZE))
896 FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
897 # entire "BIOS" region (everything directly of concern to the host system)
898 # relative to ROM_BASE
899 FMAP_BIOS_BASE := $(call int-align, $(call int-subtract, $(CONFIG_ROM_SIZE) $(CONFIG_CBFS_SIZE)), 0x10000)
900 FMAP_BIOS_SIZE := $(call int-align-down, $(shell echo $(CONFIG_CBFS_SIZE) | tr A-F a-f), 0x10000)
901 # position and size of flashmap, relative to BIOS_BASE
904 # X86 CONSOLE FMAP region
906 # position, size and entry line of CONSOLE relative to BIOS_BASE, if enabled
908 FMAP_CURRENT_BASE := 0
910 ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
911 FMAP_CONSOLE_BASE := $(FMAP_CURRENT_BASE)
912 FMAP_CONSOLE_SIZE := $(CONFIG_CONSOLE_SPI_FLASH_BUFFER_SIZE)
913 FMAP_CONSOLE_ENTRY := CONSOLE@$(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE)
914 FMAP_CURRENT_BASE := $(call int-add, $(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE))
915 else
916 FMAP_CONSOLE_ENTRY :=
917 endif
919 ifeq ($(CONFIG_CACHE_MRC_SETTINGS),y)
920 FMAP_MRC_CACHE_BASE := $(call int-align, $(FMAP_CURRENT_BASE), 0x10000)
921 FMAP_MRC_CACHE_SIZE := $(CONFIG_MRC_SETTINGS_CACHE_SIZE)
922 FMAP_MRC_CACHE_ENTRY := RW_MRC_CACHE@$(FMAP_MRC_CACHE_BASE) $(FMAP_MRC_CACHE_SIZE)
923 FMAP_CURRENT_BASE := $(call int-add, $(FMAP_MRC_CACHE_BASE) $(FMAP_MRC_CACHE_SIZE))
924 else
925 FMAP_MRC_CACHE_ENTRY :=
926 endif
928 ifeq ($(CONFIG_SMMSTORE),y)
929 FMAP_SMMSTORE_BASE := $(call int-align, $(FMAP_CURRENT_BASE), 0x10000)
930 FMAP_SMMSTORE_SIZE := $(CONFIG_SMMSTORE_SIZE)
931 FMAP_SMMSTORE_ENTRY := SMMSTORE@$(FMAP_SMMSTORE_BASE) $(FMAP_SMMSTORE_SIZE)
932 FMAP_CURRENT_BASE := $(call int-add, $(FMAP_SMMSTORE_BASE) $(FMAP_SMMSTORE_SIZE))
933 else
934 FMAP_SMMSTORE_ENTRY :=
935 endif
938 # X86 FMAP region
941 # position, size
942 FMAP_FMAP_BASE := $(FMAP_CURRENT_BASE)
943 FMAP_FMAP_SIZE := 0x200
946 # X86 COREBOOT default cbfs FMAP region
948 # position and size of CBFS, relative to BIOS_BASE
949 FMAP_CBFS_BASE := $(call int-add, $(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE))
950 FMAP_CBFS_SIZE := $(call int-subtract, $(FMAP_BIOS_SIZE) $(FMAP_CBFS_BASE))
952 else # ifeq ($(CONFIG_ARCH_X86),y)
954 DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default.fmd
955 # entire flash
956 FMAP_ROM_ADDR := 0
957 FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)
958 # entire "BIOS" region (everything directly of concern to the host system)
959 # relative to ROM_BASE
960 FMAP_BIOS_BASE := 0
961 FMAP_BIOS_SIZE := $(CONFIG_CBFS_SIZE)
962 # position and size of flashmap, relative to BIOS_BASE
963 FMAP_FMAP_BASE := 0x20000
964 FMAP_FMAP_SIZE := 0x200
966 FMAP_CURRENT_BASE := $(call int-add, $(FMAP_FMAP_BASE) $(FMAP_FMAP_SIZE))
969 # NON-X86 CONSOLE FMAP region
971 # position, size and entry line of CONSOLE relative to BIOS_BASE, if enabled
972 ifeq ($(CONFIG_CONSOLE_SPI_FLASH),y)
973 FMAP_CONSOLE_BASE := $(FMAP_CURRENT_BASE)
974 FMAP_CONSOLE_SIZE := $(CONFIG_CONSOLE_SPI_FLASH_BUFFER_SIZE)
975 FMAP_CONSOLE_ENTRY := CONSOLE@$(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE)
976 FMAP_CURRENT_BASE := $(call int-add, $(FMAP_CONSOLE_BASE) $(FMAP_CONSOLE_SIZE))
977 else
978 FMAP_CONSOLE_ENTRY :=
979 endif
982 # NON-X86 RW_MRC_CACHE FMAP region
984 # position, size and entry line of MRC_CACHE relative to BIOS_BASE, if enabled
985 ifeq ($(CONFIG_CACHE_MRC_SETTINGS),y)
986 FMAP_MRC_CACHE_BASE := $(call int-align, $(FMAP_CURRENT_BASE), 0x10000)
987 FMAP_MRC_CACHE_SIZE := $(CONFIG_MRC_SETTINGS_CACHE_SIZE)
988 FMAP_MRC_CACHE_ENTRY := RW_MRC_CACHE@$(FMAP_MRC_CACHE_BASE) $(FMAP_MRC_CACHE_SIZE)
989 FMAP_CURRENT_BASE := $(call int-add, $(FMAP_MRC_CACHE_BASE) $(FMAP_MRC_CACHE_SIZE))
990 else
991 FMAP_MRC_CACHE_ENTRY :=
992 endif
995 # NON-X86 COREBOOT default cbfs FMAP region
997 # position and size of CBFS, relative to BIOS_BASE
998 FMAP_CBFS_BASE := $(FMAP_CURRENT_BASE)
999 FMAP_CBFS_SIZE := $(call int-subtract,$(FMAP_BIOS_SIZE) $(FMAP_CBFS_BASE))
1001 endif # ifeq ($(CONFIG_ARCH_X86),y)
1003 $(obj)/fmap.fmd: $(top)/Makefile.inc $(DEFAULT_FLASHMAP) $(obj)/config.h
1004         sed -e "s,##ROM_BASE##,$(FMAP_ROM_ADDR)," \
1005             -e "s,##ROM_SIZE##,$(FMAP_ROM_SIZE)," \
1006             -e "s,##BIOS_BASE##,$(FMAP_BIOS_BASE)," \
1007             -e "s,##BIOS_SIZE##,$(FMAP_BIOS_SIZE)," \
1008             -e "s,##FMAP_BASE##,$(FMAP_FMAP_BASE)," \
1009             -e "s,##FMAP_SIZE##,$(FMAP_FMAP_SIZE)," \
1010             -e "s,##CONSOLE_ENTRY##,$(FMAP_CONSOLE_ENTRY)," \
1011             -e "s,##MRC_CACHE_ENTRY##,$(FMAP_MRC_CACHE_ENTRY)," \
1012             -e "s,##SMMSTORE_ENTRY##,$(FMAP_SMMSTORE_ENTRY)," \
1013             -e "s,##CBFS_BASE##,$(FMAP_CBFS_BASE)," \
1014             -e "s,##CBFS_SIZE##,$(FMAP_CBFS_SIZE)," \
1015                 $(DEFAULT_FLASHMAP) > $@.tmp
1016         mv $@.tmp $@
1017 else # ifeq ($(CONFIG_FMDFILE),)
1018 $(obj)/fmap.fmd: $(CONFIG_FMDFILE) $(obj)/config.h
1019         $(HOSTCC) $(PREPROCESS_ONLY) -include $(obj)/config.h $< -o $@.pre
1020         mv $@.pre $@
1021 endif # ifeq ($(CONFIG_FMDFILE),)
1023 # generated at the same time as fmap.fmap
1024 $(obj)/fmap_config.h: $(obj)/fmap.fmap
1025         true
1026 $(obj)/fmap.desc: $(obj)/fmap.fmap
1027         true
1029 $(obj)/fmap.fmap: $(obj)/fmap.fmd $(FMAPTOOL)
1030         echo "    FMAP       $(FMAPTOOL) -h $(obj)/fmap_config.h $< $@"
1031         $(FMAPTOOL) -h $(obj)/fmap_config.h -R $(obj)/fmap.desc $< $@
1033 ifeq ($(CONFIG_INTEL_ADD_TOP_SWAP_BOOTBLOCK),y)
1034 TS_OPTIONS := -j $(CONFIG_INTEL_TOP_SWAP_BOOTBLOCK_SIZE)
1035 endif
1036 ifneq ($(CONFIG_UPDATE_IMAGE),y)
1037 $(obj)/coreboot.pre: $(objcbfs)/bootblock.bin $$(prebuilt-files) $(CBFSTOOL) $(IFITTOOL) $$(cpu_ucode_cbfs_file) $(obj)/fmap.fmap $(obj)/fmap.desc
1038         $(CBFSTOOL) $@.tmp create -M $(obj)/fmap.fmap -r $(shell cat $(obj)/fmap.desc)
1039 ifeq ($(CONFIG_ARCH_X86),y)
1040         $(CBFSTOOL) $@.tmp add \
1041                 -f $(objcbfs)/bootblock.bin \
1042                 -n bootblock \
1043                 -t bootblock \
1044                 $(TXTIBB) \
1045                 -b -$(call file-size,$(objcbfs)/bootblock.bin) $(cbfs-autogen-attributes) \
1046                 $(TS_OPTIONS)
1047 else # ifeq ($(CONFIG_ARCH_X86),y)
1048         $(CBFSTOOL) $@.tmp write -u \
1049                 -r BOOTBLOCK \
1050                 -f $(objcbfs)/bootblock.bin
1051         # make space for the CBFS master header pointer. "ptr_" is just
1052         # arbitrary 4 bytes that will be overwritten by add-master-header.
1053         printf "ptr_" > $@.tmp.2
1054         $(CBFSTOOL) $@.tmp add \
1055                 -f $@.tmp.2 \
1056                 -n "header pointer" \
1057                 -t "cbfs header" \
1058                 -b -4
1059         rm -f $@.tmp.2
1060 endif # ifeq ($(CONFIG_ARCH_X86),y)
1061         $(CBFSTOOL) $@.tmp add-master-header $(TS_OPTIONS)
1062         $(prebuild-files) true
1063         mv $@.tmp $@
1064 else # ifneq ($(CONFIG_UPDATE_IMAGE),y)
1065 .PHONY: $(obj)/coreboot.pre
1066 $(obj)/coreboot.pre: $$(prebuilt-files) $(CBFSTOOL)
1067         mv $(obj)/coreboot.rom $@.tmp || \
1068         (echo "Error: You have UPDATE_IMAGE set in Kconfig, but have no existing image to update." && \
1069         echo "Exiting." && \
1070         false)
1071         $(prebuild-files) true
1072         mv $@.tmp $@
1073 endif # ifneq ($(CONFIG_UPDATE_IMAGE),y)
1075 ifeq ($(CONFIG_HAVE_REFCODE_BLOB),y)
1076 REFCODE_BLOB=$(obj)/refcode.rmod
1077 $(REFCODE_BLOB): $(RMODTOOL)
1078         $(RMODTOOL) -i $(CONFIG_REFCODE_BLOB_FILE) -o $@
1079 endif
1081 FIT_ENTRY=$(call strip_quotes, $(CONFIG_INTEL_TOP_SWAP_FIT_ENTRY_FMAP_REG))
1083 ifeq ($(CONFIG_HAVE_RAMSTAGE),y)
1084 RAMSTAGE=$(objcbfs)/ramstage.elf
1085 else
1086 RAMSTAGE=
1087 endif
1089 $(obj)/coreboot.rom: $(obj)/coreboot.pre $(RAMSTAGE) $(CBFSTOOL) $$(INTERMEDIATE)
1091         @printf "    CBFS       $(subst $(obj)/,,$(@))\n"
1092 # The full ROM may be larger than the CBFS part, so create an empty
1093 # file (filled with \377 = 0xff) and copy the CBFS image over it.
1094         dd if=/dev/zero bs=$(call _toint,$(CONFIG_ROM_SIZE)) count=1 2> /dev/null | tr '\000' '\377' > $@.tmp
1095         dd if=$(obj)/coreboot.pre of=$@.tmp bs=8192 conv=notrunc 2> /dev/null
1096 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),)
1097 ifneq ($(CONFIG_SEABIOS_PS2_TIMEOUT),0)
1098 ifneq ($(CONFIG_UPDATE_IMAGE),y)
1099         @printf "    SeaBIOS    Wait up to $(CONFIG_SEABIOS_PS2_TIMEOUT) ms for PS/2 keyboard controller initialization\n"
1100         $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_PS2_TIMEOUT) -n etc/ps2-keyboard-spinup
1101 endif
1102 endif
1103 endif
1104 ifeq ($(CONFIG_SEABIOS_ADD_SERCON_PORT_FILE),y)
1105         @printf "    SeaBIOS    Add sercon-port file\n"
1106         $(CBFSTOOL) $@.tmp add-int -i $(CONFIG_SEABIOS_SERCON_PORT_ADDR) -n etc/sercon-port
1107 endif
1108 ifeq ($(CONFIG_SEABIOS_THREAD_OPTIONROMS),y)
1109         @printf "    SeaBIOS    Thread optionroms\n"
1110         $(CBFSTOOL) $@.tmp add-int -i 2 -n etc/threads
1111 endif
1112 ifeq ($(CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE),y)
1113 ifneq ($(CONFIG_UPDATE_IMAGE),y) # never update the bootblock
1114 ifeq ($(CONFIG_CPU_MICROCODE_CBFS_EXTERNAL_HEADER),y)
1115         @printf "    UPDATE-FIT\n"
1116         $(IFITTOOL) -f $@.tmp -a -n cpu_microcode_blob.bin -t 1 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) \
1117         -r COREBOOT
1118 endif
1119 ifeq ($(CONFIG_USE_CPU_MICROCODE_CBFS_BINS),y)
1120         @printf "    UPDATE-FIT\n"
1121         $(IFITTOOL) -f $@.tmp -a -n cpu_microcode_blob.bin -t 1 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) \
1122         -r COREBOOT
1123 endif
1124         $(IFITTOOL) -f $@.tmp -D -r COREBOOT
1126 # Second FIT in TOP_SWAP bootblock
1127 ifeq ($(CONFIG_INTEL_ADD_TOP_SWAP_BOOTBLOCK),y)
1128 # INTEL_TOP_SWAP_FIT_ENTRY_FMAP_REG adds a region as first ucode into the seconds bootblock
1129 ifneq ($(FIT_ENTRY),)
1130         @printf "    UPDATE-FIT2\n"
1131         $(IFITTOOL) -f $@.tmp -A -n $(FIT_ENTRY) -t 1 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) \
1132         $(TS_OPTIONS) -r COREBOOT
1133 endif
1134 ifeq ($(CONFIG_CPU_MICROCODE_CBFS_EXTERNAL_HEADER),y)
1135         @printf "    UPDATE-FIT2\n"
1136         $(IFITTOOL) -f $@.tmp -a -n cpu_microcode_blob.bin -t 1 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) \
1137         $(TS_OPTIONS) -r COREBOOT
1138 endif
1139 ifeq ($(CONFIG_USE_CPU_MICROCODE_CBFS_BINS),y)
1140         @printf "    UPDATE-FIT2\n"
1141         $(IFITTOOL) -f $@.tmp -a -n cpu_microcode_blob.bin -t 1 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) \
1142         $(TS_OPTIONS) -r COREBOOT
1143 endif
1144         $(IFITTOOL) -f $@.tmp -D $(TS_OPTIONS) -r COREBOOT
1146 endif
1148 endif # !CONFIG_UPDATE_IMAGE
1149 endif # CONFIG_CPU_INTEL_FIRMWARE_INTERFACE_TABLE
1150         mv $@.tmp $@
1151         @printf "    CBFSLAYOUT  $(subst $(obj)/,,$(@))\n\n"
1152         $(CBFSTOOL) $@ layout
1153         @printf "    CBFSPRINT  $(subst $(obj)/,,$(@))\n\n"
1154         $(CBFSTOOL) $@ print -r $(subst $(spc),$(comma),$(all-regions))
1156 cbfs-files-y += $(CONFIG_CBFS_PREFIX)/romstage
1157 $(CONFIG_CBFS_PREFIX)/romstage-file := $(objcbfs)/romstage.elf
1158 $(CONFIG_CBFS_PREFIX)/romstage-type := stage
1159 $(CONFIG_CBFS_PREFIX)/romstage-compression := $(CBFS_PRERAM_COMPRESS_FLAG)
1160 ifeq ($(CONFIG_ARCH_ROMSTAGE_ARM),y)
1161 $(CONFIG_CBFS_PREFIX)/romstage-options := -b 0
1162 endif
1163 ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32)$(CONFIG_ARCH_ROMSTAGE_X86_64),y)
1164 # Use a 64 byte alignment to provide a minimum alignment
1165 # requirement for the overall romstage. While the first object within
1166 # romstage could have a 4 byte minimum alignment that doesn't mean the linker
1167 # won't decide the entire section should be aligned to a larger value. In the
1168 # future cbfstool should add XIP files proper and honor the alignment
1169 # requirements of the program segment.
1171 # Make sure that segment for .car.data is ignored while adding romstage.
1172 $(CONFIG_CBFS_PREFIX)/romstage-align := 64
1173 $(CONFIG_CBFS_PREFIX)/romstage-options := -S ".car.data"
1175 # If CAR does not support execution of code, romstage on x86 is expected to be
1176 # xip.
1177 ifneq ($(CONFIG_NO_XIP_EARLY_STAGES),y)
1178 $(CONFIG_CBFS_PREFIX)/romstage-options += --xip
1180 # For efficient MTRR utilisation use natural alignment for romstage.
1181 ifeq ($(CONFIG_SETUP_XIP_CACHE),y)
1182 $(CONFIG_CBFS_PREFIX)/romstage-options += --pow2page
1183 endif    # CONFIG_SETUP_XIP_CACHE
1185 endif   # CONFIG_NO_XIP_EARLY_STAGES
1186 endif   # CONFIG_ARCH_ROMSTAGE_X86_32 / CONFIG_ARCH_ROMSTAGE_X86_64
1187 ifeq ($(CONFIG_VBOOT_STARTS_IN_ROMSTAGE),y)
1188 $(CONFIG_CBFS_PREFIX)/romstage-options += $(TXTIBB)
1189 endif
1191 cbfs-files-$(CONFIG_HAVE_RAMSTAGE) += $(CONFIG_CBFS_PREFIX)/ramstage
1192 $(CONFIG_CBFS_PREFIX)/ramstage-file := $(RAMSTAGE)
1193 $(CONFIG_CBFS_PREFIX)/ramstage-type := stage
1194 $(CONFIG_CBFS_PREFIX)/ramstage-compression := $(CBFS_COMPRESS_FLAG)
1196 cbfs-files-$(CONFIG_HAVE_REFCODE_BLOB) += $(CONFIG_CBFS_PREFIX)/refcode
1197 $(CONFIG_CBFS_PREFIX)/refcode-file := $(REFCODE_BLOB)
1198 $(CONFIG_CBFS_PREFIX)/refcode-type := stage
1199 $(CONFIG_CBFS_PREFIX)/refcode-compression := $(CBFS_COMPRESS_FLAG)
1201 cbfs-files-$(CONFIG_SEABIOS_VGA_COREBOOT) += vgaroms/seavgabios.bin
1202 vgaroms/seavgabios.bin-file := $(CONFIG_PAYLOAD_VGABIOS_FILE)
1203 vgaroms/seavgabios.bin-type := raw
1205 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += config
1206 config-file := $(DOTCONFIG):defconfig
1207 config-type := raw
1209 cbfs-files-$(CONFIG_INCLUDE_CONFIG_FILE) += revision
1210 revision-file := $(obj)/build.h
1211 revision-type := raw
1213 BOOTSPLASH_SUFFIX=$(suffix $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE)))
1214 cbfs-files-$(CONFIG_BOOTSPLASH_IMAGE) += bootsplash$(BOOTSPLASH_SUFFIX)
1215 bootsplash$(BOOTSPLASH_SUFFIX)-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
1216 bootsplash$(BOOTSPLASH_SUFFIX)-type := bootsplash
1218 # Ensure that no payload segment overlaps with memory regions used by ramstage
1219 # (not for x86 since it can relocate itself in that case)
1220 ifneq ($(CONFIG_ARCH_X86),y)
1221 check-ramstage-overlap-regions := ramstage
1222 check-ramstage-overlap-files :=
1223 ifneq ($(CONFIG_PAYLOAD_NONE),y)
1224 check-ramstage-overlap-files += $(CONFIG_CBFS_PREFIX)/payload
1225 endif
1227 # will output one or more lines of "<load address in hex> <memlen in decimal>"
1228 cbfs-get-segments-cmd = $(CBFSTOOL) $(obj)/coreboot.pre print -v | sed -n \
1229         '\%$(1)%,\%^[^ ]\{4\}%s%    .*load: \(0x[0-9a-fA-F]*\),.*length: [0-9]*/\([0-9]*\).*%\1 \2%p'
1231 ramstage-symbol-addr-cmd = $(OBJDUMP_ramstage) -t $(objcbfs)/ramstage.elf | \
1232         sed -n '/ $(1)$$/s/^\([0-9a-fA-F]*\) .*/0x\1/p'
1234 check-ramstage-overlaps: $(obj)/coreboot.pre
1235         programs=$$($(foreach file,$(check-ramstage-overlap-files), \
1236                 $(call cbfs-get-segments-cmd,$(file)) ; )) ; \
1237         regions=$$($(foreach region,$(check-ramstage-overlap-regions), \
1238                 echo $(region) ; \
1239                 $(call ramstage-symbol-addr-cmd,_$(region)) ; \
1240                 $(call ramstage-symbol-addr-cmd,_e$(region)) ; )) ; \
1241         pstart= ; pend= ; \
1242         for x in $$programs; do \
1243             if [ -z $$pstart ]; then pstart=$$(($$x)) ; continue ; fi ; \
1244             pend=$$(($$pstart + $$x)) ; \
1245             rname= ; rstart= ; rend= ; \
1246             for y in $$regions ; do \
1247                 if [ -z $$rname ]; then rname=$$y ; continue ; fi ; \
1248                 if [ -z $$rstart ]; then rstart=$$(($$y)) ; continue ; fi ; \
1249                 rend=$$(($$y)) ; \
1250                 if [ $$pstart -lt $$rend -a $$rstart -lt $$pend ]; then \
1251                     echo "ERROR: Ramstage region _$$rname overlapped by:" \
1252                          $(check-ramstage-overlap-files) ; \
1253                     exit 1 ; \
1254                 fi ; \
1255                 rname= ; rstart= ; rend= ; \
1256             done ; \
1257             pstart= ; pend= ; \
1258         done
1260 INTERMEDIATE+=check-ramstage-overlaps
1261 PHONY+=check-ramstage-overlaps
1262 endif