blob: 1509c8cb59946745e193796b2806c40c9b5dd121 [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer52db0b92012-12-07 17:15:04 -08002
Julius Werner85620db2013-11-13 18:22:15 -08003#include <arch/exception.h>
Gabe Black8b685392013-09-29 03:02:55 -07004#include <bootblock_common.h>
Hung-Te Linb868d402013-02-06 22:01:18 +08005#include <console/console.h>
Julius Werner44cf8702014-12-08 13:39:14 -08006#include <delay.h>
Kyösti Mälkkib2680a12020-01-04 18:04:39 +02007#include <option.h>
Kyösti Mälkkice39ba92020-01-04 16:15:50 +02008#include <post.h>
Aaron Durbinf5d7f602015-03-17 13:20:02 -05009#include <program_loading.h>
Julius Werner8c093772016-02-09 16:09:15 -080010#include <symbols.h>
Elyes HAOUASb5622442019-07-11 09:22:02 +020011#include <timestamp.h>
David Hendricks50c0a502013-01-31 17:05:50 -080012
Aaron Durbin64031672018-04-21 14:45:32 -060013__weak void bootblock_mainboard_early_init(void) { /* no-op */ }
14__weak void bootblock_soc_early_init(void) { /* do nothing */ }
15__weak void bootblock_soc_init(void) { /* do nothing */ }
16__weak void bootblock_mainboard_init(void) { /* do nothing */ }
Vadim Bendebury0b341b32014-04-23 11:09:44 -070017
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030018/*
19 * This is a the same as the bootblock main(), with the difference that it does
20 * not collect a timestamp. Instead it accepts the initial timestamp and
21 * possibly additional timestamp entries as arguments. This can be used in cases
22 * where earlier stamps are available. Note that this function is designed to be
23 * entered from C code. This function assumes that the timer has already been
24 * initialized, so it does not call init_timer().
25 */
Kangheui Won18582232020-09-17 16:49:40 +100026void bootblock_main_with_timestamp(uint64_t base_timestamp,
Julius Werner12574dd2018-05-15 17:48:30 -070027 struct timestamp_entry *timestamps, size_t num_timestamps)
Stefan Reinauer52db0b92012-12-07 17:15:04 -080028{
Julius Werner8c093772016-02-09 16:09:15 -080029 /* Initialize timestamps if we have TIMESTAMP region in memlayout.ld. */
Julius Wernercd49cce2019-03-05 16:53:33 -080030 if (CONFIG(COLLECT_TIMESTAMPS) &&
Julius Werner7e0dea62019-02-20 18:39:22 -080031 REGION_SIZE(timestamp) > 0) {
Julius Werner12574dd2018-05-15 17:48:30 -070032 int i;
Alexandru Gagniucff196b62016-05-16 16:17:39 -070033 timestamp_init(base_timestamp);
Julius Werner12574dd2018-05-15 17:48:30 -070034 for (i = 0; i < num_timestamps; i++)
35 timestamp_add(timestamps[i].entry_id,
36 timestamps[i].entry_stamp);
37 }
Julius Werner44cf8702014-12-08 13:39:14 -080038
Kyösti Mälkkife3250d2019-11-03 08:18:15 +020039 timestamp_add_now(TS_START_BOOTBLOCK);
40
Aaron Durbinbe7cbdc2016-02-24 18:56:00 -060041 bootblock_soc_early_init();
Julius Wernerf1e32102014-11-25 13:22:20 -080042 bootblock_mainboard_early_init();
David Hendricks3d7344a2013-01-08 21:05:06 -080043
Kyösti Mälkki731e58e2020-01-04 13:00:02 +020044 if (CONFIG(USE_OPTION_TABLE))
45 sanitize_cmos();
Kyösti Mälkkibb5b9fe2020-01-04 13:00:02 +020046
47 if (CONFIG(CMOS_POST))
48 cmos_post_init();
Nico Hubere0b9aea2019-01-28 18:14:13 +010049
Julius Wernercd49cce2019-03-05 16:53:33 -080050 if (CONFIG(BOOTBLOCK_CONSOLE)) {
Julius Werner86fc11d2015-10-09 13:37:58 -070051 console_init();
52 exception_init();
53 }
Stefan Reinauer919c8042013-05-16 10:57:15 -070054
Julius Wernerf1e32102014-11-25 13:22:20 -080055 bootblock_soc_init();
56 bootblock_mainboard_init();
57
Kyösti Mälkkife3250d2019-11-03 08:18:15 +020058 timestamp_add_now(TS_END_BOOTBLOCK);
59
Aaron Durbinf5d7f602015-03-17 13:20:02 -050060 run_romstage();
Stefan Reinauer52db0b92012-12-07 17:15:04 -080061}
Alexandru Gagniucff196b62016-05-16 16:17:39 -070062
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030063void bootblock_main_with_basetime(uint64_t base_timestamp)
64{
65 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
66}
67
Alexandru Gagniucff196b62016-05-16 16:17:39 -070068void main(void)
69{
70 uint64_t base_timestamp = 0;
71
72 init_timer();
73
Julius Wernercd49cce2019-03-05 16:53:33 -080074 if (CONFIG(COLLECT_TIMESTAMPS))
Alexandru Gagniucff196b62016-05-16 16:17:39 -070075 base_timestamp = timestamp_get();
76
Julius Werner12574dd2018-05-15 17:48:30 -070077 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
Alexandru Gagniucff196b62016-05-16 16:17:39 -070078}
Julius Werner99f46832018-05-16 14:14:04 -070079
Julius Wernercd49cce2019-03-05 16:53:33 -080080#if CONFIG(COMPRESS_BOOTBLOCK)
Julius Werner99f46832018-05-16 14:14:04 -070081/*
82 * This is the bootblock entry point when it is run after a decompressor stage.
83 * For non-decompressor builds, _start is generally defined in architecture-
84 * specific assembly code. In decompressor builds that architecture
85 * initialization code already ran in the decompressor, so the bootblock can
86 * start straight into common code with a C environment.
87 */
88void _start(struct bootblock_arg *arg);
89void _start(struct bootblock_arg *arg)
90{
91 bootblock_main_with_timestamp(arg->base_timestamp, arg->timestamps,
92 arg->num_timestamps);
93}
94
95#endif