Angel Pons | 986d50e | 2020-04-02 23:48:53 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 2 | |
| 3 | #include <cbfs.h> |
| 4 | #include <console/console.h> |
Aaron Durbin | f7ce40b | 2016-08-24 14:58:12 -0500 | [diff] [blame] | 5 | #include <ec/google/chromeec/ec.h> |
Aaron Durbin | 09560fa | 2015-05-12 16:43:10 -0500 | [diff] [blame] | 6 | #include <rmodule.h> |
Philipp Deppenwiese | fea2429 | 2017-10-17 17:02:29 +0200 | [diff] [blame] | 7 | #include <security/vboot/misc.h> |
| 8 | #include <security/vboot/symbols.h> |
| 9 | #include <security/vboot/vboot_common.h> |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 10 | |
Julius Werner | 73d042b | 2017-03-17 16:54:48 -0700 | [diff] [blame] | 11 | /* Ensure vboot configuration is valid: */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 12 | _Static_assert(CONFIG(VBOOT_STARTS_IN_BOOTBLOCK) + |
| 13 | CONFIG(VBOOT_STARTS_IN_ROMSTAGE) == 1, |
Julius Werner | 73d042b | 2017-03-17 16:54:48 -0700 | [diff] [blame] | 14 | "vboot must either start in bootblock or romstage (not both!)"); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 15 | _Static_assert(!CONFIG(VBOOT_SEPARATE_VERSTAGE) || |
| 16 | CONFIG(VBOOT_STARTS_IN_BOOTBLOCK), |
Julius Werner | 73d042b | 2017-03-17 16:54:48 -0700 | [diff] [blame] | 17 | "stand-alone verstage must start in (i.e. after) bootblock"); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 18 | _Static_assert(!CONFIG(VBOOT_RETURN_FROM_VERSTAGE) || |
| 19 | CONFIG(VBOOT_SEPARATE_VERSTAGE), |
Julius Werner | 73d042b | 2017-03-17 16:54:48 -0700 | [diff] [blame] | 20 | "return from verstage only makes sense for separate verstages"); |
| 21 | |
Arthur Heymans | 344e86b | 2019-11-20 19:47:10 +0100 | [diff] [blame] | 22 | int vboot_executed; |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 23 | |
Wim Vervoorn | 1058dd8 | 2019-11-01 10:22:22 +0100 | [diff] [blame] | 24 | void vboot_run_logic(void) |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 25 | { |
Paul Kocialkowski | 1811768 | 2016-05-14 15:30:52 +0200 | [diff] [blame] | 26 | if (verification_should_run()) { |
Julius Werner | 58c3938 | 2017-02-13 17:53:29 -0800 | [diff] [blame] | 27 | /* Note: this path is not used for VBOOT_RETURN_FROM_VERSTAGE */ |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 28 | verstage_main(); |
Arthur Heymans | 344e86b | 2019-11-20 19:47:10 +0100 | [diff] [blame] | 29 | vboot_executed = 1; |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 30 | } else if (verstage_should_load()) { |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 31 | struct cbfsf file; |
Aaron Durbin | ac12c66c | 2015-05-20 12:08:55 -0500 | [diff] [blame] | 32 | struct prog verstage = |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 33 | PROG_INIT(PROG_VERSTAGE, |
Aaron Durbin | ac12c66c | 2015-05-20 12:08:55 -0500 | [diff] [blame] | 34 | CONFIG_CBFS_PREFIX "/verstage"); |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 35 | |
Aaron Durbin | ce2c50d | 2015-05-13 13:33:27 -0500 | [diff] [blame] | 36 | printk(BIOS_DEBUG, "VBOOT: Loading verstage.\n"); |
| 37 | |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 38 | /* load verstage from RO */ |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 39 | if (cbfs_boot_locate(&file, prog_name(&verstage), NULL)) |
| 40 | die("failed to load verstage"); |
| 41 | |
| 42 | cbfs_file_data(prog_rdev(&verstage), &file); |
| 43 | |
| 44 | if (cbfs_prog_stage_load(&verstage)) |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 45 | die("failed to load verstage"); |
| 46 | |
| 47 | /* verify and select a slot */ |
| 48 | prog_run(&verstage); |
| 49 | |
| 50 | /* This is not actually possible to hit this condition at |
| 51 | * runtime, but this provides a hint to the compiler for dead |
| 52 | * code elimination below. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 53 | if (!CONFIG(VBOOT_RETURN_FROM_VERSTAGE)) |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 54 | return; |
| 55 | |
Arthur Heymans | 344e86b | 2019-11-20 19:47:10 +0100 | [diff] [blame] | 56 | vboot_executed = 1; |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 57 | } |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 58 | } |
| 59 | |
Julius Werner | 815611e | 2019-12-05 22:29:07 -0800 | [diff] [blame] | 60 | int vboot_locate_cbfs(struct region_device *rdev) |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 61 | { |
Julius Werner | f8e1764 | 2019-12-12 13:23:06 -0800 | [diff] [blame] | 62 | struct vb2_context *ctx; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 63 | |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 64 | /* Don't honor vboot results until the vboot logic has run. */ |
Joel Kitching | af8471c | 2019-03-13 22:38:07 +0800 | [diff] [blame] | 65 | if (!vboot_logic_executed()) |
Aaron Durbin | b6981c0 | 2015-05-15 15:57:51 -0500 | [diff] [blame] | 66 | return -1; |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 67 | |
Yu-Ping Wu | aeb652a | 2019-11-14 15:42:25 +0800 | [diff] [blame] | 68 | ctx = vboot_get_context(); |
| 69 | |
| 70 | if (ctx->flags & VB2_CONTEXT_RECOVERY_MODE) |
Aaron Durbin | 4e50cdd | 2015-05-15 23:25:46 -0500 | [diff] [blame] | 71 | return -1; |
Aaron Durbin | b6981c0 | 2015-05-15 15:57:51 -0500 | [diff] [blame] | 72 | |
Aaron Durbin | fe338e2 | 2019-11-18 12:35:21 -0700 | [diff] [blame] | 73 | return vboot_locate_firmware(ctx, rdev); |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 74 | } |