blob: e71d75ac3219cead788fc4f052e2ba86ea7a0000 [file] [log] [blame]
Martin Rothc7acf162020-05-28 00:44:50 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include "psp_verstage.h"
4
Felix Held26935d12020-12-08 00:40:04 +01005#include <amdblocks/acpimmio.h>
Karthikeyan Ramasubramanian0822ce82022-12-05 14:54:53 -07006#include <bl_uapp/bl_errorcodes_public.h>
Martin Rothc7acf162020-05-28 00:44:50 -06007#include <bl_uapp/bl_syscall_public.h>
8#include <boot_device.h>
Martin Rothe21698b2020-06-26 08:55:15 -06009#include <cbfs.h>
Karthikeyan Ramasubramanianc2f6f352021-09-10 12:03:30 -060010#include <commonlib/region.h>
Martin Rothc7acf162020-05-28 00:44:50 -060011#include <console/console.h>
Martin Rothe21698b2020-06-26 08:55:15 -060012#include <fmap.h>
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -060013#include <fmap_config.h>
Martin Roth50cca762020-08-13 11:06:18 -060014#include <pc80/mc146818rtc.h>
Martin Roth8fc68812023-08-18 16:28:29 -060015#include <psp_verstage/psp_transfer.h>
Kangheui Wonfab6e442021-10-18 15:35:28 +110016#include <soc/iomap.h>
Rob Barnesb35acf92021-11-02 17:47:47 -060017#include <security/tpm/tspi.h>
18#include <security/tpm/tss.h>
Martin Roth50cca762020-08-13 11:06:18 -060019#include <security/vboot/vbnv.h>
Martin Rothc7acf162020-05-28 00:44:50 -060020#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>
Kangheui Won4e2f5fd2020-09-17 16:37:13 +100025#include <timestamp.h>
Martin Rothc7acf162020-05-28 00:44:50 -060026
Martin Rothc7acf162020-05-28 00:44:50 -060027extern char _bss_start, _bss_end;
Martin Rothc7acf162020-05-28 00:44:50 -060028
Martin Rothc7acf162020-05-28 00:44:50 -060029void __weak verstage_mainboard_init(void) {}
Rob Barnes188be6b2021-11-09 13:21:28 -070030
Martin Rothc7acf162020-05-28 00:44:50 -060031static void reboot_into_recovery(struct vb2_context *ctx, uint32_t subcode)
32{
33 subcode += PSP_VBOOT_ERROR_SUBCODE;
34 svc_write_postcode(subcode);
35
Martin Rothc9689e02020-08-20 17:25:37 -060036 /*
37 * If there's an error but the PSP_verstage is already booting to RO,
38 * don't reset the system. It may be that the error is fatal, but if
39 * the system is stuck, don't intentionally force it into a reboot loop.
40 */
41 if (ctx->flags & VB2_CONTEXT_RECOVERY_MODE) {
42 printk(BIOS_ERR, "Already in recovery mode. Staying in RO.\n");
43 return;
44 }
45
Martin Rothc7acf162020-05-28 00:44:50 -060046 svc_debug_print("Rebooting into recovery\n");
Jakub Czapiga605f7932022-11-04 12:18:04 +000047 vboot_fail_and_reboot(ctx, VB2_RECOVERY_RO_UNSPECIFIED, (int)subcode);
Martin Rothc7acf162020-05-28 00:44:50 -060048}
49
Martin Roth50cca762020-08-13 11:06:18 -060050static uint32_t check_cmos_recovery(void)
51{
52 /* Only reset if cmos is valid */
53 if (vbnv_cmos_failed())
54 return 0;
55
56 /* If the byte is set, clear it, then return error to reboot */
57 if (cmos_read(CMOS_RECOVERY_BYTE) == CMOS_RECOVERY_MAGIC_VAL) {
58 cmos_write(0x00, CMOS_RECOVERY_BYTE);
59 printk(BIOS_DEBUG, "Reboot into recovery requested by coreboot\n");
60 return POSTCODE_CMOS_RECOVERY;
61 }
62
63 return 0;
64}
65
Martin Rothc7acf162020-05-28 00:44:50 -060066/*
67 * Tell the PSP where to load the rest of the firmware from
68 */
69static uint32_t update_boot_region(struct vb2_context *ctx)
70{
Kangheui Won26bb4aa2021-10-18 15:31:45 +110071 struct embedded_firmware *ef_table;
Martin Rothc7acf162020-05-28 00:44:50 -060072 uint32_t psp_dir_addr, bios_dir_addr;
73 uint32_t *psp_dir_in_spi, *bios_dir_in_spi;
Kangheui Wonac7ec272021-01-15 15:04:25 +110074 const char *fname;
75 void *amdfw_location;
Karthikeyan Ramasubramanian1da03402023-05-25 15:49:29 -060076 struct region fw_slot;
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -060077 void *map_base = NULL;
Martin Rothc7acf162020-05-28 00:44:50 -060078
79 /* Continue booting from RO */
80 if (ctx->flags & VB2_CONTEXT_RECOVERY_MODE) {
81 printk(BIOS_ERR, "In recovery mode. Staying in RO.\n");
82 return 0;
83 }
84
85 if (vboot_is_firmware_slot_a(ctx)) {
Martin Rothe21698b2020-06-26 08:55:15 -060086 fname = "apu/amdfw_a";
Nico Huberf55b7112024-01-11 18:50:50 +010087 if (!fmap_locate_area("FW_MAIN_A", &fw_slot)) {
88 map_base = rdev_mmap(boot_device_ro(),
89 region_offset(&fw_slot), region_sz(&fw_slot));
90 }
Karthikeyan Ramasubramanian1da03402023-05-25 15:49:29 -060091
Martin Rothc7acf162020-05-28 00:44:50 -060092 } else {
Martin Rothe21698b2020-06-26 08:55:15 -060093 fname = "apu/amdfw_b";
Nico Huberf55b7112024-01-11 18:50:50 +010094 if (!fmap_locate_area("FW_MAIN_B", &fw_slot)) {
95 map_base = rdev_mmap(boot_device_ro(),
96 region_offset(&fw_slot), region_sz(&fw_slot));
97 }
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -060098 }
99
100 if (!map_base) {
101 printk(BIOS_ERR, "Failed to map RW FW_MAIN section.\n");
102 return POSTCODE_MAP_SPI_ROM_FAILED;
Martin Rothc7acf162020-05-28 00:44:50 -0600103 }
104
Kangheui Wonac7ec272021-01-15 15:04:25 +1100105 amdfw_location = cbfs_map(fname, NULL);
Martin Rothe21698b2020-06-26 08:55:15 -0600106 if (!amdfw_location) {
Julius Wernere9665952022-01-21 17:06:20 -0800107 printk(BIOS_ERR, "AMD Firmware table not found.\n");
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600108 rdev_munmap(boot_device_ro(), map_base);
Martin Rothe21698b2020-06-26 08:55:15 -0600109 return POSTCODE_AMD_FW_MISSING;
110 }
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600111
Kangheui Won26bb4aa2021-10-18 15:31:45 +1100112 ef_table = (struct embedded_firmware *)amdfw_location;
Martin Rothc7acf162020-05-28 00:44:50 -0600113 if (ef_table->signature != EMBEDDED_FW_SIGNATURE) {
Julius Wernere9665952022-01-21 17:06:20 -0800114 printk(BIOS_ERR, "ROMSIG address is not correct.\n");
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600115 cbfs_unmap(amdfw_location);
Karthikeyan Ramasubramanian01c9dfb2023-05-25 15:54:33 -0600116 rdev_munmap(boot_device_ro(), amdfw_location);
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600117 rdev_munmap(boot_device_ro(), map_base);
Martin Rothc7acf162020-05-28 00:44:50 -0600118 return POSTCODE_ROMSIG_MISMATCH_ERROR;
119 }
120
Felix Held4bdea412023-02-17 00:31:43 +0100121 psp_dir_addr = ef_table->new_psp_directory;
Kangheui Won5858fb42021-05-06 13:30:51 +1000122 bios_dir_addr = get_bios_dir_addr(ef_table);
Martin Rothc7acf162020-05-28 00:44:50 -0600123 psp_dir_in_spi = (uint32_t *)((psp_dir_addr & SPI_ADDR_MASK) +
Nico Huberf55b7112024-01-11 18:50:50 +0100124 (uint32_t)map_base - region_offset(&fw_slot));
Martin Rothc7acf162020-05-28 00:44:50 -0600125 if (*psp_dir_in_spi != PSP_COOKIE) {
Julius Wernere9665952022-01-21 17:06:20 -0800126 printk(BIOS_ERR, "PSP Directory address is not correct.\n");
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600127 cbfs_unmap(amdfw_location);
Karthikeyan Ramasubramanian01c9dfb2023-05-25 15:54:33 -0600128 rdev_munmap(boot_device_ro(), amdfw_location);
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600129 rdev_munmap(boot_device_ro(), map_base);
Martin Rothc7acf162020-05-28 00:44:50 -0600130 return POSTCODE_PSP_COOKIE_MISMATCH_ERROR;
131 }
Karthikeyan Ramasubramaniane3eedf72022-07-14 15:37:07 -0600132
133 if (bios_dir_addr) {
134 bios_dir_in_spi = (uint32_t *)((bios_dir_addr & SPI_ADDR_MASK) +
Nico Huberf55b7112024-01-11 18:50:50 +0100135 (uint32_t)map_base - region_offset(&fw_slot));
Karthikeyan Ramasubramaniane3eedf72022-07-14 15:37:07 -0600136 if (*bios_dir_in_spi != BHD_COOKIE) {
137 printk(BIOS_ERR, "BIOS Directory address is not correct.\n");
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600138 cbfs_unmap(amdfw_location);
Karthikeyan Ramasubramanian01c9dfb2023-05-25 15:54:33 -0600139 rdev_munmap(boot_device_ro(), amdfw_location);
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600140 rdev_munmap(boot_device_ro(), map_base);
Karthikeyan Ramasubramaniane3eedf72022-07-14 15:37:07 -0600141 return POSTCODE_BHD_COOKIE_MISMATCH_ERROR;
142 }
Martin Rothc7acf162020-05-28 00:44:50 -0600143 }
144
Kangheui Wonfab6e442021-10-18 15:35:28 +1100145 /* EFS2 uses relative address and PSP isn't happy with that */
Karthikeyan Ramasubramaniane3eedf72022-07-14 15:37:07 -0600146 if (ef_table->efs_gen.gen == EFS_SECOND_GEN &&
147 !CONFIG(PSP_SUPPORTS_EFS2_RELATIVE_ADDR)) {
Kangheui Wonfab6e442021-10-18 15:35:28 +1100148 psp_dir_addr = FLASH_BASE_ADDR + (psp_dir_addr & SPI_ADDR_MASK);
149 bios_dir_addr = FLASH_BASE_ADDR + (bios_dir_addr & SPI_ADDR_MASK);
150 }
151
Kangheui Won26bb4aa2021-10-18 15:31:45 +1100152 if (update_psp_bios_dir(&psp_dir_addr, &bios_dir_addr)) {
Julius Wernere9665952022-01-21 17:06:20 -0800153 printk(BIOS_ERR, "Updated BIOS Directory could not be set.\n");
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600154 cbfs_unmap(amdfw_location);
Karthikeyan Ramasubramanian01c9dfb2023-05-25 15:54:33 -0600155 rdev_munmap(boot_device_ro(), amdfw_location);
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600156 rdev_munmap(boot_device_ro(), map_base);
Martin Rothc7acf162020-05-28 00:44:50 -0600157 return POSTCODE_UPDATE_PSP_BIOS_DIR_ERROR;
158 }
159
Kangheui Won5fb435a2021-12-22 12:24:17 +1100160 if (CONFIG(SEPARATE_SIGNED_PSPFW))
Karthikeyan Ramasubramanian97e57cf2023-07-17 12:43:14 -0600161 update_psp_fw_hash_tables();
Kangheui Won5fb435a2021-12-22 12:24:17 +1100162
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600163 cbfs_unmap(amdfw_location);
Karthikeyan Ramasubramanian01c9dfb2023-05-25 15:54:33 -0600164 rdev_munmap(boot_device_ro(), amdfw_location);
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600165 rdev_munmap(boot_device_ro(), map_base);
Martin Rothc7acf162020-05-28 00:44:50 -0600166 return 0;
167}
168
169/*
170 * Save workbuf (and soon memory console and timestamps) to the bootloader to pass
171 * back to coreboot.
172 */
Raul E Rangel5e0ed502022-02-24 10:58:29 -0700173static uint32_t save_buffers(void)
Martin Rothc7acf162020-05-28 00:44:50 -0600174{
175 uint32_t retval;
Raul E Rangel5e0ed502022-02-24 10:58:29 -0700176 uint32_t buffer_size;
Martin Roth0c12abe2020-06-26 08:40:56 -0600177 struct transfer_info_struct buffer_info = {0};
Martin Rothc7acf162020-05-28 00:44:50 -0600178
Raul E Rangel5e0ed502022-02-24 10:58:29 -0700179 buffer_size =
180 (uint32_t)((uintptr_t)_etransfer_buffer - (uintptr_t)_transfer_buffer);
Martin Rothc7acf162020-05-28 00:44:50 -0600181
Raul E Rangel5e0ed502022-02-24 10:58:29 -0700182 buffer_info.console_offset = (uint32_t)((uintptr_t)_preram_cbmem_console -
183 (uintptr_t)_transfer_buffer);
184 buffer_info.timestamp_offset = (uint32_t)((uintptr_t)_timestamp -
185 (uintptr_t)_transfer_buffer);
186 buffer_info.fmap_offset = (uint32_t)((uintptr_t)_fmap_cache -
187 (uintptr_t)_transfer_buffer);
Martin Rothc7acf162020-05-28 00:44:50 -0600188
Martin Roth0c12abe2020-06-26 08:40:56 -0600189 buffer_info.magic_val = TRANSFER_MAGIC_VAL;
190 buffer_info.struct_bytes = sizeof(buffer_info);
191 buffer_info.buffer_size = buffer_size;
192 buffer_info.workbuf_offset = (uint32_t)((uintptr_t)_fmap_cache -
193 (uintptr_t)_vboot2_work);
194
Kangheui Won5f027fa2020-08-25 18:12:19 +1000195 memcpy(_transfer_buffer, &buffer_info, sizeof(buffer_info));
196
Kangheui Wona767eb42021-04-14 09:35:28 +1000197 retval = save_uapp_data((void *)_transfer_buffer, buffer_size);
Martin Rothc7acf162020-05-28 00:44:50 -0600198 if (retval) {
Julius Wernere9665952022-01-21 17:06:20 -0800199 printk(BIOS_ERR, "Could not save workbuf. Error code 0x%08x\n", retval);
Martin Rothc7acf162020-05-28 00:44:50 -0600200 return POSTCODE_WORKBUF_SAVE_ERROR;
201 }
202
203 return 0;
204}
205
Rob Barnesb35acf92021-11-02 17:47:47 -0600206/*
207 * S0i3 resume in PSP verstage is a special case. The FSDL is restoring mostly
208 * everything, so do the minimum necessary here. Unlike normal boot, subsequent
209 * coreboot stages are not run after s0i3 verstage.
210 * If the TPM is reset in S0i3, it must be re-initialized here.
211 */
212static void psp_verstage_s0i3_resume(void)
213{
Jon Murphyd7b8dc92023-09-05 11:36:43 -0600214 tpm_result_t rc;
Rob Barnesb35acf92021-11-02 17:47:47 -0600215
216 post_code(POSTCODE_VERSTAGE_S0I3_RESUME);
217
218 printk(BIOS_DEBUG, "Entering PSP verstage S0i3 resume\n");
219
220 if (!CONFIG(PSP_INIT_TPM_ON_S0I3_RESUME))
221 return;
222
Jon Murphy24604812023-09-05 10:37:05 -0600223 rc = tpm_setup(true);
224 if (rc != TPM_SUCCESS) {
225 printk(BIOS_ERR, "tpm_setup failed rc:%d\n", rc);
Rob Barnesb35acf92021-11-02 17:47:47 -0600226 reboot_into_recovery(vboot_get_context(), POSTCODE_INIT_TPM_FAILED);
227 }
228
Sergii Dmytruk094a0512022-10-31 18:41:52 +0200229 rc = tlcl2_disable_platform_hierarchy();
Jon Murphy24604812023-09-05 10:37:05 -0600230 if (rc != TPM_SUCCESS) {
Sergii Dmytruk094a0512022-10-31 18:41:52 +0200231 printk(BIOS_ERR, "tlcl2_disable_platform_hierarchy failed rc:%d\n", rc);
Rob Barnesb35acf92021-11-02 17:47:47 -0600232 reboot_into_recovery(vboot_get_context(), POSTCODE_INIT_TPM_FAILED);
233 }
234}
235
Martin Rothc7acf162020-05-28 00:44:50 -0600236void Main(void)
237{
238 uint32_t retval;
239 struct vb2_context *ctx = NULL;
Rob Barnesb35acf92021-11-02 17:47:47 -0600240 uint32_t bootmode;
Karthikeyan Ramasubramanianb6ab7ba2023-11-20 23:34:22 +0000241 void *boot_dev_base;
Martin Rothc7acf162020-05-28 00:44:50 -0600242
243 /*
244 * Do not use printk() before console_init()
245 * Do not use post_code() before verstage_mainboard_init()
Karthikeyan Ramasubramanian1a24d842022-03-16 16:27:49 -0600246 * Do not use svc_write_postcode before verstage_soc_espi_init() if PSP uses ESPI
247 * to write postcodes.
Martin Rothc7acf162020-05-28 00:44:50 -0600248 */
Kangheui Won4e2f5fd2020-09-17 16:37:13 +1000249 timestamp_init(timestamp_get());
Karthikeyan Ramasubramanian1a24d842022-03-16 16:27:49 -0600250 if (!CONFIG(PSP_POSTCODES_ON_ESPI))
251 svc_write_postcode(POSTCODE_ENTERED_PSP_VERSTAGE);
Martin Rothc7acf162020-05-28 00:44:50 -0600252 svc_debug_print("Entering verstage on PSP\n");
253 memset(&_bss_start, '\0', &_bss_end - &_bss_start);
254
Karthikeyan Ramasubramanian1a24d842022-03-16 16:27:49 -0600255 if (!CONFIG(PSP_POSTCODES_ON_ESPI))
256 svc_write_postcode(POSTCODE_CONSOLE_INIT);
Martin Rothc7acf162020-05-28 00:44:50 -0600257 console_init();
258
Karthikeyan Ramasubramaniane5f627a2022-12-22 13:05:12 -0700259 if (CONFIG(PSP_INCLUDES_HSP))
260 report_hsp_secure_state();
261
Karthikeyan Ramasubramanian1a24d842022-03-16 16:27:49 -0600262 if (!CONFIG(PSP_POSTCODES_ON_ESPI))
263 svc_write_postcode(POSTCODE_EARLY_INIT);
Martin Rothc7acf162020-05-28 00:44:50 -0600264 retval = verstage_soc_early_init();
265 if (retval) {
Rob Barnesc30a1fa2021-11-08 06:43:07 -0700266 /*
267 * If verstage_soc_early_init fails, cmos is probably not
268 * accessible, so rebooting into recovery is not an option.
269 * Just reboot and hope for the best.
270 */
271 svc_write_postcode(POSTCODE_EARLY_INIT_ERROR);
272 svc_debug_print("verstage_soc_early_init failed! -- rebooting\n");
273 vboot_reboot();
Martin Rothc7acf162020-05-28 00:44:50 -0600274 }
Martin Rothc7acf162020-05-28 00:44:50 -0600275
Rob Barnesf6e421f2021-11-08 13:04:18 -0700276 printk(BIOS_DEBUG, "calling verstage_mainboard_espi_init\n");
277 verstage_mainboard_espi_init();
278
Rob Barnes188be6b2021-11-09 13:21:28 -0700279 printk(BIOS_DEBUG, "calling verstage_soc_espi_init\n");
280 verstage_soc_espi_init();
281
282 printk(BIOS_DEBUG, "calling verstage_mainboard_tpm_init\n");
283 /* mainboard_tpm_init may check board_id, so make sure espi is ready first */
284 verstage_mainboard_tpm_init();
285
Rob Barnes847a39f2021-11-15 12:56:34 -0700286 printk(BIOS_DEBUG, "calling verstage_soc_aoac_init\n");
287 verstage_soc_aoac_init();
288
289 printk(BIOS_DEBUG, "calling verstage_soc_i2c_init\n");
290 verstage_soc_i2c_init();
291
Rob Barnesb35acf92021-11-02 17:47:47 -0600292 /*
293 * S0i3 resume in PSP verstage is a special case, handle it separately.
294 * Make sure TPM i2c is ready first.
295 */
296 svc_get_boot_mode(&bootmode);
297 if (bootmode == PSP_BOOT_MODE_S0i3_RESUME) {
298 psp_verstage_s0i3_resume();
Raul E Rangel737ad672022-02-24 11:49:52 -0700299
Raul E Rangel409e5cb2022-02-24 11:54:32 -0700300 post_code(POSTCODE_SAVE_BUFFERS);
301 retval = save_buffers();
302 if (retval)
303 post_code(retval);
304
Raul E Rangel737ad672022-02-24 11:49:52 -0700305 post_code(POSTCODE_UNMAP_FCH_DEVICES);
Rob Barnesb35acf92021-11-02 17:47:47 -0600306 unmap_fch_devices();
Raul E Rangel737ad672022-02-24 11:49:52 -0700307
308 post_code(POSTCODE_LEAVING_VERSTAGE);
Rob Barnesb35acf92021-11-02 17:47:47 -0600309 svc_exit(0);
310 }
311
312 printk(BIOS_DEBUG, "calling verstage_mainboard_early_init\n");
313 verstage_mainboard_early_init();
314
315 svc_write_postcode(POSTCODE_LATE_INIT);
Karthikeyan Ramasubramanian5eb77922023-07-21 18:05:25 -0600316 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPIMMIO_PM_IO_ACCESS))
317 fch_io_enable_legacy_io();
Rob Barnesb35acf92021-11-02 17:47:47 -0600318
Rob Barnes847a39f2021-11-15 12:56:34 -0700319 printk(BIOS_DEBUG, "calling verstage_soc_spi_init\n");
320 verstage_soc_spi_init();
321
Martin Rothc7acf162020-05-28 00:44:50 -0600322 verstage_mainboard_init();
323
324 post_code(POSTCODE_VERSTAGE_MAIN);
Karthikeyan Ramasubramanian0822ce82022-12-05 14:54:53 -0700325 if (CONFIG(SEPARATE_SIGNED_PSPFW))
326 report_prev_boot_status_to_vboot();
Martin Rothc7acf162020-05-28 00:44:50 -0600327
Kangheui Wonac7ec272021-01-15 15:04:25 +1100328 vboot_run_logic();
Martin Rothc7acf162020-05-28 00:44:50 -0600329
Martin Rothc9689e02020-08-20 17:25:37 -0600330 ctx = vboot_get_context();
Martin Roth50cca762020-08-13 11:06:18 -0600331 retval = check_cmos_recovery();
332 if (retval)
Martin Rothc9689e02020-08-20 17:25:37 -0600333 reboot_into_recovery(ctx, retval);
Martin Roth0c12abe2020-06-26 08:40:56 -0600334
Kangheui Won7e91db72022-01-25 18:55:04 +1100335 platform_report_mode(vboot_developer_mode_enabled());
336
Kangheui Wonac7ec272021-01-15 15:04:25 +1100337 post_code(POSTCODE_UPDATE_BOOT_REGION);
Kangheui Won97527252021-05-20 10:02:00 +1000338
339 /*
340 * Since psp_verstage doesn't load next stage we never call
341 * any cbfs API on RO path. However we still need to initialize
342 * RO CBFS MCACHE manually to pass it in transfer_buffer.
343 * In RW path, MCACHE build will be skipped for RO region since
344 * we already built here.
345 */
346 cbfs_get_boot_device(true);
347
Kangheui Wonac7ec272021-01-15 15:04:25 +1100348 retval = update_boot_region(ctx);
349 if (retval)
350 reboot_into_recovery(ctx, retval);
351
Martin Rothc7acf162020-05-28 00:44:50 -0600352 post_code(POSTCODE_SAVE_BUFFERS);
Raul E Rangel5e0ed502022-02-24 10:58:29 -0700353 retval = save_buffers();
Martin Rothc7acf162020-05-28 00:44:50 -0600354 if (retval)
Martin Rothc9689e02020-08-20 17:25:37 -0600355 reboot_into_recovery(ctx, retval);
Martin Rothc7acf162020-05-28 00:44:50 -0600356
Karthikeyan Ramasubramanianb6ab7ba2023-11-20 23:34:22 +0000357 if (CONFIG(PSP_VERSTAGE_MAP_ENTIRE_SPIROM)) {
358 post_code(POSTCODE_UNMAP_SPI_ROM);
359 boot_dev_base = rdev_mmap_full(boot_device_ro());
360 if (boot_dev_base) {
361 if (svc_unmap_spi_rom((void *)boot_dev_base))
362 printk(BIOS_ERR, "Error unmapping SPI rom\n");
363 }
364 }
Karthikeyan Ramasubramanian6f1b03b2023-04-21 14:26:51 -0600365 assert(!boot_dev_get_active_map_count());
Karthikeyan Ramasubramanianb6ab7ba2023-11-20 23:34:22 +0000366
Martin Rothc7acf162020-05-28 00:44:50 -0600367 post_code(POSTCODE_UNMAP_FCH_DEVICES);
368 unmap_fch_devices();
369
370 post_code(POSTCODE_LEAVING_VERSTAGE);
371
372 printk(BIOS_DEBUG, "Leaving verstage on PSP\n");
373 svc_exit(retval);
Martin Rothc7acf162020-05-28 00:44:50 -0600374}
375
Martin Rothc7acf162020-05-28 00:44:50 -0600376/*
377 * The stage_entry function is not used directly, but stage_entry() is marked as an entry
378 * point in arm/arch/header.h, so if stage_entry() isn't present and calling Main(), all
379 * the verstage code gets dropped by the linker. Slightly hacky, but mostly harmless.
380 */
381void stage_entry(uintptr_t stage_arg)
382{
383 Main();
384}