fix boot device for arm64 cf

On arm64 the pci bus shows up as a platform device, adjust
androidboot.boot_devices accordingly.

Bug: 152448527
Bug: 156018302
Test: boot to adb shell
Change-Id: I34d7ad6b222d3d45072ea6e31c92c35834d4f3d9
Merged-In: I34d7ad6b222d3d45072ea6e31c92c35834d4f3d9
diff --git a/common/libs/utils/environment.cpp b/common/libs/utils/environment.cpp
index 11a0b8c..e6cacd0 100644
--- a/common/libs/utils/environment.cpp
+++ b/common/libs/utils/environment.cpp
@@ -17,6 +17,8 @@
 #include "common/libs/utils/environment.h"
 
 #include <stdlib.h>
+#include <stdio.h>
+#include <iostream>
 
 namespace cvd {
 
@@ -29,4 +31,55 @@
   return valstr;
 }
 
+/**
+ * at runtime, return the arch of the host: e.g. aarch64, x86_64, etc
+ *
+ * uses "`which uname` -m"
+ *
+ * @return arch string on success, "" on failure
+ */
+std::string HostArch() {
+  static std::string arch;
+  static bool cached = false;
+
+  if (cached) {
+    return arch;
+  }
+  cached = true;
+
+  // good to check if uname exists and is executable
+  // or, guarantee uname is availabe by dependency list
+  FILE* pip = popen("uname -m", "r");
+  if (!pip) {
+    return std::string{};
+  }
+
+  auto read_from_file =
+      [](FILE* fp, size_t len) {
+        /*
+         * to see if input is longer than len,
+         * we read up to len+1. If the length is len+1,
+         * then the input is too long
+         */
+        decltype(len) upper = len + 1;
+        std::string format("%");
+        format.append(std::to_string(upper)).append("s");
+        std::shared_ptr<char> buf(new char[upper],
+                                  std::default_delete<char[]>());
+        if (fscanf(fp, format.c_str(), buf.get()) == EOF) {
+          return std::string{};
+        }
+        std::string result(buf.get());
+        return (result.length() < upper) ? result : std::string{};
+      };
+  arch = read_from_file(pip, 20);
+  pclose(pip);
+
+  // l and r trim on arch
+  static const char* whitespace = "\t\n\r\f\v ";
+  arch.erase(arch.find_last_not_of(whitespace) + 1); // r trim
+  arch.erase(0, arch.find_first_not_of(whitespace)); // l trim
+  return arch;
+}
+
 }  // namespace cvd
diff --git a/common/libs/utils/environment.h b/common/libs/utils/environment.h
index 1aab8de..5a83b49 100644
--- a/common/libs/utils/environment.h
+++ b/common/libs/utils/environment.h
@@ -22,4 +22,6 @@
 std::string StringFromEnv(const std::string& varname,
                           const std::string& defval);
 
+std::string HostArch();
+
 }  // namespace cvd
diff --git a/host/libs/vm_manager/crosvm_manager.cpp b/host/libs/vm_manager/crosvm_manager.cpp
index 4676915..f4901fa 100644
--- a/host/libs/vm_manager/crosvm_manager.cpp
+++ b/host/libs/vm_manager/crosvm_manager.cpp
@@ -25,6 +25,7 @@
 #include <android-base/strings.h>
 #include <glog/logging.h>
 
+#include "common/libs/utils/environment.h"
 #include "common/libs/utils/network.h"
 #include "common/libs/utils/subprocess.h"
 #include "host/libs/config/cuttlefish_config.h"
@@ -108,7 +109,11 @@
 std::vector<std::string> CrosvmManager::ConfigureBootDevices() {
   // PCI domain 0, bus 0, device 1, function 0
   // TODO There is no way to control this assignment with crosvm (yet)
-  return { "androidboot.boot_devices=pci0000:00/0000:00:01.0" };
+  if (cvd::HostArch() == "x86_64") {
+    return { "androidboot.boot_devices=pci0000:00/0000:00:01.0" };
+  } else {
+    return { "androidboot.boot_devices=10000.pci" };
+  }
 }
 
 CrosvmManager::CrosvmManager(const vsoc::CuttlefishConfig* config)