2020-04-02 23:48:34 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2015-05-16 06:39:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <cbfs.h>
|
|
|
|
#include <cbmem.h>
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <fallback.h>
|
|
|
|
#include <halt.h>
|
|
|
|
#include <lib.h>
|
|
|
|
#include <program_loading.h>
|
2016-10-29 00:32:24 +02:00
|
|
|
#include <reset.h>
|
2015-05-16 06:39:23 +02:00
|
|
|
#include <romstage_handoff.h>
|
|
|
|
#include <rmodule.h>
|
|
|
|
#include <stage_cache.h>
|
|
|
|
#include <symbols.h>
|
|
|
|
#include <timestamp.h>
|
2018-04-19 14:39:07 +02:00
|
|
|
#include <fit_payload.h>
|
2019-11-01 10:22:22 +01:00
|
|
|
#include <security/vboot/vboot_common.h>
|
2015-05-16 06:39:23 +02:00
|
|
|
|
2015-05-19 23:25:20 +02:00
|
|
|
/* Only can represent up to 1 byte less than size_t. */
|
2016-06-22 21:09:08 +02:00
|
|
|
const struct mem_region_device addrspace_32bit =
|
|
|
|
MEM_REGION_DEV_RO_INIT(0, ~0UL);
|
2015-05-19 23:25:20 +02:00
|
|
|
|
2015-12-09 00:00:23 +01:00
|
|
|
int prog_locate(struct prog *prog)
|
|
|
|
{
|
|
|
|
struct cbfsf file;
|
|
|
|
|
2019-06-14 14:36:37 +02:00
|
|
|
if (prog_locate_hook(prog))
|
|
|
|
return -1;
|
|
|
|
|
2015-12-09 00:00:23 +01:00
|
|
|
if (cbfs_boot_locate(&file, prog_name(prog), NULL))
|
|
|
|
return -1;
|
|
|
|
|
2018-05-03 10:35:26 +02:00
|
|
|
cbfsf_file_type(&file, &prog->cbfs_type);
|
|
|
|
|
2015-12-09 00:00:23 +01:00
|
|
|
cbfs_file_data(prog_rdev(prog), &file);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-16 06:39:23 +02:00
|
|
|
void run_romstage(void)
|
|
|
|
{
|
2015-05-20 19:08:55 +02:00
|
|
|
struct prog romstage =
|
2015-12-08 21:34:35 +01:00
|
|
|
PROG_INIT(PROG_ROMSTAGE, CONFIG_CBFS_PREFIX "/romstage");
|
2015-05-16 06:39:23 +02:00
|
|
|
|
2019-11-01 10:22:22 +01:00
|
|
|
vboot_run_logic();
|
|
|
|
|
2020-06-08 05:05:03 +02:00
|
|
|
if (ENV_X86 && CONFIG(BOOTBLOCK_NORMAL)) {
|
2019-12-16 15:00:49 +01:00
|
|
|
if (legacy_romstage_selector(&romstage))
|
|
|
|
goto fail;
|
|
|
|
} else {
|
|
|
|
if (prog_locate(&romstage))
|
|
|
|
goto fail;
|
|
|
|
}
|
2015-05-16 06:39:23 +02:00
|
|
|
|
|
|
|
timestamp_add_now(TS_START_COPYROM);
|
|
|
|
|
|
|
|
if (cbfs_prog_stage_load(&romstage))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
timestamp_add_now(TS_END_COPYROM);
|
|
|
|
|
2019-11-02 13:12:18 +01:00
|
|
|
console_time_report();
|
|
|
|
|
2015-05-16 06:39:23 +02:00
|
|
|
prog_run(&romstage);
|
|
|
|
|
|
|
|
fail:
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(BOOTBLOCK_CONSOLE))
|
2019-05-07 00:12:57 +02:00
|
|
|
die_with_post_code(POST_INVALID_ROM,
|
|
|
|
"Couldn't load romstage.\n");
|
2015-05-16 06:39:23 +02:00
|
|
|
halt();
|
|
|
|
}
|
|
|
|
|
2019-06-14 14:36:37 +02:00
|
|
|
int __weak prog_locate_hook(struct prog *prog) { return 0; }
|
|
|
|
|
2016-11-30 04:22:42 +01:00
|
|
|
static void run_ramstage_from_resume(struct prog *ramstage)
|
2015-05-16 06:39:23 +02:00
|
|
|
{
|
2016-11-30 04:22:42 +01:00
|
|
|
if (!romstage_handoff_is_resume())
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Load the cached ramstage to runtime location. */
|
|
|
|
stage_cache_load_stage(STAGE_RAMSTAGE, ramstage);
|
|
|
|
|
2019-10-23 17:07:15 +02:00
|
|
|
prog_set_arg(ramstage, cbmem_top());
|
|
|
|
|
2016-11-30 04:22:42 +01:00
|
|
|
if (prog_entry(ramstage) != NULL) {
|
|
|
|
printk(BIOS_DEBUG, "Jumping to image.\n");
|
|
|
|
prog_run(ramstage);
|
2015-05-16 06:39:23 +02:00
|
|
|
}
|
2019-12-18 18:40:48 +01:00
|
|
|
|
|
|
|
printk(BIOS_ERR, "ramstage cache invalid.\n");
|
|
|
|
board_reset();
|
2015-05-16 06:39:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int load_relocatable_ramstage(struct prog *ramstage)
|
|
|
|
{
|
|
|
|
struct rmod_stage_load rmod_ram = {
|
|
|
|
.cbmem_id = CBMEM_ID_RAMSTAGE,
|
|
|
|
.prog = ramstage,
|
|
|
|
};
|
|
|
|
|
|
|
|
return rmodule_stage_load(&rmod_ram);
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_ramstage(void)
|
|
|
|
{
|
2015-05-20 19:08:55 +02:00
|
|
|
struct prog ramstage =
|
2015-12-08 21:34:35 +01:00
|
|
|
PROG_INIT(PROG_RAMSTAGE, CONFIG_CBFS_PREFIX "/ramstage");
|
2015-05-16 06:39:23 +02:00
|
|
|
|
arch/x86/postcar: Add separate timestamp for postcar stage
This patch adds dedicated timestamp value for postcar stage.
TEST=Able to see "start of postcar" and "end of postcar" timestamp
while executing cbmem -t after booting to chrome console.
> cbmem -t
951:returning from FspMemoryInit 20,485,324 (20,103,067)
4:end of romstage 20,559,235 (73,910)
100:start of postcar 20,560,266 (1,031)
101:end of postcar 20,570,038 (9,772)
Change-Id: I084f66949667ad598f811d4233b4e639bc4c113e
Signed-off-by: Subrata Banik <subrata.banik@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/31762
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2019-03-05 12:15:14 +01:00
|
|
|
if (ENV_POSTCAR)
|
|
|
|
timestamp_add_now(TS_END_POSTCAR);
|
|
|
|
|
2019-02-25 16:01:22 +01:00
|
|
|
/* Call "end of romstage" here if postcar stage doesn't exist */
|
|
|
|
if (ENV_ROMSTAGE)
|
|
|
|
timestamp_add_now(TS_END_ROMSTAGE);
|
2015-09-24 02:54:12 +02:00
|
|
|
|
2016-05-06 18:20:35 +02:00
|
|
|
/*
|
|
|
|
* Only x86 systems using ramstage stage cache currently take the same
|
|
|
|
* firmware path on resume.
|
|
|
|
*/
|
2020-06-08 05:05:03 +02:00
|
|
|
if (ENV_X86 && !CONFIG(NO_STAGE_CACHE))
|
2016-11-30 04:22:42 +01:00
|
|
|
run_ramstage_from_resume(&ramstage);
|
2015-05-16 06:39:23 +02:00
|
|
|
|
2019-11-01 10:22:22 +01:00
|
|
|
vboot_run_logic();
|
|
|
|
|
2015-05-16 06:39:23 +02:00
|
|
|
if (prog_locate(&ramstage))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
timestamp_add_now(TS_START_COPYRAM);
|
|
|
|
|
2020-07-06 11:02:53 +02:00
|
|
|
if (ENV_X86) {
|
|
|
|
if (load_relocatable_ramstage(&ramstage))
|
|
|
|
goto fail;
|
|
|
|
} else {
|
|
|
|
if (cbfs_prog_stage_load(&ramstage))
|
|
|
|
goto fail;
|
|
|
|
}
|
2015-05-16 06:39:23 +02:00
|
|
|
|
2019-06-11 14:22:06 +02:00
|
|
|
stage_cache_add(STAGE_RAMSTAGE, &ramstage);
|
2015-05-16 06:39:23 +02:00
|
|
|
|
|
|
|
timestamp_add_now(TS_END_COPYRAM);
|
|
|
|
|
2019-11-02 13:12:18 +01:00
|
|
|
console_time_report();
|
|
|
|
|
2019-10-23 17:07:15 +02:00
|
|
|
/* This overrides the arg fetched from the relocatable module */
|
|
|
|
prog_set_arg(&ramstage, cbmem_top());
|
|
|
|
|
2015-05-16 06:39:23 +02:00
|
|
|
prog_run(&ramstage);
|
|
|
|
|
|
|
|
fail:
|
2019-05-07 00:12:57 +02:00
|
|
|
die_with_post_code(POST_INVALID_ROM, "Ramstage was not loaded!\n");
|
2015-05-16 06:39:23 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 16:57:04 +02:00
|
|
|
#if ENV_PAYLOAD_LOADER // gc-sections should take care of this
|
2015-06-18 10:19:50 +02:00
|
|
|
|
2015-05-20 19:08:55 +02:00
|
|
|
static struct prog global_payload =
|
2015-12-08 21:34:35 +01:00
|
|
|
PROG_INIT(PROG_PAYLOAD, CONFIG_CBFS_PREFIX "/payload");
|
2015-05-16 06:39:23 +02:00
|
|
|
|
|
|
|
void payload_load(void)
|
|
|
|
{
|
|
|
|
struct prog *payload = &global_payload;
|
|
|
|
|
|
|
|
timestamp_add_now(TS_LOAD_PAYLOAD);
|
|
|
|
|
|
|
|
if (prog_locate(payload))
|
|
|
|
goto out;
|
|
|
|
|
2018-04-19 14:39:07 +02:00
|
|
|
switch (prog_cbfs_type(payload)) {
|
|
|
|
case CBFS_TYPE_SELF: /* Simple ELF */
|
2019-01-28 10:22:22 +01:00
|
|
|
selfload_check(payload, BM_MEM_RAM);
|
2018-04-19 14:39:07 +02:00
|
|
|
break;
|
|
|
|
case CBFS_TYPE_FIT: /* Flattened image tree */
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(PAYLOAD_FIT_SUPPORT)) {
|
2018-04-19 14:39:07 +02:00
|
|
|
fit_payload(payload);
|
|
|
|
break;
|
|
|
|
} /* else fall-through */
|
|
|
|
default:
|
2019-05-07 00:12:57 +02:00
|
|
|
die_with_post_code(POST_INVALID_ROM,
|
|
|
|
"Unsupported payload type.\n");
|
2018-04-19 14:39:07 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-05-16 06:39:23 +02:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (prog_entry(payload) == NULL)
|
2019-05-07 00:12:57 +02:00
|
|
|
die_with_post_code(POST_INVALID_ROM, "Payload not loaded.\n");
|
2015-05-16 06:39:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void payload_run(void)
|
|
|
|
{
|
|
|
|
struct prog *payload = &global_payload;
|
|
|
|
|
|
|
|
/* Reset to booting from this image as late as possible */
|
|
|
|
boot_successful();
|
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "Jumping to boot code at %p(%p)\n",
|
|
|
|
prog_entry(payload), prog_entry_arg(payload));
|
|
|
|
|
|
|
|
post_code(POST_ENTER_ELF_BOOT);
|
|
|
|
|
|
|
|
timestamp_add_now(TS_SELFBOOT_JUMP);
|
|
|
|
|
|
|
|
/* Before we go off to run the payload, see if
|
|
|
|
* we stayed within our bounds.
|
|
|
|
*/
|
|
|
|
checkstack(_estack, 0);
|
|
|
|
|
|
|
|
prog_run(payload);
|
|
|
|
}
|
2015-06-18 10:19:50 +02:00
|
|
|
|
|
|
|
#endif
|