blob: 5ba36f7e654c52868e31666776971a3ebb58fe48 [file] [log] [blame]
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -07001/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 *
5 * Functions for querying, manipulating and locking rollback indices
6 * stored in the TPM NVRAM.
7 */
8
Daisuke Nojiri57990972014-07-15 19:47:32 -07009#ifndef ANTIROLLBACK_H_
10#define ANTIROLLBACK_H_
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070011
Daisuke Nojiri57990972014-07-15 19:47:32 -070012#include "tpm_lite/tss_constants.h"
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070013
Randall Spangler144c2282014-12-03 17:35:53 -080014struct vb2_context;
Julius Werner76e33032015-01-30 18:45:27 -080015enum vb2_pcr_digest;
Randall Spangler144c2282014-12-03 17:35:53 -080016
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070017/* TPM NVRAM location indices. */
18#define FIRMWARE_NV_INDEX 0x1007
Daisuke Nojiri97ea9c02014-09-29 13:02:29 -070019#define KERNEL_NV_INDEX 0x1008
20/* This is just an opaque space for backup purposes */
21#define BACKUP_NV_INDEX 0x1009
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070022
23/* Structure definitions for TPM spaces */
24
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070025/* Flags for firmware space */
Daisuke Nojiri57990972014-07-15 19:47:32 -070026
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070027/*
28 * Last boot was developer mode. TPM ownership is cleared when transitioning
29 * to/from developer mode.
30 */
31#define FLAG_LAST_BOOT_DEVELOPER 0x01
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070032
33/* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */
34
Daisuke Nojiri57990972014-07-15 19:47:32 -070035uint32_t antirollback_read_space_firmware(struct vb2_context *ctx);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070036
37/**
38 * Write may be called if the versions change.
39 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070040uint32_t antirollback_write_space_firmware(struct vb2_context *ctx);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070041
42/**
43 * Lock must be called.
44 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070045uint32_t antirollback_lock_space_firmware(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070046
47/****************************************************************************/
48
49/*
50 * The following functions are internal apis, listed here for use by unit tests
51 * only.
52 */
53
54/**
Julius Werner76e33032015-01-30 18:45:27 -080055 * Ask vboot for a digest and extend a TPM PCR with it.
56 */
57uint32_t tpm_extend_pcr(struct vb2_context *ctx, int pcr,
58 enum vb2_pcr_digest which_digest);
59
60/**
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070061 * Issue a TPM_Clear and reenable/reactivate the TPM.
62 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070063uint32_t tpm_clear_and_reenable(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070064
65/**
Daisuke Nojiri57990972014-07-15 19:47:32 -070066 * Like tlcl_write(), but checks for write errors due to hitting the 64-write
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070067 * limit and clears the TPM when that happens. This can only happen when the
68 * TPM is unowned, so it is OK to clear it (and we really have no choice).
69 * This is not expected to happen frequently, but it could happen.
70 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070071uint32_t safe_write(uint32_t index, const void *data, uint32_t length);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070072
73/**
Daisuke Nojiri57990972014-07-15 19:47:32 -070074 * Similarly to safe_write(), this ensures we don't fail a DefineSpace because
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070075 * we hit the TPM write limit. This is even less likely to happen than with
76 * writes because we only define spaces once at initialization, but we'd rather
77 * be paranoid about this.
78 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070079uint32_t safe_define_space(uint32_t index, uint32_t perm, uint32_t size);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070080
81/**
82 * Perform one-time initializations.
83 *
84 * Create the NVRAM spaces, and set their initial values as needed. Sets the
85 * nvLocked bit and ensures the physical presence command is enabled and
86 * locked.
87 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070088uint32_t factory_initialize_tpm(struct vb2_context *ctx);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070089
90/**
Daisuke Nojiri57990972014-07-15 19:47:32 -070091 * Start the TPM and establish the root of trust for the antirollback mechanism.
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070092 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070093uint32_t setup_tpm(struct vb2_context *ctx);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070094
Daisuke Nojiri57990972014-07-15 19:47:32 -070095#endif /* ANTIROLLBACK_H_ */