Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <amdblocks/reset.h> |
| 4 | #include <console/cbmem_console.h> |
| 5 | #include <console/console.h> |
| 6 | #include <pc80/mc146818rtc.h> |
Martin Roth | 8fc6881 | 2023-08-18 16:28:29 -0600 | [diff] [blame] | 7 | #include <psp_verstage/psp_transfer.h> |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 8 | #include <security/vboot/vbnv.h> |
| 9 | #include <security/vboot/symbols.h> |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 10 | #include <timestamp.h> |
| 11 | #include <2struct.h> |
| 12 | |
Raul E Rangel | bd58aea | 2022-02-28 12:43:02 -0700 | [diff] [blame] | 13 | DECLARE_REGION(cbmemc_transfer) |
| 14 | |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 15 | int transfer_buffer_valid(const struct transfer_info_struct *ptr) |
| 16 | { |
| 17 | if (ptr->magic_val == TRANSFER_MAGIC_VAL && ptr->struct_bytes == sizeof(*ptr)) |
| 18 | return 1; |
| 19 | else |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | void verify_psp_transfer_buf(void) |
| 24 | { |
| 25 | if (*(uint32_t *)_vboot2_work == VB2_SHARED_DATA_MAGIC) { |
| 26 | cmos_write(0x00, CMOS_RECOVERY_BYTE); |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | /* |
| 31 | * If CMOS is valid and the system has already been rebooted once, but |
| 32 | * still returns here, instead of rebooting to verstage again, assume |
| 33 | * that the system is in a reboot loop and halt. |
| 34 | */ |
| 35 | if ((!vbnv_cmos_failed()) && cmos_read(CMOS_RECOVERY_BYTE) == |
| 36 | CMOS_RECOVERY_MAGIC_VAL) |
| 37 | die("Error: Reboot into recovery was unsuccessful. Halting."); |
| 38 | |
| 39 | printk(BIOS_ERR, "VBOOT workbuf not valid.\n"); |
| 40 | printk(BIOS_DEBUG, "Signature: %#08x\n", *(uint32_t *)_vboot2_work); |
| 41 | cmos_init(0); |
| 42 | cmos_write(CMOS_RECOVERY_MAGIC_VAL, CMOS_RECOVERY_BYTE); |
| 43 | warm_reset(); |
| 44 | } |
| 45 | |
| 46 | void show_psp_transfer_info(void) |
| 47 | { |
| 48 | struct transfer_info_struct *info = (struct transfer_info_struct *) |
| 49 | (void *)(uintptr_t)_transfer_buffer; |
| 50 | |
| 51 | if (transfer_buffer_valid(info)) { |
| 52 | if ((info->psp_info & PSP_INFO_VALID) == 0) { |
| 53 | printk(BIOS_INFO, "No PSP info found in transfer buffer.\n"); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | printk(BIOS_INFO, "PSP boot mode: %s\n", |
| 58 | info->psp_info & PSP_INFO_PRODUCTION_MODE ? |
| 59 | "Production" : "Development"); |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
Raul E Rangel | 08de3e3 | 2022-02-25 17:10:09 -0700 | [diff] [blame] | 63 | void replay_transfer_buffer_cbmemc(void) |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 64 | { |
Raul E Rangel | 08de3e3 | 2022-02-25 17:10:09 -0700 | [diff] [blame] | 65 | const struct transfer_info_struct *info = (const struct transfer_info_struct *) |
| 66 | (void *)(uintptr_t)_transfer_buffer; |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 67 | |
| 68 | void *cbmemc; |
| 69 | size_t cbmemc_size; |
| 70 | |
Raul E Rangel | 08de3e3 | 2022-02-25 17:10:09 -0700 | [diff] [blame] | 71 | if (!transfer_buffer_valid(info)) |
| 72 | return; |
| 73 | |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 74 | if (info->console_offset < sizeof(*info)) |
| 75 | return; |
| 76 | |
| 77 | if (info->timestamp_offset <= info->console_offset) |
| 78 | return; |
| 79 | |
| 80 | cbmemc_size = info->timestamp_offset - info->console_offset; |
| 81 | |
| 82 | if (info->console_offset + cbmemc_size > info->buffer_size) |
| 83 | return; |
| 84 | |
| 85 | cbmemc = (void *)((uintptr_t)info + info->console_offset); |
| 86 | |
Raul E Rangel | bd58aea | 2022-02-28 12:43:02 -0700 | [diff] [blame] | 87 | /* Verify the cbmemc transfer buffer is where we expect it to be. */ |
| 88 | if ((void *)_cbmemc_transfer != (void *)cbmemc) |
| 89 | return; |
| 90 | |
| 91 | if (REGION_SIZE(cbmemc_transfer) != cbmemc_size) |
| 92 | return; |
| 93 | |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 94 | /* We need to manually initialize cbmemc so we can fill the new buffer. cbmemc_init() |
| 95 | * will also be called later in console_hw_init(), but it will be a no-op. */ |
| 96 | cbmemc_init(); |
| 97 | cbmemc_copy_in(cbmemc, cbmemc_size); |
| 98 | } |