blob: 565d619a3ead57cf739722e8bc012b74502b0ae5 [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Stefan Reinauer52db0b92012-12-07 17:15:04 -08003
Julius Werner85620db2013-11-13 18:22:15 -08004#include <arch/exception.h>
Gabe Black8b685392013-09-29 03:02:55 -07005#include <bootblock_common.h>
Hung-Te Linb868d402013-02-06 22:01:18 +08006#include <console/console.h>
Julius Werner44cf8702014-12-08 13:39:14 -08007#include <delay.h>
Kyösti Mälkkib2680a12020-01-04 18:04:39 +02008#include <option.h>
Aaron Durbin49342cd2017-01-05 10:07:19 -06009#include <pc80/mc146818rtc.h>
Aaron Durbinf5d7f602015-03-17 13:20:02 -050010#include <program_loading.h>
Julius Werner8c093772016-02-09 16:09:15 -080011#include <symbols.h>
Elyes HAOUASb5622442019-07-11 09:22:02 +020012#include <timestamp.h>
David Hendricks50c0a502013-01-31 17:05:50 -080013
Julius Werner8c093772016-02-09 16:09:15 -080014DECLARE_OPTIONAL_REGION(timestamp);
15
Aaron Durbin64031672018-04-21 14:45:32 -060016__weak void bootblock_mainboard_early_init(void) { /* no-op */ }
17__weak void bootblock_soc_early_init(void) { /* do nothing */ }
18__weak void bootblock_soc_init(void) { /* do nothing */ }
19__weak void bootblock_mainboard_init(void) { /* do nothing */ }
Vadim Bendebury0b341b32014-04-23 11:09:44 -070020
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030021/*
22 * This is a the same as the bootblock main(), with the difference that it does
23 * not collect a timestamp. Instead it accepts the initial timestamp and
24 * possibly additional timestamp entries as arguments. This can be used in cases
25 * where earlier stamps are available. Note that this function is designed to be
26 * entered from C code. This function assumes that the timer has already been
27 * initialized, so it does not call init_timer().
28 */
29static void bootblock_main_with_timestamp(uint64_t base_timestamp,
Julius Werner12574dd2018-05-15 17:48:30 -070030 struct timestamp_entry *timestamps, size_t num_timestamps)
Stefan Reinauer52db0b92012-12-07 17:15:04 -080031{
Julius Werner8c093772016-02-09 16:09:15 -080032 /* Initialize timestamps if we have TIMESTAMP region in memlayout.ld. */
Julius Wernercd49cce2019-03-05 16:53:33 -080033 if (CONFIG(COLLECT_TIMESTAMPS) &&
Julius Werner7e0dea62019-02-20 18:39:22 -080034 REGION_SIZE(timestamp) > 0) {
Julius Werner12574dd2018-05-15 17:48:30 -070035 int i;
Alexandru Gagniucff196b62016-05-16 16:17:39 -070036 timestamp_init(base_timestamp);
Julius Werner12574dd2018-05-15 17:48:30 -070037 for (i = 0; i < num_timestamps; i++)
38 timestamp_add(timestamps[i].entry_id,
39 timestamps[i].entry_stamp);
40 }
Julius Werner44cf8702014-12-08 13:39:14 -080041
Kyösti Mälkkife3250d2019-11-03 08:18:15 +020042 timestamp_add_now(TS_START_BOOTBLOCK);
43
Aaron Durbinbe7cbdc2016-02-24 18:56:00 -060044 bootblock_soc_early_init();
Julius Wernerf1e32102014-11-25 13:22:20 -080045 bootblock_mainboard_early_init();
David Hendricks3d7344a2013-01-08 21:05:06 -080046
Kyösti Mälkki731e58e2020-01-04 13:00:02 +020047 if (CONFIG(USE_OPTION_TABLE))
48 sanitize_cmos();
Kyösti Mälkkibb5b9fe2020-01-04 13:00:02 +020049
50 if (CONFIG(CMOS_POST))
51 cmos_post_init();
Nico Hubere0b9aea2019-01-28 18:14:13 +010052
Julius Wernercd49cce2019-03-05 16:53:33 -080053 if (CONFIG(BOOTBLOCK_CONSOLE)) {
Julius Werner86fc11d2015-10-09 13:37:58 -070054 console_init();
55 exception_init();
56 }
Stefan Reinauer919c8042013-05-16 10:57:15 -070057
Julius Wernerf1e32102014-11-25 13:22:20 -080058 bootblock_soc_init();
59 bootblock_mainboard_init();
60
Kyösti Mälkkife3250d2019-11-03 08:18:15 +020061 timestamp_add_now(TS_END_BOOTBLOCK);
62
Aaron Durbinf5d7f602015-03-17 13:20:02 -050063 run_romstage();
Stefan Reinauer52db0b92012-12-07 17:15:04 -080064}
Alexandru Gagniucff196b62016-05-16 16:17:39 -070065
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030066void bootblock_main_with_basetime(uint64_t base_timestamp)
67{
68 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
69}
70
Alexandru Gagniucff196b62016-05-16 16:17:39 -070071void main(void)
72{
73 uint64_t base_timestamp = 0;
74
75 init_timer();
76
Julius Wernercd49cce2019-03-05 16:53:33 -080077 if (CONFIG(COLLECT_TIMESTAMPS))
Alexandru Gagniucff196b62016-05-16 16:17:39 -070078 base_timestamp = timestamp_get();
79
Julius Werner12574dd2018-05-15 17:48:30 -070080 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
Alexandru Gagniucff196b62016-05-16 16:17:39 -070081}
Julius Werner99f46832018-05-16 14:14:04 -070082
Julius Wernercd49cce2019-03-05 16:53:33 -080083#if CONFIG(COMPRESS_BOOTBLOCK)
Julius Werner99f46832018-05-16 14:14:04 -070084/*
85 * This is the bootblock entry point when it is run after a decompressor stage.
86 * For non-decompressor builds, _start is generally defined in architecture-
87 * specific assembly code. In decompressor builds that architecture
88 * initialization code already ran in the decompressor, so the bootblock can
89 * start straight into common code with a C environment.
90 */
91void _start(struct bootblock_arg *arg);
92void _start(struct bootblock_arg *arg)
93{
94 bootblock_main_with_timestamp(arg->base_timestamp, arg->timestamps,
95 arg->num_timestamps);
96}
97
98#endif