From 2c9f1600e0553a95ecf8b1b1945c232366b570f8 Mon Sep 17 00:00:00 2001 From: Sean Rhodes Date: Sun, 15 Feb 2026 21:12:31 +0000 Subject: [PATCH] src/lib: Generate spd.hex from JSON at build time Allow mainboards to provide SPD sources as .spd.json alongside existing .spd.hex files. When a JSON source is used, spd_gen is invoked at build time to generate the corresponding .spd.hex in the build directory. Change-Id: Ie1f2b81bcc15af65f1402b31f5c1f0553217fdda Signed-off-by: Sean Rhodes Reviewed-on: https://review.coreboot.org/c/coreboot/+/91251 Tested-by: build bot (Jenkins) Reviewed-by: Alicja Michalska --- src/lib/Makefile.mk | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/lib/Makefile.mk b/src/lib/Makefile.mk index 0dc41ce921..756956aca5 100644 --- a/src/lib/Makefile.mk +++ b/src/lib/Makefile.mk @@ -375,17 +375,43 @@ romstage-y += spd_bin.c ifeq ($(CONFIG_HAVE_SPD_IN_CBFS),y) LIB_SPD_BIN = $(obj)/spd.bin -LIB_SPD_DEPS = $(foreach f, $(SPD_SOURCES), src/mainboard/$(MAINBOARDDIR)/spd/$(f).spd.hex) +SPD_SRC_DIR := src/mainboard/$(MAINBOARDDIR)/spd +SPD_OBJ_DIR := $(obj)/spd +SPD_GEN_TOOL := util/spd_tools/bin/spd_gen + +SPD_GEN_MEM_TECH ?= +SPD_GEN_SET ?= 0 + +# Some boards set SPD_SOURCES to the sentinel value "placeholder" to request +# a minimal spd.bin without any dependencies. +SPD_SOURCES_IS_PLACEHOLDER = \ + $(if $(filter placeholder,$(SPD_SOURCES)), \ + $(if $(filter-out placeholder,$(SPD_SOURCES)),,y)) + +define spd_hex_dep +$(if $(wildcard $(SPD_SRC_DIR)/$(1).spd.hex),$(SPD_SRC_DIR)/$(1).spd.hex,$(SPD_OBJ_DIR)/$(1).spd.hex) +endef + +LIB_SPD_DEPS = $(foreach f, $(SPD_SOURCES), $(call spd_hex_dep,$(f))) + +$(SPD_GEN_TOOL): + $(MAKE) -C util/spd_tools bin/spd_gen + +$(SPD_OBJ_DIR)/%.spd.hex: $(SPD_SRC_DIR)/%.spd.json | $(SPD_GEN_TOOL) + test -n "$(SPD_GEN_MEM_TECH)" || \ + (echo "SPD_GEN_MEM_TECH must be set to generate SPD hex from JSON" >&2 && exit 1) + mkdir -p $(SPD_OBJ_DIR) + $(SPD_GEN_TOOL) --set $(SPD_GEN_SET) $< $(SPD_GEN_MEM_TECH) $@ # Include spd ROM data -$(LIB_SPD_BIN): $(LIB_SPD_DEPS) +$(LIB_SPD_BIN): $$(if $$(SPD_SOURCES_IS_PLACEHOLDER),,$$(LIB_SPD_DEPS)) test -n "$(SPD_SOURCES)" || \ (echo "HAVE_SPD_IN_CBFS is set but SPD_SOURCES is empty" && exit 1) - test -n "$(LIB_SPD_DEPS)" || \ - (echo "SPD_SOURCES is set but no SPD file was found" && exit 1) if [ "$(SPD_SOURCES)" = "placeholder" ]; then \ printf '\0'; \ else \ + test -n "$(LIB_SPD_DEPS)" || \ + (echo "SPD_SOURCES is set but no SPD file was found" && exit 1); \ for f in $(LIB_SPD_DEPS); do \ if [ ! -f $$f ]; then \ echo "File not found: $$f" >&2; \