Snap for 7901677 from f6fd625606e1e99ebb62aba32b3a298dfeed0ec7 to sc-platform-release

Change-Id: I5b31e446a2e3c089847ca1eb5011622ea105b277
diff --git a/libnos_transport/transport.c b/libnos_transport/transport.c
index 85ba312..855b884 100644
--- a/libnos_transport/transport.c
+++ b/libnos_transport/transport.c
@@ -155,6 +155,10 @@
     uint8_t data[STATUS_MAX_LENGTH];
   } st;
   int retries = CRC_RETRY_COUNT;
+
+  /* All unset fields will be 0. */
+  memset(out, 0, sizeof(*out));
+
   while (retries--) {
     /* Get the status from the device */
     const uint32_t command = CMD_ID(ctx->app_id) | CMD_IS_READ | CMD_TRANSPORT;
@@ -163,9 +167,6 @@
       return -1;
     }
 
-    /* All unset fields will be 0. */
-    memset(out, 0, sizeof(*out));
-
     /* Examine v0 fields */
     out->status = le32toh(st.status.status);
     out->reply_len = le16toh(st.status.reply_len);
@@ -295,7 +296,7 @@
 
     /* Any further Writes needed to send all the args must set the MORE bit */
     command |= CMD_MORE_TO_COME;
-    args += ulen;
+    if (args) args += ulen;
     arg_len -= ulen;
   } while (arg_len);
 
diff --git a/nugget/proto/nugget/app/avb/avb.proto b/nugget/proto/nugget/app/avb/avb.proto
index bc0c700..9aec71e 100644
--- a/nugget/proto/nugget/app/avb/avb.proto
+++ b/nugget/proto/nugget/app/avb/avb.proto
@@ -53,13 +53,16 @@
 }
 
 // GetState
-message GetStateRequest {}
+message GetStateRequest {
+  bool keysclear_reset = 1;
+}
 message GetStateResponse {
   uint64 version = 1;
   bool bootloader = 2;
   bool production = 3;
   uint32 number_of_locks = 4;
   bytes locks = 5;
+  bool keysclear_required = 6;
 }
 
 // Load
diff --git a/nugget/proto/nugget/app/keymaster/keymaster.proto b/nugget/proto/nugget/app/keymaster/keymaster.proto
index e6fec75..1cb50bd 100644
--- a/nugget/proto/nugget/app/keymaster/keymaster.proto
+++ b/nugget/proto/nugget/app/keymaster/keymaster.proto
@@ -138,6 +138,11 @@
   rpc VigoReleaseSecret(VigoReleaseSecretRequest)
       returns (VigoReleaseSecretResponse);
 
+  /*
+   * pKVM implementation
+   */
+  rpc GetPerFactoryResetValue(GetPerFactoryResetValueRequest) returns (GetPerFactoryResetValueResponse);
+
   // These are implemented with a enum, so new RPCs must be appended, and
   // deprecated RPCs need placeholders.
 }
@@ -564,3 +569,14 @@
   ChipFusing chip_fusing = 3;
   bool nodelocked_ro = 4;
 }
+
+// pKVM messages
+message GetPerFactoryResetValueRequest {
+  bool bootloader_only = 1;
+  bytes input = 2;
+}
+
+message GetPerFactoryResetValueResponse {
+  ErrorCode error_code = 1;
+  bytes output = 2;
+}