Merge remote-tracking branch 'goog/upstream-master' into D2-SC-032 am: ac034789be

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/nos/host/generic/+/15798424

Change-Id: Id99f69a2c5b0edbad9514837dcedf7e5fdfc9e79
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/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;
+}