2015-05-16 06:39:23 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <cbfs.h>
|
|
|
|
#include <cbmem.h>
|
2018-04-21 22:45:32 +02:00
|
|
|
#include <compiler.h>
|
2015-05-16 06:39:23 +02:00
|
|
|
#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 <rules.h>
|
|
|
|
#include <stage_cache.h>
|
|
|
|
#include <symbols.h>
|
|
|
|
#include <timestamp.h>
|
2018-04-26 09:53:16 +02:00
|
|
|
#include <cbfs.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;
|
|
|
|
|
|
|
|
cbfs_prepare_program_locate();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (prog_locate(&romstage))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
timestamp_add_now(TS_START_COPYROM);
|
|
|
|
|
|
|
|
if (cbfs_prog_stage_load(&romstage))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
timestamp_add_now(TS_END_COPYROM);
|
|
|
|
|
|
|
|
prog_run(&romstage);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (IS_ENABLED(CONFIG_BOOTBLOCK_CONSOLE))
|
|
|
|
die("Couldn't load romstage.\n");
|
|
|
|
halt();
|
|
|
|
}
|
|
|
|
|
2018-04-21 22:45:32 +02:00
|
|
|
void __weak stage_cache_add(int stage_id,
|
2015-08-05 07:52:13 +02:00
|
|
|
const struct prog *stage) {}
|
2018-04-21 22:45:32 +02:00
|
|
|
void __weak stage_cache_load_stage(int stage_id,
|
2015-05-16 06:39:23 +02:00
|
|
|
struct prog *stage) {}
|
2016-10-29 00:32:24 +02:00
|
|
|
|
|
|
|
static void ramstage_cache_invalid(void)
|
|
|
|
{
|
|
|
|
printk(BIOS_ERR, "ramstage cache invalid.\n");
|
|
|
|
if (IS_ENABLED(CONFIG_RESET_ON_INVALID_RAMSTAGE_CACHE)) {
|
|
|
|
hard_reset();
|
|
|
|
halt();
|
|
|
|
}
|
|
|
|
}
|
2015-05-16 06:39:23 +02:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (prog_entry(ramstage) != NULL) {
|
|
|
|
printk(BIOS_DEBUG, "Jumping to image.\n");
|
|
|
|
prog_run(ramstage);
|
2015-05-16 06:39:23 +02:00
|
|
|
}
|
2016-11-30 04:22:42 +01:00
|
|
|
ramstage_cache_invalid();
|
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);
|
|
|
|
}
|
|
|
|
|
2016-06-28 06:38:46 +02:00
|
|
|
static int load_nonrelocatable_ramstage(struct prog *ramstage)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
|
|
|
|
uintptr_t base = 0;
|
|
|
|
size_t size = cbfs_prog_stage_section(ramstage, &base);
|
|
|
|
if (size)
|
|
|
|
backup_ramstage_section(base, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cbfs_prog_stage_load(ramstage);
|
|
|
|
}
|
|
|
|
|
2015-05-16 06:39:23 +02:00
|
|
|
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
|
|
|
|
2015-09-24 02:54:12 +02:00
|
|
|
timestamp_add_now(TS_END_ROMSTAGE);
|
|
|
|
|
2016-05-06 18:20:35 +02:00
|
|
|
/*
|
|
|
|
* Only x86 systems using ramstage stage cache currently take the same
|
|
|
|
* firmware path on resume.
|
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_ARCH_X86) &&
|
|
|
|
!IS_ENABLED(CONFIG_NO_STAGE_CACHE) &&
|
|
|
|
IS_ENABLED(CONFIG_EARLY_CBMEM_INIT))
|
2016-11-30 04:22:42 +01:00
|
|
|
run_ramstage_from_resume(&ramstage);
|
2015-05-16 06:39:23 +02:00
|
|
|
|
|
|
|
if (prog_locate(&ramstage))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
timestamp_add_now(TS_START_COPYRAM);
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE)) {
|
|
|
|
if (load_relocatable_ramstage(&ramstage))
|
|
|
|
goto fail;
|
2016-06-28 06:38:46 +02:00
|
|
|
} else if (load_nonrelocatable_ramstage(&ramstage))
|
2015-05-16 06:39:23 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
stage_cache_add(STAGE_RAMSTAGE, &ramstage);
|
|
|
|
|
|
|
|
timestamp_add_now(TS_END_COPYRAM);
|
|
|
|
|
|
|
|
prog_run(&ramstage);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
die("Ramstage was not loaded!\n");
|
|
|
|
}
|
|
|
|
|
2015-06-18 10:19:50 +02:00
|
|
|
#ifdef __RAMSTAGE__ // gc-sections should take care of this
|
|
|
|
|
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
|
|
|
|
2018-04-21 22:45:32 +02:00
|
|
|
void __weak mirror_payload(struct prog *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;
|
|
|
|
|
|
|
|
mirror_payload(payload);
|
|
|
|
|
2018-04-26 09:53:16 +02:00
|
|
|
selfload(payload, true);
|
2015-05-16 06:39:23 +02:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (prog_entry(payload) == NULL)
|
|
|
|
die("Payload not loaded.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|