summaryrefslogtreecommitdiff
path: root/lib/tpm-utils.h
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2018-05-15 11:57:09 +0200
committerTom Rini <trini@konsulko.com>2018-05-25 20:12:56 -0400
commitf6872816ce07b6b26c9b6a4b1ba9206805d9321d (patch)
tree2f2d6c26bae265d2690263fc4ebb5fe4aaf36d85 /lib/tpm-utils.h
parentff32245bb3b57689cd7b1699ae29ff8fc0edc0d8 (diff)
tpm: add macros to enhance TPM commands readability
TPM commands are much easier to read/write with these macros that will transform words or integers into byte strings. 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> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'lib/tpm-utils.h')
-rw-r--r--lib/tpm-utils.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/tpm-utils.h b/lib/tpm-utils.h
index bc98d1ef8f7..a9cb7dc7ee5 100644
--- a/lib/tpm-utils.h
+++ b/lib/tpm-utils.h
@@ -12,6 +12,12 @@
/* Internal error of TPM command library */
#define TPM_LIB_ERROR ((u32)~0u)
+/* To make strings of commands more easily */
+#define __MSB(x) ((x) >> 8)
+#define __LSB(x) ((x) & 0xFF)
+#define tpm_u16(x) __MSB(x), __LSB(x)
+#define tpm_u32(x) tpm_u16((x) >> 16), tpm_u16((x) & 0xFFFF)
+
/**
* tpm_open() - Request access to locality 0 for the caller
*