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 bootblock-$(CONFIG_CBFS_VERIFICATION) += metadata_hash.c
54 bootblock-$(CONFIG_GENERIC_UDELAY) += timer.c
56 bootblock-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
58 bootblock-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
59 bootblock-y += delay.c
60 bootblock-y += memchr.c
61 bootblock-y += memcmp.c
62 bootblock-y += boot_device.c
65 verstage-y += prog_loaders.c
66 verstage-y += prog_ops.c
71 verstage-y += libgcc.c
72 verstage-y += memcmp.c
73 verstage-y += string.c
75 verstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
76 verstage-y += boot_device.c
77 verstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
79 verstage-$(CONFIG_GENERIC_UDELAY) += timer.c
80 verstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
82 romstage-$(CONFIG_VENDOR_EMULATION) += ramdetect.c
83 romstage-y += prog_loaders.c
84 romstage-y += prog_ops.c
85 romstage-y += memchr.c
86 romstage-y += memcmp.c
87 $(foreach arch,$(ARCH_SUPPORTED),\
88 $(eval rmodules_$(arch)-y += memcmp.c) \
89 $(eval rmodules_$(arch)-y += rmodule.ld))
94 romstage-$(CONFIG_COMPRESS_RAMSTAGE) += lzma.c lzmadecode.c
95 romstage-y += libgcc.c
96 romstage-y += memrange.c
97 romstage-$(CONFIG_PRIMITIVE_MEMTEST) += primitive_memtest.c
98 ramstage-$(CONFIG_PRIMITIVE_MEMTEST) += primitive_memtest.c
99 romstage-y += ramtest.c
100 romstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
101 ramstage-y += region_file.c
102 romstage-y += region_file.c
103 ramstage-y += romstage_handoff.c
104 romstage-y += romstage_handoff.c
105 romstage-y += selfboot.c
106 romstage-y += stack.c
110 romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
111 romstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
113 romstage-y += compute_ip_checksum.c
114 romstage-y += dimm_info_util.c
115 ifeq ($(CONFIG_COMPILER_GCC),y)
116 bootblock-$(CONFIG_ARCH_BOOTBLOCK_X86_32) += gcc.c
117 verstage-$(CONFIG_ARCH_VERSTAGE_X86_32) += gcc.c
118 romstage-$(CONFIG_ARCH_ROMSTAGE_X86_32) += gcc.c
119 ramstage-$(CONFIG_ARCH_RAMSTAGE_X86_32) += gcc.c
123 romstage-$(CONFIG_GENERIC_UDELAY) += timer.c
125 ramstage-$(CONFIG_VENDOR_EMULATION) += ramdetect.c
126 ramstage-y += prog_loaders.c
127 ramstage-y += prog_ops.c
128 ramstage-y += hardwaremain.c
129 ramstage-y += selfboot.c
130 ramstage-y += coreboot_table.c
131 ramstage-y += bootmem.c
133 ramstage-y += memchr.c
134 ramstage-y += memcmp.c
135 ramstage-y += malloc.c
136 ramstage-y += dimm_info_util.c
137 ramstage-y += delay.c
138 ramstage-y += fallback_boot.c
139 ramstage-y += compute_ip_checksum.c
141 ramstage-y += lzma.c lzmadecode.c
142 ramstage-y += stack.c
143 ramstage-y += hexstrtobin.c
145 ramstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
146 ramstage-$(CONFIG_BMP_LOGO) += bmp_logo.c
147 ramstage-$(CONFIG_BOOTSPLASH) += bootsplash.c
148 ramstage-$(CONFIG_BOOTSPLASH) += jpeg.c
149 ramstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
150 ramstage-$(CONFIG_COVERAGE) += libgcov.c
151 ramstage-y += dp_aux.c
153 ramstage-y += edid_fill_fb.c
154 ramstage-y += memrange.c
155 ramstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
156 ramstage-$(CONFIG_GENERIC_UDELAY) += timer.c
157 ramstage-y += b64_decode.c
158 ramstage-$(CONFIG_ACPI_NHLT) += nhlt.c
159 ramstage-$(CONFIG_FLATTENED_DEVICE_TREE) += device_tree.c
160 ramstage-$(CONFIG_PAYLOAD_FIT_SUPPORT) += fit.c
161 ramstage-$(CONFIG_PAYLOAD_FIT_SUPPORT) += fit_payload.c
163 romstage-$(CONFIG_TIMER_QUEUE) += timer_queue.c
164 ramstage-$(CONFIG_TIMER_QUEUE) += timer_queue.c
166 romstage-$(CONFIG_COOP_MULTITASKING) += thread.c
167 ramstage-$(CONFIG_COOP_MULTITASKING) += thread.c
169 romstage-y += cbmem_common.c
170 romstage-y += imd_cbmem.c
173 ramstage-y += cbmem_common.c
174 ramstage-y += imd_cbmem.c
177 postcar-$(CONFIG_VENDOR_EMULATION) += ramdetect.c
178 postcar-y += cbmem_common.c
179 postcar-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
180 postcar-y += imd_cbmem.c
182 postcar-y += romstage_handoff.c
184 bootblock-y += hexdump.c
185 postcar-y += hexdump.c
186 ramstage-y += hexdump.c
187 romstage-y += hexdump.c
188 verstage-y += hexdump.c
191 bootblock-$(CONFIG_FW_CONFIG) += fw_config.c
192 verstage-$(CONFIG_FW_CONFIG) += fw_config.c
193 romstage-$(CONFIG_FW_CONFIG) += fw_config.c
194 ramstage-$(CONFIG_FW_CONFIG) += fw_config.c
196 bootblock-$(CONFIG_ESPI_DEBUG) += espi_debug.c
197 verstage-$(CONFIG_ESPI_DEBUG) += espi_debug.c
198 romstage-$(CONFIG_ESPI_DEBUG) += espi_debug.c
199 ramstage-$(CONFIG_ESPI_DEBUG) += espi_debug.c
201 bootblock-$(CONFIG_REG_SCRIPT) += reg_script.c
202 verstage-$(CONFIG_REG_SCRIPT) += reg_script.c
203 romstage-$(CONFIG_REG_SCRIPT) += reg_script.c
204 ramstage-$(CONFIG_REG_SCRIPT) += reg_script.c
206 ramstage-$(CONFIG_TSEG_STAGE_CACHE) += ext_stage_cache.c
207 romstage-$(CONFIG_TSEG_STAGE_CACHE) += ext_stage_cache.c
208 postcar-$(CONFIG_TSEG_STAGE_CACHE) += ext_stage_cache.c
210 ramstage-$(CONFIG_CBMEM_STAGE_CACHE) += cbmem_stage_cache.c
211 romstage-$(CONFIG_CBMEM_STAGE_CACHE) += cbmem_stage_cache.c
212 postcar-$(CONFIG_CBMEM_STAGE_CACHE) += cbmem_stage_cache.c
214 romstage-y += boot_device.c
215 ramstage-y += boot_device.c
217 smm-y += boot_device.c
220 smm-y += cbfs.c memcmp.c
221 smm-$(CONFIG_GENERIC_UDELAY) += timer.c
222 ifeq ($(CONFIG_DEBUG_SMI),y)
223 smm-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
226 bootblock-y += version.c
227 romstage-y += version.c
228 ramstage-y += version.c
230 verstage-y += version.c
231 postcar-y += version.c
233 $(call src-to-obj,bootblock,$(dir)/version.c) : $(obj)/build.h
234 $(call src-to-obj,romstage,$(dir)/version.c) : $(obj)/build.h
235 $(call src-to-obj,ramstage,$(dir)/version.c) : $(obj)/build.h
236 $(call src-to-obj,smm,$(dir)/version.c) : $(obj)/build.h
237 $(call src-to-obj,verstage,$(dir)/version.c) : $(obj)/build.h
238 $(call src-to-obj,postcar,$(dir)/version.c) : $(obj)/build.h
240 $(call src-to-obj,bootblock,$(dir)/fmap.c) : $(obj)/fmap_config.h
241 $(call src-to-obj,romstage,$(dir)/fmap.c) : $(obj)/fmap_config.h
242 $(call src-to-obj,ramstage,$(dir)/fmap.c) : $(obj)/fmap_config.h
243 $(call src-to-obj,smm,$(dir)/fmap.c) : $(obj)/fmap_config.h
244 $(call src-to-obj,verstage,$(dir)/fmap.c) : $(obj)/fmap_config.h
245 $(call src-to-obj,postcar,$(dir)/fmap.c) : $(obj)/fmap_config.h
247 bootblock-y += bootmode.c
248 romstage-y += bootmode.c
249 ramstage-y += bootmode.c
250 verstage-y += bootmode.c
252 decompressor-y += halt.c
253 bootblock-y += halt.c
258 decompressor-y += reset.c
259 bootblock-y += reset.c
260 verstage-y += reset.c
261 romstage-y += reset.c
263 ramstage-y += reset.c
266 decompressor-y += string.c
267 bootblock-y += string.c
268 verstage-y += string.c
269 romstage-y += string.c
270 postcar-y += string.c
271 ramstage-y += string.c
274 decompressor-y += crc_byte.c
275 bootblock-y += crc_byte.c
276 verstage-y += crc_byte.c
277 romstage-y += crc_byte.c
278 postcar-y += crc_byte.c
279 ramstage-y += crc_byte.c
282 romstage-y += xxhash.c
283 ramstage-y += xxhash.c
285 postcar-y += bootmode.c
286 postcar-y += boot_device.c
292 postcar-y += libgcc.c
293 postcar-$(CONFIG_COMPRESS_RAMSTAGE) += lzma.c lzmadecode.c
294 postcar-y += memchr.c
295 postcar-y += memcmp.c
296 postcar-y += prog_loaders.c
297 postcar-y += prog_ops.c
298 postcar-y += rmodule.c
299 postcar-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
300 postcar-$(CONFIG_GENERIC_UDELAY) += timer.c
302 # Use program.ld for all the platforms which use C fo the bootblock.
303 bootblock-y += program.ld
305 decompressor-y += program.ld
306 postcar-y += program.ld
307 romstage-y += program.ld
308 ramstage-y += program.ld
309 verstage-y += program.ld
311 ifeq ($(CONFIG_RELOCATABLE_MODULES),y)
312 ramstage-y += rmodule.c
313 romstage-y += rmodule.c
315 RMODULE_LDFLAGS := -z defs -Bsymbolic
317 # rmodule_link_rules is a function that should be called with:
318 # (1) the object name to link
319 # (2) the dependencies
320 # (3) heap size of the relocatable module
321 # (4) arch for which the rmodules are to be linked
322 # It will create the necessary Make rules to create a rmodule. The resulting
323 # rmdoule is named $(1).rmod
325 $(strip $(1)): $(strip $(2)) $$(COMPILER_RT_rmodules_$(4)) $(call src-to-obj,rmodules_$(4),src/lib/rmodule.ld) | $$(RMODTOOL)
326 $$(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
327 $$(NM_rmodules_$(4)) -n $$@ > $$(basename $$@).map
332 $(objcbfs)/%.debug.rmod: $(objcbfs)/%.debug | $(RMODTOOL)
333 $(RMODTOOL) -i $< -o $@
335 $(obj)/%.elf.rmod: $(obj)/%.elf | $(RMODTOOL)
336 $(RMODTOOL) -i $< -o $@
338 ramstage-$(CONFIG_RAMSTAGE_ADA) += cb.ads
340 ifeq ($(CONFIG_RAMSTAGE_LIBHWBASE),y)
342 to-ada-hex = $(eval $(1) := 16\\\#$(patsubst 0x%,%,$($(1)))\\\#)
344 $(call to-ada-hex,CONFIG_HWBASE_DEFAULT_MMCONF)
346 $(call add-special-class,hw)
347 hw-handler = $(eval ramstage-srcs += $$(addprefix $(1),$(2)))
349 $(call add-special-class,hw-gen)
351 $(eval additional-dirs += $(dir $(2))) \
352 $(eval ramstage-srcs += $(2)) \
353 $(eval ramstage-ads-deps += $(2)) \
354 $(eval ramstage-adb-deps += $(2)) \
355 $(eval $(2): $(obj)/config.h)
357 subdirs-y += ../../3rdparty/libhwbase
359 ramstage-$(CONFIG_HAVE_MONOTONIC_TIMER) += hw-time-timer.adb
361 endif # CONFIG_RAMSTAGE_LIBHWBASE
363 romstage-y += spd_bin.c
365 ifeq ($(CONFIG_HAVE_SPD_IN_CBFS),y)
366 LIB_SPD_BIN = $(obj)/spd.bin
368 LIB_SPD_DEPS = $(foreach f, $(SPD_SOURCES), src/mainboard/$(MAINBOARDDIR)/spd/$(f).spd.hex)
370 # Include spd ROM data
371 $(LIB_SPD_BIN): $(LIB_SPD_DEPS)
372 test -n "$(SPD_SOURCES)" || \
373 (echo "HAVE_SPD_IN_CBFS is set but SPD_SOURCES is empty" && exit 1)
374 test -n "$(LIB_SPD_DEPS)" || \
375 (echo "SPD_SOURCES is set but no SPD file was found" && exit 1)
376 if [ "$(SPD_SOURCES)" = "placeholder" ]; then \
379 for f in $(LIB_SPD_DEPS); do \
380 if [ ! -f $$f ]; then \
381 echo "File not found: $$f" >&2; \
384 for c in $$(cat $$f | grep --binary-files=text -v ^#); \
385 do printf $$(printf '\\%o' 0x$$c); \
390 cbfs-files-y += spd.bin
391 spd.bin-file := $(LIB_SPD_BIN)
397 romstage-$(CONFIG_SPD_CACHE_IN_FMAP) += spd_cache.c
399 cbfs-files-y += cbfs_master_header
400 cbfs_master_header-file := cbfs_master_header.c:struct
401 cbfs_master_header-type := "cbfs header"
402 cbfs_master_header-position := 0
404 ifeq ($(CONFIG_ARCH_X86),y)
405 $(call src-to-obj,bootblock,$(dir)/master_header_pointer.c): $(obj)/fmap_config.h
406 bootblock-y += master_header_pointer.c
411 ifneq ($(CONFIG_ARCH_X86),y)
414 ifneq ($(CONFIG_BOOTBLOCK_IN_CBFS),y)
418 cbfs-files-$(NEED_CBFS_POINTER) += header_pointer
419 header_pointer-file := master_header_pointer.c:struct
420 header_pointer-position := -4
421 header_pointer-type := "cbfs header"