[PATCH v4 6/7] tpm: Implement state command for Cr50

Ilias Apalodimas ilias.apalodimas at linaro.org
Wed Aug 24 10:32:55 CEST 2022


Hi Simon,


[...]

> +
> +static int cr50_i2c_report_state(struct udevice *dev, char *str, int str_max)
> +{
> +       char buf[50];
> +       int buf_size = sizeof(buf);

Shouldn't this be size_t?  I'll go through the rest of the patches, if
that's the only issue I find, I'll fix it while merging

Thanks
/Ilias
> +       int ret;
> +
> +       ret = tpm2_report_state(dev, TPM2_CR50_VENDOR_COMMAND,
> +                               TPM2_CR50_SUB_CMD_REPORT_TPM_STATE,
> +                               buf, &buf_size);
> +       if (ret)
> +               return ret;
> +
> +       /* TPM responded as expected */
> +       ret = stringify_state(buf, buf_size, str, str_max);
> +       if (ret)
> +               return ret;
> +
> +       return 0;
> +}
> +
>  static int cr50_i2c_open(struct udevice *dev)
>  {
>         char buf[80];
> @@ -730,6 +892,7 @@ struct acpi_ops cr50_acpi_ops = {
>  static const struct tpm_ops cr50_i2c_ops = {
>         .open           = cr50_i2c_open,
>         .get_desc       = cr50_i2c_get_desc,
> +       .report_state   = cr50_i2c_report_state,
>         .send           = cr50_i2c_send,
>         .recv           = cr50_i2c_recv,
>         .cleanup        = cr50_i2c_cleanup,
> diff --git a/include/tpm-v2.h b/include/tpm-v2.h
> index e79c90b9395..36c6ac0be6e 100644
> --- a/include/tpm-v2.h
> +++ b/include/tpm-v2.h
> @@ -658,4 +658,17 @@ u32 tpm2_disable_platform_hierarchy(struct udevice *dev);
>  u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf,
>                         u8 *recvbuf, size_t *recv_size);
>
> +/**
> + * tpm_cr50_report_state() - Report the Cr50 internal state
> + *
> + * @dev:       TPM device
> + * @vendor_cmd:        Vendor command number to send
> + * @vendor_subcmd: Vendor sub-command number to send
> + * @recvbuf:   Buffer to save the response to
> + * @recv_size: Pointer to the size of the response buffer
> + * Return: result of the operation
> + */
> +u32 tpm2_report_state(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd,
> +                     u8 *recvbuf, size_t *recv_size);
> +
>  #endif /* __TPM_V2_H */
> diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
> index 3e240bb4c67..edee9854a7c 100644
> --- a/lib/tpm-v2.c
> +++ b/lib/tpm-v2.c
> @@ -679,3 +679,28 @@ u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf,
>  {
>         return tpm_sendrecv_command(dev, sendbuf, recvbuf, recv_size);
>  }
> +
> +u32 tpm2_report_state(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd,
> +                     u8 *recvbuf, size_t *recv_size)
> +{
> +       u8 command_v2[COMMAND_BUFFER_SIZE] = {
> +               /* header 10 bytes */
> +               tpm_u16(TPM2_ST_NO_SESSIONS),           /* TAG */
> +               tpm_u32(10 + 2),                        /* Length */
> +               tpm_u32(vendor_cmd),    /* Command code */
> +
> +               tpm_u16(vendor_subcmd),
> +       };
> +       int ret;
> +
> +       ret = tpm_sendrecv_command(dev, command_v2, recvbuf, recv_size);
> +       log_debug("ret=%s, %x\n", dev->name, ret);
> +       if (ret)
> +               return ret;
> +       if (*recv_size < 12)
> +               return -ENODATA;
> +       *recv_size -= 12;
> +       memcpy(recvbuf, recvbuf + 12, *recv_size);
> +
> +       return 0;
> +}
> --
> 2.37.2.609.g9ff673ca1a-goog
>


More information about the U-Boot mailing list