TPM: Include the build type in PCR0 (bootmode)

Treat non-secure boot as "developer mode" and consider any build running
on a non-secure device a developer image.

Change-Id: Icfebe669e733c88c0530ec5cca94bf91e194b118
Google-Bug-Id: 24813975
diff --git a/arch/arm/boards/optimus/tpm.c b/arch/arm/boards/optimus/tpm.c
index 182b931..1e5081f 100644
--- a/arch/arm/boards/optimus/tpm.c
+++ b/arch/arm/boards/optimus/tpm.c
@@ -35,31 +35,49 @@
 
 #define PCR_DIGEST_LENGTH	20
 
-#define SHA1_NON_SECURE_BOOT		0
-#define SHA1_SECURE_BOOT		1
-#define SHA1_RECOVERY_MODE_NON_SECURE	2
-#define SHA1_RECOVERY_MODE_SECURE	3
+struct bootmode_pcr_values {
+	uint8_t normal_boot[PCR_DIGEST_LENGTH];
+	uint8_t recovery_mode[PCR_DIGEST_LENGTH];
+};
+
+static struct bootmode_pcr_values pcr_values_secure_boot = {
+#ifdef CONFIG_DEVELOPER_BAREBOX
+	/* secure boot, normal boot, dev firmware [0, 0, 2] */
+	.normal_boot = {0x1e, 0xf6, 0x24, 0x48, 0x2d, 0x62, 0x0e, 0x43, 0xe6, 0xd3,
+			0x4d, 0xa1, 0xaf, 0xe4, 0x62, 0x67, 0xfc, 0x69, 0x5d, 0x9b},
+	/* secure boot, recovery mode, dev firmware [0, 1, 2] */
+	.recovery_mode = {0x0c, 0x7a, 0x62, 0x3f, 0xd2, 0xbb, 0xc0, 0x5b, 0x06, 0x42,
+			  0x3b, 0xe3, 0x59, 0xe4, 0x02, 0x1d, 0x36, 0xe7, 0x21, 0xad},
+#else
+	/* secure boot, normal boot, prod firmware [0, 0, 1] */
+	.normal_boot = {0x25, 0x47, 0xcc, 0x73, 0x6e, 0x95, 0x1f, 0xa4, 0x91, 0x98,
+			0x53, 0xc4, 0x3a, 0xe8, 0x90, 0x86, 0x1a, 0x3b, 0x32, 0x64},
+	/* secure boot, recovery mode, prod firmware [0, 1, 1] */
+	.recovery_mode = {0xee, 0xe4, 0x47, 0xed, 0xc7, 0x9f, 0xea, 0x1c, 0xa7, 0xc7,
+			  0xd3, 0x4e, 0x46, 0x32, 0x61, 0xcd, 0xa4, 0xba, 0x33, 0x9e},
+#endif
+};
+
+static struct bootmode_pcr_values pcr_values_nonsecure_boot = {
+#ifdef CONFIG_DEVELOPER_BAREBOX
+	/* non-secure boot, normal boot, dev firmware [1, 0, 2] */
+	.normal_boot = {0xfa, 0x01, 0x0d, 0x26, 0x64, 0xcc, 0x5b, 0x3b, 0x82, 0xee,
+			0x48, 0x8f, 0xe2, 0xb9, 0xf5, 0x0f, 0x49, 0x32, 0xeb, 0x8f},
+	/* non-secure boot, recovery mode, dev firmware [1, 1, 2] */
+	.recovery_mode = {0x12, 0xa3, 0x40, 0xd7, 0x89, 0x7f, 0xe7, 0x13, 0xfc, 0x8f,
+			  0x02, 0xac, 0x53, 0x65, 0xb8, 0x6e, 0xbf, 0x35, 0x31, 0x78},
+#else
+	/* non-secure boot, normal boot, dev firmware [1, 0, 2] */
+	.normal_boot = {0xfa, 0x01, 0x0d, 0x26, 0x64, 0xcc, 0x5b, 0x3b, 0x82, 0xee,
+			0x48, 0x8f, 0xe2, 0xb9, 0xf5, 0x0f, 0x49, 0x32, 0xeb, 0x8f},
+	/* non-secure boot, recovery mode, dev firmware [1, 1, 2] */
+	.recovery_mode = {0x12, 0xa3, 0x40, 0xd7, 0x89, 0x7f, 0xe7, 0x13, 0xfc, 0x8f,
+			  0x02, 0xac, 0x53, 0x65, 0xb8, 0x6e, 0xbf, 0x35, 0x31, 0x78},
+#endif
+};
 
 extern int is_recovery_mode(void);
 
-static const uint8_t bootmode_digests[4][PCR_DIGEST_LENGTH] = {
-	/* non-secure boot [0, 0, 2] */
-	{0x1e, 0xf6, 0x24, 0x48, 0x2d, 0x62, 0x0e, 0x43, 0xe6, 0xd3,
-	 0x4d, 0xa1, 0xaf, 0xe4, 0x62, 0x67, 0xfc, 0x69, 0x5d, 0x9b},
-
-	/* secure boot [0, 0, 1] */
-	{0x25, 0x47, 0xcc, 0x73, 0x6e, 0x95, 0x1f, 0xa4, 0x91, 0x98,
-	 0x53, 0xc4, 0x3a, 0xe8, 0x90, 0x86, 0x1a, 0x3b, 0x32, 0x64},
-
-	/* recovery mode, non-secure [0, 1, 2] */
-	{0x0c, 0x7a, 0x62, 0x3f, 0xd2, 0xbb, 0xc0, 0x5b, 0x06, 0x42,
-	 0x3b, 0xe3, 0x59, 0xe4, 0x02, 0x1d, 0x36, 0xe7, 0x21, 0xad},
-
-	/* recovery mode, secure [0, 1, 1] */
-	{0xee, 0xe4, 0x47, 0xed, 0xc7, 0x9f, 0xea, 0x1c, 0xa7, 0xc7,
-	 0xd3, 0x4e, 0x46, 0x32, 0x61, 0xcd, 0xa4, 0xba, 0x33, 0x9e}
-};
-
 static const uint8_t sha256_gfsc100[PCR_DIGEST_LENGTH] = {
 	0x4f, 0x8c, 0x4d, 0xaf, 0x4d, 0xf3, 0x2e, 0xaf, 0xb5, 0x57,
 	0xff, 0x76, 0x58, 0x86, 0x02, 0x94, 0x42, 0xdc, 0xce, 0x06
@@ -114,9 +132,9 @@
 			const uint8_t *digest;
 
 			if (get_secure_boot_mode() == SECURE) {
-				digest = bootmode_digests[SHA1_SECURE_BOOT];
+				digest = pcr_values_secure_boot.normal_boot;
 			} else {
-				digest = bootmode_digests[SHA1_NON_SECURE_BOOT];
+				digest = pcr_values_nonsecure_boot.normal_boot;
 			}
 
 			RETURN_ON_FAILURE(tlcl_extend(0, digest, NULL));
@@ -132,9 +150,9 @@
 		RETURN_ON_FAILURE(tlcl_set_deactivated(0));
 
 		if (get_secure_boot_mode() == SECURE) {
-			digest = bootmode_digests[SHA1_RECOVERY_MODE_SECURE];
+			digest = pcr_values_secure_boot.recovery_mode;
 		} else {
-			digest = bootmode_digests[SHA1_RECOVERY_MODE_NON_SECURE];
+			digest = pcr_values_nonsecure_boot.recovery_mode;
 		}
 
 		RETURN_ON_FAILURE(tlcl_extend(0, digest, NULL));