the following patch was just integrated into master:
commit bf92b19b2a234d63d88fea6bd55ad83361e18574
Author: Hung-Te Lin <hungte(a)chromium.org>
Date: Mon Apr 29 22:11:22 2013 +0800
Google/Snow: Temporary fix for resume failure.
The DDR3 memory initialization (with "mem_reset" set on normal boot) will cause
resume to be unstable, especially when X is running. System may show X screen
for few seconds, then crash randomly and unable to recover - although text
console may still work for a while. Probably caused by corrupted memory pages.
'mem_reset' (which refers to RESET# in DDR3 spec) should be enabled according
to DDR3 spec. But it seems that on Exynos 5, memory can be initialized without
setting mem_reset for both normal boot and resume - at least no known failure
cases are found yet. So this can be a temporary workaround.
Verified by booting a Google/Snow device with X Window and ChromeOS, entering
browser session with fancy web pages, closing LID to suspend for 5 seconds, then
re-opening to resume. Suspend/resume worked as expected.
Also tried the "suspend_stress_test" with X running and finished 100 iterations
of suspend/resume test without failure.
Change-Id: I7185b362ce8b545fe77b35a552245736c89d465e
Signed-off-by: Hung-Te Lin <hungte(a)chromium.org>
Reviewed-on: http://review.coreboot.org/3148
Reviewed-by: Paul Menzel <paulepanter(a)users.sourceforge.net>
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich(a)gmail.com>
Build-Tested: build bot (Jenkins) at Mon Apr 29 20:02:13 2013, giving +1
Reviewed-By: Ronald G. Minnich <rminnich(a)gmail.com> at Tue Apr 30 05:49:42 2013, giving +2
See http://review.coreboot.org/3148 for details.
-gerrit
Aaron Durbin (adurbin(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3149
-gerrit
commit aa8457ab7d13df56ad326fb01f9a9799c8facce5
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Mon Apr 29 13:53:41 2013 -0500
rmodule: put all code/data bits in one section
While debugging a crash it was discovered that ld was inserting
address space for sections that were empty depending on section
address boundaries. This led to the assumption breaking down that
on-disk payload (code/data bits) was contiguous with the address
space. When that assumption breaks down relocation updates change
the wrong memory. Fix this by making the rmodule.ld linker script
put all code/data bits into a payload section.
Change-Id: Ib5df7941bbd64662090136e49d15a570a1c3e041
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/lib/rmodule.ld | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/lib/rmodule.ld b/src/lib/rmodule.ld
index 41d6357..96401a1 100644
--- a/src/lib/rmodule.ld
+++ b/src/lib/rmodule.ld
@@ -35,7 +35,7 @@ SECTIONS
_module_link_start_addr = .;
_payload_begin_offset = LOADADDR(.header) + SIZEOF(.header);
- .text : AT (_payload_begin_offset) {
+ .payload : AT (_payload_begin_offset) {
/* C code of the module. */
*(.textfirst);
*(.text);
@@ -66,27 +66,26 @@ SECTIONS
*(.rodata);
*(.rodata.*);
. = ALIGN(4);
- }
- .module_params : AT (LOADADDR(.text) + SIZEOF(.text)) {
/* The parameters section can be used to pass parameters
* to a module, however there has to be an prior agreement
* on how to interpret the parameters. */
_module_params_begin = .;
*(.module_parameters);
_module_params_end = .;
- . = ALIGN(4);
- }
+ . = ALIGN(8);
- .data : AT (LOADADDR(.module_params) + SIZEOF(.module_params)) {
+ /* Data section. */
_sdata = .;
*(.data);
. = ALIGN(4);
_edata = .;
+
+ . = ALIGN(8);
}
/* _payload_end marks the end of the module's code and data. */
- _payload_end_offset = LOADADDR(.data) + SIZEOF(.data);
+ _payload_end_offset = LOADADDR(.payload) + SIZEOF(.payload);
.bss (NOLOAD) : {
/* C uninitialized data of the module. */
Aaron Durbin (adurbin(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3139
-gerrit
commit c8d9b1597b62da3e2f26550260075d4cefefb97a
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Wed Apr 24 22:59:45 2013 -0500
boot state: rebalance payload load vs actual boot
The notion of loading a payload in the current boot state
machine isn't actually loading the payload. The reason is
that cbfs is just walked to find the payload. The actual
loading and booting were occuring in selfboot(). Change this
balance so that loading occurs in one function and actual
booting happens in another. This allows for ample opportunity
to delay work until just before booting.
Change-Id: Ic91ed6050fc5d8bb90c8c33a44eea3b1ec84e32d
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/include/cbfs.h | 3 ++-
src/lib/hardwaremain.c | 12 +++++++++---
src/lib/selfboot.c | 18 +++++++++++-------
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/include/cbfs.h b/src/include/cbfs.h
index ac249aa..c0098ea 100644
--- a/src/include/cbfs.h
+++ b/src/include/cbfs.h
@@ -78,7 +78,8 @@ int run_address(void *f);
/* Defined in src/lib/selfboot.c */
struct lb_memory;
-int selfboot(struct lb_memory *mem, struct cbfs_payload *payload);
+void *selfload(struct lb_memory *mem, struct cbfs_payload *payload);
+void selfboot(void *entry);
/* Defined in individual arch / board implementation. */
int init_default_cbfs_media(struct cbfs_media *media);
diff --git a/src/lib/hardwaremain.c b/src/lib/hardwaremain.c
index adee3ca..ed2a516 100644
--- a/src/lib/hardwaremain.c
+++ b/src/lib/hardwaremain.c
@@ -198,6 +198,7 @@ static boot_state_t bs_write_tables(void *arg)
static boot_state_t bs_payload_load(void *arg)
{
void *payload;
+ void *entry;
timestamp_add_now(TS_LOAD_PAYLOAD);
@@ -206,15 +207,20 @@ static boot_state_t bs_payload_load(void *arg)
if (! payload)
die("Could not find a payload\n");
+ entry = selfload(get_lb_mem(), payload);
+
+ if (! entry)
+ die("Could not load payload\n");
+
/* Pass the payload to the next state. */
- boot_states[BS_PAYLOAD_BOOT].arg = payload;
+ boot_states[BS_PAYLOAD_BOOT].arg = entry;
return BS_PAYLOAD_BOOT;
}
-static boot_state_t bs_payload_boot(void *payload)
+static boot_state_t bs_payload_boot(void *entry)
{
- selfboot(get_lb_mem(), payload);
+ selfboot(entry);
printk(BIOS_EMERG, "Boot failed");
/* Returning from this state will fail because the following signals
diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c
index 324d43e..4ebe109 100644
--- a/src/lib/selfboot.c
+++ b/src/lib/selfboot.c
@@ -512,7 +512,7 @@ static int load_self_segments(
return 1;
}
-int selfboot(struct lb_memory *mem, struct cbfs_payload *payload)
+void *selfload(struct lb_memory *mem, struct cbfs_payload *payload)
{
u32 entry=0;
struct segment head;
@@ -527,10 +527,18 @@ int selfboot(struct lb_memory *mem, struct cbfs_payload *payload)
printk(BIOS_SPEW, "Loaded segments\n");
+ return (void *)entry;
+
+out:
+ return NULL;
+}
+
+void selfboot(void *entry)
+{
/* Reset to booting from this image as late as possible */
boot_successful();
- printk(BIOS_DEBUG, "Jumping to boot code at %x\n", entry);
+ printk(BIOS_DEBUG, "Jumping to boot code at %p\n", entry);
post_code(POST_ENTER_ELF_BOOT);
#if CONFIG_COLLECT_TIMESTAMPS
@@ -543,9 +551,5 @@ int selfboot(struct lb_memory *mem, struct cbfs_payload *payload)
checkstack(_estack, 0);
/* Jump to kernel */
- jmp_to_elf_entry((void*)entry, bounce_buffer, bounce_size);
- return 1;
-
-out:
- return 0;
+ jmp_to_elf_entry(entry, bounce_buffer, bounce_size);
}
Aaron Durbin (adurbin(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3138
-gerrit
commit 3517ccdb0d5061c26b547a34bf8b3d7027d5c60d
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Wed Apr 24 20:59:43 2013 -0500
x86: use boot state callbacks to disable rom cache
On x86 systems there is a concept of cachings the ROM. However,
the typical policy is that the boot cpu is the only one with
it enabled. In order to ensure the MTRRs are the same across cores
the rom cache needs to be disabled prior to OS resume or boot handoff.
Therefore, utilize the boot state callbacks to schedule the disabling
of the ROM cache at the ramstage exit points.
Change-Id: I4da5886d9f1cf4c6af2f09bb909f0d0f0faa4e62
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/arch/x86/boot/acpi.c | 3 ---
src/cpu/x86/mtrr/mtrr.c | 10 +++++++++-
src/include/cpu/cpu.h | 3 ---
src/lib/selfboot.c | 4 ----
4 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/src/arch/x86/boot/acpi.c b/src/arch/x86/boot/acpi.c
index a3bf718..3b77caa 100644
--- a/src/arch/x86/boot/acpi.c
+++ b/src/arch/x86/boot/acpi.c
@@ -637,9 +637,6 @@ void acpi_resume(void *wake_vec)
/* Call mainboard resume handler first, if defined. */
if (mainboard_suspend_resume)
mainboard_suspend_resume();
- /* Tear down the caching of the ROM. */
- if (disable_cache_rom)
- disable_cache_rom();
post_code(POST_OS_RESUME);
acpi_jump_to_wakeup(wake_vec);
diff --git a/src/cpu/x86/mtrr/mtrr.c b/src/cpu/x86/mtrr/mtrr.c
index 6089127..b69787b 100644
--- a/src/cpu/x86/mtrr/mtrr.c
+++ b/src/cpu/x86/mtrr/mtrr.c
@@ -27,6 +27,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
+#include <bootstate.h>
#include <console/console.h>
#include <device/device.h>
#include <cpu/cpu.h>
@@ -408,10 +409,17 @@ void x86_mtrr_disable_rom_caching(void)
enable_cache();
}
-void disable_cache_rom(void)
+static void disable_cache_rom(void *unused)
{
x86_mtrr_disable_rom_caching();
}
+
+BOOT_STATE_INIT_ENTRIES(disable_rom_cache_bscb) = {
+ BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY,
+ disable_cache_rom, NULL),
+ BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
+ disable_cache_rom, NULL),
+};
#endif
struct var_mtrr_state {
diff --git a/src/include/cpu/cpu.h b/src/include/cpu/cpu.h
index a2272f3..bed77de 100644
--- a/src/include/cpu/cpu.h
+++ b/src/include/cpu/cpu.h
@@ -9,9 +9,6 @@ struct bus;
void initialize_cpus(struct bus *cpu_bus);
void asmlinkage secondary_cpu_init(unsigned int cpu_index);
-/* If a ROM cache was set up disable it before jumping to the payload or OS. */
-void __attribute__((weak)) disable_cache_rom(void);
-
#if CONFIG_HAVE_SMI_HANDLER
void smm_init(void);
void smm_lock(void);
diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c
index 934c131..324d43e 100644
--- a/src/lib/selfboot.c
+++ b/src/lib/selfboot.c
@@ -537,10 +537,6 @@ int selfboot(struct lb_memory *mem, struct cbfs_payload *payload)
timestamp_add_now(TS_SELFBOOT_JUMP);
#endif
- /* Tear down the caching of the ROM. */
- if (disable_cache_rom)
- disable_cache_rom();
-
/* Before we go off to run the payload, see if
* we stayed within our bounds.
*/
Aaron Durbin (adurbin(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3132
-gerrit
commit 4f14eda6e1dbfdd8b70c820b5c5ab784ee63ef62
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Wed Apr 24 15:14:01 2013 -0500
ramstage: introduce boot state machine
The boot flow currently has a fixed ordering. The ordering
is dictated by the device tree and on x86 the PCI device ordering
for when actions are performed. Many of the new machines and
configurations have dependencies that do not follow the device
ordering.
In order to be more flexible the concept of a boot state machine
is introduced. At the boundaries (entry and exit) of each state there
is opportunity to run callbacks. This ability allows one to schedule
actions to be performed without adding board-specific code to
the shared boot flow.
Change-Id: I757f406c97445f6d9b69c003bb9610b16b132aa6
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/include/bootstate.h | 161 ++++++++++++++++++++++++++
src/lib/hardwaremain.c | 300 ++++++++++++++++++++++++++++++++++++++----------
2 files changed, 401 insertions(+), 60 deletions(-)
diff --git a/src/include/bootstate.h b/src/include/bootstate.h
new file mode 100644
index 0000000..a2eacfb
--- /dev/null
+++ b/src/include/bootstate.h
@@ -0,0 +1,161 @@
+/*
+ * 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
+ */
+#ifndef BOOTSTATE_H
+#define BOOTSTATE_H
+
+#include <string.h>
+
+/* Control debugging of the boot state machine. */
+#define BOOT_STATE_DEBUG 0
+
+/*
+ * The boot state machine provides a mechanism for calls to be made through-
+ * out the main boot process. The boot process is separated into discrete
+ * states. Upon a state's entry and exit and callbacks can be made. For
+ * example:
+ *
+ * Enter State
+ * +
+ * |
+ * V
+ * +-----------------+
+ * | Entry callbacks |
+ * +-----------------+
+ * | State Actions |
+ * +-----------------+
+ * | Exit callbacks |
+ * +-------+---------+
+ * |
+ * V
+ * Next State
+ *
+ * Below is the current flow from top to bottom:
+ *
+ * start
+ * |
+ * BS_PRE_DEVICE
+ * |
+ * BS_DEV_INIT_CHIPS
+ * |
+ * BS_DEV_ENUMERATE
+ * |
+ * BS_DEV_RESOURCES
+ * |
+ * BS_DEV_ENABLE
+ * |
+ * BS_DEV_INIT
+ * |
+ * BS_POST_DEVICE
+ * |
+ * BS_OS_RESUME_CHECK -------- BS_OS_RESUME
+ * | |
+ * BS_WRITE_TABLES os handoff
+ * |
+ * BS_PAYLOAD_LOAD
+ * |
+ * BS_PAYLOAD_BOOT
+ * |
+ * payload run
+ *
+ * Brief description of states:
+ * BS_PRE_DEVICE - before any device tree actions take place
+ * BS_DEV_INIT_CHIPS - init all chips in device tree
+ * BS_DEV_ENUMERATE - device tree probing
+ * BS_DEV_RESOURCES - device tree resource allocation and assignment
+ * BS_DEV_ENABLE - device tree enabling/disabling of devices
+ * BS_DEV_INIT - device tree device initialization
+ * BS_POST_DEVICE - all device tree actions performed
+ * BS_OS_RESUME_CHECK - check for OS resume
+ * BS_OS_RESUME - resume to OS
+ * BS_WRITE_TABLES - write coreboot tables
+ * BS_PAYLOAD_LOAD - Load payload into memory
+ * BS_PAYLOAD_BOOT - Boot to payload
+ */
+
+typedef enum {
+ BS_PRE_DEVICE,
+ BS_DEV_INIT_CHIPS,
+ BS_DEV_ENUMERATE,
+ BS_DEV_RESOURCES,
+ BS_DEV_ENABLE,
+ BS_DEV_INIT,
+ BS_POST_DEVICE,
+ BS_OS_RESUME,
+ BS_WRITE_TABLES,
+ BS_PAYLOAD_LOAD,
+ BS_PAYLOAD_BOOT,
+} boot_state_t;
+
+/* The boot_state_sequence_t describes when a callback is to be made. It is
+ * called either before a state is entered or when a state is exited. */
+typedef enum {
+ BS_ON_ENTRY,
+ BS_ON_EXIT
+} boot_state_sequence_t;
+
+struct boot_state_callback {
+ void *arg;
+ void (*callback)(void *arg);
+ /* For use internal to the boot state machine. */
+ struct boot_state_callback *next;
+#if BOOT_STATE_DEBUG
+ const char *location;
+#endif
+};
+
+#if BOOT_STATE_DEBUG
+#define BOOT_STATE_CALLBACK_LOC __FILE__ ":" STRINGIFY(__LINE__)
+#define BOOT_STATE_CALLBACK_INIT_DEBUG .location = BOOT_STATE_CALLBACK_LOC,
+#define INIT_BOOT_STATE_CALLBACK_DEBUG(bscb_) \
+ bscb_->location = BOOT_STATE_CALLBACK_LOC;
+#else
+#define BOOT_STATE_CALLBACK_INIT_DEBUG
+#define INIT_BOOT_STATE_CALLBACK_DEBUG(bscb_)
+#endif
+
+#define BOOT_STATE_CALLBACK_INIT(func_, arg_) \
+ { \
+ .arg = arg_, \
+ .callback = func_, \
+ .next = NULL, \
+ BOOT_STATE_CALLBACK_INIT_DEBUG \
+ }
+
+#define BOOT_STATE_CALLBACK(name_, func_, arg_) \
+ struct boot_state_callback name_ = BOOT_STATE_CALLBACK_INIT(func_, arg_)
+
+/* Initialize an allocated boot_state_callback. */
+#define INIT_BOOT_STATE_CALLBACK(bscb_, func_, arg_) \
+ INIT_BOOT_STATE_CALLBACK_DEBUG(bscb_) \
+ bscb_->callback = func_; \
+ bscb_->arg = arg_
+
+/* The following 2 functions schedule a callback to be called on entry/exit
+ * to a given state. Note that thare are no ordering guarantees between the
+ * individual callbacks on a given state. 0 is returned on success < 0 on
+ * error. */
+int boot_state_sched_on_entry(struct boot_state_callback *bscb,
+ boot_state_t state);
+int boot_state_sched_on_exit(struct boot_state_callback *bscb,
+ boot_state_t state);
+
+/* Entry into the boot state machine. */
+void hardwaremain(int boot_complete);
+
+#endif /* BOOTSTATE_H */
diff --git a/src/lib/hardwaremain.c b/src/lib/hardwaremain.c
index a3ee10b..dba47a7 100644
--- a/src/lib/hardwaremain.c
+++ b/src/lib/hardwaremain.c
@@ -1,23 +1,20 @@
/*
-This software and ancillary information (herein called SOFTWARE )
-called LinuxBIOS is made available under the terms described
-here. The SOFTWARE has been approved for release with associated
-LA-CC Number 00-34 . Unless otherwise indicated, this SOFTWARE has
-been authored by an employee or employees of the University of
-California, operator of the Los Alamos National Laboratory under
-Contract No. W-7405-ENG-36 with the U.S. Department of Energy. The
-U.S. Government has rights to use, reproduce, and distribute this
-SOFTWARE. The public may copy, distribute, prepare derivative works
-and publicly display this SOFTWARE without charge, provided that this
-Notice and any statement of authorship are reproduced on all copies.
-Neither the Government nor the University makes any warranty, express
-or implied, or assumes any liability or responsibility for the use of
-this SOFTWARE. If SOFTWARE is modified to produce derivative works,
-such modified SOFTWARE should be clearly marked, so as not to confuse
-it with the version available from LANL.
- */
-/* Copyright 2000, Ron Minnich, Advanced Computing Lab, LANL
- * rminnich(a)lanl.gov
+ * 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
*/
@@ -25,6 +22,7 @@ it with the version available from LANL.
* C Bootstrap code for the coreboot
*/
+#include <bootstate.h>
#include <console/console.h>
#include <version.h>
#include <device/device.h>
@@ -43,80 +41,127 @@ it with the version available from LANL.
#include <coverage.h>
#include <timestamp.h>
-/**
- * @brief Main function of the RAM part of coreboot.
- *
- * Coreboot is divided into Pre-RAM part and RAM part.
- *
- * Device Enumeration:
- * In the dev_enumerate() phase,
- */
-
-void hardwaremain(int boot_complete);
-
-void hardwaremain(int boot_complete)
-{
- struct lb_memory *lb_mem;
- void *payload;
-
- timestamp_stash(TS_START_RAMSTAGE);
- post_code(POST_ENTRY_RAMSTAGE);
-
-#if CONFIG_COVERAGE
- coverage_init();
+#if BOOT_STATE_DEBUG
+#define BS_DEBUG_LVL BIOS_DEBUG
+#else
+#define BS_DEBUG_LVL BIOS_NEVER
#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();
+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 \
}
-
- /* FIXME: Is there a better way to handle this? */
- init_timer();
-
+#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)
+{
init_cbmem_pre_device();
+ return BS_DEV_INIT_CHIPS;
+}
+static boot_state_t bs_dev_init_chips(void *arg)
+{
timestamp_stash(TS_DEVICE_ENUMERATE);
/* Initialize chips early, they might disable unused devices. */
dev_initialize_chips();
+ return BS_DEV_ENUMERATE;
+}
+
+static boot_state_t bs_dev_enumerate(void *arg)
+{
/* Find the devices we don't have hard coded knowledge about. */
dev_enumerate();
post_code(POST_DEVICE_ENUMERATION_COMPLETE);
+ return BS_DEV_RESOURCES;
+}
+
+static boot_state_t bs_dev_resources(void *arg)
+{
timestamp_stash(TS_DEVICE_CONFIGURE);
/* Now compute and assign the bus resources. */
dev_configure();
post_code(POST_DEVICE_CONFIGURATION_COMPLETE);
+ return BS_DEV_ENABLE;
+}
+
+static boot_state_t bs_dev_eanble(void *arg)
+{
timestamp_stash(TS_DEVICE_ENABLE);
/* Now actually enable devices on the bus */
dev_enable();
post_code(POST_DEVICES_ENABLED);
+ return BS_DEV_INIT;
+}
+
+static boot_state_t bs_dev_init(void *arg)
+{
timestamp_stash(TS_DEVICE_INITIALIZE);
/* And of course initialize devices on the bus */
dev_initialize();
post_code(POST_DEVICES_INITIALIZED);
+ return BS_POST_DEVICE;
+}
+
+static boot_state_t bs_post_device(void *arg)
+{
timestamp_stash(TS_DEVICE_DONE);
init_cbmem_post_device();
timestamp_sync();
+ return BS_OS_RESUME;
+}
+
+static boot_state_t bs_os_resume(void *arg)
+{
#if CONFIG_HAVE_ACPI_RESUME
suspend_resume();
post_code(0x8a);
@@ -124,6 +169,11 @@ void hardwaremain(int boot_complete)
timestamp_add_now(TS_CBMEM_POST);
+ return BS_WRITE_TABLES;
+}
+
+static boot_state_t bs_write_tables(void *arg)
+{
if (cbmem_post_handling)
cbmem_post_handling();
@@ -132,7 +182,14 @@ void hardwaremain(int boot_complete)
/* Now that we have collected all of our information
* write our configuration tables.
*/
- lb_mem = write_tables();
+ write_tables();
+
+ return BS_PAYLOAD_LOAD;
+}
+
+static boot_state_t bs_payload_load(void *arg)
+{
+ void *payload;
timestamp_add_now(TS_LOAD_PAYLOAD);
@@ -141,7 +198,130 @@ void hardwaremain(int boot_complete)
if (! payload)
die("Could not find a payload\n");
- selfboot(lb_mem, payload);
+ /* 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);
+
printk(BIOS_EMERG, "Boot failed");
+ /* 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);
+}
+
+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();
+ }
+
+ /* FIXME: Is there a better way to handle this? */
+ init_timer();
+
+ bs_walk_state_machine(BS_PRE_DEVICE);
+ die("Boot state machine failure.\n");
}
Aaron Durbin (adurbin(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3135
-gerrit
commit 5537a6c6f81def324064eb676dd0df4a3ffdb49f
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Wed Apr 24 16:28:52 2013 -0500
coverage: use boot state callbacks
Utilize the static boot state callback scheduling to initialize
and tear down the coverage infrastructure at the appropriate points.
The coverage initialization is performed at BS_PRE_DEVICE which is the
earliest point a callback can be called. The tear down occurs at the
2 exit points of ramstage: OS resume and payload boot.
Change-Id: Ie5ee51268e1f473f98fa517710a266e38dc01b6d
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/arch/x86/boot/acpi.c | 4 ----
src/include/coverage.h | 21 ---------------------
src/lib/gcov-glue.c | 12 ++++++++----
src/lib/hardwaremain.c | 5 -----
src/lib/selfboot.c | 4 ----
5 files changed, 8 insertions(+), 38 deletions(-)
diff --git a/src/arch/x86/boot/acpi.c b/src/arch/x86/boot/acpi.c
index 1c373ac..a3bf718 100644
--- a/src/arch/x86/boot/acpi.c
+++ b/src/arch/x86/boot/acpi.c
@@ -36,7 +36,6 @@
#if CONFIG_COLLECT_TIMESTAMPS
#include <timestamp.h>
#endif
-#include <coverage.h>
/* FIXME: Kconfig doesn't support overridable defaults :-( */
#ifndef CONFIG_HPET_MIN_TICKS
@@ -638,9 +637,6 @@ void acpi_resume(void *wake_vec)
/* Call mainboard resume handler first, if defined. */
if (mainboard_suspend_resume)
mainboard_suspend_resume();
-#if CONFIG_COVERAGE
- coverage_exit();
-#endif
/* Tear down the caching of the ROM. */
if (disable_cache_rom)
disable_cache_rom();
diff --git a/src/include/coverage.h b/src/include/coverage.h
deleted file mode 100644
index e1c50c5..0000000
--- a/src/include/coverage.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2012 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
- */
-
-void coverage_init(void);
-void coverage_exit(void);
diff --git a/src/lib/gcov-glue.c b/src/lib/gcov-glue.c
index 4e2b290..ab9062b 100644
--- a/src/lib/gcov-glue.c
+++ b/src/lib/gcov-glue.c
@@ -18,8 +18,8 @@
*/
#include <stdint.h>
+#include <bootstate.h>
#include <cbmem.h>
-#include <coverage.h>
typedef struct file {
uint32_t magic;
@@ -128,7 +128,7 @@ static void setbuf(FILE *stream, char *buf)
gcc_assert(buf == 0);
}
-void coverage_init(void)
+static void coverage_init(void *unused)
{
extern long __CTOR_LIST__;
typedef void (*func_ptr)(void) ;
@@ -142,7 +142,7 @@ void coverage_init(void)
}
void __gcov_flush(void);
-void coverage_exit(void)
+static void coverage_exit(void *unused)
{
#if CONFIG_DEBUG_COVERAGE
printk(BIOS_DEBUG, "Syncing coverage data.\n");
@@ -150,4 +150,8 @@ void coverage_exit(void)
__gcov_flush();
}
-
+BOOT_STATE_INIT_ENTRIES(gcov_bscb) = {
+ BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, coverage_init, NULL),
+ BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, coverage_exit, NULL),
+ BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, coverage_exit, NULL),
+};
diff --git a/src/lib/hardwaremain.c b/src/lib/hardwaremain.c
index d8b9d43..e4b2659 100644
--- a/src/lib/hardwaremain.c
+++ b/src/lib/hardwaremain.c
@@ -38,7 +38,6 @@
#include <arch/acpi.h>
#endif
#include <cbmem.h>
-#include <coverage.h>
#include <timestamp.h>
#if BOOT_STATE_DEBUG
@@ -331,10 +330,6 @@ 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();
diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c
index be03b85..934c131 100644
--- a/src/lib/selfboot.c
+++ b/src/lib/selfboot.c
@@ -33,7 +33,6 @@
#if CONFIG_COLLECT_TIMESTAMPS
#include <timestamp.h>
#endif
-#include <coverage.h>
/* Maximum physical address we can use for the coreboot bounce buffer. */
#ifndef MAX_ADDR
@@ -537,9 +536,6 @@ int selfboot(struct lb_memory *mem, struct cbfs_payload *payload)
#if CONFIG_COLLECT_TIMESTAMPS
timestamp_add_now(TS_SELFBOOT_JUMP);
#endif
-#if CONFIG_COVERAGE
- coverage_exit();
-#endif
/* Tear down the caching of the ROM. */
if (disable_cache_rom)