Matt DeVillier has submitted this change. ( https://review.coreboot.org/c/coreboot/+/68122?usp=email )
Change subject: soc/amd/common: Support sbin ucode files ......................................................................
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 --- M src/soc/amd/common/Makefile.mk M src/soc/amd/common/block/cpu/Makefile.mk 2 files changed, 45 insertions(+), 13 deletions(-)
Approvals: Patrick Rudolph: Looks good to me, approved Fred Reitberger: Looks good to me, but someone else must approve build bot (Jenkins): Verified
diff --git a/src/soc/amd/common/Makefile.mk b/src/soc/amd/common/Makefile.mk index 626260f..a030687 100644 --- a/src/soc/amd/common/Makefile.mk +++ b/src/soc/amd/common/Makefile.mk @@ -38,8 +38,6 @@ 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 $< $@ diff --git a/src/soc/amd/common/block/cpu/Makefile.mk b/src/soc/amd/common/block/cpu/Makefile.mk index 1c4331c..ea40801 100644 --- a/src/soc/amd/common/block/cpu/Makefile.mk +++ b/src/soc/amd/common/block/cpu/Makefile.mk @@ -9,18 +9,52 @@ 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)