1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <amdblocks/reset.h>
4 #include <console/cbmem_console.h>
5 #include <console/console.h>
6 #include <pc80/mc146818rtc.h>
7 #include <psp_verstage/psp_transfer.h>
8 #include <security/vboot/vbnv.h>
9 #include <security/vboot/symbols.h>
12 DECLARE_REGION(cbmemc_transfer
)
14 int transfer_buffer_valid(const struct transfer_info_struct
*ptr
)
16 if (ptr
->magic_val
== TRANSFER_MAGIC_VAL
&& ptr
->struct_bytes
== sizeof(*ptr
))
22 void verify_psp_transfer_buf(void)
24 if (*(uint32_t *)_vboot2_work
== VB2_SHARED_DATA_MAGIC
) {
25 cmos_write(0x00, CMOS_RECOVERY_BYTE
);
30 * If CMOS is valid and the system has already been rebooted once, but
31 * still returns here, instead of rebooting to verstage again, assume
32 * that the system is in a reboot loop and halt.
34 if ((!vbnv_cmos_failed()) && cmos_read(CMOS_RECOVERY_BYTE
) ==
35 CMOS_RECOVERY_MAGIC_VAL
)
36 die("Error: Reboot into recovery was unsuccessful. Halting.");
38 printk(BIOS_ERR
, "VBOOT workbuf not valid.\n");
39 printk(BIOS_DEBUG
, "Signature: %#08x\n", *(uint32_t *)_vboot2_work
);
41 cmos_write(CMOS_RECOVERY_MAGIC_VAL
, CMOS_RECOVERY_BYTE
);
45 void show_psp_transfer_info(void)
47 struct transfer_info_struct
*info
= (struct transfer_info_struct
*)
48 (void *)(uintptr_t)_transfer_buffer
;
50 if (transfer_buffer_valid(info
)) {
51 if ((info
->psp_info
& PSP_INFO_VALID
) == 0) {
52 printk(BIOS_INFO
, "No PSP info found in transfer buffer.\n");
56 printk(BIOS_INFO
, "PSP boot mode: %s\n",
57 info
->psp_info
& PSP_INFO_PRODUCTION_MODE
?
58 "Production" : "Development");
62 void replay_transfer_buffer_cbmemc(void)
64 const struct transfer_info_struct
*info
= (const struct transfer_info_struct
*)
65 (void *)(uintptr_t)_transfer_buffer
;
70 if (!transfer_buffer_valid(info
))
73 if (info
->console_offset
< sizeof(*info
))
76 if (info
->timestamp_offset
<= info
->console_offset
)
79 cbmemc_size
= info
->timestamp_offset
- info
->console_offset
;
81 if (info
->console_offset
+ cbmemc_size
> info
->buffer_size
)
84 cbmemc
= (void *)((uintptr_t)info
+ info
->console_offset
);
86 /* Verify the cbmemc transfer buffer is where we expect it to be. */
87 if ((void *)_cbmemc_transfer
!= (void *)cbmemc
)
90 if (REGION_SIZE(cbmemc_transfer
) != cbmemc_size
)
93 /* We need to manually initialize cbmemc so we can fill the new buffer. cbmemc_init()
94 * will also be called later in console_hw_init(), but it will be a no-op. */
96 cbmemc_copy_in(cbmemc
, cbmemc_size
);