Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 1 | #include "host/commands/launch/flags.h" |
| 2 | |
| 3 | #include <iostream> |
| 4 | |
| 5 | #include <gflags/gflags.h> |
| 6 | #include <glog/logging.h> |
| 7 | |
Cody Schuffelen | 90b2fb2 | 2019-02-28 18:55:21 -0800 | [diff] [blame] | 8 | #include "common/libs/strings/str_split.h" |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 9 | #include "common/libs/utils/environment.h" |
| 10 | #include "common/libs/utils/files.h" |
| 11 | #include "common/vsoc/lib/vsoc_memory.h" |
| 12 | #include "host/commands/launch/boot_image_unpacker.h" |
| 13 | #include "host/commands/launch/data_image.h" |
| 14 | #include "host/commands/launch/launch.h" |
| 15 | #include "host/commands/launch/launcher_defs.h" |
Jorge E. Moreira | ba673b7 | 2019-02-07 14:03:45 -0800 | [diff] [blame] | 16 | #include "host/commands/launch/ril_config.h" |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 17 | #include "host/libs/vm_manager/crosvm_manager.h" |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 18 | #include "host/libs/vm_manager/qemu_manager.h" |
| 19 | #include "host/libs/vm_manager/vm_manager.h" |
| 20 | |
| 21 | using vsoc::GetPerInstanceDefault; |
| 22 | using cvd::LauncherExitCodes; |
| 23 | |
| 24 | DEFINE_string( |
| 25 | system_image, "", |
| 26 | "Path to the system image, if empty it is assumed to be a file named " |
| 27 | "system.img in the directory specified by -system_image_dir"); |
| 28 | DEFINE_string(cache_image, "", "Location of the cache partition image."); |
Paul Trautrim | ba8f8e9 | 2019-03-12 17:55:48 +0900 | [diff] [blame] | 29 | DEFINE_string(metadata_image, "", "Location of the metadata partition image " |
| 30 | "to be generated."); |
| 31 | DEFINE_int32(blank_metadata_image_mb, 16, |
| 32 | "The size of the blank metadata image to generate, MB."); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 33 | DEFINE_int32(cpus, 2, "Virtual CPU count."); |
| 34 | DEFINE_string(data_image, "", "Location of the data partition image."); |
| 35 | DEFINE_string(data_policy, "use_existing", "How to handle userdata partition." |
| 36 | " Either 'use_existing', 'create_if_missing', 'resize_up_to', or " |
| 37 | "'always_create'."); |
| 38 | DEFINE_int32(blank_data_image_mb, 0, |
| 39 | "The size of the blank data image to generate, MB."); |
| 40 | DEFINE_string(blank_data_image_fmt, "ext4", |
| 41 | "The fs format for the blank data image. Used with mkfs."); |
| 42 | DEFINE_string(qemu_gdb, "", |
Matthias Maennich | 454d787 | 2019-02-06 16:35:17 +0000 | [diff] [blame] | 43 | "Debug flag to pass to qemu. e.g. -qemu_gdb=tcp::1234"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 44 | |
| 45 | DEFINE_int32(x_res, 720, "Width of the screen in pixels"); |
| 46 | DEFINE_int32(y_res, 1280, "Height of the screen in pixels"); |
| 47 | DEFINE_int32(dpi, 160, "Pixels per inch for the screen"); |
| 48 | DEFINE_int32(refresh_rate_hz, 60, "Screen refresh rate in Hertz"); |
| 49 | DEFINE_int32(num_screen_buffers, 3, "The number of screen buffers"); |
| 50 | DEFINE_string(kernel_path, "", |
| 51 | "Path to the kernel. Overrides the one from the boot image"); |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 52 | DEFINE_bool(decompress_kernel, false, |
| 53 | "Whether to decompress the kernel image. Required for crosvm."); |
| 54 | DEFINE_string(kernel_decompresser_executable, |
| 55 | vsoc::DefaultHostArtifactsPath("bin/extract-vmlinux"), |
| 56 | "Path to the extract-vmlinux executable."); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 57 | DEFINE_string(extra_kernel_cmdline, "", |
| 58 | "Additional flags to put on the kernel command line"); |
| 59 | DEFINE_int32(loop_max_part, 7, "Maximum number of loop partitions"); |
| 60 | DEFINE_string(console, "ttyS0", "Console device for the guest kernel."); |
| 61 | DEFINE_string(androidboot_console, "ttyS1", |
| 62 | "Console device for the Android framework"); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 63 | DEFINE_string( |
| 64 | hardware_name, "", |
Jorge E. Moreira | fd1a6b0 | 2019-02-27 16:25:00 -0800 | [diff] [blame] | 65 | "The codename of the device's hardware, one of {cutf_ivsh, cutf_cvm}"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 66 | DEFINE_string(guest_security, "selinux", |
| 67 | "The security module to use in the guest"); |
Alistair Strachan | 245597b | 2019-03-20 17:20:22 +0000 | [diff] [blame^] | 68 | DEFINE_bool(guest_enforce_security, true, |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 69 | "Whether to run in enforcing mode (non permissive). Ignored if " |
| 70 | "-guest_security is empty."); |
| 71 | DEFINE_bool(guest_audit_security, true, |
| 72 | "Whether to log security audits."); |
| 73 | DEFINE_string(boot_image, "", "Location of cuttlefish boot image."); |
| 74 | DEFINE_int32(memory_mb, 2048, |
| 75 | "Total amount of memory available for guest, MB."); |
| 76 | std::string g_default_mempath{vsoc::GetDefaultMempath()}; |
| 77 | DEFINE_string(mempath, g_default_mempath.c_str(), |
| 78 | "Target location for the shmem file."); |
| 79 | DEFINE_string(mobile_interface, "", // default handled on ParseCommandLine |
| 80 | "Network interface to use for mobile networking"); |
| 81 | DEFINE_string(mobile_tap_name, "", // default handled on ParseCommandLine |
| 82 | "The name of the tap interface to use for mobile"); |
| 83 | std::string g_default_serial_number{GetPerInstanceDefault("CUTTLEFISHCVD")}; |
| 84 | DEFINE_string(serial_number, g_default_serial_number.c_str(), |
| 85 | "Serial number to use for the device"); |
| 86 | DEFINE_string(instance_dir, "", // default handled on ParseCommandLine |
| 87 | "A directory to put all instance specific files"); |
| 88 | DEFINE_string( |
| 89 | vm_manager, vm_manager::QemuManager::name(), |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 90 | "What virtual machine manager to use, one of {qemu_cli, crosvm}"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 91 | DEFINE_string(system_image_dir, vsoc::DefaultGuestImagePath(""), |
| 92 | "Location of the system partition images."); |
| 93 | DEFINE_string(vendor_image, "", "Location of the vendor partition image."); |
| 94 | |
| 95 | DEFINE_bool(deprecated_boot_completed, false, "Log boot completed message to" |
| 96 | " host kernel. This is only used during transition of our clients." |
| 97 | " Will be deprecated soon."); |
| 98 | DEFINE_bool(start_vnc_server, true, "Whether to start the vnc server process."); |
| 99 | DEFINE_string(vnc_server_binary, |
| 100 | vsoc::DefaultHostArtifactsPath("bin/vnc_server"), |
| 101 | "Location of the vnc server binary."); |
Alistair Strachan | 7eeddf4 | 2019-03-04 18:13:34 -0800 | [diff] [blame] | 102 | DEFINE_bool(start_stream_audio, false, |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 103 | "Whether to start the stream audio process."); |
| 104 | DEFINE_string(stream_audio_binary, |
| 105 | vsoc::DefaultHostArtifactsPath("bin/stream_audio"), |
| 106 | "Location of the stream_audio binary."); |
| 107 | DEFINE_string(virtual_usb_manager_binary, |
| 108 | vsoc::DefaultHostArtifactsPath("bin/virtual_usb_manager"), |
| 109 | "Location of the virtual usb manager binary."); |
| 110 | DEFINE_string(kernel_log_monitor_binary, |
| 111 | vsoc::DefaultHostArtifactsPath("bin/kernel_log_monitor"), |
| 112 | "Location of the log monitor binary."); |
| 113 | DEFINE_string(ivserver_binary, |
| 114 | vsoc::DefaultHostArtifactsPath("bin/ivserver"), |
| 115 | "Location of the ivshmem server binary."); |
| 116 | DEFINE_int32(vnc_server_port, GetPerInstanceDefault(6444), |
| 117 | "The port on which the vnc server should listen"); |
| 118 | DEFINE_int32(stream_audio_port, GetPerInstanceDefault(7444), |
| 119 | "The port on which stream_audio should listen."); |
| 120 | DEFINE_string(socket_forward_proxy_binary, |
| 121 | vsoc::DefaultHostArtifactsPath("bin/socket_forward_proxy"), |
| 122 | "Location of the socket_forward_proxy binary."); |
| 123 | DEFINE_string(socket_vsock_proxy_binary, |
| 124 | vsoc::DefaultHostArtifactsPath("bin/socket_vsock_proxy"), |
| 125 | "Location of the socket_vsock_proxy binary."); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 126 | DEFINE_string(adb_mode, "", |
Cody Schuffelen | 63d1005 | 2019-02-26 12:21:53 -0800 | [diff] [blame] | 127 | "Mode for ADB connection. Can be 'usb' for USB forwarding, " |
| 128 | "'tunnel' for a TCP connection tunneled through VSoC, " |
| 129 | "'vsock_tunnel' for a TCP connection tunneled through vsock, " |
| 130 | "'native_vsock' for a direct connection to the guest ADB over " |
| 131 | "vsock, 'vsock_half_tunnel' for a TCP connection forwarded to " |
| 132 | "the guest ADB server, or a comma separated list of types as in " |
| 133 | "'usb,tunnel'"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 134 | DEFINE_bool(run_adb_connector, true, |
| 135 | "Maintain adb connection by sending 'adb connect' commands to the " |
Matthias Maennich | 454d787 | 2019-02-06 16:35:17 +0000 | [diff] [blame] | 136 | "server. Only relevant with -adb_mode=tunnel or vsock_tunnel"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 137 | DEFINE_string(adb_connector_binary, |
| 138 | vsoc::DefaultHostArtifactsPath("bin/adb_connector"), |
| 139 | "Location of the adb_connector binary. Only relevant if " |
Matthias Maennich | 454d787 | 2019-02-06 16:35:17 +0000 | [diff] [blame] | 140 | "-run_adb_connector is true"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 141 | DEFINE_int32(vhci_port, GetPerInstanceDefault(0), "VHCI port to use for usb"); |
| 142 | DEFINE_string(guest_mac_address, |
| 143 | GetPerInstanceDefault("00:43:56:44:80:"), // 00:43:56:44:80:0x |
| 144 | "MAC address of the wifi interface to be created on the guest."); |
| 145 | DEFINE_string(host_mac_address, |
| 146 | "42:00:00:00:00:00", |
| 147 | "MAC address of the wifi interface running on the host."); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 148 | DEFINE_string(wifi_tap_name, "", // default handled on ParseCommandLine |
| 149 | "The name of the tap interface to use for wifi"); |
| 150 | DEFINE_int32(vsock_guest_cid, |
| 151 | vsoc::GetDefaultPerInstanceVsockCid(), |
| 152 | "Guest identifier for vsock. Disabled if under 3."); |
| 153 | |
| 154 | // TODO(b/72969289) This should be generated |
| 155 | DEFINE_string(dtb, "", "Path to the cuttlefish.dtb file"); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 156 | DEFINE_string(gsi_fstab, |
| 157 | vsoc::DefaultHostArtifactsPath("config/gsi.fstab"), |
| 158 | "Path to the GSI fstab file"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 159 | |
| 160 | DEFINE_string(uuid, vsoc::GetPerInstanceDefault(vsoc::kDefaultUuidPrefix), |
| 161 | "UUID to use for the device. Random if not specified"); |
| 162 | DEFINE_bool(daemon, false, |
| 163 | "Run cuttlefish in background, the launcher exits on boot " |
| 164 | "completed/failed"); |
| 165 | |
| 166 | DEFINE_string(device_title, "", "Human readable name for the instance, " |
| 167 | "used by the vnc_server for its server title"); |
| 168 | DEFINE_string(setupwizard_mode, "DISABLED", |
| 169 | "One of DISABLED,OPTIONAL,REQUIRED"); |
| 170 | |
| 171 | DEFINE_string(qemu_binary, |
| 172 | "/usr/bin/qemu-system-x86_64", |
| 173 | "The qemu binary to use"); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 174 | DEFINE_string(crosvm_binary, |
| 175 | vsoc::DefaultHostArtifactsPath("bin/crosvm"), |
| 176 | "The Crosvm binary to use"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 177 | DEFINE_bool(restart_subprocesses, true, "Restart any crashed host process"); |
| 178 | DEFINE_bool(run_e2e_test, true, "Run e2e test after device launches"); |
| 179 | DEFINE_string(e2e_test_binary, |
| 180 | vsoc::DefaultHostArtifactsPath("bin/host_region_e2e_test"), |
| 181 | "Location of the region end to end test binary"); |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 182 | DEFINE_string(logcat_receiver_binary, |
| 183 | vsoc::DefaultHostArtifactsPath("bin/logcat_receiver"), |
| 184 | "Binary for the logcat server"); |
| 185 | DEFINE_string(logcat_mode, "", "How to send android's log messages from " |
| 186 | "guest to host. One of [serial, vsock]"); |
| 187 | DEFINE_int32(logcat_vsock_port, vsoc::GetPerInstanceDefault(5620), |
| 188 | "The port for logcat over vsock"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 189 | namespace { |
| 190 | |
| 191 | template<typename S, typename T> |
| 192 | static std::string concat(const S& s, const T& t) { |
| 193 | std::ostringstream os; |
| 194 | os << s << t; |
| 195 | return os.str(); |
| 196 | } |
| 197 | |
| 198 | bool ResolveInstanceFiles() { |
| 199 | if (FLAGS_system_image_dir.empty()) { |
| 200 | LOG(ERROR) << "--system_image_dir must be specified."; |
| 201 | return false; |
| 202 | } |
| 203 | |
| 204 | // If user did not specify location of either of these files, expect them to |
| 205 | // be placed in --system_image_dir location. |
| 206 | std::string default_system_image = FLAGS_system_image_dir + "/system.img"; |
| 207 | SetCommandLineOptionWithMode("system_image", default_system_image.c_str(), |
| 208 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 209 | std::string default_boot_image = FLAGS_system_image_dir + "/boot.img"; |
| 210 | SetCommandLineOptionWithMode("boot_image", default_boot_image.c_str(), |
| 211 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 212 | std::string default_cache_image = FLAGS_system_image_dir + "/cache.img"; |
| 213 | SetCommandLineOptionWithMode("cache_image", default_cache_image.c_str(), |
| 214 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 215 | std::string default_data_image = FLAGS_system_image_dir + "/userdata.img"; |
| 216 | SetCommandLineOptionWithMode("data_image", default_data_image.c_str(), |
| 217 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 218 | std::string default_vendor_image = FLAGS_system_image_dir + "/vendor.img"; |
| 219 | SetCommandLineOptionWithMode("vendor_image", default_vendor_image.c_str(), |
| 220 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Paul Trautrim | ba8f8e9 | 2019-03-12 17:55:48 +0900 | [diff] [blame] | 221 | std::string default_metadata_image = FLAGS_system_image_dir + "/metadata.img"; |
| 222 | SetCommandLineOptionWithMode("metadata_image", default_metadata_image.c_str(), |
| 223 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 224 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 225 | return true; |
| 226 | } |
| 227 | |
| 228 | std::string GetCuttlefishEnvPath() { |
| 229 | return cvd::StringFromEnv("HOME", ".") + "/.cuttlefish.sh"; |
| 230 | } |
| 231 | |
| 232 | // Initializes the config object and saves it to file. It doesn't return it, all |
| 233 | // further uses of the config should happen through the singleton |
| 234 | bool InitializeCuttlefishConfiguration( |
| 235 | const cvd::BootImageUnpacker& boot_image_unpacker) { |
| 236 | vsoc::CuttlefishConfig tmp_config_obj; |
| 237 | auto& memory_layout = *vsoc::VSoCMemoryLayout::Get(); |
| 238 | // Set this first so that calls to PerInstancePath below are correct |
| 239 | tmp_config_obj.set_instance_dir(FLAGS_instance_dir); |
| 240 | if (!vm_manager::VmManager::IsValidName(FLAGS_vm_manager)) { |
| 241 | LOG(ERROR) << "Invalid vm_manager: " << FLAGS_vm_manager; |
| 242 | return false; |
| 243 | } |
| 244 | tmp_config_obj.set_vm_manager(FLAGS_vm_manager); |
| 245 | |
| 246 | tmp_config_obj.set_serial_number(FLAGS_serial_number); |
| 247 | |
| 248 | tmp_config_obj.set_cpus(FLAGS_cpus); |
| 249 | tmp_config_obj.set_memory_mb(FLAGS_memory_mb); |
| 250 | |
| 251 | tmp_config_obj.set_dpi(FLAGS_dpi); |
| 252 | tmp_config_obj.set_setupwizard_mode(FLAGS_setupwizard_mode); |
| 253 | tmp_config_obj.set_x_res(FLAGS_x_res); |
| 254 | tmp_config_obj.set_y_res(FLAGS_y_res); |
| 255 | tmp_config_obj.set_num_screen_buffers(FLAGS_num_screen_buffers); |
| 256 | tmp_config_obj.set_refresh_rate_hz(FLAGS_refresh_rate_hz); |
| 257 | tmp_config_obj.set_gdb_flag(FLAGS_qemu_gdb); |
Cody Schuffelen | 90b2fb2 | 2019-02-28 18:55:21 -0800 | [diff] [blame] | 258 | std::vector<std::string> adb = cvd::StrSplit(FLAGS_adb_mode, ','); |
| 259 | tmp_config_obj.set_adb_mode(std::set<std::string>(adb.begin(), adb.end())); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 260 | tmp_config_obj.set_adb_ip_and_port("127.0.0.1:" + std::to_string(GetHostPort())); |
| 261 | |
| 262 | tmp_config_obj.set_device_title(FLAGS_device_title); |
| 263 | if (FLAGS_kernel_path.size()) { |
| 264 | tmp_config_obj.set_kernel_image_path(FLAGS_kernel_path); |
| 265 | tmp_config_obj.set_use_unpacked_kernel(false); |
| 266 | } else { |
| 267 | tmp_config_obj.set_kernel_image_path( |
| 268 | tmp_config_obj.PerInstancePath("kernel")); |
| 269 | tmp_config_obj.set_use_unpacked_kernel(true); |
| 270 | } |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 271 | tmp_config_obj.set_decompress_kernel(FLAGS_decompress_kernel); |
| 272 | if (FLAGS_decompress_kernel) { |
| 273 | tmp_config_obj.set_decompressed_kernel_image_path( |
| 274 | tmp_config_obj.PerInstancePath("vmlinux")); |
| 275 | } |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 276 | |
| 277 | auto ramdisk_path = tmp_config_obj.PerInstancePath("ramdisk.img"); |
| 278 | bool use_ramdisk = boot_image_unpacker.HasRamdiskImage(); |
| 279 | if (!use_ramdisk) { |
| 280 | LOG(INFO) << "No ramdisk present; assuming system-as-root build"; |
| 281 | ramdisk_path = ""; |
| 282 | } |
| 283 | |
| 284 | // This needs to be done here because the dtb path depends on the presence of |
| 285 | // the ramdisk |
| 286 | if (FLAGS_dtb.empty()) { |
| 287 | if (use_ramdisk) { |
| 288 | FLAGS_dtb = vsoc::DefaultHostArtifactsPath("config/initrd-root.dtb"); |
| 289 | } else { |
| 290 | FLAGS_dtb = vsoc::DefaultHostArtifactsPath("config/system-root.dtb"); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | tmp_config_obj.add_kernel_cmdline(boot_image_unpacker.kernel_cmdline()); |
| 295 | if (!use_ramdisk) { |
| 296 | tmp_config_obj.add_kernel_cmdline("root=/dev/vda"); |
| 297 | } |
| 298 | tmp_config_obj.add_kernel_cmdline("init=/init"); |
| 299 | tmp_config_obj.add_kernel_cmdline( |
| 300 | concat("androidboot.serialno=", FLAGS_serial_number)); |
| 301 | tmp_config_obj.add_kernel_cmdline("mac80211_hwsim.radios=0"); |
| 302 | tmp_config_obj.add_kernel_cmdline(concat("androidboot.lcd_density=", FLAGS_dpi)); |
| 303 | tmp_config_obj.add_kernel_cmdline( |
| 304 | concat("androidboot.setupwizard_mode=", FLAGS_setupwizard_mode)); |
| 305 | tmp_config_obj.add_kernel_cmdline(concat("loop.max_part=", FLAGS_loop_max_part)); |
| 306 | if (!FLAGS_console.empty()) { |
| 307 | tmp_config_obj.add_kernel_cmdline(concat("console=", FLAGS_console)); |
| 308 | } |
| 309 | if (!FLAGS_androidboot_console.empty()) { |
| 310 | tmp_config_obj.add_kernel_cmdline( |
| 311 | concat("androidboot.console=", FLAGS_androidboot_console)); |
| 312 | } |
| 313 | if (!FLAGS_hardware_name.empty()) { |
| 314 | tmp_config_obj.add_kernel_cmdline( |
| 315 | concat("androidboot.hardware=", FLAGS_hardware_name)); |
| 316 | } |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 317 | if (FLAGS_logcat_mode == cvd::kLogcatVsockMode) { |
| 318 | tmp_config_obj.add_kernel_cmdline(concat("androidboot.vsock_logcat_port=", |
| 319 | FLAGS_logcat_vsock_port)); |
| 320 | } |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 321 | tmp_config_obj.set_hardware_name(FLAGS_hardware_name); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 322 | if (!FLAGS_guest_security.empty()) { |
| 323 | tmp_config_obj.add_kernel_cmdline(concat("security=", FLAGS_guest_security)); |
| 324 | if (FLAGS_guest_enforce_security) { |
| 325 | tmp_config_obj.add_kernel_cmdline("enforcing=1"); |
| 326 | } else { |
| 327 | tmp_config_obj.add_kernel_cmdline("enforcing=0"); |
| 328 | tmp_config_obj.add_kernel_cmdline("androidboot.selinux=permissive"); |
| 329 | } |
| 330 | if (FLAGS_guest_audit_security) { |
| 331 | tmp_config_obj.add_kernel_cmdline("audit=1"); |
| 332 | } else { |
| 333 | tmp_config_obj.add_kernel_cmdline("audit=0"); |
| 334 | } |
| 335 | } |
| 336 | if (FLAGS_run_e2e_test) { |
| 337 | tmp_config_obj.add_kernel_cmdline("androidboot.vsoc_e2e_test=1"); |
| 338 | } |
| 339 | if (FLAGS_extra_kernel_cmdline.size()) { |
| 340 | tmp_config_obj.add_kernel_cmdline(FLAGS_extra_kernel_cmdline); |
| 341 | } |
| 342 | |
| 343 | tmp_config_obj.set_ramdisk_image_path(ramdisk_path); |
| 344 | tmp_config_obj.set_system_image_path(FLAGS_system_image); |
| 345 | tmp_config_obj.set_cache_image_path(FLAGS_cache_image); |
| 346 | tmp_config_obj.set_data_image_path(FLAGS_data_image); |
| 347 | tmp_config_obj.set_vendor_image_path(FLAGS_vendor_image); |
Paul Trautrim | ba8f8e9 | 2019-03-12 17:55:48 +0900 | [diff] [blame] | 348 | tmp_config_obj.set_metadata_image_path(FLAGS_metadata_image); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 349 | tmp_config_obj.set_dtb_path(FLAGS_dtb); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 350 | tmp_config_obj.set_gsi_fstab_path(FLAGS_gsi_fstab); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 351 | |
| 352 | tmp_config_obj.set_mempath(FLAGS_mempath); |
| 353 | tmp_config_obj.set_ivshmem_qemu_socket_path( |
| 354 | tmp_config_obj.PerInstancePath("ivshmem_socket_qemu")); |
| 355 | tmp_config_obj.set_ivshmem_client_socket_path( |
| 356 | tmp_config_obj.PerInstancePath("ivshmem_socket_client")); |
| 357 | tmp_config_obj.set_ivshmem_vector_count(memory_layout.GetRegions().size()); |
| 358 | |
| 359 | if (AdbUsbEnabled(tmp_config_obj)) { |
| 360 | tmp_config_obj.set_usb_v1_socket_name(tmp_config_obj.PerInstancePath("usb-v1")); |
| 361 | tmp_config_obj.set_vhci_port(FLAGS_vhci_port); |
| 362 | tmp_config_obj.set_usb_ip_socket_name(tmp_config_obj.PerInstancePath("usb-ip")); |
| 363 | } |
| 364 | |
| 365 | tmp_config_obj.set_kernel_log_socket_name(tmp_config_obj.PerInstancePath("kernel-log")); |
| 366 | tmp_config_obj.set_deprecated_boot_completed(FLAGS_deprecated_boot_completed); |
| 367 | tmp_config_obj.set_console_path(tmp_config_obj.PerInstancePath("console")); |
| 368 | tmp_config_obj.set_logcat_path(tmp_config_obj.PerInstancePath("logcat")); |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 369 | tmp_config_obj.set_logcat_receiver_binary(FLAGS_logcat_receiver_binary); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 370 | tmp_config_obj.set_launcher_log_path(tmp_config_obj.PerInstancePath("launcher.log")); |
| 371 | tmp_config_obj.set_launcher_monitor_socket_path( |
| 372 | tmp_config_obj.PerInstancePath("launcher_monitor.sock")); |
| 373 | |
| 374 | tmp_config_obj.set_mobile_bridge_name(FLAGS_mobile_interface); |
| 375 | tmp_config_obj.set_mobile_tap_name(FLAGS_mobile_tap_name); |
Jorge E. Moreira | ba673b7 | 2019-02-07 14:03:45 -0800 | [diff] [blame] | 376 | ConfigureRil(&tmp_config_obj); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 377 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 378 | tmp_config_obj.set_wifi_tap_name(FLAGS_wifi_tap_name); |
| 379 | |
| 380 | tmp_config_obj.set_wifi_guest_mac_addr(FLAGS_guest_mac_address); |
| 381 | tmp_config_obj.set_wifi_host_mac_addr(FLAGS_host_mac_address); |
| 382 | |
| 383 | tmp_config_obj.set_vsock_guest_cid(FLAGS_vsock_guest_cid); |
| 384 | |
| 385 | tmp_config_obj.set_entropy_source("/dev/urandom"); |
| 386 | tmp_config_obj.set_uuid(FLAGS_uuid); |
| 387 | |
| 388 | tmp_config_obj.set_qemu_binary(FLAGS_qemu_binary); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 389 | tmp_config_obj.set_crosvm_binary(FLAGS_crosvm_binary); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 390 | tmp_config_obj.set_ivserver_binary(FLAGS_ivserver_binary); |
| 391 | tmp_config_obj.set_kernel_log_monitor_binary(FLAGS_kernel_log_monitor_binary); |
| 392 | |
| 393 | tmp_config_obj.set_enable_vnc_server(FLAGS_start_vnc_server); |
| 394 | tmp_config_obj.set_vnc_server_binary(FLAGS_vnc_server_binary); |
| 395 | tmp_config_obj.set_vnc_server_port(FLAGS_vnc_server_port); |
| 396 | |
| 397 | tmp_config_obj.set_enable_stream_audio(FLAGS_start_stream_audio); |
| 398 | tmp_config_obj.set_stream_audio_binary(FLAGS_stream_audio_binary); |
| 399 | tmp_config_obj.set_stream_audio_port(FLAGS_stream_audio_port); |
| 400 | |
| 401 | tmp_config_obj.set_restart_subprocesses(FLAGS_restart_subprocesses); |
| 402 | tmp_config_obj.set_run_adb_connector(FLAGS_run_adb_connector); |
| 403 | tmp_config_obj.set_adb_connector_binary(FLAGS_adb_connector_binary); |
| 404 | tmp_config_obj.set_virtual_usb_manager_binary( |
| 405 | FLAGS_virtual_usb_manager_binary); |
| 406 | tmp_config_obj.set_socket_forward_proxy_binary( |
| 407 | FLAGS_socket_forward_proxy_binary); |
| 408 | tmp_config_obj.set_socket_vsock_proxy_binary(FLAGS_socket_vsock_proxy_binary); |
| 409 | tmp_config_obj.set_run_as_daemon(FLAGS_daemon); |
| 410 | tmp_config_obj.set_run_e2e_test(FLAGS_run_e2e_test); |
| 411 | tmp_config_obj.set_e2e_test_binary(FLAGS_e2e_test_binary); |
| 412 | |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 413 | tmp_config_obj.set_data_policy(FLAGS_data_policy); |
| 414 | tmp_config_obj.set_blank_data_image_mb(FLAGS_blank_data_image_mb); |
| 415 | tmp_config_obj.set_blank_data_image_fmt(FLAGS_blank_data_image_fmt); |
| 416 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 417 | if(!AdbUsbEnabled(tmp_config_obj)) { |
| 418 | tmp_config_obj.disable_usb_adb(); |
| 419 | } |
| 420 | |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 421 | tmp_config_obj.set_logcat_mode(FLAGS_logcat_mode); |
| 422 | tmp_config_obj.set_logcat_vsock_port(FLAGS_logcat_vsock_port); |
| 423 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 424 | tmp_config_obj.set_cuttlefish_env_path(GetCuttlefishEnvPath()); |
| 425 | |
| 426 | auto config_file = GetConfigFilePath(tmp_config_obj); |
| 427 | auto config_link = vsoc::GetGlobalConfigFileLink(); |
| 428 | // Save the config object before starting any host process |
| 429 | if (!tmp_config_obj.SaveToFile(config_file)) { |
| 430 | LOG(ERROR) << "Unable to save config object"; |
| 431 | return false; |
| 432 | } |
| 433 | setenv(vsoc::kCuttlefishConfigEnvVarName, config_file.c_str(), true); |
| 434 | if (symlink(config_file.c_str(), config_link.c_str()) != 0) { |
| 435 | LOG(ERROR) << "Failed to create symlink to config file at " << config_link |
| 436 | << ": " << strerror(errno); |
| 437 | return false; |
| 438 | } |
| 439 | |
| 440 | return true; |
| 441 | } |
| 442 | |
| 443 | void SetDefaultFlagsForQemu() { |
| 444 | auto default_mobile_interface = GetPerInstanceDefault("cvd-mbr-"); |
| 445 | SetCommandLineOptionWithMode("mobile_interface", |
| 446 | default_mobile_interface.c_str(), |
| 447 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 448 | auto default_mobile_tap_name = GetPerInstanceDefault("cvd-mtap-"); |
| 449 | SetCommandLineOptionWithMode("mobile_tap_name", |
| 450 | default_mobile_tap_name.c_str(), |
| 451 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 452 | auto default_wifi_tap_name = GetPerInstanceDefault("cvd-wtap-"); |
| 453 | SetCommandLineOptionWithMode("wifi_tap_name", |
| 454 | default_wifi_tap_name.c_str(), |
| 455 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 456 | auto default_instance_dir = |
| 457 | cvd::StringFromEnv("HOME", ".") + "/cuttlefish_runtime"; |
| 458 | SetCommandLineOptionWithMode("instance_dir", |
| 459 | default_instance_dir.c_str(), |
| 460 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | fd1a6b0 | 2019-02-27 16:25:00 -0800 | [diff] [blame] | 461 | SetCommandLineOptionWithMode("hardware_name", "cutf_ivsh", |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 462 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 463 | SetCommandLineOptionWithMode("adb_mode", "tunnel", |
| 464 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 465 | SetCommandLineOptionWithMode("decompress_kernel", "false", |
| 466 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 467 | SetCommandLineOptionWithMode("logcat_mode", cvd::kLogcatSerialMode, |
| 468 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | void SetDefaultFlagsForCrosvm() { |
| 472 | auto default_mobile_interface = GetPerInstanceDefault("cvd-mbr-"); |
| 473 | SetCommandLineOptionWithMode("mobile_interface", |
| 474 | default_mobile_interface.c_str(), |
| 475 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 476 | auto default_mobile_tap_name = GetPerInstanceDefault("cvd-mtap-"); |
| 477 | SetCommandLineOptionWithMode("mobile_tap_name", |
| 478 | default_mobile_tap_name.c_str(), |
| 479 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 480 | auto default_wifi_tap_name = GetPerInstanceDefault("cvd-wtap-"); |
| 481 | SetCommandLineOptionWithMode("wifi_tap_name", |
| 482 | default_wifi_tap_name.c_str(), |
| 483 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 484 | auto default_instance_dir = |
| 485 | cvd::StringFromEnv("HOME", ".") + "/cuttlefish_runtime"; |
| 486 | SetCommandLineOptionWithMode("instance_dir", |
| 487 | default_instance_dir.c_str(), |
| 488 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | fd1a6b0 | 2019-02-27 16:25:00 -0800 | [diff] [blame] | 489 | SetCommandLineOptionWithMode("hardware_name", "cutf_cvm", |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 490 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 491 | SetCommandLineOptionWithMode("adb_mode", "vsock_tunnel", |
| 492 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 493 | SetCommandLineOptionWithMode("decompress_kernel", "true", |
| 494 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | 84d93c1 | 2019-02-05 12:02:29 -0800 | [diff] [blame] | 495 | SetCommandLineOptionWithMode("run_e2e_test", "false", |
| 496 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | cf4fc2a | 2019-02-05 17:33:20 -0800 | [diff] [blame] | 497 | SetCommandLineOptionWithMode("start_vnc_server", "false", |
| 498 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 499 | SetCommandLineOptionWithMode("logcat_mode", cvd::kLogcatVsockMode, |
| 500 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | bool ParseCommandLineFlags(int* argc, char*** argv) { |
| 504 | // The config_file is created by the launcher, so the launcher is the only |
| 505 | // host process that doesn't use the flag. |
| 506 | // Set the default to empty. |
| 507 | google::SetCommandLineOptionWithMode("config_file", "", |
| 508 | gflags::SET_FLAGS_DEFAULT); |
| 509 | google::ParseCommandLineNonHelpFlags(argc, argv, true); |
| 510 | bool invalid_manager = false; |
| 511 | if (FLAGS_vm_manager == vm_manager::QemuManager::name()) { |
| 512 | SetDefaultFlagsForQemu(); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 513 | } else if (FLAGS_vm_manager == vm_manager::CrosvmManager::name()) { |
| 514 | SetDefaultFlagsForCrosvm(); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 515 | } else { |
| 516 | std::cerr << "Unknown Virtual Machine Manager: " << FLAGS_vm_manager |
| 517 | << std::endl; |
| 518 | invalid_manager = true; |
| 519 | } |
| 520 | google::HandleCommandLineHelpFlags(); |
| 521 | if (invalid_manager) { |
| 522 | return false; |
| 523 | } |
| 524 | // Set the env variable to empty (in case the caller passed a value for it). |
| 525 | unsetenv(vsoc::kCuttlefishConfigEnvVarName); |
| 526 | |
| 527 | return ResolveInstanceFiles(); |
| 528 | } |
| 529 | |
| 530 | bool CleanPriorFiles() { |
| 531 | // Everything on the instance directory |
| 532 | std::string prior_files = FLAGS_instance_dir + "/*"; |
| 533 | // The shared memory file |
| 534 | prior_files += " " + FLAGS_mempath; |
| 535 | // The environment file |
| 536 | prior_files += " " + GetCuttlefishEnvPath(); |
| 537 | // The global link to the config file |
| 538 | prior_files += " " + vsoc::GetGlobalConfigFileLink(); |
| 539 | LOG(INFO) << "Assuming prior files of " << prior_files; |
| 540 | std::string fuser_cmd = "fuser " + prior_files + " 2> /dev/null"; |
| 541 | int rval = std::system(fuser_cmd.c_str()); |
| 542 | // fuser returns 0 if any of the files are open |
| 543 | if (WEXITSTATUS(rval) == 0) { |
| 544 | LOG(ERROR) << "Clean aborted: files are in use"; |
| 545 | return false; |
| 546 | } |
| 547 | std::string clean_command = "rm -rf " + prior_files; |
| 548 | rval = std::system(clean_command.c_str()); |
| 549 | if (WEXITSTATUS(rval) != 0) { |
| 550 | LOG(ERROR) << "Remove of files failed"; |
| 551 | return false; |
| 552 | } |
| 553 | return true; |
| 554 | } |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 555 | |
| 556 | bool DecompressKernel(const std::string& src, const std::string& dst) { |
| 557 | cvd::Command decomp_cmd(FLAGS_kernel_decompresser_executable); |
| 558 | decomp_cmd.AddParameter(src); |
| 559 | auto output_file = cvd::SharedFD::Creat(dst.c_str(), 0666); |
| 560 | if (!output_file->IsOpen()) { |
| 561 | LOG(ERROR) << "Unable to create decompressed image file: " |
| 562 | << output_file->StrError(); |
| 563 | return false; |
| 564 | } |
| 565 | decomp_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut, output_file); |
| 566 | auto decomp_proc = decomp_cmd.Start(false); |
| 567 | return decomp_proc.Started() && decomp_proc.Wait() == 0; |
| 568 | } |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 569 | } // namespace |
| 570 | |
| 571 | vsoc::CuttlefishConfig* InitFilesystemAndCreateConfig(int* argc, char*** argv) { |
| 572 | if (!ParseCommandLineFlags(argc, argv)) { |
| 573 | LOG(ERROR) << "Failed to parse command arguments"; |
| 574 | exit(LauncherExitCodes::kArgumentParsingError); |
| 575 | } |
| 576 | |
| 577 | // Clean up prior files before saving the config file (doing it after would |
| 578 | // delete it) |
| 579 | if (!CleanPriorFiles()) { |
| 580 | LOG(ERROR) << "Failed to clean prior files"; |
| 581 | exit(LauncherExitCodes::kPrioFilesCleanupError); |
| 582 | } |
| 583 | // Create instance directory if it doesn't exist. |
| 584 | if (!cvd::DirectoryExists(FLAGS_instance_dir.c_str())) { |
| 585 | LOG(INFO) << "Setting up " << FLAGS_instance_dir; |
| 586 | if (mkdir(FLAGS_instance_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) { |
| 587 | LOG(ERROR) << "Failed to create instance directory: " |
| 588 | << FLAGS_instance_dir << ". Error: " << errno; |
| 589 | exit(LauncherExitCodes::kInstanceDirCreationError); |
| 590 | } |
| 591 | } |
| 592 | |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 593 | if (!cvd::FileHasContent(FLAGS_boot_image)) { |
| 594 | LOG(ERROR) << "File not found: " << FLAGS_boot_image; |
| 595 | exit(cvd::kCuttlefishConfigurationInitError); |
| 596 | } |
| 597 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 598 | auto boot_img_unpacker = cvd::BootImageUnpacker::FromImage(FLAGS_boot_image); |
| 599 | |
| 600 | if (!InitializeCuttlefishConfiguration(*boot_img_unpacker)) { |
| 601 | LOG(ERROR) << "Failed to initialize configuration"; |
| 602 | exit(LauncherExitCodes::kCuttlefishConfigurationInitError); |
| 603 | } |
| 604 | // Do this early so that the config object is ready for anything that needs it |
| 605 | auto config = vsoc::CuttlefishConfig::Get(); |
| 606 | if (!config) { |
| 607 | LOG(ERROR) << "Failed to obtain config singleton"; |
| 608 | exit(LauncherExitCodes::kCuttlefishConfigurationInitError); |
| 609 | } |
| 610 | |
| 611 | if (!boot_img_unpacker->Unpack(config->ramdisk_image_path(), |
| 612 | config->use_unpacked_kernel() |
| 613 | ? config->kernel_image_path() |
| 614 | : "")) { |
| 615 | LOG(ERROR) << "Failed to unpack boot image"; |
| 616 | exit(LauncherExitCodes::kBootImageUnpackError); |
| 617 | } |
| 618 | |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 619 | if (config->decompress_kernel()) { |
| 620 | if (!DecompressKernel(config->kernel_image_path(), |
| 621 | config->decompressed_kernel_image_path())) { |
| 622 | LOG(ERROR) << "Failed to decompress kernel"; |
| 623 | exit(LauncherExitCodes::kKernelDecompressError); |
| 624 | } |
| 625 | } |
| 626 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 627 | ValidateAdbModeFlag(*config); |
| 628 | |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 629 | // Create data if necessary |
| 630 | if (!ApplyDataImagePolicy(*config)) { |
| 631 | exit(cvd::kCuttlefishConfigurationInitError); |
| 632 | } |
| 633 | |
Paul Trautrim | ba8f8e9 | 2019-03-12 17:55:48 +0900 | [diff] [blame] | 634 | CreateBlankImage(FLAGS_metadata_image, FLAGS_blank_metadata_image_mb, "none"); |
| 635 | |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 636 | // Check that the files exist |
| 637 | for (const auto& file : |
| 638 | {config->system_image_path(), config->vendor_image_path(), |
Paul Trautrim | ba8f8e9 | 2019-03-12 17:55:48 +0900 | [diff] [blame] | 639 | config->cache_image_path(), config->data_image_path(), |
| 640 | config->metadata_image_path()}) { |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 641 | if (!cvd::FileHasContent(file.c_str())) { |
| 642 | LOG(ERROR) << "File not found: " << file; |
| 643 | exit(cvd::kCuttlefishConfigurationInitError); |
| 644 | } |
| 645 | } |
| 646 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 647 | return config; |
| 648 | } |
| 649 | |
| 650 | std::string GetConfigFilePath(const vsoc::CuttlefishConfig& config) { |
| 651 | return config.PerInstancePath("cuttlefish_config.json"); |
| 652 | } |