1 # SPDX-License-Identifier: GPL-2.0-only
5 ifeq ($(CONFIG_UBSAN),y)
7 CFLAGS_ramstage += -fsanitize=undefined
10 # Ensure that asan_shadow_offset_callback patch is applied to GCC before ASan is used.
11 CFLAGS_asan += -fsanitize=kernel-address --param asan-use-shadow-offset-callback=1 \
12 --param asan-stack=1 -fsanitize-address-use-after-scope \
13 --param asan-instrumentation-with-call-threshold=0 \
14 --param use-after-scope-direct-emission-threshold=0
16 ifeq ($(CONFIG_ASAN_IN_ROMSTAGE),y)
18 CFLAGS_asan += --param asan-globals=0
19 CFLAGS_romstage += $(CFLAGS_asan)
20 # Allow memory access without __asan_load and __asan_store checks.
21 $(obj)/romstage/lib/asan.o: CFLAGS_asan =
24 ifeq ($(CONFIG_ASAN_IN_RAMSTAGE),y)
26 CFLAGS_asan += --param asan-globals=1
27 CFLAGS_ramstage += $(CFLAGS_asan)
28 $(obj)/ramstage/lib/asan.o: CFLAGS_asan =
33 decompressor-y += decompressor.c
34 $(call src-to-obj,decompressor,$(dir)/decompressor.c): $(objcbfs)/bootblock.lz4
35 $(call src-to-obj,decompressor,$(dir)/decompressor.c): CCACHE_EXTRAFILES=$(objcbfs)/bootblock.lz4
36 # Must reset CCACHE_EXTRAFILES or make applies it transitively to dependencies.
37 $(objcbfs)/bootblock.lz4: CCACHE_EXTRAFILES=
39 decompressor-y += delay.c
40 decompressor-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
41 decompressor-y += memchr.c
42 decompressor-y += memcmp.c
43 decompressor-$(CONFIG_CBFS_VERIFICATION) += metadata_hash.c
44 decompressor-y += prog_ops.c
45 decompressor-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
47 bootblock-y += bootblock.c
48 bootblock-y += prog_loaders.c
49 bootblock-y += prog_ops.c
51 bootblock-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
52 bootblock-y += libgcc.c
53 ifneq ($(CONFIG_VBOOT_STARTS_BEFORE_BOOTBLOCK),y)
54 bootblock-$(CONFIG_CBFS_VERIFICATION) += metadata_hash.c
55 else # ($(CONFIG_VBOOT_STARTS_BEFORE_BOOTBLOCK),y)
56 verstage-$(CONFIG_CBFS_VERIFICATION) += metadata_hash.c
57 endif # ($(CONFIG_VBOOT_STARTS_BEFORE_BOOTBLOCK),y)
58 bootblock-$(CONFIG_GENERIC_UDELAY) += timer.c
60 bootblock-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
62 bootblock-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
63 bootblock-y += delay.c
64 bootblock-y += memchr.c
65 bootblock-y += memcmp.c
66 bootblock-y += boot_device.c
69 verstage-y += prog_loaders.c
70 verstage-y += prog_ops.c
75 verstage-y += libgcc.c
76 verstage-y += memcmp.c
77 verstage-y += string.c
79 verstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
80 verstage-y += boot_device.c
81 verstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
83 verstage-$(CONFIG_GENERIC_UDELAY) += timer.c
84 verstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
86 romstage-$(CONFIG_VENDOR_EMULATION) += ramdetect.c
87 romstage-y += prog_loaders.c
88 romstage-y += prog_ops.c
89 romstage-y += memchr.c
90 romstage-y += memcmp.c
91 $(foreach arch,$(ARCH_SUPPORTED),\
92 $(eval rmodules_$(arch)-y += memcmp.c) \
93 $(eval rmodules_$(arch)-y += rmodule.ld))
98 ifneq ($(CONFIG_COMPRESS_RAMSTAGE_LZMA)$(CONFIG_FSP_COMPRESS_FSP_M_LZMA),)
99 romstage-y += lzma.c lzmadecode.c
101 romstage-y += libgcc.c
102 romstage-y += memrange.c
103 romstage-$(CONFIG_PRIMITIVE_MEMTEST) += primitive_memtest.c
104 ramstage-$(CONFIG_PRIMITIVE_MEMTEST) += primitive_memtest.c
105 romstage-y += ramtest.c
106 romstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
107 ramstage-y += region_file.c
108 romstage-y += region_file.c
109 ramstage-y += romstage_handoff.c
110 romstage-y += romstage_handoff.c
111 romstage-y += selfboot.c
112 romstage-y += stack.c
116 romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
117 romstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
119 romstage-y += compute_ip_checksum.c
120 romstage-y += dimm_info_util.c
121 ifeq ($(CONFIG_COMPILER_GCC),y)
122 bootblock-$(CONFIG_ARCH_BOOTBLOCK_X86_32) += gcc.c
123 verstage-$(CONFIG_ARCH_VERSTAGE_X86_32) += gcc.c
124 romstage-$(CONFIG_ARCH_ROMSTAGE_X86_32) += gcc.c
125 ramstage-$(CONFIG_ARCH_RAMSTAGE_X86_32) += gcc.c
129 romstage-$(CONFIG_GENERIC_UDELAY) += timer.c
131 ramstage-$(CONFIG_VENDOR_EMULATION) += ramdetect.c
132 ramstage-y += prog_loaders.c
133 ramstage-y += prog_ops.c
134 ramstage-y += hardwaremain.c
135 ramstage-y += selfboot.c
136 ramstage-y += coreboot_table.c
137 ramstage-y += bootmem.c
139 ramstage-y += memchr.c
140 ramstage-y += memcmp.c
141 ramstage-y += malloc.c
142 ramstage-y += dimm_info_util.c
143 ramstage-y += delay.c
144 ramstage-y += fallback_boot.c
145 ramstage-y += compute_ip_checksum.c
147 ramstage-y += lzma.c lzmadecode.c
148 ramstage-y += stack.c
149 ramstage-y += hexstrtobin.c
151 ramstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
152 ramstage-$(CONFIG_BMP_LOGO) += bmp_logo.c
153 ramstage-$(CONFIG_BOOTSPLASH) += bootsplash.c
154 ramstage-$(CONFIG_BOOTSPLASH) += jpeg.c
155 ramstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
156 ramstage-$(CONFIG_COVERAGE) += libgcov.c
157 ramstage-y += dp_aux.c
159 ramstage-y += edid_fill_fb.c
160 ramstage-y += memrange.c
161 ramstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
162 ramstage-$(CONFIG_GENERIC_UDELAY) += timer.c
163 ramstage-y += b64_decode.c
164 ramstage-$(CONFIG_ACPI_NHLT) += nhlt.c
165 ramstage-$(CONFIG_FLATTENED_DEVICE_TREE) += device_tree.c
166 ramstage-$(CONFIG_PAYLOAD_FIT_SUPPORT) += fit.c
167 ramstage-$(CONFIG_PAYLOAD_FIT_SUPPORT) += fit_payload.c
169 romstage-$(CONFIG_TIMER_QUEUE) += timer_queue.c
170 ramstage-$(CONFIG_TIMER_QUEUE) += timer_queue.c
172 romstage-$(CONFIG_COOP_MULTITASKING) += thread.c
173 ramstage-$(CONFIG_COOP_MULTITASKING) += thread.c
175 romstage-y += cbmem_common.c
176 romstage-y += imd_cbmem.c
179 ramstage-y += cbmem_common.c
180 ramstage-y += imd_cbmem.c
183 postcar-$(CONFIG_VENDOR_EMULATION) += ramdetect.c
184 postcar-y += cbmem_common.c
185 postcar-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
186 postcar-y += imd_cbmem.c
188 postcar-y += romstage_handoff.c
190 bootblock-y += hexdump.c
191 postcar-y += hexdump.c
192 ramstage-y += hexdump.c
193 romstage-y += hexdump.c
194 verstage-y += hexdump.c
197 bootblock-$(CONFIG_FW_CONFIG) += fw_config.c
198 verstage-$(CONFIG_FW_CONFIG) += fw_config.c
199 romstage-$(CONFIG_FW_CONFIG) += fw_config.c
200 ramstage-$(CONFIG_FW_CONFIG) += fw_config.c
202 bootblock-$(CONFIG_ESPI_DEBUG) += espi_debug.c
203 verstage-$(CONFIG_ESPI_DEBUG) += espi_debug.c
204 romstage-$(CONFIG_ESPI_DEBUG) += espi_debug.c
205 ramstage-$(CONFIG_ESPI_DEBUG) += espi_debug.c
207 bootblock-$(CONFIG_REG_SCRIPT) += reg_script.c
208 verstage-$(CONFIG_REG_SCRIPT) += reg_script.c
209 romstage-$(CONFIG_REG_SCRIPT) += reg_script.c
210 ramstage-$(CONFIG_REG_SCRIPT) += reg_script.c
212 ramstage-$(CONFIG_TSEG_STAGE_CACHE) += ext_stage_cache.c
213 romstage-$(CONFIG_TSEG_STAGE_CACHE) += ext_stage_cache.c
214 postcar-$(CONFIG_TSEG_STAGE_CACHE) += ext_stage_cache.c
216 ramstage-$(CONFIG_CBMEM_STAGE_CACHE) += cbmem_stage_cache.c
217 romstage-$(CONFIG_CBMEM_STAGE_CACHE) += cbmem_stage_cache.c
218 postcar-$(CONFIG_CBMEM_STAGE_CACHE) += cbmem_stage_cache.c
220 romstage-y += boot_device.c
221 ramstage-y += boot_device.c
223 smm-y += boot_device.c
226 smm-y += cbfs.c memcmp.c
227 smm-$(CONFIG_GENERIC_UDELAY) += timer.c
228 ifeq ($(CONFIG_DEBUG_SMI),y)
229 smm-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
232 bootblock-y += version.c
233 romstage-y += version.c
234 ramstage-y += version.c
236 verstage-y += version.c
237 postcar-y += version.c
239 $(call src-to-obj,bootblock,$(dir)/version.c) : $(obj)/build.h
240 $(call src-to-obj,romstage,$(dir)/version.c) : $(obj)/build.h
241 $(call src-to-obj,ramstage,$(dir)/version.c) : $(obj)/build.h
242 $(call src-to-obj,smm,$(dir)/version.c) : $(obj)/build.h
243 $(call src-to-obj,verstage,$(dir)/version.c) : $(obj)/build.h
244 $(call src-to-obj,postcar,$(dir)/version.c) : $(obj)/build.h
246 $(call src-to-obj,bootblock,$(dir)/fmap.c) : $(obj)/fmap_config.h
247 $(call src-to-obj,romstage,$(dir)/fmap.c) : $(obj)/fmap_config.h
248 $(call src-to-obj,ramstage,$(dir)/fmap.c) : $(obj)/fmap_config.h
249 $(call src-to-obj,smm,$(dir)/fmap.c) : $(obj)/fmap_config.h
250 $(call src-to-obj,verstage,$(dir)/fmap.c) : $(obj)/fmap_config.h
251 $(call src-to-obj,postcar,$(dir)/fmap.c) : $(obj)/fmap_config.h
253 bootblock-y += bootmode.c
254 romstage-y += bootmode.c
255 ramstage-y += bootmode.c
256 verstage-y += bootmode.c
258 decompressor-y += halt.c
259 bootblock-y += halt.c
264 decompressor-y += reset.c
265 bootblock-y += reset.c
266 verstage-y += reset.c
267 romstage-y += reset.c
269 ramstage-y += reset.c
272 decompressor-y += string.c
273 bootblock-y += string.c
274 verstage-y += string.c
275 romstage-y += string.c
276 postcar-y += string.c
277 ramstage-y += string.c
280 decompressor-y += crc_byte.c
281 bootblock-y += crc_byte.c
282 verstage-y += crc_byte.c
283 romstage-y += crc_byte.c
284 postcar-y += crc_byte.c
285 ramstage-y += crc_byte.c
288 romstage-y += xxhash.c
289 ramstage-y += xxhash.c
291 postcar-y += bootmode.c
292 postcar-y += boot_device.c
298 postcar-y += libgcc.c
299 postcar-$(CONFIG_COMPRESS_RAMSTAGE_LZMA) += lzma.c lzmadecode.c
300 postcar-y += memchr.c
301 postcar-y += memcmp.c
302 postcar-y += prog_loaders.c
303 postcar-y += prog_ops.c
304 postcar-y += rmodule.c
305 postcar-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
306 postcar-$(CONFIG_GENERIC_UDELAY) += timer.c
308 # Use program.ld for all the platforms which use C fo the bootblock.
309 bootblock-y += program.ld
311 decompressor-y += program.ld
312 postcar-y += program.ld
313 romstage-y += program.ld
314 ramstage-y += program.ld
315 verstage-y += program.ld
317 ifeq ($(CONFIG_RELOCATABLE_MODULES),y)
318 ramstage-y += rmodule.c
319 romstage-y += rmodule.c
321 RMODULE_LDFLAGS := -z defs -Bsymbolic
323 # rmodule_link_rules is a function that should be called with:
324 # (1) the object name to link
325 # (2) the dependencies
326 # (3) heap size of the relocatable module
327 # (4) arch for which the rmodules are to be linked
328 # It will create the necessary Make rules to create a rmodule. The resulting
329 # rmdoule is named $(1).rmod
331 $(strip $(1)): $(strip $(2)) $$(COMPILER_RT_rmodules_$(4)) $(call src-to-obj,rmodules_$(4),src/lib/rmodule.ld) | $$(RMODTOOL)
332 $$(LD_rmodules_$(4)) $$(LDFLAGS_rmodules_$(4)) $(RMODULE_LDFLAGS) $($(1)-ldflags) -T $(call src-to-obj,rmodules_$(4),src/lib/rmodule.ld) --defsym=__heap_size=$(strip $(3)) -o $$@ --whole-archive --start-group $(filter-out %.ld,$(2)) --end-group
333 $$(NM_rmodules_$(4)) -n $$@ > $$(basename $$@).map
338 $(objcbfs)/%.debug.rmod: $(objcbfs)/%.debug | $(RMODTOOL)
339 $(RMODTOOL) -i $< -o $@
341 $(obj)/%.elf.rmod: $(obj)/%.elf | $(RMODTOOL)
342 $(RMODTOOL) -i $< -o $@
344 romstage-$(CONFIG_ROMSTAGE_ADA) += cb.ads
345 ramstage-$(CONFIG_RAMSTAGE_ADA) += cb.ads
347 ifneq (,$(filter y, $(CONFIG_RAMSTAGE_LIBHWBASE) $(CONFIG_ROMSTAGE_LIBHWBASE)))
349 to-ada-hex = $(eval $(1) := 16\\\#$(patsubst 0x%,%,$($(1)))\\\#)
351 $(call to-ada-hex,CONFIG_HWBASE_DEFAULT_MMCONF)
353 libhwbase-stages = $(foreach stage, romstage ramstage, \
354 $(if $(filter y,$(CONFIG_$(call toupper,$(stage))_LIBHWBASE)),$(stage)))
356 $(call add-special-class,hw)
357 hw-handler +=$(foreach stage, $(libhwbase-stages), \
358 $(eval $(stage)-srcs += $$(addprefix $(1),$(2))))
360 $(call add-special-class,hw-gen)
362 $(eval additional-dirs += $(dir $(2))) \
363 $(foreach stage, $(libhwbase-stages), \
364 $(eval $(stage)-srcs += $(2)) \
365 $(eval $(stage)-ads-deps += $(2)) \
366 $(eval $(stage)-adb-deps += $(2))) \
367 $(eval $(2): $(obj)/config.h)
369 subdirs-y += ../../3rdparty/libhwbase
371 $(foreach stage,$(libhwbase-stages), \
372 $(eval $(stage)-$(CONFIG_HAVE_MONOTONIC_TIMER) += hw-time-timer.adb))
374 endif # CONFIG_ROMSTAGE_LIBHWBASE || CONFIG_RAMSTAGE_LIBHWBASE
376 romstage-y += spd_bin.c
378 ifeq ($(CONFIG_HAVE_SPD_IN_CBFS),y)
379 LIB_SPD_BIN = $(obj)/spd.bin
381 LIB_SPD_DEPS = $(foreach f, $(SPD_SOURCES), src/mainboard/$(MAINBOARDDIR)/spd/$(f).spd.hex)
383 # Include spd ROM data
384 $(LIB_SPD_BIN): $(LIB_SPD_DEPS)
385 test -n "$(SPD_SOURCES)" || \
386 (echo "HAVE_SPD_IN_CBFS is set but SPD_SOURCES is empty" && exit 1)
387 test -n "$(LIB_SPD_DEPS)" || \
388 (echo "SPD_SOURCES is set but no SPD file was found" && exit 1)
389 if [ "$(SPD_SOURCES)" = "placeholder" ]; then \
392 for f in $(LIB_SPD_DEPS); do \
393 if [ ! -f $$f ]; then \
394 echo "File not found: $$f" >&2; \
397 for c in $$(cat $$f | grep --binary-files=text -v ^#); \
398 do printf $$(printf '\\%o' 0x$$c); \
403 cbfs-files-y += spd.bin
404 spd.bin-file := $(LIB_SPD_BIN)
410 romstage-$(CONFIG_SPD_CACHE_IN_FMAP) += spd_cache.c
412 cbfs-files-y += cbfs_master_header
413 cbfs_master_header-file := cbfs_master_header.c:struct
414 cbfs_master_header-type := "cbfs header"
415 cbfs_master_header-position := 0
417 ifeq ($(CONFIG_ARCH_X86),y)
418 $(call src-to-obj,bootblock,$(dir)/master_header_pointer.c): $(obj)/fmap_config.h
419 bootblock-y += master_header_pointer.c
424 ifneq ($(CONFIG_ARCH_X86),y)
427 ifneq ($(CONFIG_BOOTBLOCK_IN_CBFS),y)
431 cbfs-files-$(NEED_CBFS_POINTER) += header_pointer
432 header_pointer-file := master_header_pointer.c:struct
433 header_pointer-position := -4
434 header_pointer-type := "cbfs header"