All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 13/25] tpm: add TPM2_GetCapability command support
Date: Wed, 2 May 2018 20:32:13 -0600	[thread overview]
Message-ID: <CAPnjgZ2c2VOD9fTKP4nJR3EDZsVCA5zSXM2dF0z3heAqVSA1Uw@mail.gmail.com> (raw)
In-Reply-To: <20180502085934.29292-14-miquel.raynal@bootlin.com>

Hi Miquel,

On 2 May 2018 at 02:59, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> Add support for the TPM2_GetCapability command.
>
> Change the command file and the help accordingly.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  cmd/tpm-v2.c     | 41 +++++++++++++++++++++++++++++++++++++++++
>  include/tpm-v2.h | 15 +++++++++++++++
>  lib/tpm-v2.c     | 25 +++++++++++++++++++++++++
>  3 files changed, 81 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

nits below

>
> diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c
> index a61d751b4a..39fd9f0064 100644
> --- a/cmd/tpm-v2.c
> +++ b/cmd/tpm-v2.c
> @@ -108,6 +108,39 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
>         return report_return_code(rc);
>  }
>
> +static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
> +                                char * const argv[])
> +{
> +       u32 capability, property, rc;
> +       u8 *data;
> +       size_t count;
> +       int i, j;
> +
> +       if (argc != 5)
> +               return CMD_RET_USAGE;
> +
> +       capability = simple_strtoul(argv[1], NULL, 0);
> +       property = simple_strtoul(argv[2], NULL, 0);
> +       data = (void *)simple_strtoul(argv[3], NULL, 0);

map_sysmem() again - can you please fix globally in your patches?

> +       count = simple_strtoul(argv[4], NULL, 0);
> +
> +       rc = tpm2_get_capability(capability, property, data, count);
> +       if (!rc) {

How about:

if (rc)
   return report_return_code(rc);
printf()...
...

return 0;


> +               printf("Capabilities read from TPM:\n");
> +               for (i = 0; i < count; i++) {
> +                       printf("Property 0x");
> +                       for (j = 0; j < 4; j++)
> +                               printf("%02x", data[(i * 8) + j]);
> +                       printf(": 0x");
> +                       for (j = 4; j < 8; j++)
> +                               printf("%02x", data[(i * 8) + j]);
> +                       printf("\n");
> +               }
> +       }
> +
> +       return report_return_code(rc);
> +}
> +
>  static cmd_tbl_t tpm2_commands[] = {
>         U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
>         U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
> @@ -116,6 +149,7 @@ static cmd_tbl_t tpm2_commands[] = {
>         U_BOOT_CMD_MKENT(clear, 0, 1, do_tpm2_clear, "", ""),
>         U_BOOT_CMD_MKENT(pcr_extend, 0, 1, do_tpm2_pcr_extend, "", ""),
>         U_BOOT_CMD_MKENT(pcr_read, 0, 1, do_tpm_pcr_read, "", ""),
> +       U_BOOT_CMD_MKENT(get_capability, 0, 1, do_tpm_get_capability, "", ""),
>  };
>
>  cmd_tbl_t *get_tpm_commands(unsigned int *size)
> @@ -155,4 +189,11 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
>  "    Read PCR #<pcr> to memory address <digest_addr>.\n"
>  "    <pcr>: index of the PCR\n"
>  "    <digest_addr>: address to store the a 32-byte SHA256 digest\n"
> +"get_capability <capability> <property> <addr> <count>\n"
> +"    Read and display <count> entries indexed by <capability>/<property>.\n"
> +"    Values are 4-byte long and are written at <addr>.\n"

4 bytes long

> +"    <capability>: capability\n"
> +"    <property>: property\n"
> +"    <addr>: address to store <count> entries of 4 bytes\n"
> +"    <count>: number of entries to retrieve\n"
>  );
> diff --git a/include/tpm-v2.h b/include/tpm-v2.h
> index 54d14df365..07cd3a5e99 100644
> --- a/include/tpm-v2.h
> +++ b/include/tpm-v2.h
> @@ -175,4 +175,19 @@ u32 tpm2_pcr_extend(u32 index, const uint8_t *digest);
>   */
>  u32 tpm2_pcr_read(u32 index, void *data, unsigned int *updates);
>
> +/**
> + * Issue a TPM2_GetCapability command.  This implementation is limited
> + * to query property index that is 4-byte wide.
> + *
> + * @param capability   Partition of capabilities
> + * @param property     Further definition of capability, which is
> + *                     limited to be 4-byte wide
> + * @param buf          Output buffer for capability information
> + * @param prop_count   Size of output buffer
> + *
> + * @return return code of the operation
> + */
> +u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
> +                       size_t prop_count);
> +
>  #endif /* __TPM_V2_H */
> diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
> index d557b08f8b..c567c943df 100644
> --- a/lib/tpm-v2.c
> +++ b/lib/tpm-v2.c
> @@ -158,3 +158,28 @@ u32 tpm2_pcr_read(u32 index, void *data, unsigned int *updates)
>
>         return 0;
>  }
> +
> +u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
> +                       size_t prop_count)
> +{
> +       u8 command_v2[COMMAND_BUFFER_SIZE] = {
> +               tpm_u16(TPM2_ST_NO_SESSIONS),           /* TAG */
> +               tpm_u32(22),                            /* Length */
> +               tpm_u32(TPM2_CC_GET_CAPABILITY),        /* Command code */
> +
> +               tpm_u32(capability),                    /* Capability */
> +               tpm_u32(property),                      /* Property */
> +               tpm_u32(prop_count),                    /* Property count */
> +       };
> +       u8 response[COMMAND_BUFFER_SIZE];
> +       size_t response_len = COMMAND_BUFFER_SIZE;
> +       int ret;
> +
> +       ret = tpm_sendrecv_command(command_v2, response, &response_len);
> +       if (ret)
> +               return ret;
> +
> +       memcpy(buf, &response[19], response_len - 19);

What is 19 here? It is confusing to have open-coded values with no
meaning. Is it sizeof() something, or a number in the spec?

> +
> +       return 0;
> +}
> --
> 2.14.1
>

