1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2018, Bootlin
10 #include <asm/unaligned.h>
11 #include <linux/bitops.h>
12 #include <u-boot/crc.h>
13 #include <u-boot/sha256.h>
14 #include "sandbox_common.h"
18 TPM2_HIERARCHY_LOCKOUT = 0,
19 TPM2_HIERARCHY_ENDORSEMENT,
20 TPM2_HIERARCHY_PLATFORM,
24 /* Subset of supported properties */
25 #define TPM2_PROPERTIES_OFFSET 0x0000020E
27 enum tpm2_cap_tpm_property {
28 TPM2_FAIL_COUNTER = 0,
31 TPM2_LOCKOUT_RECOVERY,
35 #define SANDBOX_TPM_PCR_NB TPM2_MAX_PCRS
36 #define SANDBOX_TPM_PCR_SELECT_MAX ((SANDBOX_TPM_PCR_NB + 7) / 8)
39 * Information about our TPM emulation. This is preserved in the sandbox
40 * state file if enabled.
42 * @valid: true if this is valid (only used in s_state)
43 * @init_done: true if open() has been called
44 * @startup_done: true if TPM2_CC_STARTUP has been processed
45 * @tests_done: true if TPM2_CC_SELF_TEST has be processed
46 * @pw: TPM password per hierarchy
47 * @pw_sz: Size of each password in bytes
48 * @properties: TPM properties
49 * @pcr: TPM Platform Configuration Registers. Each of these holds a hash and
50 * can be 'extended' a number of times, meaning another hash is added into
51 * its value (initial value all zeroes)
52 * @pcr_extensions: Number of times each PCR has been extended (starts at 0)
53 * @nvdata: non-volatile data, used to store important things for the platform
57 /* TPM internal states */
61 char pw[TPM2_HIERARCHY_NB][TPM2_DIGEST_LEN + 1];
62 int pw_sz[TPM2_HIERARCHY_NB];
63 u32 properties[TPM2_PROPERTY_NB];
64 u8 pcr[SANDBOX_TPM_PCR_NB][TPM2_DIGEST_LEN];
65 u32 pcr_extensions[SANDBOX_TPM_PCR_NB];
66 struct nvdata_state nvdata[NV_SEQ_COUNT];
69 static struct sandbox_tpm2 s_state, *g_state;
72 * sandbox_tpm2_read_state() - read the sandbox EC state from the state file
74 * If data is available, then blob and node will provide access to it. If
75 * not this function sets up an empty TPM.
77 * @blob: Pointer to device tree blob, or NULL if no data to read
78 * @node: Node offset to read from
80 static int sandbox_tpm2_read_state(const void *blob, int node)
82 struct sandbox_tpm2 *state = &s_state;
90 state->tests_done = fdtdec_get_int(blob, node, "tests-done", 0);
92 for (i = 0; i < TPM2_HIERARCHY_NB; i++) {
93 snprintf(prop_name, sizeof(prop_name), "pw%d", i);
95 prop = fdt_getprop(blob, node, prop_name, &len);
96 if (len > TPM2_DIGEST_LEN)
97 return log_msg_ret("pw", -E2BIG);
99 memcpy(state->pw[i], prop, len);
100 state->pw_sz[i] = len;
104 for (i = 0; i < TPM2_PROPERTY_NB; i++) {
105 snprintf(prop_name, sizeof(prop_name), "properties%d", i);
106 state->properties[i] = fdtdec_get_uint(blob, node, prop_name,
110 for (i = 0; i < SANDBOX_TPM_PCR_NB; i++) {
113 snprintf(prop_name, sizeof(prop_name), "pcr%d", i);
114 subnode = fdt_subnode_offset(blob, node, prop_name);
117 prop = fdt_getprop(blob, subnode, "value", &len);
118 if (len != TPM2_DIGEST_LEN)
119 return log_msg_ret("pcr", -E2BIG);
120 memcpy(state->pcr[i], prop, TPM2_DIGEST_LEN);
121 state->pcr_extensions[i] = fdtdec_get_uint(blob, subnode,
125 for (i = 0; i < NV_SEQ_COUNT; i++) {
126 struct nvdata_state *nvd = &state->nvdata[i];
128 sprintf(prop_name, "nvdata%d", i);
129 prop = fdt_getprop(blob, node, prop_name, &len);
130 if (len > NV_DATA_SIZE)
131 return log_msg_ret("nvd", -E2BIG);
133 memcpy(nvd->data, prop, len);
138 s_state.valid = true;
144 * sandbox_tpm2_write_state() - Write out our state to the state file
146 * The caller will ensure that there is a node ready for the state. The node
147 * may already contain the old state, in which case it is overridden.
149 * @blob: Device tree blob holding state
150 * @node: Node to write our state into
152 static int sandbox_tpm2_write_state(void *blob, int node)
154 const struct sandbox_tpm2 *state = g_state;
162 * We are guaranteed enough space to write basic properties. This is
163 * SANDBOX_STATE_MIN_SPACE.
165 * We could use fdt_add_subnode() to put each set of data in its
166 * own node - perhaps useful if we add access information to each.
168 fdt_setprop_u32(blob, node, "tests-done", state->tests_done);
170 for (i = 0; i < TPM2_HIERARCHY_NB; i++) {
171 if (state->pw_sz[i]) {
172 snprintf(prop_name, sizeof(prop_name), "pw%d", i);
173 fdt_setprop(blob, node, prop_name, state->pw[i],
178 for (i = 0; i < TPM2_PROPERTY_NB; i++) {
179 snprintf(prop_name, sizeof(prop_name), "properties%d", i);
180 fdt_setprop_u32(blob, node, prop_name, state->properties[i]);
183 for (i = 0; i < SANDBOX_TPM_PCR_NB; i++) {
186 snprintf(prop_name, sizeof(prop_name), "pcr%d", i);
187 subnode = fdt_add_subnode(blob, node, prop_name);
188 fdt_setprop(blob, subnode, "value", state->pcr[i],
190 fdt_setprop_u32(blob, subnode, "extensions",
191 state->pcr_extensions[i]);
194 for (i = 0; i < NV_SEQ_COUNT; i++) {
195 const struct nvdata_state *nvd = &state->nvdata[i];
198 snprintf(prop_name, sizeof(prop_name), "nvdata%d", i);
199 fdt_setprop(blob, node, prop_name, nvd->data,
207 SANDBOX_STATE_IO(sandbox_tpm2, "sandbox,tpm2", sandbox_tpm2_read_state,
208 sandbox_tpm2_write_state);
211 * Check the tag validity depending on the command (authentication required or
212 * not). If authentication is required, check it is valid. Update the auth
213 * pointer to point to the next chunk of data to process if needed.
215 static int sandbox_tpm2_check_session(struct udevice *dev, u32 command, u16 tag,
217 enum tpm2_hierarchy *hierarchy)
219 struct sandbox_tpm2 *tpm = dev_get_priv(dev);
220 u32 handle, auth_sz, session_handle;
225 case TPM2_CC_STARTUP:
226 case TPM2_CC_SELF_TEST:
227 case TPM2_CC_GET_CAPABILITY:
228 case TPM2_CC_PCR_READ:
229 if (tag != TPM2_ST_NO_SESSIONS) {
230 printf("No session required for command 0x%x\n",
232 return TPM2_RC_BAD_TAG;
238 case TPM2_CC_HIERCHANGEAUTH:
239 case TPM2_CC_DAM_RESET:
240 case TPM2_CC_DAM_PARAMETERS:
241 case TPM2_CC_PCR_EXTEND:
242 case TPM2_CC_NV_READ:
243 case TPM2_CC_NV_WRITE:
244 case TPM2_CC_NV_WRITELOCK:
245 case TPM2_CC_NV_DEFINE_SPACE:
246 if (tag != TPM2_ST_SESSIONS) {
247 printf("Session required for command 0x%x\n", command);
248 return TPM2_RC_AUTH_CONTEXT;
251 handle = get_unaligned_be32(*auth);
252 *auth += sizeof(handle);
255 * PCR_Extend had a different protection mechanism and does not
256 * use the same standards as other commands.
258 if (command == TPM2_CC_PCR_EXTEND)
262 case TPM2_RH_LOCKOUT:
263 *hierarchy = TPM2_HIERARCHY_LOCKOUT;
265 case TPM2_RH_ENDORSEMENT:
266 if (command == TPM2_CC_CLEAR) {
267 printf("Endorsement hierarchy unsupported\n");
268 return TPM2_RC_AUTH_MISSING;
270 *hierarchy = TPM2_HIERARCHY_ENDORSEMENT;
272 case TPM2_RH_PLATFORM:
273 *hierarchy = TPM2_HIERARCHY_PLATFORM;
274 if (command == TPM2_CC_NV_READ ||
275 command == TPM2_CC_NV_WRITE ||
276 command == TPM2_CC_NV_WRITELOCK)
277 *auth += sizeof(u32);
280 printf("Wrong handle 0x%x\n", handle);
281 return TPM2_RC_VALUE;
287 printf("Command code not recognized: 0x%x\n", command);
288 return TPM2_RC_COMMAND_CODE;
291 auth_sz = get_unaligned_be32(*auth);
292 *auth += sizeof(auth_sz);
294 session_handle = get_unaligned_be32(*auth);
295 *auth += sizeof(session_handle);
296 if (session_handle != TPM2_RS_PW) {
297 printf("Wrong session handle 0x%x\n", session_handle);
298 return TPM2_RC_VALUE;
301 nonce_sz = get_unaligned_be16(*auth);
302 *auth += sizeof(nonce_sz);
304 printf("Nonces not supported in Sandbox, aborting\n");
305 return TPM2_RC_HANDLE;
308 /* Ignore attributes */
311 pw_sz = get_unaligned_be16(*auth);
312 *auth += sizeof(pw_sz);
313 if (auth_sz != (9 + nonce_sz + pw_sz)) {
314 printf("Authentication size (%d) do not match %d\n",
315 auth_sz, 9 + nonce_sz + pw_sz);
319 /* No passwork is acceptable */
320 if (!pw_sz && !tpm->pw_sz[*hierarchy])
321 return TPM2_RC_SUCCESS;
323 /* Password is too long */
324 if (pw_sz > TPM2_DIGEST_LEN) {
325 printf("Password should not be more than %dB\n",
327 return TPM2_RC_AUTHSIZE;
330 pw = (const char *)*auth;
333 /* Password is wrong */
334 if (pw_sz != tpm->pw_sz[*hierarchy] ||
335 strncmp(pw, tpm->pw[*hierarchy], tpm->pw_sz[*hierarchy])) {
336 printf("Authentication failed: wrong password.\n");
337 return TPM2_RC_BAD_AUTH;
340 return TPM2_RC_SUCCESS;
343 static int sandbox_tpm2_check_readyness(struct udevice *dev, int command)
345 struct sandbox_tpm2 *tpm = dev_get_priv(dev);
348 case TPM2_CC_STARTUP:
349 if (!tpm->init_done || tpm->startup_done)
350 return TPM2_RC_INITIALIZE;
353 case TPM2_CC_GET_CAPABILITY:
354 if (!tpm->init_done || !tpm->startup_done)
355 return TPM2_RC_INITIALIZE;
358 case TPM2_CC_SELF_TEST:
359 if (!tpm->startup_done)
360 return TPM2_RC_INITIALIZE;
364 /* Skip this, since the startup may have happened in SPL
365 * if (!tpm->tests_done)
366 * return TPM2_RC_NEEDS_TEST;
375 static int sandbox_tpm2_fill_buf(u8 *recv, size_t *recv_len, u16 tag, u32 rc)
377 *recv_len = sizeof(tag) + sizeof(u32) + sizeof(rc);
380 put_unaligned_be16(tag, recv);
384 put_unaligned_be32(*recv_len, recv);
387 /* Write return code */
388 put_unaligned_be32(rc, recv);
391 /* Add trailing \0 */
397 static int sandbox_tpm2_extend(struct udevice *dev, int pcr_index,
400 struct sandbox_tpm2 *tpm = dev_get_priv(dev);
403 /* Zero the PCR if this is the first use */
404 if (!tpm->pcr_extensions[pcr_index])
405 memset(tpm->pcr[pcr_index], '\0', TPM2_DIGEST_LEN);
408 sha256_update(&ctx, tpm->pcr[pcr_index], TPM2_DIGEST_LEN);
409 sha256_update(&ctx, extension, TPM2_DIGEST_LEN);
410 sha256_finish(&ctx, tpm->pcr[pcr_index]);
412 tpm->pcr_extensions[pcr_index]++;
417 static int sandbox_tpm2_xfer(struct udevice *dev, const u8 *sendbuf,
418 size_t send_size, u8 *recvbuf,
421 struct sandbox_tpm2 *tpm = dev_get_priv(dev);
422 enum tpm2_hierarchy hierarchy = 0;
423 const u8 *sent = sendbuf;
425 u32 length, command, rc = 0;
426 u16 tag, mode, new_pw_sz;
430 /* TPM2_GetProperty */
431 u32 capability, property, property_count, val;
433 /* TPM2_PCR_Read/Extend variables */
436 u32 selections, pcr_nb;
440 tag = get_unaligned_be16(sent);
443 length = get_unaligned_be32(sent);
444 sent += sizeof(length);
445 if (length != send_size) {
446 printf("TPM2: Unmatching length, received: %zd, expected: %d\n",
449 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
453 command = get_unaligned_be32(sent);
454 sent += sizeof(command);
455 rc = sandbox_tpm2_check_readyness(dev, command);
457 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
461 rc = sandbox_tpm2_check_session(dev, command, tag, &sent, &hierarchy);
463 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
468 case TPM2_CC_STARTUP:
469 mode = get_unaligned_be16(sent);
470 sent += sizeof(mode);
479 tpm->startup_done = true;
481 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
484 case TPM2_CC_SELF_TEST:
486 sent += sizeof(yes_no);
495 tpm->tests_done = true;
497 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
501 /* Reset this hierarchy password */
502 tpm->pw_sz[hierarchy] = 0;
504 /* Reset all password if thisis the PLATFORM hierarchy */
505 if (hierarchy == TPM2_HIERARCHY_PLATFORM)
506 for (i = 0; i < TPM2_HIERARCHY_NB; i++)
509 /* Reset the properties */
510 for (i = 0; i < TPM2_PROPERTY_NB; i++)
511 tpm->properties[i] = 0;
513 /* Reset the PCRs and their number of extensions */
514 for (i = 0; i < SANDBOX_TPM_PCR_NB; i++) {
515 tpm->pcr_extensions[i] = 0;
516 for (j = 0; j < TPM2_DIGEST_LEN; j++)
520 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
523 case TPM2_CC_HIERCHANGEAUTH:
524 new_pw_sz = get_unaligned_be16(sent);
525 sent += sizeof(new_pw_sz);
526 if (new_pw_sz > TPM2_DIGEST_LEN) {
528 } else if (new_pw_sz) {
529 tpm->pw_sz[hierarchy] = new_pw_sz;
530 memcpy(tpm->pw[hierarchy], sent, new_pw_sz);
534 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
537 case TPM2_CC_GET_CAPABILITY:
538 capability = get_unaligned_be32(sent);
539 sent += sizeof(capability);
540 property = get_unaligned_be32(sent);
541 sent += sizeof(property);
542 property_count = get_unaligned_be32(sent);
543 sent += sizeof(property_count);
545 switch (capability) {
548 case TPM2_CAP_TPM_PROPERTIES:
549 if (!property_count) {
551 return sandbox_tpm2_fill_buf(recv, recv_len,
555 if (property >= TPM2_PROPERTIES_OFFSET &&
556 ((property - TPM2_PROPERTIES_OFFSET) +
557 property_count > TPM2_PROPERTY_NB)) {
559 return sandbox_tpm2_fill_buf(recv, recv_len,
564 printf("Sandbox TPM2 only supports TPM2_CAP_PCRS or "
565 "TPM2_CAP_TPM_PROPERTIES\n");
567 return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
571 put_unaligned_be16(tag, recv);
574 /* Ignore length for now */
577 /* Write return code */
578 put_unaligned_be32(rc, recv);
581 /* Tell there is more data to read */
583 recv += sizeof(yes_no);
585 /* Repeat the capability */
586 put_unaligned_be32(capability, recv);
587 recv += sizeof(capability);
589 switch (capability) {
591 /* Give the number of algorithms supported - just SHA256 */
592 put_unaligned_be32(1, recv);
595 /* Give SHA256 algorithm */
596 put_unaligned_be16(TPM2_ALG_SHA256, recv);
599 /* Select the PCRs supported */
600 *recv = SANDBOX_TPM_PCR_SELECT_MAX;
603 /* Activate all the PCR bits */
604 for (i = 0; i < SANDBOX_TPM_PCR_SELECT_MAX; ++i) {
609 case TPM2_CAP_TPM_PROPERTIES:
610 /* Give the number of properties that follow */
611 put_unaligned_be32(property_count, recv);
612 recv += sizeof(property_count);
614 /* Fill with the properties */
615 for (i = 0; i < property_count; i++) {
616 put_unaligned_be32(property + i, recv);
617 recv += sizeof(property);
618 if (property >= TPM2_PROPERTIES_OFFSET) {
619 val = tpm->properties[(property -
620 TPM2_PROPERTIES_OFFSET) + i];
623 case TPM2_PT_PCR_COUNT:
624 val = SANDBOX_TPM_PCR_NB;
632 put_unaligned_be32(val, recv);
633 recv += sizeof(property);
638 /* Add trailing \0 */
641 /* Write response length */
642 *recv_len = recv - recvbuf;
643 put_unaligned_be32(*recv_len, recvbuf + sizeof(tag));
647 case TPM2_CC_DAM_PARAMETERS:
648 tpm->properties[TPM2_PROP_MAX_TRIES] = get_unaligned_be32(sent);
649 sent += sizeof(*tpm->properties);
650 tpm->properties[TPM2_RECOVERY_TIME] = get_unaligned_be32(sent);
651 sent += sizeof(*tpm->properties);
652 tpm->properties[TPM2_LOCKOUT_RECOVERY] = get_unaligned_be32(sent);
653 sent += sizeof(*tpm->properties);
655 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
658 case TPM2_CC_PCR_READ:
659 selections = get_unaligned_be32(sent);
660 sent += sizeof(selections);
661 if (selections != 1) {
662 printf("Sandbox cannot handle more than one PCR\n");
664 return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
667 alg = get_unaligned_be16(sent);
669 if (alg != TPM2_ALG_SHA256) {
670 printf("Sandbox TPM only handle SHA256 algorithm\n");
672 return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
675 pcr_array_sz = *sent;
676 sent += sizeof(pcr_array_sz);
677 if (!pcr_array_sz || pcr_array_sz > 8) {
678 printf("Sandbox TPM cannot handle so much PCRs\n");
680 return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
683 for (i = 0; i < pcr_array_sz; i++)
684 pcr_map += (u64)sent[i] << (i * 8);
687 printf("Empty PCR map\n");
689 return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
692 for (i = 0; i < SANDBOX_TPM_PCR_NB; i++)
693 if (pcr_map & BIT(i))
696 if (pcr_index >= SANDBOX_TPM_PCR_NB) {
697 printf("Invalid index %d, sandbox TPM handles up to %d PCR(s)\n",
698 pcr_index, SANDBOX_TPM_PCR_NB);
700 return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
704 put_unaligned_be16(tag, recv);
707 /* Ignore length for now */
710 /* Write return code */
711 put_unaligned_be32(rc, recv);
714 /* Number of extensions */
715 put_unaligned_be32(tpm->pcr_extensions[pcr_index], recv);
719 memcpy(recv, tpm->pcr[pcr_index], TPM2_DIGEST_LEN);
720 recv += TPM2_DIGEST_LEN;
722 /* Add trailing \0 */
725 /* Write response length */
726 *recv_len = recv - recvbuf;
727 put_unaligned_be32(*recv_len, recvbuf + sizeof(tag));
731 case TPM2_CC_PCR_EXTEND:
732 /* Get the PCR index */
733 pcr_index = get_unaligned_be32(sendbuf + sizeof(tag) +
736 if (pcr_index >= SANDBOX_TPM_PCR_NB) {
737 printf("Invalid index %d, sandbox TPM handles up to %d PCR(s)\n",
738 pcr_index, SANDBOX_TPM_PCR_NB);
742 /* Check the number of hashes */
743 pcr_nb = get_unaligned_be32(sent);
744 sent += sizeof(pcr_nb);
746 printf("Sandbox cannot handle more than one PCR\n");
748 return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
751 /* Check the hash algorithm */
752 alg = get_unaligned_be16(sent);
754 if (alg != TPM2_ALG_SHA256) {
755 printf("Sandbox TPM only handle SHA256 algorithm\n");
757 return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
761 rc = sandbox_tpm2_extend(dev, pcr_index, sent);
763 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
766 case TPM2_CC_NV_READ: {
769 index = get_unaligned_be32(sendbuf + TPM2_HDR_LEN + 4);
770 length = get_unaligned_be16(sent);
772 seq = sb_tpm_index_to_seq(index);
774 return log_msg_ret("index", -EINVAL);
775 printf("tpm: nvread index=%#02x, len=%#02x, seq=%#02x\n", index,
777 *recv_len = TPM2_HDR_LEN + 6 + length;
778 memset(recvbuf, '\0', *recv_len);
779 put_unaligned_be32(length, recvbuf + 2);
780 sb_tpm_read_data(tpm->nvdata, seq, recvbuf,
781 TPM2_HDR_LEN + 4 + 2, length);
784 case TPM2_CC_NV_WRITE: {
787 index = get_unaligned_be32(sendbuf + TPM2_HDR_LEN + 4);
788 length = get_unaligned_be16(sent);
792 seq = sb_tpm_index_to_seq(index);
794 return log_msg_ret("index", -EINVAL);
795 printf("tpm: nvwrite index=%#02x, len=%#02x, seq=%#02x\n", index,
797 memcpy(&tpm->nvdata[seq].data, sent, length);
798 tpm->nvdata[seq].present = true;
799 *recv_len = TPM2_HDR_LEN + 2;
800 memset(recvbuf, '\0', *recv_len);
803 case TPM2_CC_NV_DEFINE_SPACE: {
804 int policy_size, index, seq;
806 policy_size = get_unaligned_be16(sent + 12);
807 index = get_unaligned_be32(sent + 2);
808 sent += 14 + policy_size;
809 length = get_unaligned_be16(sent);
810 seq = sb_tpm_index_to_seq(index);
813 printf("tpm: define_space index=%x, len=%x, seq=%x, policy_size=%x\n",
814 index, length, seq, policy_size);
815 sb_tpm_define_data(tpm->nvdata, seq, length);
817 memset(recvbuf, '\0', *recv_len);
820 case TPM2_CC_NV_WRITELOCK:
822 memset(recvbuf, '\0', *recv_len);
825 printf("TPM2 command %02x unknown in Sandbox\n", command);
826 rc = TPM2_RC_COMMAND_CODE;
827 sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
833 static int sandbox_tpm2_get_desc(struct udevice *dev, char *buf, int size)
838 return snprintf(buf, size, "Sandbox TPM2.x");
841 static int sandbox_tpm2_report_state(struct udevice *dev, char *buf, int size)
843 struct sandbox_tpm2 *priv = dev_get_priv(dev);
848 return snprintf(buf, size, "init_done=%d", priv->init_done);
851 static int sandbox_tpm2_open(struct udevice *dev)
853 struct sandbox_tpm2 *tpm = dev_get_priv(dev);
858 tpm->init_done = true;
863 static int sandbox_tpm2_probe(struct udevice *dev)
865 struct sandbox_tpm2 *tpm = dev_get_priv(dev);
866 struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
868 /* Use the TPM v2 stack */
869 priv->version = TPM_V2;
871 priv->pcr_count = 32;
872 priv->pcr_select_min = 2;
875 memcpy(tpm, &s_state, sizeof(*tpm));
881 static int sandbox_tpm2_close(struct udevice *dev)
886 static const struct tpm_ops sandbox_tpm2_ops = {
887 .open = sandbox_tpm2_open,
888 .close = sandbox_tpm2_close,
889 .get_desc = sandbox_tpm2_get_desc,
890 .report_state = sandbox_tpm2_report_state,
891 .xfer = sandbox_tpm2_xfer,
894 static const struct udevice_id sandbox_tpm2_ids[] = {
895 { .compatible = "sandbox,tpm2" },
899 U_BOOT_DRIVER(sandbox_tpm2) = {
900 .name = "sandbox_tpm2",
902 .of_match = sandbox_tpm2_ids,
903 .ops = &sandbox_tpm2_ops,
904 .probe = sandbox_tpm2_probe,
905 .priv_auto = sizeof(struct sandbox_tpm2),