tpm-v2.c 660 B

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2018 Bootlin
  4. * Author: Miquel Raynal <miquel.raynal@bootlin.com>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <tpm-common.h>
  9. #include <tpm-v2.h>
  10. #include "tpm-utils.h"
  11. u32 tpm2_startup(enum tpm2_startup_types mode)
  12. {
  13. const u8 command_v2[12] = {
  14. tpm_u16(TPM2_ST_NO_SESSIONS),
  15. tpm_u32(12),
  16. tpm_u32(TPM2_CC_STARTUP),
  17. tpm_u16(mode),
  18. };
  19. int ret;
  20. /*
  21. * Note TPM2_Startup command will return RC_SUCCESS the first time,
  22. * but will return RC_INITIALIZE otherwise.
  23. */
  24. ret = tpm_sendrecv_command(command_v2, NULL, NULL);
  25. if (ret && ret != TPM2_RC_INITIALIZE)
  26. return ret;
  27. return 0;
  28. }