From b6425a9a787997133520f92206fb8bd8e3376958 Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Mon, 14 Apr 2025 08:09:53 +0200 Subject: [PATCH] soc/amd/common: Add comments about bootblock Since the boot flow is different on AMD compared to other x86 platforms document what is done and where. Explain that AMDCOMPRESS does more than compressing the input. It also parses the input as an ELF and extracts the first PT_LOAD marked area from it and discards all other information from the ELF. Explain bootblock.bin generation and that it has not much to do with bootblock.elf, unlike on other platforms. While on it also fix a whitespace in the following line. Change-Id: Ida763f879c133be54ea1ca2abd3059db0d2c1ef7 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/c/coreboot/+/87316 Reviewed-by: Alexander Goncharov Reviewed-by: Maximilian Brune Tested-by: build bot (Jenkins) Reviewed-by: Martin L Roth --- Documentation/soc/amd/psp_integration.md | 14 ++++++++++++-- src/soc/amd/cezanne/Makefile.mk | 7 +++++++ src/soc/amd/common/Makefile.mk | 6 +++++- src/soc/amd/genoa_poc/Makefile.mk | 7 +++++++ src/soc/amd/glinda/Makefile.mk | 7 +++++++ src/soc/amd/mendocino/Makefile.mk | 7 +++++++ src/soc/amd/phoenix/Makefile.mk | 7 +++++++ src/soc/amd/picasso/Makefile.mk | 7 +++++++ 8 files changed, 59 insertions(+), 3 deletions(-) diff --git a/Documentation/soc/amd/psp_integration.md b/Documentation/soc/amd/psp_integration.md index 74f35b9e2e..3606753838 100644 --- a/Documentation/soc/amd/psp_integration.md +++ b/Documentation/soc/amd/psp_integration.md @@ -382,8 +382,18 @@ The BIOS Directory table structure is slightly different from the PSP Directory: `cbfstool/amdcompress` is a helper for creating the BIOS Reset Image (BIOS Directory Table type 0x62). This is the code the PSP uncompresses into DRAM at the location where the x86 begins execution when released from reset. -Typical usage is for amdcompress to convert an ELF file’s program section -into a zlib compressed image. +To tool expects an ELF as input (the bootblock.elf) and extracts the **first** +`PT_LOAD` area out of it. Since only `PT_LOAD` contains what's needed, everything +else can be discarded from the input ELF when the following points are valid: +* The binary is loaded at the address it is linked for + This is done by the PSP at boot time. +* The BSS segment is cleared + This is not done by PSP, but by bootblock assembly code. +* The data segment is initialized + Done automatically when it's part of `PT_LOAD` area or done by bootblock assembly code + when `ENV_SEPARATE_DATA_AND_BSS` is set + +Amdcompress finally compresses the ELF file’s `PT_LOAD` section into a zlib compressed image. ### amdfwtool diff --git a/src/soc/amd/cezanne/Makefile.mk b/src/soc/amd/cezanne/Makefile.mk index ee193e1bf2..80a877a978 100644 --- a/src/soc/amd/cezanne/Makefile.mk +++ b/src/soc/amd/cezanne/Makefile.mk @@ -231,6 +231,13 @@ $(obj)/amdfw.rom: $(call strip_quotes, $(PSP_BIOSBIN_FILE)) \ --multilevel \ --output $@ +# +# Extracts everything from the ELF's first PT_LOAD area and compresses it. +# This discards everything before PT_LOAD, every symbol, debug information +# and relocations. The generated binary is expected to run at PSP_BIOSBIN_DEST +# with a maximum size of PSP_BIOSBIN_SIZE. The entrypoint is fixed at +# PSP_BIOSBIN_DEST + PSP_BIOSBIN_SIZE - 0x10. +# $(PSP_BIOSBIN_FILE): $(PSP_ELF_FILE) $(AMDCOMPRESS) rm -f $@ @printf " AMDCOMPRS $(subst $(obj)/,,$(@))\n" diff --git a/src/soc/amd/common/Makefile.mk b/src/soc/amd/common/Makefile.mk index db60c01b87..5d41968493 100644 --- a/src/soc/amd/common/Makefile.mk +++ b/src/soc/amd/common/Makefile.mk @@ -39,6 +39,10 @@ DEP_FILES = $(patsubst %,$(FIRMWARE_LOCATION)/%, $(AMDFW_CFG_IN_FW_LOC)) \ $(AMDFW_CFG_WITH_PATH) ifeq ($(CONFIG_RESET_VECTOR_IN_RAM),y) +# Even though the target is called bootblock.bin it's way more than that, +# but the name is mandatory for the 'add_bootblock' directive below. +# On AMD the bootblock resides within the AMD FW as part of the +# Bios Directory Tables (BDT), thus about 1% of this file is actually the bootblock. $(objcbfs)/bootblock.bin: $(obj)/amdfw.rom $(obj)/fmap_config.h cp $< $@ @@ -49,7 +53,7 @@ amdfw_offset=$(call int-subtract, \ add_bootblock = \ $(CBFSTOOL) $(1) add -f $(2) -n apu/amdfw -t amdfw \ - -b $(amdfw_offset) -r $(call regions-for-file,apu/amdfw) \ + -b $(amdfw_offset) -r $(call regions-for-file,apu/amdfw) \ $(CBFSTOOL_ADD_CMD_OPTIONS) endif # ifeq ($(CONFIG_RESET_VECTOR_IN_RAM),y) diff --git a/src/soc/amd/genoa_poc/Makefile.mk b/src/soc/amd/genoa_poc/Makefile.mk index 6e98378542..162180dec4 100644 --- a/src/soc/amd/genoa_poc/Makefile.mk +++ b/src/soc/amd/genoa_poc/Makefile.mk @@ -144,6 +144,13 @@ $(obj)/amdfw.rom: $(call strip_quotes, $(PSP_BIOSBIN_FILE)) \ --multilevel \ --output $@ +# +# Extracts everything from the ELF's first PT_LOAD area and compresses it. +# This discards everything before PT_LOAD, every symbol, debug information +# and relocations. The generated binary is expected to run at PSP_BIOSBIN_DEST +# with a maximum size of PSP_BIOSBIN_SIZE. The entrypoint is fixed at +# PSP_BIOSBIN_DEST + PSP_BIOSBIN_SIZE - 0x10. +# $(PSP_BIOSBIN_FILE): $(PSP_ELF_FILE) $(AMDCOMPRESS) rm -f $@ @printf " AMDCOMPRS $(subst $(obj)/,,$(@))\n" diff --git a/src/soc/amd/glinda/Makefile.mk b/src/soc/amd/glinda/Makefile.mk index f4c55c6e33..e0ce02c666 100644 --- a/src/soc/amd/glinda/Makefile.mk +++ b/src/soc/amd/glinda/Makefile.mk @@ -250,6 +250,13 @@ $(obj)/amdfw.rom: $(call strip_quotes, $(PSP_BIOSBIN_FILE)) \ --location $(CONFIG_AMD_FWM_POSITION) \ --output $@ +# +# Extracts everything from the ELF's first PT_LOAD area and compresses it. +# This discards everything before PT_LOAD, every symbol, debug information +# and relocations. The generated binary is expected to run at PSP_BIOSBIN_DEST +# with a maximum size of PSP_BIOSBIN_SIZE. The entrypoint is fixed at +# PSP_BIOSBIN_DEST + PSP_BIOSBIN_SIZE - 0x10. +# $(PSP_BIOSBIN_FILE): $(PSP_ELF_FILE) $(AMDCOMPRESS) rm -f $@ @printf " AMDCOMPRS $(subst $(obj)/,,$(@))\n" diff --git a/src/soc/amd/mendocino/Makefile.mk b/src/soc/amd/mendocino/Makefile.mk index b8fec5701c..4f93e490a4 100644 --- a/src/soc/amd/mendocino/Makefile.mk +++ b/src/soc/amd/mendocino/Makefile.mk @@ -284,6 +284,13 @@ $(PSP_BIOSBIN_FILE): $(PSP_ELF_FILE) rm -f $@ $(OBJCOPY_bootblock) -O binary $< $@ else +# +# Extracts everything from the ELF's first PT_LOAD area and compresses it. +# This discards everything before PT_LOAD, every symbol, debug information +# and relocations. The generated binary is expected to run at PSP_BIOSBIN_DEST +# with a maximum size of PSP_BIOSBIN_SIZE. The entrypoint is fixed at +# PSP_BIOSBIN_DEST + PSP_BIOSBIN_SIZE - 0x10. +# $(PSP_BIOSBIN_FILE): $(PSP_ELF_FILE) $(AMDCOMPRESS) rm -f $@ @printf " AMDCOMPRS $(subst $(obj)/,,$(@))\n" diff --git a/src/soc/amd/phoenix/Makefile.mk b/src/soc/amd/phoenix/Makefile.mk index 21f10c56b9..672e10fb8d 100644 --- a/src/soc/amd/phoenix/Makefile.mk +++ b/src/soc/amd/phoenix/Makefile.mk @@ -285,6 +285,13 @@ $(call add_intermediate, add_amdfwbody, $(obj)/amdfw.rom.body) $(CBFSTOOL) $(obj)/coreboot.pre write -r AMDFWBODY -f $(obj)/amdfw.rom.body --fill-upward endif +# +# Extracts everything from the ELF's first PT_LOAD area and compresses it. +# This discards everything before PT_LOAD, every symbol, debug information +# and relocations. The generated binary is expected to run at PSP_BIOSBIN_DEST +# with a maximum size of PSP_BIOSBIN_SIZE. The entrypoint is fixed at +# PSP_BIOSBIN_DEST + PSP_BIOSBIN_SIZE - 0x10. +# $(PSP_BIOSBIN_FILE): $(PSP_ELF_FILE) $(AMDCOMPRESS) rm -f $@ @printf " AMDCOMPRS $(subst $(obj)/,,$(@))\n" diff --git a/src/soc/amd/picasso/Makefile.mk b/src/soc/amd/picasso/Makefile.mk index 0b574db845..3f4395478b 100644 --- a/src/soc/amd/picasso/Makefile.mk +++ b/src/soc/amd/picasso/Makefile.mk @@ -238,6 +238,13 @@ $(obj)/amdfw.rom: $(call strip_quotes, $(PSP_BIOSBIN_FILE)) \ --location $(CONFIG_AMD_FWM_POSITION) \ --output $@ +# +# Extracts everything from the ELF's first PT_LOAD area and compresses it. +# This discards everything before PT_LOAD, every symbol, debug information +# and relocations. The generated binary is expected to run at PSP_BIOSBIN_DEST +# with a maximum size of PSP_BIOSBIN_SIZE. The entrypoint is fixed at +# PSP_BIOSBIN_DEST + PSP_BIOSBIN_SIZE - 0x10. +# $(PSP_BIOSBIN_FILE): $(PSP_ELF_FILE) $(AMDCOMPRESS) rm -f $@ @printf " AMDCOMPRS $(subst $(obj)/,,$(@))\n"