diff mbox series

[U-Boot,v2,06/19] tpm: add macros for TPMv2 commands

Message ID 20180329074401.8691-7-miquel.raynal@bootlin.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series Introduce SPI TPM v2.0 support | expand

Commit Message

Miquel Raynal March 29, 2018, 7:43 a.m. UTC
TPM commands are much easier to handle with these macros that will
transform words or integers into byte string. This way, there is no need
to call pack_byte_string() while all variable length in a command are
known (and at must 4 bytes, which is a lot of them).

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 lib/tpm.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Simon Glass March 29, 2018, 10:42 p.m. UTC | #1
Hi Miquel,

On 29 March 2018 at 15:43, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> TPM commands are much easier to handle with these macros that will
> transform words or integers into byte string. This way, there is no need
> to call pack_byte_string() while all variable length in a command are
> known (and at must 4 bytes, which is a lot of them).
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  lib/tpm.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/lib/tpm.c b/lib/tpm.c
> index 38b76b4961..2b329145be 100644
> --- a/lib/tpm.c
> +++ b/lib/tpm.c
> @@ -15,6 +15,12 @@
>  /* Internal error of TPM command library */
>  #define TPM_LIB_ERROR  ((uint32_t)~0u)
>
> +/* To make strings of commands more easily */
> +#define __MSB(x) ((x) >> 8)
> +#define __LSB(x) ((x) & 0xFF)
> +#define U16_TO_ARRAY(x) __MSB(x), __LSB(x)
> +#define U32_TO_ARRAY(x) U16_TO_ARRAY((x) >> 16), U16_TO_ARRAY((x) & 0xFFFF)
> +
>  /* Global boolean to discriminate TPMv2.x from TPMv1.x functions */
>  static bool is_tpmv2;
>
> --
> 2.14.1
>

See my later comments about these macros.

Regards,
Simon
diff mbox series

Patch

diff --git a/lib/tpm.c b/lib/tpm.c
index 38b76b4961..2b329145be 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -15,6 +15,12 @@ 
 /* Internal error of TPM command library */
 #define TPM_LIB_ERROR	((uint32_t)~0u)
 
+/* To make strings of commands more easily */
+#define __MSB(x) ((x) >> 8)
+#define __LSB(x) ((x) & 0xFF)
+#define U16_TO_ARRAY(x) __MSB(x), __LSB(x)
+#define U32_TO_ARRAY(x) U16_TO_ARRAY((x) >> 16), U16_TO_ARRAY((x) & 0xFFFF)
+
 /* Global boolean to discriminate TPMv2.x from TPMv1.x functions */
 static bool is_tpmv2;