blob: 386f4e38d712885e0311307c563bced9972067e4 [file] [log] [blame]
Stefan Reinauer52db0b92012-12-07 17:15:04 -08001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer08dc3572013-05-14 16:57:50 -07004 * Copyright 2010 Google Inc.
Stefan Reinauer52db0b92012-12-07 17:15:04 -08005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Stefan Reinauer52db0b92012-12-07 17:15:04 -080015 */
16
Julius Werner85620db2013-11-13 18:22:15 -080017#include <arch/exception.h>
Gabe Black8b685392013-09-29 03:02:55 -070018#include <bootblock_common.h>
Hung-Te Linb868d402013-02-06 22:01:18 +080019#include <console/console.h>
Julius Werner44cf8702014-12-08 13:39:14 -080020#include <delay.h>
Kyösti Mälkkib2680a12020-01-04 18:04:39 +020021#include <option.h>
Aaron Durbin49342cd2017-01-05 10:07:19 -060022#include <pc80/mc146818rtc.h>
Aaron Durbinf5d7f602015-03-17 13:20:02 -050023#include <program_loading.h>
Julius Werner8c093772016-02-09 16:09:15 -080024#include <symbols.h>
Elyes HAOUASb5622442019-07-11 09:22:02 +020025#include <timestamp.h>
David Hendricks50c0a502013-01-31 17:05:50 -080026
Julius Werner8c093772016-02-09 16:09:15 -080027DECLARE_OPTIONAL_REGION(timestamp);
28
Aaron Durbin64031672018-04-21 14:45:32 -060029__weak void bootblock_mainboard_early_init(void) { /* no-op */ }
30__weak void bootblock_soc_early_init(void) { /* do nothing */ }
31__weak void bootblock_soc_init(void) { /* do nothing */ }
32__weak void bootblock_mainboard_init(void) { /* do nothing */ }
Vadim Bendebury0b341b32014-04-23 11:09:44 -070033
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030034/*
35 * This is a the same as the bootblock main(), with the difference that it does
36 * not collect a timestamp. Instead it accepts the initial timestamp and
37 * possibly additional timestamp entries as arguments. This can be used in cases
38 * where earlier stamps are available. Note that this function is designed to be
39 * entered from C code. This function assumes that the timer has already been
40 * initialized, so it does not call init_timer().
41 */
42static void bootblock_main_with_timestamp(uint64_t base_timestamp,
Julius Werner12574dd2018-05-15 17:48:30 -070043 struct timestamp_entry *timestamps, size_t num_timestamps)
Stefan Reinauer52db0b92012-12-07 17:15:04 -080044{
Julius Werner8c093772016-02-09 16:09:15 -080045 /* Initialize timestamps if we have TIMESTAMP region in memlayout.ld. */
Julius Wernercd49cce2019-03-05 16:53:33 -080046 if (CONFIG(COLLECT_TIMESTAMPS) &&
Julius Werner7e0dea62019-02-20 18:39:22 -080047 REGION_SIZE(timestamp) > 0) {
Julius Werner12574dd2018-05-15 17:48:30 -070048 int i;
Alexandru Gagniucff196b62016-05-16 16:17:39 -070049 timestamp_init(base_timestamp);
Julius Werner12574dd2018-05-15 17:48:30 -070050 for (i = 0; i < num_timestamps; i++)
51 timestamp_add(timestamps[i].entry_id,
52 timestamps[i].entry_stamp);
53 }
Julius Werner44cf8702014-12-08 13:39:14 -080054
Kyösti Mälkkife3250d2019-11-03 08:18:15 +020055 timestamp_add_now(TS_START_BOOTBLOCK);
56
Aaron Durbinbe7cbdc2016-02-24 18:56:00 -060057 bootblock_soc_early_init();
Julius Wernerf1e32102014-11-25 13:22:20 -080058 bootblock_mainboard_early_init();
David Hendricks3d7344a2013-01-08 21:05:06 -080059
Kyösti Mälkki731e58e2020-01-04 13:00:02 +020060 if (CONFIG(USE_OPTION_TABLE))
61 sanitize_cmos();
Kyösti Mälkkibb5b9fe2020-01-04 13:00:02 +020062
63 if (CONFIG(CMOS_POST))
64 cmos_post_init();
Nico Hubere0b9aea2019-01-28 18:14:13 +010065
Julius Wernercd49cce2019-03-05 16:53:33 -080066 if (CONFIG(BOOTBLOCK_CONSOLE)) {
Julius Werner86fc11d2015-10-09 13:37:58 -070067 console_init();
68 exception_init();
69 }
Stefan Reinauer919c8042013-05-16 10:57:15 -070070
Julius Wernerf1e32102014-11-25 13:22:20 -080071 bootblock_soc_init();
72 bootblock_mainboard_init();
73
Kyösti Mälkkife3250d2019-11-03 08:18:15 +020074 timestamp_add_now(TS_END_BOOTBLOCK);
75
Aaron Durbinf5d7f602015-03-17 13:20:02 -050076 run_romstage();
Stefan Reinauer52db0b92012-12-07 17:15:04 -080077}
Alexandru Gagniucff196b62016-05-16 16:17:39 -070078
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030079void bootblock_main_with_basetime(uint64_t base_timestamp)
80{
81 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
82}
83
Alexandru Gagniucff196b62016-05-16 16:17:39 -070084void main(void)
85{
86 uint64_t base_timestamp = 0;
87
88 init_timer();
89
Julius Wernercd49cce2019-03-05 16:53:33 -080090 if (CONFIG(COLLECT_TIMESTAMPS))
Alexandru Gagniucff196b62016-05-16 16:17:39 -070091 base_timestamp = timestamp_get();
92
Julius Werner12574dd2018-05-15 17:48:30 -070093 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
Alexandru Gagniucff196b62016-05-16 16:17:39 -070094}
Julius Werner99f46832018-05-16 14:14:04 -070095
Julius Wernercd49cce2019-03-05 16:53:33 -080096#if CONFIG(COMPRESS_BOOTBLOCK)
Julius Werner99f46832018-05-16 14:14:04 -070097/*
98 * This is the bootblock entry point when it is run after a decompressor stage.
99 * For non-decompressor builds, _start is generally defined in architecture-
100 * specific assembly code. In decompressor builds that architecture
101 * initialization code already ran in the decompressor, so the bootblock can
102 * start straight into common code with a C environment.
103 */
104void _start(struct bootblock_arg *arg);
105void _start(struct bootblock_arg *arg)
106{
107 bootblock_main_with_timestamp(arg->base_timestamp, arg->timestamps,
108 arg->num_timestamps);
109}
110
111#endif