blob: da9a16d75fb3ee97a588efb6c78e9b2a5765ae1f [file] [log] [blame]
Vadim Bendeburyb9126fe2017-03-22 16:16:34 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2017 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <bootstate.h>
17#include <console/console.h>
18#include <ec/google/chromeec/ec.h>
19#include <elog.h>
20#include <halt.h>
Philipp Deppenwiesed88fb362017-10-18 20:26:18 +020021#include <security/tpm/tss.h>
Vadim Bendeburyb9126fe2017-03-22 16:16:34 -070022#include <vb2_api.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020023#include <security/vboot/vboot_common.h>
Duncan Laurief131fc72019-01-23 15:01:21 -080024#include <vendorcode/google/chromeos/chromeos.h>
25
26void __weak mainboard_cr50_update_reset(void) {}
Vadim Bendeburyb9126fe2017-03-22 16:16:34 -070027
28static void enable_update(void *unused)
29{
30 int ret;
31 uint8_t num_restored_headers;
32
33 /* Nothing to do on recovery mode. */
34 if (vboot_recovery_mode_enabled())
35 return;
36
37 ret = tlcl_lib_init();
38
39 if (ret != VB2_SUCCESS) {
40 printk(BIOS_ERR, "tlcl_lib_init() failed for CR50 update: %x\n",
41 ret);
42 return;
43 }
44
45 /* Reboot in 1000 ms if necessary. */
46 ret = tlcl_cr50_enable_update(1000, &num_restored_headers);
47
48 if (ret != TPM_SUCCESS) {
49 printk(BIOS_ERR, "Attempt to enable CR50 update failed: %x\n",
50 ret);
51 return;
52 }
53
54 /* If no headers were restored there is no reset forthcoming. */
55 if (!num_restored_headers)
56 return;
57
Duncan Laurief131fc72019-01-23 15:01:21 -080058 /* Give mainboard a chance to take action */
59 mainboard_cr50_update_reset();
60
Vadim Bendeburyb9126fe2017-03-22 16:16:34 -070061 elog_add_event(ELOG_TYPE_CR50_UPDATE);
62
63 /* clear current post code avoid chatty eventlog on subsequent boot*/
64 post_code(0);
65
66 printk(BIOS_INFO, "Waiting for CR50 reset to pick up update.\n");
67
Aaron Durbin6db1b2f2018-10-12 12:33:34 -060068 if (IS_ENABLED(CONFIG_POWER_OFF_ON_CR50_UPDATE))
Vadim Bendeburyb9126fe2017-03-22 16:16:34 -070069 poweroff();
Vadim Bendeburyb9126fe2017-03-22 16:16:34 -070070 halt();
71}
72BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_ENTRY, enable_update, NULL);