summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2016-10-25 14:14:19 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-26 19:59:15 -0700
commitf2c33b73b265c2229ffd6b94e86e5f8956ffab6f (patch)
tree3a1877aa1f4a4fe420b3ca51ff7c7068291b26a8
parenta5393caeb591dce6ad14fe3580ce182f644a51eb (diff)
downloadchrome-ec-f2c33b73b265c2229ffd6b94e86e5f8956ffab6f.tar.gz
cr50: provide platform API for fw version capability
The tpm is supposed to report its firmware version when TPM_PT_FIRMWARE_VERSION_1 and TPM_PT_FIRMWARE_VERSION_2 capabilities are requested. This patch retrieves form the build info string SHA1s of the ec and tpm2 repositories and returns them to the caller. BRANCH=none BUG=chrome-os-partner:58177 TEST=with the appropriate tpm2 source tree changes the ec and tpm SHA1s are now reported: localhost ~ # tpm_version TPM 2.0 Version Info: Chip Version: 2.0.0.0 .... Firmware Version: 0a92ec7c01b9c924 (the first half is the zero prepended 7 characters of the ec SHA1, and the second half is the zero prepended 7 characters of the tpm2 SHA1). Change-Id: I01e4fffdafbbdc4668342ea511ca9c4a555e20a9 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/403115 Reviewed-by: Andrey Pronin <apronin@chromium.org>
-rw-r--r--board/cr50/tpm2/platform.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/board/cr50/tpm2/platform.c b/board/cr50/tpm2/platform.c
index 20b5854625..7c98c353a0 100644
--- a/board/cr50/tpm2/platform.c
+++ b/board/cr50/tpm2/platform.c
@@ -7,6 +7,8 @@
#include "TPM_Types.h"
#include "trng.h"
+#include "util.h"
+#include "version.h"
uint16_t _cpri__GenerateRandom(size_t random_size,
uint8_t *buffer)
@@ -14,3 +16,47 @@ uint16_t _cpri__GenerateRandom(size_t random_size,
rand_bytes(buffer, random_size);
return random_size;
}
+
+/*
+ * Return the pointer to the character immediately after the first dash
+ * encountered in the passed in string, or NULL if there is no dashes in the
+ * string.
+ */
+static const char *char_after_dash(const char *str)
+{
+ char c;
+
+ do {
+ c = *str++;
+
+ if (c == '-')
+ return str;
+ } while (c);
+
+ return NULL;
+}
+
+/*
+ * The properly formatted build_info string has the ec code SHA1 after the
+ * first dash, and tpm2 code sha1 after the second dash.
+ */
+
+void _plat__GetFwVersion(uint32_t *firmwareV1, uint32_t *firmwareV2)
+{
+ const char *ver_str = char_after_dash(build_info);
+
+ /* Just in case the build_info string is misformatted. */
+ *firmwareV1 = 0;
+ *firmwareV2 = 0;
+
+ if (!ver_str)
+ return;
+
+ *firmwareV1 = strtoi(ver_str, NULL, 16);
+
+ ver_str = char_after_dash(ver_str);
+ if (!ver_str)
+ return;
+
+ *firmwareV2 = strtoi(ver_str, NULL, 16);
+}