Add misc partition

misc partition is used to store bootloader messages and
commands to recovery.

Originally aosp/955522

Bug: 79094284
Test: boot with -composite_disk, check /dev/block/by-name
Change-Id: I8e697676cbc5770aabfc707aa31308e0c6126670
diff --git a/host/commands/launch/data_image.cc b/host/commands/launch/data_image.cc
index dad88d8..f817506 100644
--- a/host/commands/launch/data_image.cc
+++ b/host/commands/launch/data_image.cc
@@ -134,3 +134,16 @@
 
   return true;
 }
+
+bool InitializeMiscImage(const std::string& misc_image) {
+  bool misc_exists = cvd::FileHasContent(misc_image.c_str());
+
+  if (misc_exists) {
+    LOG(INFO) << "misc partition image: use existing";
+    return true;
+  }
+
+  LOG(INFO) << "misc partition image: creating empty";
+  CreateBlankImage(misc_image, 1 /* mb */, "none");
+  return true;
+}
diff --git a/host/commands/launch/data_image.h b/host/commands/launch/data_image.h
index 664467e..aed01c3 100644
--- a/host/commands/launch/data_image.h
+++ b/host/commands/launch/data_image.h
@@ -6,5 +6,6 @@
 
 bool ApplyDataImagePolicy(const vsoc::CuttlefishConfig& config,
                           const std::string& path);
+bool InitializeMiscImage(const std::string& misc_image);
 void CreateBlankImage(
     const std::string& image, int image_mb, const std::string& image_fmt);
diff --git a/host/commands/launch/flags.cc b/host/commands/launch/flags.cc
index ffe117f..1ff795c 100644
--- a/host/commands/launch/flags.cc
+++ b/host/commands/launch/flags.cc
@@ -71,7 +71,9 @@
             "-guest_security is empty.");
 DEFINE_bool(guest_audit_security, true,
             "Whether to log security audits.");
-DEFINE_string(boot_image, "", "Location of cuttlefish boot image.");
+DEFINE_string(boot_image, "",
+              "Location of cuttlefish boot image. If empty it is assumed to be "
+              "boot.img in the directory specified by -system_image_dir.");
 DEFINE_int32(memory_mb, 2048,
              "Total amount of memory available for guest, MB.");
 std::string g_default_mempath{vsoc::GetDefaultMempath()};
@@ -103,6 +105,9 @@
 DEFINE_string(product_image, "", "Location of the product partition image.");
 DEFINE_string(super_image, "", "Location of the super partition image.");
 DEFINE_string(system_ext_image, "", "Location of the system extension partition image.");
+DEFINE_string(misc_image, "",
+              "Location of the misc partition image. If the image does not "
+              "exist, a blank new misc partition image is created.");
 DEFINE_string(composite_disk, "", "Location of the composite disk image.");
 
 DEFINE_bool(deprecated_boot_completed, false, "Log boot completed message to"
@@ -210,6 +215,7 @@
               "Binary for the tombstone server");
 DEFINE_int32(tombstone_receiver_port, vsoc::GetPerInstanceDefault(5630),
              "The vsock port for tombstones");
+
 namespace {
 
 template<typename S, typename T>
@@ -254,6 +260,9 @@
   std::string default_super_image = FLAGS_system_image_dir + "/super.img";
   SetCommandLineOptionWithMode("super_image", default_super_image.c_str(),
                                google::FlagSettingMode::SET_FLAGS_DEFAULT);
+  std::string default_misc_image = FLAGS_system_image_dir + "/misc.img";
+  SetCommandLineOptionWithMode("misc_image", default_misc_image.c_str(),
+                               google::FlagSettingMode::SET_FLAGS_DEFAULT);
 
   return true;
 }
@@ -445,6 +454,7 @@
       FLAGS_vendor_image,
       FLAGS_product_image,
       FLAGS_system_ext_image,
+      FLAGS_misc_image,
     });
   }
 
@@ -733,6 +743,10 @@
     .label = "boot",
     .image_file_path = FLAGS_boot_image,
   });
+  partitions.push_back(ImagePartition {
+    .label = "misc",
+    .image_file_path = FLAGS_misc_image
+  });
   return partitions;
 }
 
@@ -843,6 +857,11 @@
 
   ValidateAdbModeFlag(*config);
 
+  // Create misc if necessary
+  if (!InitializeMiscImage(FLAGS_misc_image)) {
+    exit(cvd::kCuttlefishConfigurationInitError);
+  }
+
   // Create data if necessary
   if (!ApplyDataImagePolicy(*config, FLAGS_data_image)) {
     exit(cvd::kCuttlefishConfigurationInitError);