blob: 5989964921218842ef706480f2357a709b9e9118 [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
Arthur Heymans6f8e9442021-03-29 14:23:53 +02003#include <acpi/acpi.h>
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>
Julius Werner6296ca82021-04-02 16:31:21 -07008#include <metadata_hash.h>
Kyösti Mälkkib2680a12020-01-04 18:04:39 +02009#include <option.h>
Kyösti Mälkkice39ba92020-01-04 16:15:50 +020010#include <post.h>
Aaron Durbinf5d7f602015-03-17 13:20:02 -050011#include <program_loading.h>
Arthur Heymans6f8e9442021-03-29 14:23:53 +020012#include <security/tpm/tspi.h>
Julius Werner8c093772016-02-09 16:09:15 -080013#include <symbols.h>
Elyes HAOUASb5622442019-07-11 09:22:02 +020014#include <timestamp.h>
David Hendricks50c0a502013-01-31 17:05:50 -080015
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 */
Kangheui Won18582232020-09-17 16:49:40 +100029void 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
Arthur Heymans6f8e9442021-03-29 14:23:53 +020061 if (CONFIG(TPM_MEASURED_BOOT_INIT_BOOTBLOCK)) {
62 int s3resume = acpi_is_wakeup_s3();
63 tpm_setup(s3resume);
64 }
65
Kyösti Mälkkife3250d2019-11-03 08:18:15 +020066 timestamp_add_now(TS_END_BOOTBLOCK);
67
Aaron Durbinf5d7f602015-03-17 13:20:02 -050068 run_romstage();
Stefan Reinauer52db0b92012-12-07 17:15:04 -080069}
Alexandru Gagniucff196b62016-05-16 16:17:39 -070070
Kyösti Mälkki101ef0b2019-08-18 06:58:42 +030071void bootblock_main_with_basetime(uint64_t base_timestamp)
72{
73 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
74}
75
Alexandru Gagniucff196b62016-05-16 16:17:39 -070076void main(void)
77{
78 uint64_t base_timestamp = 0;
79
80 init_timer();
81
Julius Wernercd49cce2019-03-05 16:53:33 -080082 if (CONFIG(COLLECT_TIMESTAMPS))
Alexandru Gagniucff196b62016-05-16 16:17:39 -070083 base_timestamp = timestamp_get();
84
Julius Werner12574dd2018-05-15 17:48:30 -070085 bootblock_main_with_timestamp(base_timestamp, NULL, 0);
Alexandru Gagniucff196b62016-05-16 16:17:39 -070086}
Julius Werner99f46832018-05-16 14:14:04 -070087
Julius Wernercd49cce2019-03-05 16:53:33 -080088#if CONFIG(COMPRESS_BOOTBLOCK)
Julius Werner99f46832018-05-16 14:14:04 -070089/*
90 * This is the bootblock entry point when it is run after a decompressor stage.
91 * For non-decompressor builds, _start is generally defined in architecture-
92 * specific assembly code. In decompressor builds that architecture
93 * initialization code already ran in the decompressor, so the bootblock can
94 * start straight into common code with a C environment.
95 */
96void _start(struct bootblock_arg *arg);
97void _start(struct bootblock_arg *arg)
98{
Julius Werner6296ca82021-04-02 16:31:21 -070099 if (CONFIG(CBFS_VERIFICATION))
100 metadata_hash_import_anchor(arg->metadata_hash_anchor);
Julius Werner99f46832018-05-16 14:14:04 -0700101 bootblock_main_with_timestamp(arg->base_timestamp, arg->timestamps,
102 arg->num_timestamps);
103}
104
105#endif