summaryrefslogtreecommitdiff
path: root/extra/usb_updater/gsctool.h
blob: 1ac23b53bcf9a99a93b78d6e542f8bb9b30ec995 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright 2018 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef __EXTRA_USB_UPDATER_GSCTOOL_H
#define __EXTRA_USB_UPDATER_GSCTOOL_H

#include <stdint.h>
#include <sys/types.h>

#include "usb_if.h"

/*
 * gsctool uses this structure to keep information about the communications
 * channel used to talk to the Cr50, and about the state of the Cr50 image.
 */
struct transfer_descriptor {
	/*
	 * Set to true for use in an upstart script. Do not reboot after
	 * transfer, and do not transfer RW if versions are the same.
	 *
	 * When using in development environment it is beneficial to transfer
	 * RW images with the same version, as they get started based on the
	 * header timestamp.
	 */
	uint32_t upstart_mode;
	/*
	 * Override in case updater is used w/ boards that do not follow
	 * the cr50 versioning scheme.
	 */
	uint32_t background_update_supported;

	/*
	 * offsets of RO and WR sections available for update (not currently
	 * active).
	 */
	uint32_t ro_offset;
	uint32_t rw_offset;
	uint32_t post_reset;

	/* Type of channel used to communicate with Cr50. */
	enum transfer_type {
		usb_xfer = 0,  /* usb interface. */
		dev_xfer = 1,  /* /dev/tpm0 */
		ts_xfer = 2    /* trunks_send */
	} ep_type;
	union {
		struct usb_endpoint uep;
		int tpm_fd;
	};
};

/*
 * These are values returned by the gsctool utility, they are interpreted by
 * the startup files to decide how to proceed (try to update to a new Cr50
 * image or not).
 */
enum exit_values {
	noop = 0,	  /* All up to date, no update needed. */
	all_updated = 1,  /* Update completed, reboot required. */
	rw_updated  = 2,  /* RO was not updated, reboot required. */
	update_error = 3  /* Something went wrong. */
};


struct board_id {
	uint32_t type;	    /* Board type */
	uint32_t type_inv;  /* Board type (inverted) */
	uint32_t flags;	    /* Flags */
};

enum board_id_action {
	bid_none,
	bid_get,
	bid_set
};

/*
 * This function allows to retrieve or set (if not initialized) board ID of
 * the H1 chip.
 */
void process_bid(struct transfer_descriptor *td,
		 enum board_id_action bid_action,
		 struct board_id *bid);

/*
 * This function can be used to retrieve the current PP status from Cr50 and
 * prompt the user when a PP press is required.
 *
 * Physical presence can be required by different gsctool options, for which
 * Cr50 behavior also differs. The 'command' and 'poll_type' parameters are
 * used by Cr50 to tell what the host is polling for.
 */
void poll_for_pp(struct transfer_descriptor *td,
		 uint16_t command,
		 uint8_t poll_type);

/*
 * Function used to send vendor command to the Cr50 and receive a response.
 * Returns the error code from TPM response header, which is set to zero on
 * success.
 */
uint32_t send_vendor_command(struct transfer_descriptor *td,
			     uint16_t subcommand,
			     const void *command_body,
			     size_t command_body_size,
			     void *response,
			     size_t *response_size);


#endif // __EXTRA_USB_UPDATER_GSCTOOL_H