diff options
author | Raul E Rangel <rrangel@chromium.org> | 2022-02-24 12:36:38 -0700 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2022-03-02 21:11:32 +0000 |
commit | fe1418db3dbb4e513dbda269665d38f054098ab7 (patch) | |
tree | 631da381139fef57277cc5121168315e2835648d /src/soc/amd | |
parent | 409e5cb0f6c4c2374d88713deec8e39a1ce776f4 (diff) |
soc/amd/common/vboot: Split transfer buffer methods into separate file
I want to reuse the transfer buffer methods in SMM, so I need to add
them into their own file. I renamed `setup_cbmem_console` to
`replay_transfer_buffer_cbmemc` so it has a more descriptive name. I
also fixed the comment on `verify_psp_transfer_buf`.
BUG=b:221231786
TEST=Boot guybrush to OS
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Change-Id: I4f3a8b414b91f601c3a9c3dc7af8f388286fe4da
Reviewed-on: https://review.coreboot.org/c/coreboot/+/62348
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Diffstat (limited to 'src/soc/amd')
-rw-r--r-- | src/soc/amd/cezanne/include/soc/psp_transfer.h | 4 | ||||
-rw-r--r-- | src/soc/amd/common/vboot/Makefile.inc | 1 | ||||
-rw-r--r-- | src/soc/amd/common/vboot/transfer_buffer.c | 87 | ||||
-rw-r--r-- | src/soc/amd/common/vboot/vboot_bootblock.c | 85 | ||||
-rw-r--r-- | src/soc/amd/picasso/include/soc/psp_transfer.h | 4 | ||||
-rw-r--r-- | src/soc/amd/sabrina/include/soc/psp_transfer.h | 4 |
6 files changed, 102 insertions, 83 deletions
diff --git a/src/soc/amd/cezanne/include/soc/psp_transfer.h b/src/soc/amd/cezanne/include/soc/psp_transfer.h index 96cdae192f..afa6a58a3c 100644 --- a/src/soc/amd/cezanne/include/soc/psp_transfer.h +++ b/src/soc/amd/cezanne/include/soc/psp_transfer.h @@ -48,9 +48,13 @@ _Static_assert(sizeof(struct transfer_info_struct) == TRANSFER_INFO_SIZE, "TRANSFER_INFO_SIZE is incorrect"); /* Make sure the PSP transferred information over to x86 side. */ +int transfer_buffer_valid(const struct transfer_info_struct *ptr); +/* Verify vboot work buffer is valid in transfer buffer */ void verify_psp_transfer_buf(void); /* Display the transfer block's PSP_info data */ void show_psp_transfer_info(void); +/* Replays the pre-x86 cbmem console into the x86 cbmem console */ +void replay_transfer_buffer_cbmemc(const struct transfer_info_struct *info); /* Called by bootblock_c_entry in the VBOOT_STARTS_BEFORE_BOOTBLOCK case */ void boot_with_psp_timestamp(uint64_t base_timestamp); diff --git a/src/soc/amd/common/vboot/Makefile.inc b/src/soc/amd/common/vboot/Makefile.inc index 8a6f1162f8..6938d16e69 100644 --- a/src/soc/amd/common/vboot/Makefile.inc +++ b/src/soc/amd/common/vboot/Makefile.inc @@ -6,3 +6,4 @@ ramstage-y += vbnv_cmos.c endif bootblock-$(CONFIG_VBOOT_STARTS_BEFORE_BOOTBLOCK) += vboot_bootblock.c +bootblock-$(CONFIG_VBOOT_STARTS_BEFORE_BOOTBLOCK) += transfer_buffer.c diff --git a/src/soc/amd/common/vboot/transfer_buffer.c b/src/soc/amd/common/vboot/transfer_buffer.c new file mode 100644 index 0000000000..06e564a2f3 --- /dev/null +++ b/src/soc/amd/common/vboot/transfer_buffer.c @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <amdblocks/reset.h> +#include <console/cbmem_console.h> +#include <console/console.h> +#include <pc80/mc146818rtc.h> +#include <security/vboot/vbnv.h> +#include <security/vboot/symbols.h> +#include <soc/psp_transfer.h> +#include <timestamp.h> +#include <2struct.h> + +int transfer_buffer_valid(const struct transfer_info_struct *ptr) +{ + if (ptr->magic_val == TRANSFER_MAGIC_VAL && ptr->struct_bytes == sizeof(*ptr)) + return 1; + else + return 0; +} + +void verify_psp_transfer_buf(void) +{ + if (*(uint32_t *)_vboot2_work == VB2_SHARED_DATA_MAGIC) { + cmos_write(0x00, CMOS_RECOVERY_BYTE); + return; + } + + /* + * If CMOS is valid and the system has already been rebooted once, but + * still returns here, instead of rebooting to verstage again, assume + * that the system is in a reboot loop and halt. + */ + if ((!vbnv_cmos_failed()) && cmos_read(CMOS_RECOVERY_BYTE) == + CMOS_RECOVERY_MAGIC_VAL) + die("Error: Reboot into recovery was unsuccessful. Halting."); + + printk(BIOS_ERR, "VBOOT workbuf not valid.\n"); + printk(BIOS_DEBUG, "Signature: %#08x\n", *(uint32_t *)_vboot2_work); + cmos_init(0); + cmos_write(CMOS_RECOVERY_MAGIC_VAL, CMOS_RECOVERY_BYTE); + warm_reset(); +} + +void show_psp_transfer_info(void) +{ + struct transfer_info_struct *info = (struct transfer_info_struct *) + (void *)(uintptr_t)_transfer_buffer; + + if (transfer_buffer_valid(info)) { + if ((info->psp_info & PSP_INFO_VALID) == 0) { + printk(BIOS_INFO, "No PSP info found in transfer buffer.\n"); + return; + } + + printk(BIOS_INFO, "PSP boot mode: %s\n", + info->psp_info & PSP_INFO_PRODUCTION_MODE ? + "Production" : "Development"); + printk(BIOS_INFO, "Silicon level: %s\n", + info->psp_info & PSP_INFO_PRODUCTION_SILICON ? + "Production" : "Pre-Production"); + } +} + +void replay_transfer_buffer_cbmemc(const struct transfer_info_struct *info) +{ + + void *cbmemc; + size_t cbmemc_size; + + if (info->console_offset < sizeof(*info)) + return; + + if (info->timestamp_offset <= info->console_offset) + return; + + cbmemc_size = info->timestamp_offset - info->console_offset; + + if (info->console_offset + cbmemc_size > info->buffer_size) + return; + + cbmemc = (void *)((uintptr_t)info + info->console_offset); + + /* We need to manually initialize cbmemc so we can fill the new buffer. cbmemc_init() + * will also be called later in console_hw_init(), but it will be a no-op. */ + cbmemc_init(); + cbmemc_copy_in(cbmemc, cbmemc_size); +} diff --git a/src/soc/amd/common/vboot/vboot_bootblock.c b/src/soc/amd/common/vboot/vboot_bootblock.c index e3705d1d6a..72648368e4 100644 --- a/src/soc/amd/common/vboot/vboot_bootblock.c +++ b/src/soc/amd/common/vboot/vboot_bootblock.c @@ -1,91 +1,10 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include <amdblocks/reset.h> #include <bootblock_common.h> -#include <console/cbmem_console.h> #include <console/console.h> -#include <pc80/mc146818rtc.h> -#include <security/vboot/vbnv.h> -#include <security/vboot/symbols.h> #include <soc/psp_transfer.h> +#include <symbols.h> #include <timestamp.h> -#include <2struct.h> - -static int transfer_buffer_valid(const struct transfer_info_struct *ptr) -{ - if (ptr->magic_val == TRANSFER_MAGIC_VAL && ptr->struct_bytes == sizeof(*ptr)) - return 1; - else - return 0; -} - -void verify_psp_transfer_buf(void) -{ - if (*(uint32_t *)_vboot2_work == VB2_SHARED_DATA_MAGIC) { - cmos_write(0x00, CMOS_RECOVERY_BYTE); - return; - } - - /* - * If CMOS is valid and the system has already been rebooted once, but - * still returns here, instead of rebooting to verstage again, assume - * that the system is in a reboot loop and halt. - */ - if ((!vbnv_cmos_failed()) && cmos_read(CMOS_RECOVERY_BYTE) == - CMOS_RECOVERY_MAGIC_VAL) - die("Error: Reboot into recovery was unsuccessful. Halting."); - - printk(BIOS_ERR, "VBOOT workbuf not valid.\n"); - printk(BIOS_DEBUG, "Signature: %#08x\n", *(uint32_t *)_vboot2_work); - cmos_init(0); - cmos_write(CMOS_RECOVERY_MAGIC_VAL, CMOS_RECOVERY_BYTE); - warm_reset(); -} - -void show_psp_transfer_info(void) -{ - struct transfer_info_struct *info = (struct transfer_info_struct *) - (void *)(uintptr_t)_transfer_buffer; - - if (transfer_buffer_valid(info)) { - if ((info->psp_info & PSP_INFO_VALID) == 0) { - printk(BIOS_INFO, "No PSP info found in transfer buffer.\n"); - return; - } - - printk(BIOS_INFO, "PSP boot mode: %s\n", - info->psp_info & PSP_INFO_PRODUCTION_MODE ? - "Production" : "Development"); - printk(BIOS_INFO, "Silicon level: %s\n", - info->psp_info & PSP_INFO_PRODUCTION_SILICON ? - "Production" : "Pre-Production"); - } -} - -static void setup_cbmem_console(const struct transfer_info_struct *info) -{ - - void *cbmemc; - size_t cbmemc_size; - - if (info->console_offset < sizeof(*info)) - return; - - if (info->timestamp_offset <= info->console_offset) - return; - - cbmemc_size = info->timestamp_offset - info->console_offset; - - if (info->console_offset + cbmemc_size > info->buffer_size) - return; - - cbmemc = (void *)((uintptr_t)info + info->console_offset); - - /* We need to manually initialize cbmemc so we can fill the new buffer. cbmemc_init() - * will also be called later in console_hw_init(), but it will be a no-op. */ - cbmemc_init(); - cbmemc_copy_in(cbmemc, cbmemc_size); -} void boot_with_psp_timestamp(uint64_t base_timestamp) { @@ -95,7 +14,7 @@ void boot_with_psp_timestamp(uint64_t base_timestamp) if (!transfer_buffer_valid(info) || info->timestamp == 0) return; - setup_cbmem_console(info); + replay_transfer_buffer_cbmemc(info); /* * info->timestamp is PSP's timestamp (in microseconds) diff --git a/src/soc/amd/picasso/include/soc/psp_transfer.h b/src/soc/amd/picasso/include/soc/psp_transfer.h index b5dffe7b39..6b10ad27ed 100644 --- a/src/soc/amd/picasso/include/soc/psp_transfer.h +++ b/src/soc/amd/picasso/include/soc/psp_transfer.h @@ -48,9 +48,13 @@ _Static_assert(sizeof(struct transfer_info_struct) == TRANSFER_INFO_SIZE, "TRANSFER_INFO_SIZE is incorrect"); /* Make sure the PSP transferred information over to x86 side. */ +int transfer_buffer_valid(const struct transfer_info_struct *ptr); +/* Verify vboot work buffer is valid in transfer buffer */ void verify_psp_transfer_buf(void); /* Display the transfer block's PSP_info data */ void show_psp_transfer_info(void); +/* Replays the pre-x86 cbmem console into the x86 cbmem console */ +void replay_transfer_buffer_cbmemc(const struct transfer_info_struct *info); /* Called by bootblock_c_entry in the VBOOT_STARTS_BEFORE_BOOTBLOCK case */ void boot_with_psp_timestamp(uint64_t base_timestamp); diff --git a/src/soc/amd/sabrina/include/soc/psp_transfer.h b/src/soc/amd/sabrina/include/soc/psp_transfer.h index 60555991ca..0fe204d2d3 100644 --- a/src/soc/amd/sabrina/include/soc/psp_transfer.h +++ b/src/soc/amd/sabrina/include/soc/psp_transfer.h @@ -50,9 +50,13 @@ _Static_assert(sizeof(struct transfer_info_struct) == TRANSFER_INFO_SIZE, "TRANSFER_INFO_SIZE is incorrect"); /* Make sure the PSP transferred information over to x86 side. */ +int transfer_buffer_valid(const struct transfer_info_struct *ptr); +/* Verify vboot work buffer is valid in transfer buffer */ void verify_psp_transfer_buf(void); /* Display the transfer block's PSP_info data */ void show_psp_transfer_info(void); +/* Replays the pre-x86 cbmem console into the x86 cbmem console */ +void replay_transfer_buffer_cbmemc(const struct transfer_info_struct *info); /* Called by bootblock_c_entry in the VBOOT_STARTS_BEFORE_BOOTBLOCK case */ void boot_with_psp_timestamp(uint64_t base_timestamp); |