blob: 23fb392276439d7838ce93a7d2058c6be0c24084 [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>
Julius Werner6296ca82021-04-02 16:31:21 -07007#include <metadata_hash.h>
Kyösti Mälkkib2680a12020-01-04 18:04:39 +02008#include <option.h>
Kyösti Mälkkice39ba92020-01-04 16:15:50 +02009#include <post.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
Aaron Durbin64031672018-04-21 14:45:32 -060014__weak void bootblock_mainboard_early_init(void) { /* no-op */ }
15__weak void bootblock_soc_early_init(void) { /* do nothing */ }
16__weak void bootblock_soc_init(void) { /* do nothing */ }
17__weak void bootblock_mainboard_init(void) { /* do nothing */ }
Vadim Bendebury0b341b32014-04-23 11:09:44 -070018
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030019/*
20 * This is a the same as the bootblock main(), with the difference that it does
21 * not collect a timestamp. Instead it accepts the initial timestamp and
22 * possibly additional timestamp entries as arguments. This can be used in cases
23 * where earlier stamps are available. Note that this function is designed to be
24 * entered from C code. This function assumes that the timer has already been
25 * initialized, so it does not call init_timer().
26 */
Kangheui Won18582232020-09-17 16:49:40 +100027void bootblock_main_with_timestamp(uint64_t base_timestamp,
Julius Werner12574dd2018-05-15 17:48:30 -070028 struct timestamp_entry *timestamps, size_t num_timestamps)
Stefan Reinauer52db0b92012-12-07 17:15:04 -080029{
Julius Werner8c093772016-02-09 16:09:15 -080030 /* Initialize timestamps if we have TIMESTAMP region in memlayout.ld. */
Julius Wernercd49cce2019-03-05 16:53:33 -080031 if (CONFIG(COLLECT_TIMESTAMPS) &&
Julius Werner7e0dea62019-02-20 18:39:22 -080032 REGION_SIZE(timestamp) > 0) {
Julius Werner12574dd2018-05-15 17:48:30 -070033 int i;
Alexandru Gagniucff196b62016-05-16 16:17:39 -070034 timestamp_init(base_timestamp);
Julius Werner12574dd2018-05-15 17:48:30 -070035 for (i = 0; i < num_timestamps; i++)
36 timestamp_add(timestamps[i].entry_id,
37 timestamps[i].entry_stamp);
38 }
Julius Werner44cf8702014-12-08 13:39:14 -080039
Kyösti Mälkkife3250d2019-11-03 08:18:15 +020040 timestamp_add_now(TS_START_BOOTBLOCK);
41
Aaron Durbinbe7cbdc2016-02-24 18:56:00 -060042 bootblock_soc_early_init();
Julius Wernerf1e32102014-11-25 13:22:20 -080043 bootblock_mainboard_early_init();
David Hendricks3d7344a2013-01-08 21:05:06 -080044
Kyösti Mälkki731e58e2020-01-04 13:00:02 +020045 if (CONFIG(USE_OPTION_TABLE))
46 sanitize_cmos();
Kyösti Mälkkibb5b9fe2020-01-04 13:00:02 +020047
48 if (CONFIG(CMOS_POST))
49 cmos_post_init();
Nico Hubere0b9aea2019-01-28 18:14:13 +010050
Julius Wernercd49cce2019-03-05 16:53:33 -080051 if (CONFIG(BOOTBLOCK_CONSOLE)) {
Julius Werner86fc11d2015-10-09 13:37:58 -070052 console_init();
53 exception_init();
54 }
Stefan Reinauer919c8042013-05-16 10:57:15 -070055
Julius Wernerf1e32102014-11-25 13:22:20 -080056 bootblock_soc_init();
57 bootblock_mainboard_init();
58
Kyösti Mälkkife3250d2019-11-03 08:18:15 +020059 timestamp_add_now(TS_END_BOOTBLOCK);
60
Aaron Durbinf5d7f602015-03-17 13:20:02 -050061 run_romstage();
Stefan Reinauer52db0b92012-12-07 17:15:04 -080062}
Alexandru Gagniucff196b62016-05-16 16:17:39 -070063
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030064void bootblock_main_with_basetime(uint64_t base_timestamp)
65{
66 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
67}
68
Alexandru Gagniucff196b62016-05-16 16:17:39 -070069void main(void)
70{
71 uint64_t base_timestamp = 0;
72
73 init_timer();
74
Julius Wernercd49cce2019-03-05 16:53:33 -080075 if (CONFIG(COLLECT_TIMESTAMPS))
Alexandru Gagniucff196b62016-05-16 16:17:39 -070076 base_timestamp = timestamp_get();
77
Julius Werner12574dd2018-05-15 17:48:30 -070078 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
Alexandru Gagniucff196b62016-05-16 16:17:39 -070079}
Julius Werner99f46832018-05-16 14:14:04 -070080
Julius Wernercd49cce2019-03-05 16:53:33 -080081#if CONFIG(COMPRESS_BOOTBLOCK)
Julius Werner99f46832018-05-16 14:14:04 -070082/*
83 * This is the bootblock entry point when it is run after a decompressor stage.
84 * For non-decompressor builds, _start is generally defined in architecture-
85 * specific assembly code. In decompressor builds that architecture
86 * initialization code already ran in the decompressor, so the bootblock can
87 * start straight into common code with a C environment.
88 */
89void _start(struct bootblock_arg *arg);
90void _start(struct bootblock_arg *arg)
91{
Julius Werner6296ca82021-04-02 16:31:21 -070092 if (CONFIG(CBFS_VERIFICATION))
93 metadata_hash_import_anchor(arg->metadata_hash_anchor);
Julius Werner99f46832018-05-16 14:14:04 -070094 bootblock_main_with_timestamp(arg->base_timestamp, arg->timestamps,
95 arg->num_timestamps);
96}
97
98#endif