Regards,
Simon

  reply	other threads:[~2018-05-03  2:32 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-02  8:59 [U-Boot] [PATCH v3 00/25] Introduce TPMv2.0 support Miquel Raynal
2018-05-02  8:59 ` [U-Boot] [PATCH v3 01/25] tpm: add Revision ID field in the chip structure Miquel Raynal
2018-05-02  8:59 ` [U-Boot] [PATCH v3 02/25] tpm: prepare introduction of TPMv2.x support in Kconfig Miquel Raynal
2018-05-02 19:33   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 03/25] tpm: disociate TPMv1.x specific and generic code Miquel Raynal
2018-05-03  2:31   ` Simon Glass
2018-05-14 18:01     ` Miquel Raynal
2018-05-14 19:43       ` Tom Rini
2018-05-15  8:56         ` Miquel Raynal
2018-05-02  8:59 ` [U-Boot] [PATCH v3 04/25] tpm: prepare support for TPMv2.x commands Miquel Raynal
2018-05-03  2:31   ` Simon Glass
2018-05-03 12:27     ` Miquel Raynal
2018-05-02  8:59 ` [U-Boot] [PATCH v3 05/25] tpm: add macros to enhance TPM commands readability Miquel Raynal
2018-05-03  2:31   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 06/25] tpm: add possible traces to analyze buffers returned by the TPM Miquel Raynal
2018-05-02  8:59 ` [U-Boot] [PATCH v3 07/25] tpm: report driver error code to upper layer Miquel Raynal
2018-05-03  2:31   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 08/25] tpm: add TPM2_Startup command support Miquel Raynal
2018-05-03  2:31   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 09/25] tpm: add TPM2_SelfTest " Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 10/25] tpm: add TPM2_Clear " Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 11/25] tpm: add TPM2_PCR_Extend " Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 12/25] tpm: add TPM2_PCR_Read " Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-15  7:52     ` Miquel Raynal
2018-05-02  8:59 ` [U-Boot] [PATCH v3 13/25] tpm: add TPM2_GetCapability " Miquel Raynal
2018-05-03  2:32   ` Simon Glass [this message]
2018-05-15  8:19     ` Miquel Raynal
2018-05-02  8:59 ` [U-Boot] [PATCH v3 14/25] tpm: add dictionary attack mitigation commands support Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 15/25] tpm: add TPM2_HierarchyChangeAuth command support Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 16/25] tpm: add PCR authentication commands support Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 17/25] tpm: add support for TPMv2.x SPI modules Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-15  8:48     ` Miquel Raynal
2018-05-02  8:59 ` [U-Boot] [PATCH v3 18/25] tpm: add the possibility to reset the chip with a gpio Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 19/25] doc: device-tree-bindings: add ST33TPHF20 TPMv2.0 module info Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 20/25] test/py: add TPMv2.x test suite Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 21/25] tpm: add a Sandbox TPMv2.x driver Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 22/25] doc: device-tree-bindings: add Sandbox TPMv2.0 module info Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-03 12:45     ` Miquel Raynal
2018-05-02  8:59 ` [U-Boot] [PATCH v3 23/25] sandbox: dts: add Sandbox TPMv2.x node Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 24/25] configs: add TPMv2.x support in Sandbox Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-02  8:59 ` [U-Boot] [PATCH v3 25/25] tpm: allow Sandbox to run TPMv2.x commands Miquel Raynal
2018-05-03  2:32   ` Simon Glass
2018-05-03 12:56     ` Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPnjgZ2c2VOD9fTKP4nJR3EDZsVCA5zSXM2dF0z3heAqVSA1Uw@mail.gmail.com \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.