Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include "psp_verstage.h" |
| 4 | |
Felix Held | 26935d1 | 2020-12-08 00:40:04 +0100 | [diff] [blame] | 5 | #include <amdblocks/acpimmio.h> |
Karthikeyan Ramasubramanian | 0822ce8 | 2022-12-05 14:54:53 -0700 | [diff] [blame] | 6 | #include <bl_uapp/bl_errorcodes_public.h> |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 7 | #include <bl_uapp/bl_syscall_public.h> |
| 8 | #include <boot_device.h> |
Martin Roth | e21698b | 2020-06-26 08:55:15 -0600 | [diff] [blame] | 9 | #include <cbfs.h> |
Karthikeyan Ramasubramanian | c2f6f35 | 2021-09-10 12:03:30 -0600 | [diff] [blame] | 10 | #include <commonlib/region.h> |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 11 | #include <console/console.h> |
Martin Roth | e21698b | 2020-06-26 08:55:15 -0600 | [diff] [blame] | 12 | #include <fmap.h> |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 13 | #include <fmap_config.h> |
Martin Roth | 50cca76 | 2020-08-13 11:06:18 -0600 | [diff] [blame] | 14 | #include <pc80/mc146818rtc.h> |
Martin Roth | 8fc6881 | 2023-08-18 16:28:29 -0600 | [diff] [blame] | 15 | #include <psp_verstage/psp_transfer.h> |
Kangheui Won | fab6e44 | 2021-10-18 15:35:28 +1100 | [diff] [blame] | 16 | #include <soc/iomap.h> |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 17 | #include <security/tpm/tspi.h> |
| 18 | #include <security/tpm/tss.h> |
Martin Roth | 50cca76 | 2020-08-13 11:06:18 -0600 | [diff] [blame] | 19 | #include <security/vboot/vbnv.h> |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 20 | #include <security/vboot/misc.h> |
| 21 | #include <security/vboot/symbols.h> |
| 22 | #include <security/vboot/vboot_common.h> |
| 23 | #include <arch/stages.h> |
| 24 | #include <stdarg.h> |
| 25 | #include <stdio.h> |
Kangheui Won | 4e2f5fd | 2020-09-17 16:37:13 +1000 | [diff] [blame] | 26 | #include <timestamp.h> |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 27 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 28 | extern char _bss_start, _bss_end; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 29 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 30 | void __weak verstage_mainboard_init(void) {} |
Rob Barnes | 188be6b | 2021-11-09 13:21:28 -0700 | [diff] [blame] | 31 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 32 | static void reboot_into_recovery(struct vb2_context *ctx, uint32_t subcode) |
| 33 | { |
| 34 | subcode += PSP_VBOOT_ERROR_SUBCODE; |
| 35 | svc_write_postcode(subcode); |
| 36 | |
Martin Roth | c9689e0 | 2020-08-20 17:25:37 -0600 | [diff] [blame] | 37 | /* |
| 38 | * If there's an error but the PSP_verstage is already booting to RO, |
| 39 | * don't reset the system. It may be that the error is fatal, but if |
| 40 | * the system is stuck, don't intentionally force it into a reboot loop. |
| 41 | */ |
| 42 | if (ctx->flags & VB2_CONTEXT_RECOVERY_MODE) { |
| 43 | printk(BIOS_ERR, "Already in recovery mode. Staying in RO.\n"); |
| 44 | return; |
| 45 | } |
| 46 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 47 | svc_debug_print("Rebooting into recovery\n"); |
Jakub Czapiga | 605f793 | 2022-11-04 12:18:04 +0000 | [diff] [blame] | 48 | vboot_fail_and_reboot(ctx, VB2_RECOVERY_RO_UNSPECIFIED, (int)subcode); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 49 | } |
| 50 | |
Martin Roth | 50cca76 | 2020-08-13 11:06:18 -0600 | [diff] [blame] | 51 | static uint32_t check_cmos_recovery(void) |
| 52 | { |
| 53 | /* Only reset if cmos is valid */ |
| 54 | if (vbnv_cmos_failed()) |
| 55 | return 0; |
| 56 | |
| 57 | /* If the byte is set, clear it, then return error to reboot */ |
| 58 | if (cmos_read(CMOS_RECOVERY_BYTE) == CMOS_RECOVERY_MAGIC_VAL) { |
| 59 | cmos_write(0x00, CMOS_RECOVERY_BYTE); |
| 60 | printk(BIOS_DEBUG, "Reboot into recovery requested by coreboot\n"); |
| 61 | return POSTCODE_CMOS_RECOVERY; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 67 | /* |
| 68 | * Tell the PSP where to load the rest of the firmware from |
| 69 | */ |
| 70 | static uint32_t update_boot_region(struct vb2_context *ctx) |
| 71 | { |
Kangheui Won | 26bb4aa | 2021-10-18 15:31:45 +1100 | [diff] [blame] | 72 | struct embedded_firmware *ef_table; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 73 | uint32_t psp_dir_addr, bios_dir_addr; |
| 74 | uint32_t *psp_dir_in_spi, *bios_dir_in_spi; |
Kangheui Won | ac7ec27 | 2021-01-15 15:04:25 +1100 | [diff] [blame] | 75 | const char *fname; |
| 76 | void *amdfw_location; |
Karthikeyan Ramasubramanian | 1da0340 | 2023-05-25 15:49:29 -0600 | [diff] [blame] | 77 | struct region fw_slot; |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 78 | void *map_base = NULL; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 79 | |
| 80 | /* Continue booting from RO */ |
| 81 | if (ctx->flags & VB2_CONTEXT_RECOVERY_MODE) { |
| 82 | printk(BIOS_ERR, "In recovery mode. Staying in RO.\n"); |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | if (vboot_is_firmware_slot_a(ctx)) { |
Martin Roth | e21698b | 2020-06-26 08:55:15 -0600 | [diff] [blame] | 87 | fname = "apu/amdfw_a"; |
Karthikeyan Ramasubramanian | 1da0340 | 2023-05-25 15:49:29 -0600 | [diff] [blame] | 88 | if (!fmap_locate_area("FW_MAIN_A", &fw_slot)) |
| 89 | map_base = rdev_mmap(boot_device_ro(), fw_slot.offset, fw_slot.size); |
| 90 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 91 | } else { |
Martin Roth | e21698b | 2020-06-26 08:55:15 -0600 | [diff] [blame] | 92 | fname = "apu/amdfw_b"; |
Karthikeyan Ramasubramanian | 1da0340 | 2023-05-25 15:49:29 -0600 | [diff] [blame] | 93 | if (!fmap_locate_area("FW_MAIN_B", &fw_slot)) |
| 94 | map_base = rdev_mmap(boot_device_ro(), fw_slot.offset, fw_slot.size); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | if (!map_base) { |
| 98 | printk(BIOS_ERR, "Failed to map RW FW_MAIN section.\n"); |
| 99 | return POSTCODE_MAP_SPI_ROM_FAILED; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 100 | } |
| 101 | |
Kangheui Won | ac7ec27 | 2021-01-15 15:04:25 +1100 | [diff] [blame] | 102 | amdfw_location = cbfs_map(fname, NULL); |
Martin Roth | e21698b | 2020-06-26 08:55:15 -0600 | [diff] [blame] | 103 | if (!amdfw_location) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 104 | printk(BIOS_ERR, "AMD Firmware table not found.\n"); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 105 | rdev_munmap(boot_device_ro(), map_base); |
Martin Roth | e21698b | 2020-06-26 08:55:15 -0600 | [diff] [blame] | 106 | return POSTCODE_AMD_FW_MISSING; |
| 107 | } |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 108 | |
Kangheui Won | 26bb4aa | 2021-10-18 15:31:45 +1100 | [diff] [blame] | 109 | ef_table = (struct embedded_firmware *)amdfw_location; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 110 | if (ef_table->signature != EMBEDDED_FW_SIGNATURE) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 111 | printk(BIOS_ERR, "ROMSIG address is not correct.\n"); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 112 | cbfs_unmap(amdfw_location); |
Karthikeyan Ramasubramanian | 01c9dfb | 2023-05-25 15:54:33 -0600 | [diff] [blame] | 113 | rdev_munmap(boot_device_ro(), amdfw_location); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 114 | rdev_munmap(boot_device_ro(), map_base); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 115 | return POSTCODE_ROMSIG_MISMATCH_ERROR; |
| 116 | } |
| 117 | |
Felix Held | 4bdea41 | 2023-02-17 00:31:43 +0100 | [diff] [blame] | 118 | psp_dir_addr = ef_table->new_psp_directory; |
Kangheui Won | 5858fb4 | 2021-05-06 13:30:51 +1000 | [diff] [blame] | 119 | bios_dir_addr = get_bios_dir_addr(ef_table); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 120 | psp_dir_in_spi = (uint32_t *)((psp_dir_addr & SPI_ADDR_MASK) + |
Karthikeyan Ramasubramanian | 1da0340 | 2023-05-25 15:49:29 -0600 | [diff] [blame] | 121 | (uint32_t)map_base - fw_slot.offset); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 122 | if (*psp_dir_in_spi != PSP_COOKIE) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 123 | printk(BIOS_ERR, "PSP Directory address is not correct.\n"); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 124 | cbfs_unmap(amdfw_location); |
Karthikeyan Ramasubramanian | 01c9dfb | 2023-05-25 15:54:33 -0600 | [diff] [blame] | 125 | rdev_munmap(boot_device_ro(), amdfw_location); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 126 | rdev_munmap(boot_device_ro(), map_base); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 127 | return POSTCODE_PSP_COOKIE_MISMATCH_ERROR; |
| 128 | } |
Karthikeyan Ramasubramanian | e3eedf7 | 2022-07-14 15:37:07 -0600 | [diff] [blame] | 129 | |
| 130 | if (bios_dir_addr) { |
| 131 | bios_dir_in_spi = (uint32_t *)((bios_dir_addr & SPI_ADDR_MASK) + |
Karthikeyan Ramasubramanian | 1da0340 | 2023-05-25 15:49:29 -0600 | [diff] [blame] | 132 | (uint32_t)map_base - fw_slot.offset); |
Karthikeyan Ramasubramanian | e3eedf7 | 2022-07-14 15:37:07 -0600 | [diff] [blame] | 133 | if (*bios_dir_in_spi != BHD_COOKIE) { |
| 134 | printk(BIOS_ERR, "BIOS Directory address is not correct.\n"); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 135 | cbfs_unmap(amdfw_location); |
Karthikeyan Ramasubramanian | 01c9dfb | 2023-05-25 15:54:33 -0600 | [diff] [blame] | 136 | rdev_munmap(boot_device_ro(), amdfw_location); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 137 | rdev_munmap(boot_device_ro(), map_base); |
Karthikeyan Ramasubramanian | e3eedf7 | 2022-07-14 15:37:07 -0600 | [diff] [blame] | 138 | return POSTCODE_BHD_COOKIE_MISMATCH_ERROR; |
| 139 | } |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 140 | } |
| 141 | |
Kangheui Won | fab6e44 | 2021-10-18 15:35:28 +1100 | [diff] [blame] | 142 | /* EFS2 uses relative address and PSP isn't happy with that */ |
Karthikeyan Ramasubramanian | e3eedf7 | 2022-07-14 15:37:07 -0600 | [diff] [blame] | 143 | if (ef_table->efs_gen.gen == EFS_SECOND_GEN && |
| 144 | !CONFIG(PSP_SUPPORTS_EFS2_RELATIVE_ADDR)) { |
Kangheui Won | fab6e44 | 2021-10-18 15:35:28 +1100 | [diff] [blame] | 145 | psp_dir_addr = FLASH_BASE_ADDR + (psp_dir_addr & SPI_ADDR_MASK); |
| 146 | bios_dir_addr = FLASH_BASE_ADDR + (bios_dir_addr & SPI_ADDR_MASK); |
| 147 | } |
| 148 | |
Kangheui Won | 26bb4aa | 2021-10-18 15:31:45 +1100 | [diff] [blame] | 149 | if (update_psp_bios_dir(&psp_dir_addr, &bios_dir_addr)) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 150 | printk(BIOS_ERR, "Updated BIOS Directory could not be set.\n"); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 151 | cbfs_unmap(amdfw_location); |
Karthikeyan Ramasubramanian | 01c9dfb | 2023-05-25 15:54:33 -0600 | [diff] [blame] | 152 | rdev_munmap(boot_device_ro(), amdfw_location); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 153 | rdev_munmap(boot_device_ro(), map_base); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 154 | return POSTCODE_UPDATE_PSP_BIOS_DIR_ERROR; |
| 155 | } |
| 156 | |
Kangheui Won | 5fb435a | 2021-12-22 12:24:17 +1100 | [diff] [blame] | 157 | if (CONFIG(SEPARATE_SIGNED_PSPFW)) |
Karthikeyan Ramasubramanian | 97e57cf | 2023-07-17 12:43:14 -0600 | [diff] [blame] | 158 | update_psp_fw_hash_tables(); |
Kangheui Won | 5fb435a | 2021-12-22 12:24:17 +1100 | [diff] [blame] | 159 | |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 160 | cbfs_unmap(amdfw_location); |
Karthikeyan Ramasubramanian | 01c9dfb | 2023-05-25 15:54:33 -0600 | [diff] [blame] | 161 | rdev_munmap(boot_device_ro(), amdfw_location); |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 162 | rdev_munmap(boot_device_ro(), map_base); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * Save workbuf (and soon memory console and timestamps) to the bootloader to pass |
| 168 | * back to coreboot. |
| 169 | */ |
Raul E Rangel | 5e0ed50 | 2022-02-24 10:58:29 -0700 | [diff] [blame] | 170 | static uint32_t save_buffers(void) |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 171 | { |
| 172 | uint32_t retval; |
Raul E Rangel | 5e0ed50 | 2022-02-24 10:58:29 -0700 | [diff] [blame] | 173 | uint32_t buffer_size; |
Martin Roth | 0c12abe | 2020-06-26 08:40:56 -0600 | [diff] [blame] | 174 | struct transfer_info_struct buffer_info = {0}; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 175 | |
Raul E Rangel | 5e0ed50 | 2022-02-24 10:58:29 -0700 | [diff] [blame] | 176 | buffer_size = |
| 177 | (uint32_t)((uintptr_t)_etransfer_buffer - (uintptr_t)_transfer_buffer); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 178 | |
Raul E Rangel | 5e0ed50 | 2022-02-24 10:58:29 -0700 | [diff] [blame] | 179 | buffer_info.console_offset = (uint32_t)((uintptr_t)_preram_cbmem_console - |
| 180 | (uintptr_t)_transfer_buffer); |
| 181 | buffer_info.timestamp_offset = (uint32_t)((uintptr_t)_timestamp - |
| 182 | (uintptr_t)_transfer_buffer); |
| 183 | buffer_info.fmap_offset = (uint32_t)((uintptr_t)_fmap_cache - |
| 184 | (uintptr_t)_transfer_buffer); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 185 | |
Martin Roth | 0c12abe | 2020-06-26 08:40:56 -0600 | [diff] [blame] | 186 | buffer_info.magic_val = TRANSFER_MAGIC_VAL; |
| 187 | buffer_info.struct_bytes = sizeof(buffer_info); |
| 188 | buffer_info.buffer_size = buffer_size; |
| 189 | buffer_info.workbuf_offset = (uint32_t)((uintptr_t)_fmap_cache - |
| 190 | (uintptr_t)_vboot2_work); |
| 191 | |
Kangheui Won | 5f027fa | 2020-08-25 18:12:19 +1000 | [diff] [blame] | 192 | memcpy(_transfer_buffer, &buffer_info, sizeof(buffer_info)); |
| 193 | |
Kangheui Won | a767eb4 | 2021-04-14 09:35:28 +1000 | [diff] [blame] | 194 | retval = save_uapp_data((void *)_transfer_buffer, buffer_size); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 195 | if (retval) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 196 | printk(BIOS_ERR, "Could not save workbuf. Error code 0x%08x\n", retval); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 197 | return POSTCODE_WORKBUF_SAVE_ERROR; |
| 198 | } |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 203 | /* |
| 204 | * S0i3 resume in PSP verstage is a special case. The FSDL is restoring mostly |
| 205 | * everything, so do the minimum necessary here. Unlike normal boot, subsequent |
| 206 | * coreboot stages are not run after s0i3 verstage. |
| 207 | * If the TPM is reset in S0i3, it must be re-initialized here. |
| 208 | */ |
| 209 | static void psp_verstage_s0i3_resume(void) |
| 210 | { |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 211 | tpm_result_t rc; |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 212 | |
| 213 | post_code(POSTCODE_VERSTAGE_S0I3_RESUME); |
| 214 | |
| 215 | printk(BIOS_DEBUG, "Entering PSP verstage S0i3 resume\n"); |
| 216 | |
| 217 | if (!CONFIG(PSP_INIT_TPM_ON_S0I3_RESUME)) |
| 218 | return; |
| 219 | |
Jon Murphy | 2460481 | 2023-09-05 10:37:05 -0600 | [diff] [blame] | 220 | rc = tpm_setup(true); |
| 221 | if (rc != TPM_SUCCESS) { |
| 222 | printk(BIOS_ERR, "tpm_setup failed rc:%d\n", rc); |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 223 | reboot_into_recovery(vboot_get_context(), POSTCODE_INIT_TPM_FAILED); |
| 224 | } |
| 225 | |
Jon Murphy | 2460481 | 2023-09-05 10:37:05 -0600 | [diff] [blame] | 226 | rc = tlcl_disable_platform_hierarchy(); |
| 227 | if (rc != TPM_SUCCESS) { |
| 228 | printk(BIOS_ERR, "tlcl_disable_platform_hierarchy failed rc:%d\n", rc); |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 229 | reboot_into_recovery(vboot_get_context(), POSTCODE_INIT_TPM_FAILED); |
| 230 | } |
| 231 | } |
| 232 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 233 | void Main(void) |
| 234 | { |
| 235 | uint32_t retval; |
| 236 | struct vb2_context *ctx = NULL; |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 237 | uint32_t bootmode; |
Karthikeyan Ramasubramanian | b6ab7ba | 2023-11-20 23:34:22 +0000 | [diff] [blame^] | 238 | void *boot_dev_base; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 239 | |
| 240 | /* |
| 241 | * Do not use printk() before console_init() |
| 242 | * Do not use post_code() before verstage_mainboard_init() |
Karthikeyan Ramasubramanian | 1a24d84 | 2022-03-16 16:27:49 -0600 | [diff] [blame] | 243 | * Do not use svc_write_postcode before verstage_soc_espi_init() if PSP uses ESPI |
| 244 | * to write postcodes. |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 245 | */ |
Kangheui Won | 4e2f5fd | 2020-09-17 16:37:13 +1000 | [diff] [blame] | 246 | timestamp_init(timestamp_get()); |
Karthikeyan Ramasubramanian | 1a24d84 | 2022-03-16 16:27:49 -0600 | [diff] [blame] | 247 | if (!CONFIG(PSP_POSTCODES_ON_ESPI)) |
| 248 | svc_write_postcode(POSTCODE_ENTERED_PSP_VERSTAGE); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 249 | svc_debug_print("Entering verstage on PSP\n"); |
| 250 | memset(&_bss_start, '\0', &_bss_end - &_bss_start); |
| 251 | |
Karthikeyan Ramasubramanian | 1a24d84 | 2022-03-16 16:27:49 -0600 | [diff] [blame] | 252 | if (!CONFIG(PSP_POSTCODES_ON_ESPI)) |
| 253 | svc_write_postcode(POSTCODE_CONSOLE_INIT); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 254 | console_init(); |
| 255 | |
Karthikeyan Ramasubramanian | e5f627a | 2022-12-22 13:05:12 -0700 | [diff] [blame] | 256 | if (CONFIG(PSP_INCLUDES_HSP)) |
| 257 | report_hsp_secure_state(); |
| 258 | |
Karthikeyan Ramasubramanian | 1a24d84 | 2022-03-16 16:27:49 -0600 | [diff] [blame] | 259 | if (!CONFIG(PSP_POSTCODES_ON_ESPI)) |
| 260 | svc_write_postcode(POSTCODE_EARLY_INIT); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 261 | retval = verstage_soc_early_init(); |
| 262 | if (retval) { |
Rob Barnes | c30a1fa | 2021-11-08 06:43:07 -0700 | [diff] [blame] | 263 | /* |
| 264 | * If verstage_soc_early_init fails, cmos is probably not |
| 265 | * accessible, so rebooting into recovery is not an option. |
| 266 | * Just reboot and hope for the best. |
| 267 | */ |
| 268 | svc_write_postcode(POSTCODE_EARLY_INIT_ERROR); |
| 269 | svc_debug_print("verstage_soc_early_init failed! -- rebooting\n"); |
| 270 | vboot_reboot(); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 271 | } |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 272 | |
Rob Barnes | f6e421f | 2021-11-08 13:04:18 -0700 | [diff] [blame] | 273 | printk(BIOS_DEBUG, "calling verstage_mainboard_espi_init\n"); |
| 274 | verstage_mainboard_espi_init(); |
| 275 | |
Rob Barnes | 188be6b | 2021-11-09 13:21:28 -0700 | [diff] [blame] | 276 | printk(BIOS_DEBUG, "calling verstage_soc_espi_init\n"); |
| 277 | verstage_soc_espi_init(); |
| 278 | |
| 279 | printk(BIOS_DEBUG, "calling verstage_mainboard_tpm_init\n"); |
| 280 | /* mainboard_tpm_init may check board_id, so make sure espi is ready first */ |
| 281 | verstage_mainboard_tpm_init(); |
| 282 | |
Rob Barnes | 847a39f | 2021-11-15 12:56:34 -0700 | [diff] [blame] | 283 | printk(BIOS_DEBUG, "calling verstage_soc_aoac_init\n"); |
| 284 | verstage_soc_aoac_init(); |
| 285 | |
| 286 | printk(BIOS_DEBUG, "calling verstage_soc_i2c_init\n"); |
| 287 | verstage_soc_i2c_init(); |
| 288 | |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 289 | /* |
| 290 | * S0i3 resume in PSP verstage is a special case, handle it separately. |
| 291 | * Make sure TPM i2c is ready first. |
| 292 | */ |
| 293 | svc_get_boot_mode(&bootmode); |
| 294 | if (bootmode == PSP_BOOT_MODE_S0i3_RESUME) { |
| 295 | psp_verstage_s0i3_resume(); |
Raul E Rangel | 737ad67 | 2022-02-24 11:49:52 -0700 | [diff] [blame] | 296 | |
Raul E Rangel | 409e5cb | 2022-02-24 11:54:32 -0700 | [diff] [blame] | 297 | post_code(POSTCODE_SAVE_BUFFERS); |
| 298 | retval = save_buffers(); |
| 299 | if (retval) |
| 300 | post_code(retval); |
| 301 | |
Raul E Rangel | 737ad67 | 2022-02-24 11:49:52 -0700 | [diff] [blame] | 302 | post_code(POSTCODE_UNMAP_FCH_DEVICES); |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 303 | unmap_fch_devices(); |
Raul E Rangel | 737ad67 | 2022-02-24 11:49:52 -0700 | [diff] [blame] | 304 | |
| 305 | post_code(POSTCODE_LEAVING_VERSTAGE); |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 306 | svc_exit(0); |
| 307 | } |
| 308 | |
| 309 | printk(BIOS_DEBUG, "calling verstage_mainboard_early_init\n"); |
| 310 | verstage_mainboard_early_init(); |
| 311 | |
| 312 | svc_write_postcode(POSTCODE_LATE_INIT); |
Karthikeyan Ramasubramanian | 5eb7792 | 2023-07-21 18:05:25 -0600 | [diff] [blame] | 313 | if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPIMMIO_PM_IO_ACCESS)) |
| 314 | fch_io_enable_legacy_io(); |
Rob Barnes | b35acf9 | 2021-11-02 17:47:47 -0600 | [diff] [blame] | 315 | |
Rob Barnes | 847a39f | 2021-11-15 12:56:34 -0700 | [diff] [blame] | 316 | printk(BIOS_DEBUG, "calling verstage_soc_spi_init\n"); |
| 317 | verstage_soc_spi_init(); |
| 318 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 319 | verstage_mainboard_init(); |
| 320 | |
| 321 | post_code(POSTCODE_VERSTAGE_MAIN); |
Karthikeyan Ramasubramanian | 0822ce8 | 2022-12-05 14:54:53 -0700 | [diff] [blame] | 322 | if (CONFIG(SEPARATE_SIGNED_PSPFW)) |
| 323 | report_prev_boot_status_to_vboot(); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 324 | |
Kangheui Won | ac7ec27 | 2021-01-15 15:04:25 +1100 | [diff] [blame] | 325 | vboot_run_logic(); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 326 | |
Martin Roth | c9689e0 | 2020-08-20 17:25:37 -0600 | [diff] [blame] | 327 | ctx = vboot_get_context(); |
Martin Roth | 50cca76 | 2020-08-13 11:06:18 -0600 | [diff] [blame] | 328 | retval = check_cmos_recovery(); |
| 329 | if (retval) |
Martin Roth | c9689e0 | 2020-08-20 17:25:37 -0600 | [diff] [blame] | 330 | reboot_into_recovery(ctx, retval); |
Martin Roth | 0c12abe | 2020-06-26 08:40:56 -0600 | [diff] [blame] | 331 | |
Kangheui Won | 7e91db7 | 2022-01-25 18:55:04 +1100 | [diff] [blame] | 332 | platform_report_mode(vboot_developer_mode_enabled()); |
| 333 | |
Kangheui Won | ac7ec27 | 2021-01-15 15:04:25 +1100 | [diff] [blame] | 334 | post_code(POSTCODE_UPDATE_BOOT_REGION); |
Kangheui Won | 9752725 | 2021-05-20 10:02:00 +1000 | [diff] [blame] | 335 | |
| 336 | /* |
| 337 | * Since psp_verstage doesn't load next stage we never call |
| 338 | * any cbfs API on RO path. However we still need to initialize |
| 339 | * RO CBFS MCACHE manually to pass it in transfer_buffer. |
| 340 | * In RW path, MCACHE build will be skipped for RO region since |
| 341 | * we already built here. |
| 342 | */ |
| 343 | cbfs_get_boot_device(true); |
| 344 | |
Kangheui Won | ac7ec27 | 2021-01-15 15:04:25 +1100 | [diff] [blame] | 345 | retval = update_boot_region(ctx); |
| 346 | if (retval) |
| 347 | reboot_into_recovery(ctx, retval); |
| 348 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 349 | post_code(POSTCODE_SAVE_BUFFERS); |
Raul E Rangel | 5e0ed50 | 2022-02-24 10:58:29 -0700 | [diff] [blame] | 350 | retval = save_buffers(); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 351 | if (retval) |
Martin Roth | c9689e0 | 2020-08-20 17:25:37 -0600 | [diff] [blame] | 352 | reboot_into_recovery(ctx, retval); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 353 | |
Karthikeyan Ramasubramanian | b6ab7ba | 2023-11-20 23:34:22 +0000 | [diff] [blame^] | 354 | if (CONFIG(PSP_VERSTAGE_MAP_ENTIRE_SPIROM)) { |
| 355 | post_code(POSTCODE_UNMAP_SPI_ROM); |
| 356 | boot_dev_base = rdev_mmap_full(boot_device_ro()); |
| 357 | if (boot_dev_base) { |
| 358 | if (svc_unmap_spi_rom((void *)boot_dev_base)) |
| 359 | printk(BIOS_ERR, "Error unmapping SPI rom\n"); |
| 360 | } |
| 361 | } |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame] | 362 | assert(!boot_dev_get_active_map_count()); |
Karthikeyan Ramasubramanian | b6ab7ba | 2023-11-20 23:34:22 +0000 | [diff] [blame^] | 363 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 364 | post_code(POSTCODE_UNMAP_FCH_DEVICES); |
| 365 | unmap_fch_devices(); |
| 366 | |
| 367 | post_code(POSTCODE_LEAVING_VERSTAGE); |
| 368 | |
| 369 | printk(BIOS_DEBUG, "Leaving verstage on PSP\n"); |
| 370 | svc_exit(retval); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 371 | } |
| 372 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 373 | /* |
| 374 | * The stage_entry function is not used directly, but stage_entry() is marked as an entry |
| 375 | * point in arm/arch/header.h, so if stage_entry() isn't present and calling Main(), all |
| 376 | * the verstage code gets dropped by the linker. Slightly hacky, but mostly harmless. |
| 377 | */ |
| 378 | void stage_entry(uintptr_t stage_arg) |
| 379 | { |
| 380 | Main(); |
| 381 | } |