Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 2 | |
Arthur Heymans | 6f8e944 | 2021-03-29 14:23:53 +0200 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Julius Werner | 85620db | 2013-11-13 18:22:15 -0800 | [diff] [blame] | 4 | #include <arch/exception.h> |
Gabe Black | 8b68539 | 2013-09-29 03:02:55 -0700 | [diff] [blame] | 5 | #include <bootblock_common.h> |
Hung-Te Lin | b868d40 | 2013-02-06 22:01:18 +0800 | [diff] [blame] | 6 | #include <console/console.h> |
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 7 | #include <delay.h> |
Julius Werner | 6296ca8 | 2021-04-02 16:31:21 -0700 | [diff] [blame] | 8 | #include <metadata_hash.h> |
Kyösti Mälkki | b2680a1 | 2020-01-04 18:04:39 +0200 | [diff] [blame] | 9 | #include <option.h> |
Kyösti Mälkki | ce39ba9 | 2020-01-04 16:15:50 +0200 | [diff] [blame] | 10 | #include <post.h> |
Aaron Durbin | f5d7f60 | 2015-03-17 13:20:02 -0500 | [diff] [blame] | 11 | #include <program_loading.h> |
Arthur Heymans | 6f8e944 | 2021-03-29 14:23:53 +0200 | [diff] [blame] | 12 | #include <security/tpm/tspi.h> |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 13 | #include <symbols.h> |
Elyes HAOUAS | b562244 | 2019-07-11 09:22:02 +0200 | [diff] [blame] | 14 | #include <timestamp.h> |
David Hendricks | 50c0a50 | 2013-01-31 17:05:50 -0800 | [diff] [blame] | 15 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 16 | __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 Bendebury | 0b341b3 | 2014-04-23 11:09:44 -0700 | [diff] [blame] | 20 | |
Kyösti Mälkki | 101ef0b | 2019-08-18 06:58:42 +0300 | [diff] [blame] | 21 | /* |
| 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 Won | 1858223 | 2020-09-17 16:49:40 +1000 | [diff] [blame] | 29 | void bootblock_main_with_timestamp(uint64_t base_timestamp, |
Julius Werner | 12574dd | 2018-05-15 17:48:30 -0700 | [diff] [blame] | 30 | struct timestamp_entry *timestamps, size_t num_timestamps) |
Stefan Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 31 | { |
Julius Werner | 8c09377 | 2016-02-09 16:09:15 -0800 | [diff] [blame] | 32 | /* Initialize timestamps if we have TIMESTAMP region in memlayout.ld. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 33 | if (CONFIG(COLLECT_TIMESTAMPS) && |
Julius Werner | 7e0dea6 | 2019-02-20 18:39:22 -0800 | [diff] [blame] | 34 | REGION_SIZE(timestamp) > 0) { |
Julius Werner | 12574dd | 2018-05-15 17:48:30 -0700 | [diff] [blame] | 35 | int i; |
Alexandru Gagniuc | ff196b6 | 2016-05-16 16:17:39 -0700 | [diff] [blame] | 36 | timestamp_init(base_timestamp); |
Julius Werner | 12574dd | 2018-05-15 17:48:30 -0700 | [diff] [blame] | 37 | for (i = 0; i < num_timestamps; i++) |
| 38 | timestamp_add(timestamps[i].entry_id, |
| 39 | timestamps[i].entry_stamp); |
| 40 | } |
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 41 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 42 | timestamp_add_now(TS_BOOTBLOCK_START); |
Kyösti Mälkki | fe3250d | 2019-11-03 08:18:15 +0200 | [diff] [blame] | 43 | |
Aaron Durbin | be7cbdc | 2016-02-24 18:56:00 -0600 | [diff] [blame] | 44 | bootblock_soc_early_init(); |
Julius Werner | f1e3210 | 2014-11-25 13:22:20 -0800 | [diff] [blame] | 45 | bootblock_mainboard_early_init(); |
David Hendricks | 3d7344a | 2013-01-08 21:05:06 -0800 | [diff] [blame] | 46 | |
Kyösti Mälkki | 731e58e | 2020-01-04 13:00:02 +0200 | [diff] [blame] | 47 | if (CONFIG(USE_OPTION_TABLE)) |
| 48 | sanitize_cmos(); |
Kyösti Mälkki | bb5b9fe | 2020-01-04 13:00:02 +0200 | [diff] [blame] | 49 | |
| 50 | if (CONFIG(CMOS_POST)) |
| 51 | cmos_post_init(); |
Nico Huber | e0b9aea | 2019-01-28 18:14:13 +0100 | [diff] [blame] | 52 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 53 | if (CONFIG(BOOTBLOCK_CONSOLE)) { |
Julius Werner | 86fc11d | 2015-10-09 13:37:58 -0700 | [diff] [blame] | 54 | console_init(); |
| 55 | exception_init(); |
| 56 | } |
Stefan Reinauer | 919c804 | 2013-05-16 10:57:15 -0700 | [diff] [blame] | 57 | |
Julius Werner | f1e3210 | 2014-11-25 13:22:20 -0800 | [diff] [blame] | 58 | bootblock_soc_init(); |
| 59 | bootblock_mainboard_init(); |
| 60 | |
Arthur Heymans | 6f8e944 | 2021-03-29 14:23:53 +0200 | [diff] [blame] | 61 | if (CONFIG(TPM_MEASURED_BOOT_INIT_BOOTBLOCK)) { |
| 62 | int s3resume = acpi_is_wakeup_s3(); |
| 63 | tpm_setup(s3resume); |
| 64 | } |
| 65 | |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 66 | timestamp_add_now(TS_BOOTBLOCK_END); |
Kyösti Mälkki | fe3250d | 2019-11-03 08:18:15 +0200 | [diff] [blame] | 67 | |
Aaron Durbin | f5d7f60 | 2015-03-17 13:20:02 -0500 | [diff] [blame] | 68 | run_romstage(); |
Stefan Reinauer | 52db0b9 | 2012-12-07 17:15:04 -0800 | [diff] [blame] | 69 | } |
Alexandru Gagniuc | ff196b6 | 2016-05-16 16:17:39 -0700 | [diff] [blame] | 70 | |
Kyösti Mälkki | 101ef0b | 2019-08-18 06:58:42 +0300 | [diff] [blame] | 71 | void bootblock_main_with_basetime(uint64_t base_timestamp) |
| 72 | { |
| 73 | bootblock_main_with_timestamp(base_timestamp, NULL, 0); |
| 74 | } |
| 75 | |
Alexandru Gagniuc | ff196b6 | 2016-05-16 16:17:39 -0700 | [diff] [blame] | 76 | void main(void) |
| 77 | { |
| 78 | uint64_t base_timestamp = 0; |
| 79 | |
| 80 | init_timer(); |
| 81 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 82 | if (CONFIG(COLLECT_TIMESTAMPS)) |
Alexandru Gagniuc | ff196b6 | 2016-05-16 16:17:39 -0700 | [diff] [blame] | 83 | base_timestamp = timestamp_get(); |
| 84 | |
Julius Werner | 12574dd | 2018-05-15 17:48:30 -0700 | [diff] [blame] | 85 | bootblock_main_with_timestamp(base_timestamp, NULL, 0); |
Alexandru Gagniuc | ff196b6 | 2016-05-16 16:17:39 -0700 | [diff] [blame] | 86 | } |
Julius Werner | 99f4683 | 2018-05-16 14:14:04 -0700 | [diff] [blame] | 87 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 88 | #if CONFIG(COMPRESS_BOOTBLOCK) |
Julius Werner | 99f4683 | 2018-05-16 14:14:04 -0700 | [diff] [blame] | 89 | /* |
| 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 | */ |
| 96 | void _start(struct bootblock_arg *arg); |
| 97 | void _start(struct bootblock_arg *arg) |
| 98 | { |
Julius Werner | 6296ca8 | 2021-04-02 16:31:21 -0700 | [diff] [blame] | 99 | if (CONFIG(CBFS_VERIFICATION)) |
| 100 | metadata_hash_import_anchor(arg->metadata_hash_anchor); |
Julius Werner | 99f4683 | 2018-05-16 14:14:04 -0700 | [diff] [blame] | 101 | bootblock_main_with_timestamp(arg->base_timestamp, arg->timestamps, |
| 102 | arg->num_timestamps); |
| 103 | } |
| 104 | |
| 105 | #endif |