Add a command to enable the physical presence command.

Change-Id: Id8b6ac3c75d1ee34237cde8adde55cea33b25889

Review URL: http://codereview.chromium.org/3163045
diff --git a/firmware/lib/tpm_lite/include/tlcl.h b/firmware/lib/tpm_lite/include/tlcl.h
index cb0c1e6..8a65621 100644
--- a/firmware/lib/tpm_lite/include/tlcl.h
+++ b/firmware/lib/tpm_lite/include/tlcl.h
@@ -88,6 +88,10 @@
  */
 uint32_t TlclAssertPhysicalPresence(void);
 
+/* Enable the physical presence command.  The TPM error code is returned.
+ */
+uint32_t TlclPhysicalPresenceCMDEnable(void);
+
 /* Turns off physical presence and locks it off until next reboot.  The TPM
  * error code is returned.
  */
diff --git a/firmware/lib/tpm_lite/include/tlcl_structures.h b/firmware/lib/tpm_lite/include/tlcl_structures.h
index 039ee37..c35ecbe 100644
--- a/firmware/lib/tpm_lite/include/tlcl_structures.h
+++ b/firmware/lib/tpm_lite/include/tlcl_structures.h
@@ -69,6 +69,11 @@
 } tpm_pplock_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x4, },
 };
 
+struct s_tpm_ppenable_cmd{
+  uint8_t buffer[12];
+} tpm_ppenable_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x20, },
+};
+
 struct s_tpm_ppassert_cmd{
   uint8_t buffer[12];
 } tpm_ppassert_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x8, },
diff --git a/firmware/lib/tpm_lite/tlcl.c b/firmware/lib/tpm_lite/tlcl.c
index 09b07e6..5a28f67 100644
--- a/firmware/lib/tpm_lite/tlcl.c
+++ b/firmware/lib/tpm_lite/tlcl.c
@@ -176,6 +176,11 @@
   return Send(tpm_ppassert_cmd.buffer);
 }
 
+uint32_t TlclPhysicalPresenceCMDEnable(void) {
+  VBDEBUG(("TPM: Enable the physical presence command\n"));
+  return Send(tpm_ppenable_cmd.buffer);
+}
+
 uint32_t TlclAssertPhysicalPresenceResult(void) {
   uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
   return TlclSendReceive(tpm_ppassert_cmd.buffer, response, sizeof(response));
@@ -269,7 +274,7 @@
   }
   return result;
 }
-    
+
 uint32_t TlclSetGlobalLock(void) {
   uint32_t x;
   VBDEBUG(("TPM: Set global lock\n"));
diff --git a/firmware/version.c b/firmware/version.c
index 0ecee87..cdcd335 100644
--- a/firmware/version.c
+++ b/firmware/version.c
@@ -1 +1 @@
-char* VbootVersion = "VBOOv=c58c9bc8";
+char* VbootVersion = "VBOOv=ef12322e";
diff --git a/utility/tlcl_generator.c b/utility/tlcl_generator.c
index 0b8258b..cf2e485 100644
--- a/utility/tlcl_generator.c
+++ b/utility/tlcl_generator.c
@@ -180,6 +180,16 @@
   return cmd;
 }
 
+Command* BuildPPEnableCommand(void) {
+  int size = kTpmRequestHeaderLength + sizeof(TPM_PHYSICAL_PRESENCE);
+  Command* cmd = newCommand(TSC_ORD_PhysicalPresence, size);
+  cmd->name = "tpm_ppenable_cmd";
+  AddInitializedField(cmd, kTpmRequestHeaderLength,
+                      sizeof(TPM_PHYSICAL_PRESENCE),
+                      TPM_PHYSICAL_PRESENCE_CMD_ENABLE);
+  return cmd;
+}
+
 Command* BuildPPLockCommand(void) {
   int size = kTpmRequestHeaderLength + sizeof(TPM_PHYSICAL_PRESENCE);
   Command* cmd = newCommand(TSC_ORD_PhysicalPresence, size);
@@ -416,6 +426,7 @@
   BuildWriteCommand,
   BuildReadCommand,
   BuildPPAssertCommand,
+  BuildPPEnableCommand,
   BuildPPLockCommand,
   BuildStartupCommand,
   BuildSelftestfullCommand,
diff --git a/utility/tpmc.c b/utility/tpmc.c
index 0213b4b..2c23aa6 100644
--- a/utility/tpmc.c
+++ b/utility/tpmc.c
@@ -257,6 +257,8 @@
     TlclContinueSelfTest },
   { "assertphysicalpresence", "ppon", "assert Physical Presence",
     TlclAssertPhysicalPresence },
+  { "physicalpresencecmdenable", "ppcmd", "turn on software PP",
+    TlclPhysicalPresenceCMDEnable },
   { "enable", "ena", "enable the TPM (needs PP)", TlclSetEnable },
   { "disable", "dis", "disable the TPM (needs PP)", TlclClearEnable },
   { "activate", "act", "activate the TPM (needs PP, maybe reboot)",
@@ -298,9 +300,9 @@
     args = argv;
 
     if (strcmp(cmd, "help") == 0) {
-      printf("%23s %7s  %s\n\n", "command", "abbr.", "description");
+      printf("%26s %7s  %s\n\n", "command", "abbr.", "description");
       for (c = command_table; c < command_table + n_commands; c++) {
-        printf("%23s %7s  %s\n", c->name, c->abbr, c->description);
+        printf("%26s %7s  %s\n", c->name, c->abbr, c->description);
       }
       return 0;
     }