2003-04-22 21:02:15 +02:00
|
|
|
/*
|
2013-04-24 22:14:01 +02:00
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-01-18 16:08:58 +01:00
|
|
|
* C Bootstrap code for the coreboot
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
#include <bootstate.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <version.h>
|
2003-04-24 08:25:08 +02:00
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
2003-07-19 06:28:22 +02:00
|
|
|
#include <delay.h>
|
2004-10-14 22:54:17 +02:00
|
|
|
#include <stdlib.h>
|
2010-02-22 07:09:43 +01:00
|
|
|
#include <reset.h>
|
2009-04-22 10:17:38 +02:00
|
|
|
#include <boot/tables.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
#include <boot/elf.h>
|
2009-04-14 09:40:01 +02:00
|
|
|
#include <cbfs.h>
|
2012-06-13 01:29:32 +02:00
|
|
|
#include <lib.h>
|
2009-06-30 17:17:49 +02:00
|
|
|
#if CONFIG_HAVE_ACPI_RESUME
|
2009-04-13 19:57:44 +02:00
|
|
|
#include <arch/acpi.h>
|
2009-04-14 08:38:15 +02:00
|
|
|
#endif
|
2009-10-26 18:04:28 +01:00
|
|
|
#include <cbmem.h>
|
Implement GCC code coverage analysis
In order to provide some insight on what code is executed during
coreboot's run time and how well our test scenarios work, this
adds code coverage support to coreboot's ram stage. This should
be easily adaptable for payloads, and maybe even romstage.
See http://gcc.gnu.org/onlinedocs/gcc/Gcov.html for
more information.
To instrument coreboot, select CONFIG_COVERAGE ("Code coverage
support") in Kconfig, and recompile coreboot. coreboot will then
store its code coverage information into CBMEM, if possible.
Then, run "cbmem -CV" as root on the target system running the
instrumented coreboot binary. This will create a whole bunch of
.gcda files that contain coverage information. Tar them up, copy
them to your build system machine, and untar them. Then you can
use your favorite coverage utility (gcov, lcov, ...) to visualize
code coverage.
For a sneak peak of what will expect you, please take a look
at http://www.coreboot.org/~stepan/coreboot-coverage/
Change-Id: Ib287d8309878a1f5c4be770c38b1bc0bb3aa6ec7
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2052
Tested-by: build bot (Jenkins)
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Martin Roth <martin@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2012-12-19 01:23:28 +01:00
|
|
|
#include <coverage.h>
|
2011-11-04 20:31:58 +01:00
|
|
|
#include <timestamp.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
#if BOOT_STATE_DEBUG
|
|
|
|
#define BS_DEBUG_LVL BIOS_DEBUG
|
|
|
|
#else
|
|
|
|
#define BS_DEBUG_LVL BIOS_NEVER
|
Implement GCC code coverage analysis
In order to provide some insight on what code is executed during
coreboot's run time and how well our test scenarios work, this
adds code coverage support to coreboot's ram stage. This should
be easily adaptable for payloads, and maybe even romstage.
See http://gcc.gnu.org/onlinedocs/gcc/Gcov.html for
more information.
To instrument coreboot, select CONFIG_COVERAGE ("Code coverage
support") in Kconfig, and recompile coreboot. coreboot will then
store its code coverage information into CBMEM, if possible.
Then, run "cbmem -CV" as root on the target system running the
instrumented coreboot binary. This will create a whole bunch of
.gcda files that contain coverage information. Tar them up, copy
them to your build system machine, and untar them. Then you can
use your favorite coverage utility (gcov, lcov, ...) to visualize
code coverage.
For a sneak peak of what will expect you, please take a look
at http://www.coreboot.org/~stepan/coreboot-coverage/
Change-Id: Ib287d8309878a1f5c4be770c38b1bc0bb3aa6ec7
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/2052
Tested-by: build bot (Jenkins)
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Martin Roth <martin@se-eng.com>
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2012-12-19 01:23:28 +01:00
|
|
|
#endif
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
static boot_state_t bs_pre_device(void *arg);
|
|
|
|
static boot_state_t bs_dev_init_chips(void *arg);
|
|
|
|
static boot_state_t bs_dev_enumerate(void *arg);
|
|
|
|
static boot_state_t bs_dev_resources(void *arg);
|
|
|
|
static boot_state_t bs_dev_eanble(void *arg);
|
|
|
|
static boot_state_t bs_dev_init(void *arg);
|
|
|
|
static boot_state_t bs_post_device(void *arg);
|
|
|
|
static boot_state_t bs_os_resume(void *arg);
|
|
|
|
static boot_state_t bs_write_tables(void *arg);
|
|
|
|
static boot_state_t bs_payload_load(void *arg);
|
|
|
|
static boot_state_t bs_payload_boot(void *arg);
|
|
|
|
|
|
|
|
struct boot_state {
|
|
|
|
const char *name;
|
|
|
|
boot_state_t id;
|
|
|
|
struct boot_state_callback *seq_callbacks[2];
|
|
|
|
boot_state_t (*run_state)(void *arg);
|
|
|
|
void *arg;
|
|
|
|
int complete;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BS_INIT(state_, run_func_) \
|
|
|
|
{ \
|
|
|
|
.name = #state_, \
|
|
|
|
.id = state_, \
|
|
|
|
.seq_callbacks = { NULL, NULL },\
|
|
|
|
.run_state = run_func_, \
|
|
|
|
.arg = NULL, \
|
|
|
|
.complete = 0 \
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
2013-04-24 22:14:01 +02:00
|
|
|
#define BS_INIT_ENTRY(state_, run_func_) \
|
|
|
|
[state_] = BS_INIT(state_, run_func_)
|
|
|
|
|
|
|
|
static struct boot_state boot_states[] = {
|
|
|
|
BS_INIT_ENTRY(BS_PRE_DEVICE, bs_pre_device),
|
|
|
|
BS_INIT_ENTRY(BS_DEV_INIT_CHIPS, bs_dev_init_chips),
|
|
|
|
BS_INIT_ENTRY(BS_DEV_ENUMERATE, bs_dev_enumerate),
|
|
|
|
BS_INIT_ENTRY(BS_DEV_RESOURCES, bs_dev_resources),
|
|
|
|
BS_INIT_ENTRY(BS_DEV_ENABLE, bs_dev_eanble),
|
|
|
|
BS_INIT_ENTRY(BS_DEV_INIT, bs_dev_init),
|
|
|
|
BS_INIT_ENTRY(BS_POST_DEVICE, bs_post_device),
|
|
|
|
BS_INIT_ENTRY(BS_OS_RESUME, bs_os_resume),
|
|
|
|
BS_INIT_ENTRY(BS_WRITE_TABLES, bs_write_tables),
|
|
|
|
BS_INIT_ENTRY(BS_PAYLOAD_LOAD, bs_payload_load),
|
|
|
|
BS_INIT_ENTRY(BS_PAYLOAD_BOOT, bs_payload_boot),
|
|
|
|
};
|
|
|
|
|
|
|
|
static boot_state_t bs_pre_device(void *arg)
|
|
|
|
{
|
2013-03-13 18:41:44 +01:00
|
|
|
init_cbmem_pre_device();
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_DEV_INIT_CHIPS;
|
|
|
|
}
|
2013-02-12 07:40:30 +01:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
static boot_state_t bs_dev_init_chips(void *arg)
|
|
|
|
{
|
2012-10-16 00:23:20 +02:00
|
|
|
timestamp_stash(TS_DEVICE_ENUMERATE);
|
2012-07-25 10:33:05 +02:00
|
|
|
|
|
|
|
/* Initialize chips early, they might disable unused devices. */
|
|
|
|
dev_initialize_chips();
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_DEV_ENUMERATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_dev_enumerate(void *arg)
|
|
|
|
{
|
2004-11-04 12:04:33 +01:00
|
|
|
/* Find the devices we don't have hard coded knowledge about. */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_enumerate();
|
2011-04-11 22:17:22 +02:00
|
|
|
post_code(POST_DEVICE_ENUMERATION_COMPLETE);
|
2011-11-04 20:31:58 +01:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_DEV_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_dev_resources(void *arg)
|
|
|
|
{
|
2012-10-16 00:23:20 +02:00
|
|
|
timestamp_stash(TS_DEVICE_CONFIGURE);
|
2004-11-04 12:04:33 +01:00
|
|
|
/* Now compute and assign the bus resources. */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_configure();
|
2011-04-11 22:17:22 +02:00
|
|
|
post_code(POST_DEVICE_CONFIGURATION_COMPLETE);
|
2011-11-04 20:31:58 +01:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_DEV_ENABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_dev_eanble(void *arg)
|
|
|
|
{
|
2012-10-16 00:23:20 +02:00
|
|
|
timestamp_stash(TS_DEVICE_ENABLE);
|
2004-11-04 12:04:33 +01:00
|
|
|
/* Now actually enable devices on the bus */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_enable();
|
2012-08-07 22:14:20 +02:00
|
|
|
post_code(POST_DEVICES_ENABLED);
|
2011-11-04 20:31:58 +01:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_DEV_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_dev_init(void *arg)
|
|
|
|
{
|
2012-10-16 00:23:20 +02:00
|
|
|
timestamp_stash(TS_DEVICE_INITIALIZE);
|
2004-11-04 12:04:33 +01:00
|
|
|
/* And of course initialize devices on the bus */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_initialize();
|
2012-08-07 22:14:20 +02:00
|
|
|
post_code(POST_DEVICES_INITIALIZED);
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_POST_DEVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_post_device(void *arg)
|
|
|
|
{
|
2012-10-16 00:23:20 +02:00
|
|
|
timestamp_stash(TS_DEVICE_DONE);
|
2012-04-24 16:01:24 +02:00
|
|
|
|
2013-03-13 18:41:44 +01:00
|
|
|
init_cbmem_post_device();
|
|
|
|
|
2012-10-16 00:23:20 +02:00
|
|
|
timestamp_sync();
|
2012-10-15 22:41:56 +02:00
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_OS_RESUME;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_os_resume(void *arg)
|
|
|
|
{
|
2012-10-15 22:41:56 +02:00
|
|
|
#if CONFIG_HAVE_ACPI_RESUME
|
|
|
|
suspend_resume();
|
|
|
|
post_code(0x8a);
|
|
|
|
#endif
|
|
|
|
|
2012-05-10 21:15:18 +02:00
|
|
|
timestamp_add_now(TS_CBMEM_POST);
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
return BS_WRITE_TABLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_write_tables(void *arg)
|
|
|
|
{
|
2012-05-10 21:15:18 +02:00
|
|
|
if (cbmem_post_handling)
|
|
|
|
cbmem_post_handling();
|
|
|
|
|
2011-11-04 20:31:58 +01:00
|
|
|
timestamp_add_now(TS_WRITE_TABLES);
|
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
/* Now that we have collected all of our information
|
|
|
|
* write our configuration tables.
|
|
|
|
*/
|
2013-04-24 22:14:01 +02:00
|
|
|
write_tables();
|
|
|
|
|
|
|
|
return BS_PAYLOAD_LOAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_payload_load(void *arg)
|
|
|
|
{
|
|
|
|
void *payload;
|
2011-11-04 20:31:58 +01:00
|
|
|
|
|
|
|
timestamp_add_now(TS_LOAD_PAYLOAD);
|
2012-06-13 01:29:32 +02:00
|
|
|
|
Extend CBFS to support arbitrary ROM source media.
Summary:
Isolate CBFS underlying I/O to board/arch-specific implementations as
"media stream", to allow loading and booting romstage on non-x86.
CBFS functions now all take a new "media source" parameter; use
CBFS_DEFAULT_MEDIA if you simply want to load from main firmware.
API Changes:
cbfs_find => cbfs_get_file.
cbfs_find_file => cbfs_get_file_content.
cbfs_get_file => cbfs_get_file_content with correct type.
CBFS used to work only on memory-mapped ROM (all x86). For platforms like ARM,
the ROM may come from USB, UART, or SPI -- any serial devices and not available
for memory mapping.
To support these devices (and allowing CBFS to read from multiple source
at the same time), CBFS operations are now virtual-ized into "cbfs_media". To
simplify porting existing code, every media source must support both "reading
into pre-allocated memory (read)" and "read and return an allocated buffer
(map)". For devices without native memory-mapped ROM, "cbfs_simple_buffer*"
provides simple memory mapping simulation.
Every CBFS function now takes a cbfs_media* as parameter. CBFS_DEFAULT_MEDIA
is defined for CBFS functions to automatically initialize a per-board default
media (CBFS will internally calls init_default_cbfs_media). Also revised CBFS
function names relying on memory mapped backend (ex, "cbfs_find" => actually
loads files). Now we only have two getters:
struct cbfs_file *entry = cbfs_get_file(media, name);
void *data = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, name, type);
Test results:
- Verified to work on x86/qemu.
- Compiles on ARM, and follow up commit will provide working SPI driver.
Change-Id: Iac911ded25a6f2feffbf3101a81364625bb07746
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2182
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2013-01-22 11:57:56 +01:00
|
|
|
payload = cbfs_load_payload(CBFS_DEFAULT_MEDIA,
|
|
|
|
CONFIG_CBFS_PREFIX "/payload");
|
2012-06-13 01:29:32 +02:00
|
|
|
if (! payload)
|
|
|
|
die("Could not find a payload\n");
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
/* Pass the payload to the next state. */
|
|
|
|
boot_states[BS_PAYLOAD_BOOT].arg = payload;
|
|
|
|
|
|
|
|
return BS_PAYLOAD_BOOT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boot_state_t bs_payload_boot(void *payload)
|
|
|
|
{
|
|
|
|
selfboot(get_lb_mem(), payload);
|
|
|
|
|
2012-06-13 01:29:32 +02:00
|
|
|
printk(BIOS_EMERG, "Boot failed");
|
2013-04-24 22:14:01 +02:00
|
|
|
/* Returning from this state will fail because the following signals
|
|
|
|
* return to a completed state. */
|
|
|
|
return BS_PAYLOAD_BOOT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bs_call_callbacks(struct boot_state *state,
|
|
|
|
boot_state_sequence_t seq)
|
|
|
|
{
|
|
|
|
while (state->seq_callbacks[seq] != NULL) {
|
|
|
|
struct boot_state_callback *bscb;
|
|
|
|
|
|
|
|
/* Remove the first callback. */
|
|
|
|
bscb = state->seq_callbacks[seq];
|
|
|
|
state->seq_callbacks[seq] = bscb->next;
|
|
|
|
bscb->next = NULL;
|
|
|
|
|
|
|
|
#if BOOT_STATE_DEBUG
|
|
|
|
printk(BS_DEBUG_LVL, "BS: callback (%p) @ %s.\n",
|
|
|
|
bscb, bscb->location);
|
|
|
|
#endif
|
|
|
|
bscb->callback(bscb->arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bs_walk_state_machine(boot_state_t current_state_id)
|
|
|
|
{
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
struct boot_state *state;
|
|
|
|
|
|
|
|
state = &boot_states[current_state_id];
|
|
|
|
|
|
|
|
if (state->complete) {
|
|
|
|
printk(BIOS_EMERG, "BS: %s state already executed.\n",
|
|
|
|
state->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(BS_DEBUG_LVL, "BS: Entering %s state.\n", state->name);
|
|
|
|
bs_call_callbacks(state, BS_ON_ENTRY);
|
|
|
|
|
|
|
|
current_state_id = state->run_state(state->arg);
|
|
|
|
|
|
|
|
printk(BS_DEBUG_LVL, "BS: Exiting %s state.\n", state->name);
|
|
|
|
bs_call_callbacks(state, BS_ON_EXIT);
|
|
|
|
|
|
|
|
state->complete = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int boot_state_sched_callback(struct boot_state *state,
|
|
|
|
struct boot_state_callback *bscb,
|
|
|
|
boot_state_sequence_t seq)
|
|
|
|
{
|
|
|
|
if (state->complete) {
|
|
|
|
printk(BIOS_WARNING,
|
|
|
|
"Tried to schedule callback on completed state %s.\n",
|
|
|
|
state->name);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bscb->next = state->seq_callbacks[seq];
|
|
|
|
state->seq_callbacks[seq] = bscb;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int boot_state_sched_on_entry(struct boot_state_callback *bscb,
|
|
|
|
boot_state_t state_id)
|
|
|
|
{
|
|
|
|
struct boot_state *state = &boot_states[state_id];
|
|
|
|
|
|
|
|
return boot_state_sched_callback(state, bscb, BS_ON_ENTRY);
|
|
|
|
}
|
|
|
|
|
|
|
|
int boot_state_sched_on_exit(struct boot_state_callback *bscb,
|
|
|
|
boot_state_t state_id)
|
|
|
|
{
|
|
|
|
struct boot_state *state = &boot_states[state_id];
|
|
|
|
|
|
|
|
return boot_state_sched_callback(state, bscb, BS_ON_EXIT);
|
|
|
|
}
|
|
|
|
|
2013-04-24 23:12:52 +02:00
|
|
|
static void boot_state_schedule_static_entries(void)
|
|
|
|
{
|
|
|
|
extern struct boot_state_init_entry _bs_init_begin;
|
|
|
|
extern struct boot_state_init_entry _bs_init_end;
|
|
|
|
struct boot_state_init_entry *cur;
|
|
|
|
|
|
|
|
cur = &_bs_init_begin;
|
|
|
|
|
|
|
|
while (cur != &_bs_init_end) {
|
|
|
|
if (cur->when == BS_ON_ENTRY)
|
|
|
|
boot_state_sched_on_entry(&cur->bscb, cur->state);
|
|
|
|
else
|
|
|
|
boot_state_sched_on_exit(&cur->bscb, cur->state);
|
|
|
|
cur++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
void hardwaremain(int boot_complete)
|
|
|
|
{
|
|
|
|
timestamp_stash(TS_START_RAMSTAGE);
|
|
|
|
post_code(POST_ENTRY_RAMSTAGE);
|
|
|
|
|
|
|
|
#if CONFIG_COVERAGE
|
|
|
|
coverage_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* console_init() MUST PRECEDE ALL printk()! */
|
|
|
|
console_init();
|
|
|
|
|
|
|
|
post_code(POST_CONSOLE_READY);
|
|
|
|
|
|
|
|
printk(BIOS_NOTICE, "coreboot-%s%s %s %s...\n",
|
|
|
|
coreboot_version, coreboot_extra_version, coreboot_build,
|
|
|
|
(boot_complete)?"rebooting":"booting");
|
|
|
|
|
|
|
|
post_code(POST_CONSOLE_BOOT_MSG);
|
|
|
|
|
|
|
|
/* If we have already booted attempt a hard reboot */
|
|
|
|
if (boot_complete) {
|
|
|
|
hard_reset();
|
|
|
|
}
|
|
|
|
|
2013-04-24 23:12:52 +02:00
|
|
|
/* Schedule the static boot state entries. */
|
|
|
|
boot_state_schedule_static_entries();
|
|
|
|
|
2013-04-24 22:14:01 +02:00
|
|
|
/* FIXME: Is there a better way to handle this? */
|
|
|
|
init_timer();
|
|
|
|
|
|
|
|
bs_walk_state_machine(BS_PRE_DEVICE);
|
|
|
|
die("Boot state machine failure.\n");
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|