Add human friendly payload information to the manifest.

This adds new strings to the payload manifest that describe what images
the payload updates from/to. These strings are passed in when delta_generator
is invoked, and are trusted implicitly.

BUG=chromium:226310
TEST=Built/Updated.

Change-Id: I278137c97cf8376d4e2fd8e82402cbb7d4f1a104
Reviewed-on: https://gerrit.chromium.org/gerrit/47347
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
Commit-Queue: Don Garrett <dgarrett@chromium.org>
diff --git a/generate_delta_main.cc b/generate_delta_main.cc
index 7c8b54b..1f49c42 100644
--- a/generate_delta_main.cc
+++ b/generate_delta_main.cc
@@ -65,6 +65,42 @@
              chromeos_update_engine::kRootFSPartitionSize,
              "RootFS partition size for the image once installed");
 
+DEFINE_string(old_channel, "",
+              "The channel for the old image. 'dev-channel', 'npo-channel', "
+              "etc. Ignored, except during delta generation.");
+DEFINE_string(old_board, "",
+              "The board for the old image. 'x86-mario', 'lumpy', "
+              "etc. Ignored, except during delta generation.");
+DEFINE_string(old_version, "",
+              "The build version of the old image. 1.2.3, etc.");
+DEFINE_string(old_key, "",
+              "The key used to sign the old image. 'premp', 'mp', 'mp-v3',"
+              " etc");
+DEFINE_string(old_build_channel, "",
+              "The channel for the build of the old image. 'dev-channel', "
+              "etc, but will never contain special channels such as "
+              "'npo-channel'. Ignored, except during delta generation.");
+DEFINE_string(old_build_version, "",
+              "The version of the build containing the old image.");
+
+DEFINE_string(new_channel, "",
+              "The channel for the new image. 'dev-channel', 'npo-channel', "
+              "etc. Ignored, except during delta generation.");
+DEFINE_string(new_board, "",
+              "The board for the new image. 'x86-mario', 'lumpy', "
+              "etc. Ignored, except during delta generation.");
+DEFINE_string(new_version, "",
+              "The build version of the new image. 1.2.3, etc.");
+DEFINE_string(new_key, "",
+              "The key used to sign the new image. 'premp', 'mp', 'mp-v3',"
+              " etc");
+DEFINE_string(new_build_channel, "",
+              "The channel for the build of the new image. 'dev-channel', "
+              "etc, but will never contain special channels such as "
+              "'npo-channel'. Ignored, except during delta generation.");
+DEFINE_string(new_build_version, "",
+              "The version of the build containing the new image.");
+
 // This file contains a simple program that takes an old path, a new path,
 // and an output file as arguments and the path to an output file and
 // generates a delta that can be sent to Chrome OS clients.
@@ -99,6 +135,40 @@
 }
 
 
+bool ParseImageInfo(const string& channel,
+                    const string& board,
+                    const string& version,
+                    const string& key,
+                    const string& build_channel,
+                    const string& build_version,
+                    ImageInfo* image_info) {
+
+  // All of these arguments should be present or missing.
+  bool empty = channel.empty();
+
+  CHECK_EQ(channel.empty(), empty);
+  CHECK_EQ(board.empty(), empty);
+  CHECK_EQ(version.empty(), empty);
+  CHECK_EQ(key.empty(), empty);
+
+  if (empty)
+    return false;
+
+  image_info->set_channel(channel);
+  image_info->set_board(board);
+  image_info->set_version(version);
+  image_info->set_key(key);
+
+  image_info->set_build_channel(
+      build_channel.empty() ? channel : build_channel);
+
+  image_info->set_build_version(
+      build_version.empty() ? version : build_version);
+
+  return true;
+}
+
+
 void CalculatePayloadHashForSigning() {
   LOG(INFO) << "Calculating payload hash for signing.";
   LOG_IF(FATAL, FLAGS_in_file.empty())
@@ -257,28 +327,56 @@
   CHECK(!FLAGS_new_image.empty());
   CHECK(!FLAGS_out_file.empty());
   CHECK(!FLAGS_new_kernel.empty());
-  if (FLAGS_old_image.empty()) {
-    LOG(INFO) << "Generating full update";
-  } else {
+
+  bool is_delta = !FLAGS_old_image.empty();
+
+  ImageInfo old_image_info;
+  ImageInfo new_image_info;
+
+  // TODO(dgarrett) Check the result is True when these args are required.
+  ParseImageInfo(FLAGS_new_channel,
+                 FLAGS_new_board,
+                 FLAGS_new_version,
+                 FLAGS_new_key,
+                 FLAGS_new_build_channel,
+                 FLAGS_new_build_version,
+                 &new_image_info);
+
+  CHECK(is_delta || !ParseImageInfo(FLAGS_old_channel,
+                                    FLAGS_old_board,
+                                    FLAGS_old_version,
+                                    FLAGS_old_key,
+                                    FLAGS_old_build_channel,
+                                    FLAGS_old_build_version,
+                                    &old_image_info));
+
+
+  if (is_delta) {
     LOG(INFO) << "Generating delta update";
     CHECK(!FLAGS_old_dir.empty());
     CHECK(!FLAGS_new_dir.empty());
     if ((!IsDir(FLAGS_old_dir.c_str())) || (!IsDir(FLAGS_new_dir.c_str()))) {
       LOG(FATAL) << "old_dir or new_dir not directory";
     }
+  } else {
+    LOG(INFO) << "Generating full update";
   }
+
   uint64_t metadata_size;
-  if (!DeltaDiffGenerator::GenerateDeltaUpdateFile(FLAGS_old_dir,
-                                                   FLAGS_old_image,
-                                                   FLAGS_new_dir,
-                                                   FLAGS_new_image,
-                                                   FLAGS_old_kernel,
-                                                   FLAGS_new_kernel,
-                                                   FLAGS_out_file,
-                                                   FLAGS_private_key,
-                                                   FLAGS_chunk_size,
-                                                   FLAGS_rootfs_partition_size,
-                                                   &metadata_size)) {
+  if (!DeltaDiffGenerator::GenerateDeltaUpdateFile(
+      FLAGS_old_dir,
+      FLAGS_old_image,
+      FLAGS_new_dir,
+      FLAGS_new_image,
+      FLAGS_old_kernel,
+      FLAGS_new_kernel,
+      FLAGS_out_file,
+      FLAGS_private_key,
+      FLAGS_chunk_size,
+      FLAGS_rootfs_partition_size,
+      is_delta ? &old_image_info : NULL,
+      &new_image_info,
+      &metadata_size)) {
     return 1;
   }
   return 0;