soc/amd/common: Support sbin ucode files

Recent PI releases have been distributing the ucode patch files as sbin
files instead of bin files. The sbin uses a 256 byte amd_fw_header to
wrap the bin file.

Offset 0x14 of the header is the size field. The can be extracted with
od to get the size of the ucode bin file. The bin file can then be
extracted with dd and placed in the build directory for inclusion as a
cbfs file.

In the case where both an sbin and bin ucode file are present, the bin
file will be added and a note will print at the start of the build about
the sbin file being skipped.

TEST=builds with only bin, only sbin, non-matching bin and sbin,
matching bin and sbin files

Signed-off-by: Fred Reitberger <reitbergerfred@gmail.com>
Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Change-Id: I29768ea19543bdc76662e687f59bf31b76f555ae
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68122
Reviewed-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Fred Reitberger 2022-10-04 15:07:49 -04:00 committed by Matt DeVillier
commit 4cfc5db6b6
2 changed files with 45 additions and 13 deletions

View file

@ -38,8 +38,6 @@ AMDFW_CFG_WITH_PATH = $(shell echo "$(AMDFW_CFG_FILES)" | tr ' ' '\n' | grep "/"
DEP_FILES = $(patsubst %,$(FIRMWARE_LOCATION)/%, $(AMDFW_CFG_IN_FW_LOC)) \
$(AMDFW_CFG_WITH_PATH)
amd_microcode_bins += $(wildcard ${FIRMWARE_LOCATION}/*U?odePatch*.bin)
ifeq ($(CONFIG_RESET_VECTOR_IN_RAM),y)
$(objcbfs)/bootblock.bin: $(obj)/amdfw.rom $(obj)/fmap_config.h
cp $< $@

View file

@ -9,18 +9,52 @@ ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_SVI3) += svi3.c
ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_UCODE) += update_microcode.c
ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_UCODE),y)
define add-ucode-as-cbfs
$(if $(value cpu_microcode_$(2).bin-file),$(info File1: $(cpu_microcode_$(2).bin-file)) $(info File2: $(1)) $(error Error: The cbfs filename "cpu_microcode_$(2).bin" is used for both above files. Check your microcode patches for duplicates.))
cbfs-files-y += cpu_microcode_$(2).bin
cpu_microcode_$(2).bin-file := $(1)
cpu_microcode_$(2).bin-type := microcode
ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_LPC_SPI_DMA),y)
cpu_microcode_$(2).bin-align := 64
else
cpu_microcode_$(2).bin-align := 16
define add-ucode-as-cbfs
# check for duplicate microcode files. Same sbin and bin ucode is allowed here though, because mendocino has a duplicate.
ifeq ($(cpu_microcode_$(2).bin-file), $(obj)/cpu_microcode_$(2).$(3))
$$(info Tried to add ucode: $(1))
$$(error Error: The cbfs filename "cpu_microcode_$(2).bin" is already used. Check your microcode patches for duplicates.)
endif
# offset 0x14 contains the size of the unwrapped ucode file
# .sbin files contain a 256 wrapper around the usual microcode file
$(obj)/cpu_microcode_$(2).$(3): $(1)
echo $$< "->" $$@
if [ $(3) = "bin" ]; then \
cp $$< $$@; \
elif [ $(3) = "sbin" ]; then \
size=$$$$(od --endian little --address-radix n --read-bytes 4 --skip-bytes 0x14 --format u4 $$<); \
dd status=none ibs=1 skip=256 count=$$$$((size)) if=$$< of=$$@; \
fi
# if there is both a sbin and bin microcode only include the bin one to keep the old behaviour
ifeq ($(cpu_microcode_$(2).bin-file),)
cbfs-files-y += cpu_microcode_$(2).bin
cpu_microcode_$(2).bin-file := $(obj)/cpu_microcode_$(2).$(3)
cpu_microcode_$(2).bin-type := microcode
ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_LPC_SPI_DMA),y)
cpu_microcode_$(2).bin-align := 64
else
cpu_microcode_$(2).bin-align := 16
endif
endif
endef
$(foreach ucode,$(amd_microcode_bins),$(eval $(call add-ucode-as-cbfs,$(ucode),$(shell hexdump -n 2 -s 0x18 -e '"%x"' $(ucode)))))
endif
amd_microcode_bins += $(wildcard ${FIRMWARE_LOCATION}/*U?odePatch*.bin)
amd_microcode_sbins += $(wildcard ${FIRMWARE_LOCATION}/*UcodePatch_*.sbin)
# Function to grab bytes from a file and format them as desired
# $(call extract-bytes,filename,bytes-to-read,offset-to-bytes,output-format)
extract-bytes = $(shell echo $(shell od --endian little --address-radix n --read-bytes $(2) --skip-bytes $(3) --format $(4) $(1)))
$(foreach ucode, $(amd_microcode_bins), \
$(eval $(call add-ucode-as-cbfs,$(ucode),$(call extract-bytes,$(ucode),2,0x18,x2),bin)))
$(foreach ucode, $(amd_microcode_sbins), \
$(eval $(call add-ucode-as-cbfs,$(ucode),$(call extract-bytes,$(ucode),2,0x118,x2),sbin)))
endif #ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_UCODE),y)