blob: a9644d3a0892b5a172d535c231d871774536d6a0 [file] [log] [blame]
Raul E Rangelfe1418d2022-02-24 12:36:38 -07001/* 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 Roth8fc68812023-08-18 16:28:29 -06007#include <psp_verstage/psp_transfer.h>
Raul E Rangelfe1418d2022-02-24 12:36:38 -07008#include <security/vboot/vbnv.h>
9#include <security/vboot/symbols.h>
Raul E Rangelfe1418d2022-02-24 12:36:38 -070010#include <timestamp.h>
11#include <2struct.h>
12
Raul E Rangelbd58aea2022-02-28 12:43:02 -070013DECLARE_REGION(cbmemc_transfer)
14
Raul E Rangelfe1418d2022-02-24 12:36:38 -070015int 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
23void 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
46void 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");
60 printk(BIOS_INFO, "Silicon level: %s\n",
61 info->psp_info & PSP_INFO_PRODUCTION_SILICON ?
62 "Production" : "Pre-Production");
63 }
64}
65
Raul E Rangel08de3e32022-02-25 17:10:09 -070066void replay_transfer_buffer_cbmemc(void)
Raul E Rangelfe1418d2022-02-24 12:36:38 -070067{
Raul E Rangel08de3e32022-02-25 17:10:09 -070068 const struct transfer_info_struct *info = (const struct transfer_info_struct *)
69 (void *)(uintptr_t)_transfer_buffer;
Raul E Rangelfe1418d2022-02-24 12:36:38 -070070
71 void *cbmemc;
72 size_t cbmemc_size;
73
Raul E Rangel08de3e32022-02-25 17:10:09 -070074 if (!transfer_buffer_valid(info))
75 return;
76
Raul E Rangelfe1418d2022-02-24 12:36:38 -070077 if (info->console_offset < sizeof(*info))
78 return;
79
80 if (info->timestamp_offset <= info->console_offset)
81 return;
82
83 cbmemc_size = info->timestamp_offset - info->console_offset;
84
85 if (info->console_offset + cbmemc_size > info->buffer_size)
86 return;
87
88 cbmemc = (void *)((uintptr_t)info + info->console_offset);
89
Raul E Rangelbd58aea2022-02-28 12:43:02 -070090 /* Verify the cbmemc transfer buffer is where we expect it to be. */
91 if ((void *)_cbmemc_transfer != (void *)cbmemc)
92 return;
93
94 if (REGION_SIZE(cbmemc_transfer) != cbmemc_size)
95 return;
96
Raul E Rangelfe1418d2022-02-24 12:36:38 -070097 /* We need to manually initialize cbmemc so we can fill the new buffer. cbmemc_init()
98 * will also be called later in console_hw_init(), but it will be a no-op. */
99 cbmemc_init();
100 cbmemc_copy_in(cbmemc, cbmemc_size);
101}