xref: /aosp_15_r20/external/gsc-utils/extra/usb_updater/gsctool.h (revision 4f2df630800bdcf1d4f0decf95d8a1cb87344f5f)
1 /*
2  * Copyright 2018 The ChromiumOS Authors
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6 
7 #ifndef __EXTRA_USB_UPDATER_GSCTOOL_H
8 #define __EXTRA_USB_UPDATER_GSCTOOL_H
9 
10 #include <stdbool.h>
11 #include <stdint.h>
12 #include <sys/types.h>
13 
14 #include "usb_if.h"
15 
16 /*
17  * gsctool uses this structure to keep information about the communications
18  * channel used to talk to the Cr50, and about the state of the Cr50 image.
19  */
20 struct transfer_descriptor {
21 	/*
22 	 * Set to true for use in an upstart script. Do not reboot after
23 	 * transfer, and do not transfer RW if versions are the same.
24 	 *
25 	 * When using in development environment it is beneficial to transfer
26 	 * RW images with the same version, as they get started based on the
27 	 * header timestamp.
28 	 */
29 	int upstart_mode;
30 	/*
31 	 * Override in case updater is used w/ boards that do not follow
32 	 * the cr50 versioning scheme.
33 	 */
34 	int background_update_supported;
35 	/*
36 	 * Unconditionally update the inactive RO, helps to make sure both RO
37 	 * sections are at the same level.
38 	 */
39 	int force_ro;
40 	/*
41 	 * offsets of RO and WR sections available for update (not currently
42 	 * active).
43 	 */
44 	uint32_t ro_offset;
45 	uint32_t rw_offset;
46 
47 	/* Do not reset the H1 immediately after update, wait for TPM reset. */
48 	int post_reset;
49 
50 	/* Type of channel used to communicate with Cr50. */
51 	enum transfer_type {
52 		usb_xfer = 0, /* usb interface. */
53 		dev_xfer = 1, /* /dev/tpm0 */
54 		ts_xfer = 2 /* trunks_send */
55 	} ep_type;
56 	union {
57 		struct usb_endpoint uep;
58 		int tpm_fd;
59 	};
60 };
61 
62 /*
63  * These are values returned by the gsctool utility, they are interpreted by
64  * the startup files to decide how to proceed (try to update to a new Cr50
65  * image or not).
66  */
67 enum exit_values {
68 	noop = 0, /* All up to date, no update needed. */
69 	all_updated = 1, /* Update completed, reboot required. */
70 	rw_updated = 2, /* RO was not updated, reboot required. */
71 	update_error = 3 /* Something went wrong. */
72 };
73 
74 struct board_id {
75 	uint32_t type; /* Board type */
76 	uint32_t type_inv; /* Board type (inverted) */
77 	uint32_t flags; /* Flags */
78 };
79 
80 enum board_id_action { bid_none, bid_get, bid_set };
81 
82 /*
83  * This function allows to retrieve or set (if not initialized) board ID of
84  * the H1 chip. If bid_action is bid_get and show_machine_output is set,
85  * prints out board ID in a machine-friendly format.
86  */
87 void process_bid(struct transfer_descriptor *td,
88 		 enum board_id_action bid_action, struct board_id *bid,
89 		 bool show_machine_output);
90 
91 /*
92  * This function can be used to retrieve the current PP status from Cr50 and
93  * prompt the user when a PP press is required.
94  *
95  * Physical presence can be required by different gsctool options, for which
96  * Cr50 behavior also differs. The 'command' and 'poll_type' parameters are
97  * used by Cr50 to tell what the host is polling for.
98  */
99 void poll_for_pp(struct transfer_descriptor *td, uint16_t command,
100 		 uint8_t poll_type);
101 
102 /*
103  * Function used to send vendor command to the Cr50 and receive a response.
104  * Returns the error code from TPM response header, which is set to zero on
105  * success.
106  */
107 uint32_t send_vendor_command(struct transfer_descriptor *td,
108 			     uint16_t subcommand, const void *command_body,
109 			     size_t command_body_size, void *response,
110 			     size_t *response_size);
111 
112 #endif // __EXTRA_USB_UPDATER_GSCTOOL_H
113