Fred Reitberger has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/68122 )
Change subject: soc/amd/common/[,block/cpu/]Makefile.inc: Add support for sbin ucode files ......................................................................
soc/amd/common/[,block/cpu/]Makefile.inc: Add support for 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 hexdump 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 sbin file will be added and a note will print at the start of the build about the bin file being skipped.
TEST=chausie/morphius builds with only bin, only sbin, non-matching bin and sbin, matching bin and sbin files
Signed-off-by: Fred Reitberger reitbergerfred@gmail.com Change-Id: I29768ea19543bdc76662e687f59bf31b76f555ae --- M src/soc/amd/common/Makefile.inc M src/soc/amd/common/block/cpu/Makefile.inc 2 files changed, 59 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/22/68122/1
diff --git a/src/soc/amd/common/Makefile.inc b/src/soc/amd/common/Makefile.inc index a935565..eeb68aa 100644 --- a/src/soc/amd/common/Makefile.inc +++ b/src/soc/amd/common/Makefile.inc @@ -13,5 +13,6 @@ DEP_FILES= $(patsubst %,$(FIRMWARE_LOCATION)/%, $(shell sed -e /^$(POUND_SIGN)/d -e /*/d -e /^FIRMWARE_LOCATION/d $(CONFIG_AMDFW_CONFIG_FILE) | awk '{print $$2}' ))
amd_microcode_bins += $(wildcard ${FIRMWARE_LOCATION}/*UcodePatch_*.bin) +amd_microcode_sbins += $(wildcard ${FIRMWARE_LOCATION}/*UcodePatch_*.sbin)
endif diff --git a/src/soc/amd/common/block/cpu/Makefile.inc b/src/soc/amd/common/block/cpu/Makefile.inc index 7541a9b..174027b 100644 --- a/src/soc/amd/common/block/cpu/Makefile.inc +++ b/src/soc/amd/common/block/cpu/Makefile.inc @@ -16,5 +16,35 @@ endif endef
-$(foreach ucode,$(amd_microcode_bins),$(eval $(call add-ucode-as-cbfs,$(ucode),$(shell hexdump -n 2 -s 0x18 -e '"%x"' $(ucode))))) -endif +# 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 hexdump -n $(2) -s $(3) -e '$(4)' $(1)) + +# Function to grab part of one file and put it into another +# $(call extract-to-file,input-filename,output-filename,offset-into-file,bytes-to-get) +extract-to-file = $(shell dd ibs=1 status=none skip=$(3) count=$(4) if=$(1) of=$(2)) + +# Standardize the name of the temp file created in the build directory +tmp-ucode-name = $(obj)/$(subst .sbin,.bin,$(notdir $(1))) + +# add-ucode-sbin-as-cbfs +# $(call add-ucode-sbin-as-cbfs,sbin-ucode-file) +# Convert the sbin to a bin file located at tmp-ucode-name, then add the bin file with add-ucode-as-cbfs +# The sbin header is 256 bytes, and the size of the unwrapped file is at offset 0x14 +define add-ucode-sbin-as-cbfs + $(eval $(call extract-to-file,$(1),$(call tmp-ucode-name,$(1)),256,$(call extract-bytes,$(1),4,0x14,"%d"))) + $(eval $(call add-ucode-as-cbfs,$(call tmp-ucode-name,$(1)),$(call extract-bytes,$(1),2,0x118,"%04x"))) +endef + +# check if there is already an sbin wrapped ucode file and only add if there is not +define add-ucode-if-not-sbin + $(if $(findstring $(call tmp-ucode-name,$(1)),$(call tmp-ucode-name,$(amd_microcode_sbins))),\ + $(info skipping $(1) due to .sbin),\ + $(call add-ucode-as-cbfs,$(1),$(call extract-bytes,$(1),2,0x18,"%04x"))) +endef + +$(foreach ucsbin,$(amd_microcode_sbins),$(eval $(call add-ucode-sbin-as-cbfs,$(ucsbin)))) +$(foreach ucode,$(amd_microcode_bins),$(eval $(call add-ucode-if-not-sbin,$(ucode)))) + +endif #ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_UCODE),y) +