Cody Schuffelen | 147b88e | 2019-09-09 16:00:11 -0700 | [diff] [blame] | 1 | #include "host/commands/assemble_cvd/flags.h" |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 2 | |
| 3 | #include <iostream> |
Ram Muthiah | aad97c5 | 2019-08-14 17:05:01 -0700 | [diff] [blame] | 4 | #include <fstream> |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 5 | |
| 6 | #include <gflags/gflags.h> |
| 7 | #include <glog/logging.h> |
| 8 | |
Cody Schuffelen | 90b2fb2 | 2019-02-28 18:55:21 -0800 | [diff] [blame] | 9 | #include "common/libs/strings/str_split.h" |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 10 | #include "common/libs/utils/environment.h" |
| 11 | #include "common/libs/utils/files.h" |
| 12 | #include "common/vsoc/lib/vsoc_memory.h" |
Cody Schuffelen | 147b88e | 2019-09-09 16:00:11 -0700 | [diff] [blame] | 13 | #include "host/commands/assemble_cvd/boot_image_unpacker.h" |
| 14 | #include "host/commands/assemble_cvd/data_image.h" |
| 15 | #include "host/commands/assemble_cvd/image_aggregator.h" |
| 16 | #include "host/commands/assemble_cvd/assembler_defs.h" |
Cody Schuffelen | b737ef5 | 2019-09-25 14:54:38 -0700 | [diff] [blame] | 17 | #include "host/commands/assemble_cvd/super_image_mixer.h" |
Cody Schuffelen | 605e685 | 2019-10-16 16:22:24 -0700 | [diff] [blame] | 18 | #include "host/libs/config/fetcher_config.h" |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 19 | #include "host/libs/vm_manager/crosvm_manager.h" |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 20 | #include "host/libs/vm_manager/qemu_manager.h" |
| 21 | #include "host/libs/vm_manager/vm_manager.h" |
| 22 | |
| 23 | using vsoc::GetPerInstanceDefault; |
Cody Schuffelen | e71fa35 | 2019-09-10 16:11:58 -0700 | [diff] [blame] | 24 | using cvd::AssemblerExitCodes; |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 25 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 26 | DEFINE_string(cache_image, "", "Location of the cache partition image."); |
Paul Trautrim | ba8f8e9 | 2019-03-12 17:55:48 +0900 | [diff] [blame] | 27 | DEFINE_string(metadata_image, "", "Location of the metadata partition image " |
| 28 | "to be generated."); |
| 29 | DEFINE_int32(blank_metadata_image_mb, 16, |
| 30 | "The size of the blank metadata image to generate, MB."); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 31 | DEFINE_int32(cpus, 2, "Virtual CPU count."); |
| 32 | DEFINE_string(data_image, "", "Location of the data partition image."); |
| 33 | DEFINE_string(data_policy, "use_existing", "How to handle userdata partition." |
| 34 | " Either 'use_existing', 'create_if_missing', 'resize_up_to', or " |
| 35 | "'always_create'."); |
| 36 | DEFINE_int32(blank_data_image_mb, 0, |
| 37 | "The size of the blank data image to generate, MB."); |
| 38 | DEFINE_string(blank_data_image_fmt, "ext4", |
| 39 | "The fs format for the blank data image. Used with mkfs."); |
| 40 | DEFINE_string(qemu_gdb, "", |
Matthias Maennich | 454d787 | 2019-02-06 16:35:17 +0000 | [diff] [blame] | 41 | "Debug flag to pass to qemu. e.g. -qemu_gdb=tcp::1234"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 42 | |
| 43 | DEFINE_int32(x_res, 720, "Width of the screen in pixels"); |
| 44 | DEFINE_int32(y_res, 1280, "Height of the screen in pixels"); |
| 45 | DEFINE_int32(dpi, 160, "Pixels per inch for the screen"); |
| 46 | DEFINE_int32(refresh_rate_hz, 60, "Screen refresh rate in Hertz"); |
| 47 | DEFINE_int32(num_screen_buffers, 3, "The number of screen buffers"); |
| 48 | DEFINE_string(kernel_path, "", |
| 49 | "Path to the kernel. Overrides the one from the boot image"); |
Ram Muthiah | aad97c5 | 2019-08-14 17:05:01 -0700 | [diff] [blame] | 50 | DEFINE_string(initramfs_path, "", "Path to the initramfs"); |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 51 | DEFINE_bool(decompress_kernel, false, |
Jorge E. Moreira | 3629404 | 2019-06-07 15:23:18 -0700 | [diff] [blame] | 52 | "Whether to decompress the kernel image."); |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 53 | DEFINE_string(kernel_decompresser_executable, |
| 54 | vsoc::DefaultHostArtifactsPath("bin/extract-vmlinux"), |
| 55 | "Path to the extract-vmlinux executable."); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 56 | DEFINE_string(extra_kernel_cmdline, "", |
| 57 | "Additional flags to put on the kernel command line"); |
| 58 | DEFINE_int32(loop_max_part, 7, "Maximum number of loop partitions"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 59 | DEFINE_string(androidboot_console, "ttyS1", |
| 60 | "Console device for the Android framework"); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 61 | DEFINE_string( |
| 62 | hardware_name, "", |
Jorge E. Moreira | fd1a6b0 | 2019-02-27 16:25:00 -0800 | [diff] [blame] | 63 | "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] | 64 | DEFINE_string(guest_security, "selinux", |
| 65 | "The security module to use in the guest"); |
Jorge E. Moreira | 300f97f | 2019-04-09 13:48:01 -0700 | [diff] [blame] | 66 | DEFINE_bool(guest_enforce_security, true, |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 67 | "Whether to run in enforcing mode (non permissive). Ignored if " |
| 68 | "-guest_security is empty."); |
| 69 | DEFINE_bool(guest_audit_security, true, |
| 70 | "Whether to log security audits."); |
Yifan Hong | 19d713e | 2019-05-01 14:12:07 -0700 | [diff] [blame] | 71 | DEFINE_string(boot_image, "", |
| 72 | "Location of cuttlefish boot image. If empty it is assumed to be " |
| 73 | "boot.img in the directory specified by -system_image_dir."); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 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( |
Alistair Strachan | 5ab095c | 2019-05-23 20:41:20 +0000 | [diff] [blame] | 89 | vm_manager, vm_manager::CrosvmManager::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}"); |
Greg Hartman | a3c552d | 2019-03-28 18:20:48 -0700 | [diff] [blame] | 91 | DEFINE_string( |
Greg Hartman | bc1bed4 | 2019-04-05 20:02:00 -0700 | [diff] [blame] | 92 | gpu_mode, vsoc::kGpuModeGuestSwiftshader, |
| 93 | "What gpu configuration to use, one of {guest_swiftshader, drm_virgl}"); |
Greg Hartman | a3c552d | 2019-03-28 18:20:48 -0700 | [diff] [blame] | 94 | DEFINE_string(wayland_socket, "", |
Greg Hartman | bc1bed4 | 2019-04-05 20:02:00 -0700 | [diff] [blame] | 95 | "Location of the wayland socket to use for drm_virgl gpu_mode."); |
Greg Hartman | eb04ac5 | 2019-07-16 16:44:18 -0700 | [diff] [blame] | 96 | DEFINE_string(x_display, "", |
| 97 | "X display to use for drm_virgl gpu_mode."); |
Greg Hartman | a3c552d | 2019-03-28 18:20:48 -0700 | [diff] [blame] | 98 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 99 | DEFINE_string(system_image_dir, vsoc::DefaultGuestImagePath(""), |
| 100 | "Location of the system partition images."); |
Alistair Strachan | 050ca93 | 2018-11-27 12:41:19 -0800 | [diff] [blame] | 101 | DEFINE_string(super_image, "", "Location of the super partition image."); |
Yifan Hong | 19d713e | 2019-05-01 14:12:07 -0700 | [diff] [blame] | 102 | DEFINE_string(misc_image, "", |
| 103 | "Location of the misc partition image. If the image does not " |
| 104 | "exist, a blank new misc partition image is created."); |
David Anderson | 64581ce | 2019-10-03 17:52:22 -0700 | [diff] [blame] | 105 | DEFINE_string(composite_disk, "", "Location of the composite disk image. " |
| 106 | "If empty, a composite disk is not used."); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 107 | |
| 108 | DEFINE_bool(deprecated_boot_completed, false, "Log boot completed message to" |
| 109 | " host kernel. This is only used during transition of our clients." |
| 110 | " Will be deprecated soon."); |
| 111 | DEFINE_bool(start_vnc_server, true, "Whether to start the vnc server process."); |
| 112 | DEFINE_string(vnc_server_binary, |
| 113 | vsoc::DefaultHostArtifactsPath("bin/vnc_server"), |
| 114 | "Location of the vnc server binary."); |
Alistair Strachan | 7eeddf4 | 2019-03-04 18:13:34 -0800 | [diff] [blame] | 115 | DEFINE_bool(start_stream_audio, false, |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 116 | "Whether to start the stream audio process."); |
| 117 | DEFINE_string(stream_audio_binary, |
| 118 | vsoc::DefaultHostArtifactsPath("bin/stream_audio"), |
| 119 | "Location of the stream_audio binary."); |
| 120 | DEFINE_string(virtual_usb_manager_binary, |
| 121 | vsoc::DefaultHostArtifactsPath("bin/virtual_usb_manager"), |
| 122 | "Location of the virtual usb manager binary."); |
| 123 | DEFINE_string(kernel_log_monitor_binary, |
| 124 | vsoc::DefaultHostArtifactsPath("bin/kernel_log_monitor"), |
| 125 | "Location of the log monitor binary."); |
| 126 | DEFINE_string(ivserver_binary, |
| 127 | vsoc::DefaultHostArtifactsPath("bin/ivserver"), |
| 128 | "Location of the ivshmem server binary."); |
| 129 | DEFINE_int32(vnc_server_port, GetPerInstanceDefault(6444), |
| 130 | "The port on which the vnc server should listen"); |
| 131 | DEFINE_int32(stream_audio_port, GetPerInstanceDefault(7444), |
| 132 | "The port on which stream_audio should listen."); |
| 133 | DEFINE_string(socket_forward_proxy_binary, |
| 134 | vsoc::DefaultHostArtifactsPath("bin/socket_forward_proxy"), |
| 135 | "Location of the socket_forward_proxy binary."); |
| 136 | DEFINE_string(socket_vsock_proxy_binary, |
| 137 | vsoc::DefaultHostArtifactsPath("bin/socket_vsock_proxy"), |
| 138 | "Location of the socket_vsock_proxy binary."); |
Cody Schuffelen | 1074333 | 2019-04-15 16:50:49 -0700 | [diff] [blame] | 139 | DEFINE_string(adb_mode, "vsock_half_tunnel", |
Cody Schuffelen | 63d1005 | 2019-02-26 12:21:53 -0800 | [diff] [blame] | 140 | "Mode for ADB connection. Can be 'usb' for USB forwarding, " |
| 141 | "'tunnel' for a TCP connection tunneled through VSoC, " |
| 142 | "'vsock_tunnel' for a TCP connection tunneled through vsock, " |
| 143 | "'native_vsock' for a direct connection to the guest ADB over " |
| 144 | "vsock, 'vsock_half_tunnel' for a TCP connection forwarded to " |
| 145 | "the guest ADB server, or a comma separated list of types as in " |
| 146 | "'usb,tunnel'"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 147 | DEFINE_bool(run_adb_connector, true, |
| 148 | "Maintain adb connection by sending 'adb connect' commands to the " |
Matthias Maennich | 454d787 | 2019-02-06 16:35:17 +0000 | [diff] [blame] | 149 | "server. Only relevant with -adb_mode=tunnel or vsock_tunnel"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 150 | DEFINE_string(adb_connector_binary, |
| 151 | vsoc::DefaultHostArtifactsPath("bin/adb_connector"), |
| 152 | "Location of the adb_connector binary. Only relevant if " |
Matthias Maennich | 454d787 | 2019-02-06 16:35:17 +0000 | [diff] [blame] | 153 | "-run_adb_connector is true"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 154 | DEFINE_int32(vhci_port, GetPerInstanceDefault(0), "VHCI port to use for usb"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 155 | DEFINE_string(wifi_tap_name, "", // default handled on ParseCommandLine |
| 156 | "The name of the tap interface to use for wifi"); |
| 157 | DEFINE_int32(vsock_guest_cid, |
| 158 | vsoc::GetDefaultPerInstanceVsockCid(), |
| 159 | "Guest identifier for vsock. Disabled if under 3."); |
| 160 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 161 | DEFINE_string(uuid, vsoc::GetPerInstanceDefault(vsoc::kDefaultUuidPrefix), |
| 162 | "UUID to use for the device. Random if not specified"); |
| 163 | DEFINE_bool(daemon, false, |
| 164 | "Run cuttlefish in background, the launcher exits on boot " |
| 165 | "completed/failed"); |
| 166 | |
| 167 | DEFINE_string(device_title, "", "Human readable name for the instance, " |
| 168 | "used by the vnc_server for its server title"); |
| 169 | DEFINE_string(setupwizard_mode, "DISABLED", |
| 170 | "One of DISABLED,OPTIONAL,REQUIRED"); |
| 171 | |
| 172 | DEFINE_string(qemu_binary, |
| 173 | "/usr/bin/qemu-system-x86_64", |
| 174 | "The qemu binary to use"); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 175 | DEFINE_string(crosvm_binary, |
| 176 | vsoc::DefaultHostArtifactsPath("bin/crosvm"), |
| 177 | "The Crosvm binary to use"); |
Jorge E. Moreira | 13cbd98 | 2019-06-06 16:06:34 -0700 | [diff] [blame] | 178 | DEFINE_string(console_forwarder_binary, |
| 179 | vsoc::DefaultHostArtifactsPath("bin/console_forwarder"), |
| 180 | "The Console Forwarder binary to use"); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 181 | DEFINE_bool(restart_subprocesses, true, "Restart any crashed host process"); |
| 182 | DEFINE_bool(run_e2e_test, true, "Run e2e test after device launches"); |
| 183 | DEFINE_string(e2e_test_binary, |
| 184 | vsoc::DefaultHostArtifactsPath("bin/host_region_e2e_test"), |
| 185 | "Location of the region end to end test binary"); |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 186 | DEFINE_string(logcat_receiver_binary, |
| 187 | vsoc::DefaultHostArtifactsPath("bin/logcat_receiver"), |
| 188 | "Binary for the logcat server"); |
| 189 | DEFINE_string(logcat_mode, "", "How to send android's log messages from " |
| 190 | "guest to host. One of [serial, vsock]"); |
| 191 | DEFINE_int32(logcat_vsock_port, vsoc::GetPerInstanceDefault(5620), |
| 192 | "The port for logcat over vsock"); |
Jorge E. Moreira | f1f7cb3 | 2019-04-15 18:44:41 -0700 | [diff] [blame] | 193 | DEFINE_string(config_server_binary, |
| 194 | vsoc::DefaultHostArtifactsPath("bin/config_server"), |
| 195 | "Binary for the configuration server"); |
| 196 | DEFINE_int32(config_server_port, vsoc::GetPerInstanceDefault(4680), |
| 197 | "The (vsock) port for the configuration server"); |
Jorge E. Moreira | c87c2c7 | 2019-03-06 16:12:23 -0800 | [diff] [blame] | 198 | DEFINE_int32(frames_vsock_port, vsoc::GetPerInstanceDefault(5580), |
| 199 | "The vsock port to receive frames from the guest on"); |
Ram Muthiah | 6e9c98c | 2019-05-28 15:18:27 -0700 | [diff] [blame] | 200 | DEFINE_bool(enable_tombstone_receiver, true, "Enables the tombstone logger on " |
Ram Muthiah | 792e2ad | 2019-04-19 11:19:46 -0700 | [diff] [blame] | 201 | "both the guest and the host"); |
| 202 | DEFINE_string(tombstone_receiver_binary, |
| 203 | vsoc::DefaultHostArtifactsPath("bin/tombstone_receiver"), |
| 204 | "Binary for the tombstone server"); |
| 205 | DEFINE_int32(tombstone_receiver_port, vsoc::GetPerInstanceDefault(5630), |
| 206 | "The vsock port for tombstones"); |
Cody Schuffelen | 1300f12 | 2019-05-28 18:24:34 -0700 | [diff] [blame] | 207 | DEFINE_bool(use_bootloader, false, "Boots the device using a bootloader"); |
| 208 | DEFINE_string(bootloader, "", "Bootloader binary path"); |
David Anderson | 637bfd6 | 2019-09-26 13:23:21 -0700 | [diff] [blame^] | 209 | DEFINE_string(boot_slot, "", "Force booting into the given slot. If empty, " |
| 210 | "the slot will be chosen based on the misc partition if using a " |
| 211 | "bootloader. It will default to 'a' if empty and not using a " |
| 212 | "bootloader."); |
Yifan Hong | 19d713e | 2019-05-01 14:12:07 -0700 | [diff] [blame] | 213 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 214 | namespace { |
| 215 | |
Cody Schuffelen | 9fd9547 | 2019-10-04 13:49:57 -0700 | [diff] [blame] | 216 | std::string kRamdiskConcatExt = ".concat"; |
| 217 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 218 | template<typename S, typename T> |
| 219 | static std::string concat(const S& s, const T& t) { |
| 220 | std::ostringstream os; |
| 221 | os << s << t; |
| 222 | return os.str(); |
| 223 | } |
| 224 | |
| 225 | bool ResolveInstanceFiles() { |
| 226 | if (FLAGS_system_image_dir.empty()) { |
| 227 | LOG(ERROR) << "--system_image_dir must be specified."; |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | // If user did not specify location of either of these files, expect them to |
| 232 | // be placed in --system_image_dir location. |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 233 | std::string default_boot_image = FLAGS_system_image_dir + "/boot.img"; |
| 234 | SetCommandLineOptionWithMode("boot_image", default_boot_image.c_str(), |
| 235 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 236 | std::string default_cache_image = FLAGS_system_image_dir + "/cache.img"; |
| 237 | SetCommandLineOptionWithMode("cache_image", default_cache_image.c_str(), |
| 238 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 239 | std::string default_data_image = FLAGS_system_image_dir + "/userdata.img"; |
| 240 | SetCommandLineOptionWithMode("data_image", default_data_image.c_str(), |
| 241 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Paul Trautrim | ba8f8e9 | 2019-03-12 17:55:48 +0900 | [diff] [blame] | 242 | std::string default_metadata_image = FLAGS_system_image_dir + "/metadata.img"; |
| 243 | SetCommandLineOptionWithMode("metadata_image", default_metadata_image.c_str(), |
| 244 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Alistair Strachan | 050ca93 | 2018-11-27 12:41:19 -0800 | [diff] [blame] | 245 | std::string default_super_image = FLAGS_system_image_dir + "/super.img"; |
| 246 | SetCommandLineOptionWithMode("super_image", default_super_image.c_str(), |
| 247 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Yifan Hong | 19d713e | 2019-05-01 14:12:07 -0700 | [diff] [blame] | 248 | std::string default_misc_image = FLAGS_system_image_dir + "/misc.img"; |
| 249 | SetCommandLineOptionWithMode("misc_image", default_misc_image.c_str(), |
| 250 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
David Anderson | 64581ce | 2019-10-03 17:52:22 -0700 | [diff] [blame] | 251 | std::string default_composite_disk = FLAGS_system_image_dir + "/composite.img"; |
| 252 | SetCommandLineOptionWithMode("composite_disk", default_composite_disk.c_str(), |
| 253 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 254 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 255 | return true; |
| 256 | } |
| 257 | |
| 258 | std::string GetCuttlefishEnvPath() { |
| 259 | return cvd::StringFromEnv("HOME", ".") + "/.cuttlefish.sh"; |
| 260 | } |
| 261 | |
Cody Schuffelen | e0d0c46 | 2019-09-09 14:13:01 -0700 | [diff] [blame] | 262 | int GetHostPort() { |
| 263 | constexpr int kFirstHostPort = 6520; |
| 264 | return vsoc::GetPerInstanceDefault(kFirstHostPort); |
| 265 | } |
| 266 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 267 | // Initializes the config object and saves it to file. It doesn't return it, all |
| 268 | // further uses of the config should happen through the singleton |
| 269 | bool InitializeCuttlefishConfiguration( |
| 270 | const cvd::BootImageUnpacker& boot_image_unpacker) { |
| 271 | vsoc::CuttlefishConfig tmp_config_obj; |
| 272 | auto& memory_layout = *vsoc::VSoCMemoryLayout::Get(); |
| 273 | // Set this first so that calls to PerInstancePath below are correct |
| 274 | tmp_config_obj.set_instance_dir(FLAGS_instance_dir); |
| 275 | if (!vm_manager::VmManager::IsValidName(FLAGS_vm_manager)) { |
| 276 | LOG(ERROR) << "Invalid vm_manager: " << FLAGS_vm_manager; |
| 277 | return false; |
| 278 | } |
Greg Hartman | a3c552d | 2019-03-28 18:20:48 -0700 | [diff] [blame] | 279 | if (!vm_manager::VmManager::IsValidName(FLAGS_vm_manager)) { |
| 280 | LOG(ERROR) << "Invalid vm_manager: " << FLAGS_vm_manager; |
| 281 | return false; |
| 282 | } |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 283 | tmp_config_obj.set_vm_manager(FLAGS_vm_manager); |
Greg Hartman | a3c552d | 2019-03-28 18:20:48 -0700 | [diff] [blame] | 284 | tmp_config_obj.set_gpu_mode(FLAGS_gpu_mode); |
| 285 | if (!vm_manager::VmManager::ConfigureGpuMode(&tmp_config_obj)) { |
| 286 | LOG(ERROR) << "Invalid gpu_mode=" << FLAGS_gpu_mode << |
| 287 | " does not work with vm_manager=" << FLAGS_vm_manager; |
| 288 | return false; |
| 289 | } |
| 290 | tmp_config_obj.set_wayland_socket(FLAGS_wayland_socket); |
Greg Hartman | eb04ac5 | 2019-07-16 16:44:18 -0700 | [diff] [blame] | 291 | tmp_config_obj.set_x_display(FLAGS_x_display); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 292 | |
Alistair Strachan | 050ca93 | 2018-11-27 12:41:19 -0800 | [diff] [blame] | 293 | vm_manager::VmManager::ConfigureBootDevices(&tmp_config_obj); |
| 294 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 295 | tmp_config_obj.set_serial_number(FLAGS_serial_number); |
| 296 | |
| 297 | tmp_config_obj.set_cpus(FLAGS_cpus); |
| 298 | tmp_config_obj.set_memory_mb(FLAGS_memory_mb); |
| 299 | |
| 300 | tmp_config_obj.set_dpi(FLAGS_dpi); |
| 301 | tmp_config_obj.set_setupwizard_mode(FLAGS_setupwizard_mode); |
| 302 | tmp_config_obj.set_x_res(FLAGS_x_res); |
| 303 | tmp_config_obj.set_y_res(FLAGS_y_res); |
| 304 | tmp_config_obj.set_num_screen_buffers(FLAGS_num_screen_buffers); |
| 305 | tmp_config_obj.set_refresh_rate_hz(FLAGS_refresh_rate_hz); |
| 306 | tmp_config_obj.set_gdb_flag(FLAGS_qemu_gdb); |
Cody Schuffelen | 90b2fb2 | 2019-02-28 18:55:21 -0800 | [diff] [blame] | 307 | std::vector<std::string> adb = cvd::StrSplit(FLAGS_adb_mode, ','); |
| 308 | tmp_config_obj.set_adb_mode(std::set<std::string>(adb.begin(), adb.end())); |
Cody Schuffelen | e0d0c46 | 2019-09-09 14:13:01 -0700 | [diff] [blame] | 309 | tmp_config_obj.set_host_port(GetHostPort()); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 310 | tmp_config_obj.set_adb_ip_and_port("127.0.0.1:" + std::to_string(GetHostPort())); |
| 311 | |
| 312 | tmp_config_obj.set_device_title(FLAGS_device_title); |
| 313 | if (FLAGS_kernel_path.size()) { |
| 314 | tmp_config_obj.set_kernel_image_path(FLAGS_kernel_path); |
| 315 | tmp_config_obj.set_use_unpacked_kernel(false); |
| 316 | } else { |
| 317 | tmp_config_obj.set_kernel_image_path( |
| 318 | tmp_config_obj.PerInstancePath("kernel")); |
| 319 | tmp_config_obj.set_use_unpacked_kernel(true); |
| 320 | } |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 321 | tmp_config_obj.set_decompress_kernel(FLAGS_decompress_kernel); |
| 322 | if (FLAGS_decompress_kernel) { |
| 323 | tmp_config_obj.set_decompressed_kernel_image_path( |
| 324 | tmp_config_obj.PerInstancePath("vmlinux")); |
| 325 | } |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 326 | |
| 327 | auto ramdisk_path = tmp_config_obj.PerInstancePath("ramdisk.img"); |
| 328 | bool use_ramdisk = boot_image_unpacker.HasRamdiskImage(); |
| 329 | if (!use_ramdisk) { |
| 330 | LOG(INFO) << "No ramdisk present; assuming system-as-root build"; |
| 331 | ramdisk_path = ""; |
| 332 | } |
| 333 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 334 | tmp_config_obj.add_kernel_cmdline(boot_image_unpacker.kernel_cmdline()); |
Cody Schuffelen | 88b82d5 | 2019-05-29 14:16:03 -0700 | [diff] [blame] | 335 | |
| 336 | if (use_ramdisk) { |
| 337 | if (FLAGS_composite_disk.empty()) { |
| 338 | tmp_config_obj.add_kernel_cmdline("androidboot.fstab_name=fstab"); |
| 339 | } else { |
Alistair Delva | 73ad5ec | 2019-08-30 15:37:19 -0700 | [diff] [blame] | 340 | tmp_config_obj.add_kernel_cmdline("androidboot.fstab_name=fstab.composite"); |
Cody Schuffelen | 88b82d5 | 2019-05-29 14:16:03 -0700 | [diff] [blame] | 341 | } |
| 342 | } else { |
| 343 | if (FLAGS_composite_disk.empty()) { |
| 344 | tmp_config_obj.add_kernel_cmdline("root=/dev/vda"); |
| 345 | tmp_config_obj.add_kernel_cmdline("androidboot.fstab_name=fstab"); |
| 346 | } else { |
| 347 | tmp_config_obj.add_kernel_cmdline("root=/dev/vda1"); |
Alistair Delva | 73ad5ec | 2019-08-30 15:37:19 -0700 | [diff] [blame] | 348 | tmp_config_obj.add_kernel_cmdline("androidboot.fstab_name=fstab.composite"); |
Cody Schuffelen | 88b82d5 | 2019-05-29 14:16:03 -0700 | [diff] [blame] | 349 | } |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 350 | } |
Cody Schuffelen | 88b82d5 | 2019-05-29 14:16:03 -0700 | [diff] [blame] | 351 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 352 | tmp_config_obj.add_kernel_cmdline("init=/init"); |
| 353 | tmp_config_obj.add_kernel_cmdline( |
| 354 | concat("androidboot.serialno=", FLAGS_serial_number)); |
| 355 | tmp_config_obj.add_kernel_cmdline("mac80211_hwsim.radios=0"); |
| 356 | tmp_config_obj.add_kernel_cmdline(concat("androidboot.lcd_density=", FLAGS_dpi)); |
| 357 | tmp_config_obj.add_kernel_cmdline( |
| 358 | concat("androidboot.setupwizard_mode=", FLAGS_setupwizard_mode)); |
| 359 | tmp_config_obj.add_kernel_cmdline(concat("loop.max_part=", FLAGS_loop_max_part)); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 360 | if (!FLAGS_androidboot_console.empty()) { |
| 361 | tmp_config_obj.add_kernel_cmdline( |
| 362 | concat("androidboot.console=", FLAGS_androidboot_console)); |
| 363 | } |
| 364 | if (!FLAGS_hardware_name.empty()) { |
| 365 | tmp_config_obj.add_kernel_cmdline( |
| 366 | concat("androidboot.hardware=", FLAGS_hardware_name)); |
| 367 | } |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 368 | if (FLAGS_logcat_mode == cvd::kLogcatVsockMode) { |
| 369 | tmp_config_obj.add_kernel_cmdline(concat("androidboot.vsock_logcat_port=", |
| 370 | FLAGS_logcat_vsock_port)); |
| 371 | } |
Jorge E. Moreira | f1f7cb3 | 2019-04-15 18:44:41 -0700 | [diff] [blame] | 372 | tmp_config_obj.add_kernel_cmdline(concat("androidboot.cuttlefish_config_server_port=", |
| 373 | FLAGS_config_server_port)); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 374 | tmp_config_obj.set_hardware_name(FLAGS_hardware_name); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 375 | if (!FLAGS_guest_security.empty()) { |
| 376 | tmp_config_obj.add_kernel_cmdline(concat("security=", FLAGS_guest_security)); |
| 377 | if (FLAGS_guest_enforce_security) { |
| 378 | tmp_config_obj.add_kernel_cmdline("enforcing=1"); |
| 379 | } else { |
| 380 | tmp_config_obj.add_kernel_cmdline("enforcing=0"); |
| 381 | tmp_config_obj.add_kernel_cmdline("androidboot.selinux=permissive"); |
| 382 | } |
| 383 | if (FLAGS_guest_audit_security) { |
| 384 | tmp_config_obj.add_kernel_cmdline("audit=1"); |
| 385 | } else { |
| 386 | tmp_config_obj.add_kernel_cmdline("audit=0"); |
| 387 | } |
| 388 | } |
| 389 | if (FLAGS_run_e2e_test) { |
| 390 | tmp_config_obj.add_kernel_cmdline("androidboot.vsoc_e2e_test=1"); |
| 391 | } |
| 392 | if (FLAGS_extra_kernel_cmdline.size()) { |
| 393 | tmp_config_obj.add_kernel_cmdline(FLAGS_extra_kernel_cmdline); |
| 394 | } |
| 395 | |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 396 | if (!FLAGS_composite_disk.empty()) { |
| 397 | tmp_config_obj.set_virtual_disk_paths({FLAGS_composite_disk}); |
Cody Schuffelen | 4f7e441 | 2019-08-30 16:10:59 -0700 | [diff] [blame] | 398 | } else { |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 399 | tmp_config_obj.set_virtual_disk_paths({ |
| 400 | FLAGS_super_image, |
| 401 | FLAGS_data_image, |
| 402 | FLAGS_cache_image, |
| 403 | FLAGS_metadata_image, |
| 404 | }); |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 407 | tmp_config_obj.set_ramdisk_image_path(ramdisk_path); |
Cody Schuffelen | 9fd9547 | 2019-10-04 13:49:57 -0700 | [diff] [blame] | 408 | if(FLAGS_initramfs_path.size() > 0) { |
| 409 | tmp_config_obj.set_initramfs_path(FLAGS_initramfs_path); |
| 410 | tmp_config_obj.set_final_ramdisk_path(ramdisk_path + kRamdiskConcatExt); |
| 411 | } else { |
| 412 | tmp_config_obj.set_final_ramdisk_path(ramdisk_path); |
| 413 | } |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 414 | |
| 415 | tmp_config_obj.set_mempath(FLAGS_mempath); |
| 416 | tmp_config_obj.set_ivshmem_qemu_socket_path( |
Jorge E. Moreira | 1e8e2f1 | 2019-10-07 18:09:49 -0700 | [diff] [blame] | 417 | tmp_config_obj.PerInstanceInternalPath("ivshmem_socket_qemu")); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 418 | tmp_config_obj.set_ivshmem_client_socket_path( |
Jorge E. Moreira | 1e8e2f1 | 2019-10-07 18:09:49 -0700 | [diff] [blame] | 419 | tmp_config_obj.PerInstanceInternalPath("ivshmem_socket_client")); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 420 | tmp_config_obj.set_ivshmem_vector_count(memory_layout.GetRegions().size()); |
| 421 | |
Cody Schuffelen | 75ef887 | 2019-09-06 17:35:54 -0700 | [diff] [blame] | 422 | if (tmp_config_obj.adb_mode().count(vsoc::AdbMode::Usb) > 0) { |
Jorge E. Moreira | 1e8e2f1 | 2019-10-07 18:09:49 -0700 | [diff] [blame] | 423 | tmp_config_obj.set_usb_v1_socket_name( |
| 424 | tmp_config_obj.PerInstanceInternalPath("usb-v1")); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 425 | tmp_config_obj.set_vhci_port(FLAGS_vhci_port); |
Jorge E. Moreira | 1e8e2f1 | 2019-10-07 18:09:49 -0700 | [diff] [blame] | 426 | tmp_config_obj.set_usb_ip_socket_name( |
| 427 | tmp_config_obj.PerInstanceInternalPath("usb-ip")); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Jorge E. Moreira | 1e8e2f1 | 2019-10-07 18:09:49 -0700 | [diff] [blame] | 430 | tmp_config_obj.set_kernel_log_pipe_name( |
| 431 | tmp_config_obj.PerInstanceInternalPath("kernel-log-pipe")); |
| 432 | tmp_config_obj.set_console_pipe_name( |
| 433 | tmp_config_obj.PerInstanceInternalPath("console-pipe")); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 434 | tmp_config_obj.set_deprecated_boot_completed(FLAGS_deprecated_boot_completed); |
| 435 | tmp_config_obj.set_console_path(tmp_config_obj.PerInstancePath("console")); |
| 436 | tmp_config_obj.set_logcat_path(tmp_config_obj.PerInstancePath("logcat")); |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 437 | tmp_config_obj.set_logcat_receiver_binary(FLAGS_logcat_receiver_binary); |
Jorge E. Moreira | f1f7cb3 | 2019-04-15 18:44:41 -0700 | [diff] [blame] | 438 | tmp_config_obj.set_config_server_binary(FLAGS_config_server_binary); |
Jorge E. Moreira | 1e8e2f1 | 2019-10-07 18:09:49 -0700 | [diff] [blame] | 439 | tmp_config_obj.set_launcher_log_path( |
| 440 | tmp_config_obj.PerInstancePath("launcher.log")); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 441 | tmp_config_obj.set_launcher_monitor_socket_path( |
| 442 | tmp_config_obj.PerInstancePath("launcher_monitor.sock")); |
| 443 | |
| 444 | tmp_config_obj.set_mobile_bridge_name(FLAGS_mobile_interface); |
| 445 | tmp_config_obj.set_mobile_tap_name(FLAGS_mobile_tap_name); |
| 446 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 447 | tmp_config_obj.set_wifi_tap_name(FLAGS_wifi_tap_name); |
| 448 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 449 | tmp_config_obj.set_vsock_guest_cid(FLAGS_vsock_guest_cid); |
| 450 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 451 | tmp_config_obj.set_uuid(FLAGS_uuid); |
| 452 | |
| 453 | tmp_config_obj.set_qemu_binary(FLAGS_qemu_binary); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 454 | tmp_config_obj.set_crosvm_binary(FLAGS_crosvm_binary); |
Jorge E. Moreira | 13cbd98 | 2019-06-06 16:06:34 -0700 | [diff] [blame] | 455 | tmp_config_obj.set_console_forwarder_binary(FLAGS_console_forwarder_binary); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 456 | tmp_config_obj.set_ivserver_binary(FLAGS_ivserver_binary); |
| 457 | tmp_config_obj.set_kernel_log_monitor_binary(FLAGS_kernel_log_monitor_binary); |
| 458 | |
| 459 | tmp_config_obj.set_enable_vnc_server(FLAGS_start_vnc_server); |
| 460 | tmp_config_obj.set_vnc_server_binary(FLAGS_vnc_server_binary); |
| 461 | tmp_config_obj.set_vnc_server_port(FLAGS_vnc_server_port); |
| 462 | |
| 463 | tmp_config_obj.set_enable_stream_audio(FLAGS_start_stream_audio); |
| 464 | tmp_config_obj.set_stream_audio_binary(FLAGS_stream_audio_binary); |
| 465 | tmp_config_obj.set_stream_audio_port(FLAGS_stream_audio_port); |
| 466 | |
| 467 | tmp_config_obj.set_restart_subprocesses(FLAGS_restart_subprocesses); |
| 468 | tmp_config_obj.set_run_adb_connector(FLAGS_run_adb_connector); |
| 469 | tmp_config_obj.set_adb_connector_binary(FLAGS_adb_connector_binary); |
| 470 | tmp_config_obj.set_virtual_usb_manager_binary( |
| 471 | FLAGS_virtual_usb_manager_binary); |
| 472 | tmp_config_obj.set_socket_forward_proxy_binary( |
| 473 | FLAGS_socket_forward_proxy_binary); |
| 474 | tmp_config_obj.set_socket_vsock_proxy_binary(FLAGS_socket_vsock_proxy_binary); |
| 475 | tmp_config_obj.set_run_as_daemon(FLAGS_daemon); |
| 476 | tmp_config_obj.set_run_e2e_test(FLAGS_run_e2e_test); |
| 477 | tmp_config_obj.set_e2e_test_binary(FLAGS_e2e_test_binary); |
| 478 | |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 479 | tmp_config_obj.set_data_policy(FLAGS_data_policy); |
| 480 | tmp_config_obj.set_blank_data_image_mb(FLAGS_blank_data_image_mb); |
| 481 | tmp_config_obj.set_blank_data_image_fmt(FLAGS_blank_data_image_fmt); |
| 482 | |
Cody Schuffelen | 75ef887 | 2019-09-06 17:35:54 -0700 | [diff] [blame] | 483 | if(tmp_config_obj.adb_mode().count(vsoc::AdbMode::Usb) == 0) { |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 484 | tmp_config_obj.disable_usb_adb(); |
| 485 | } |
| 486 | |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 487 | tmp_config_obj.set_logcat_mode(FLAGS_logcat_mode); |
| 488 | tmp_config_obj.set_logcat_vsock_port(FLAGS_logcat_vsock_port); |
Jorge E. Moreira | f1f7cb3 | 2019-04-15 18:44:41 -0700 | [diff] [blame] | 489 | tmp_config_obj.set_config_server_port(FLAGS_config_server_port); |
Jorge E. Moreira | c87c2c7 | 2019-03-06 16:12:23 -0800 | [diff] [blame] | 490 | tmp_config_obj.set_frames_vsock_port(FLAGS_frames_vsock_port); |
Jorge E. Moreira | 1859ccc | 2019-05-14 15:15:27 -0700 | [diff] [blame] | 491 | if (!tmp_config_obj.enable_ivserver() && tmp_config_obj.enable_vnc_server()) { |
Jorge E. Moreira | c87c2c7 | 2019-03-06 16:12:23 -0800 | [diff] [blame] | 492 | tmp_config_obj.add_kernel_cmdline(concat("androidboot.vsock_frames_port=", |
| 493 | FLAGS_frames_vsock_port)); |
| 494 | } |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 495 | |
Ram Muthiah | 792e2ad | 2019-04-19 11:19:46 -0700 | [diff] [blame] | 496 | tmp_config_obj.set_enable_tombstone_receiver(FLAGS_enable_tombstone_receiver); |
| 497 | tmp_config_obj.set_tombstone_receiver_port(FLAGS_tombstone_receiver_port); |
| 498 | tmp_config_obj.set_tombstone_receiver_binary(FLAGS_tombstone_receiver_binary); |
| 499 | if (FLAGS_enable_tombstone_receiver) { |
| 500 | tmp_config_obj.add_kernel_cmdline("androidboot.tombstone_transmit=1"); |
| 501 | tmp_config_obj.add_kernel_cmdline(concat("androidboot.vsock_tombstone_port=" |
| 502 | ,FLAGS_tombstone_receiver_port)); |
Alistair Strachan | 050ca93 | 2018-11-27 12:41:19 -0800 | [diff] [blame] | 503 | // TODO (b/128842613) populate a cid flag to read the host CID during |
Ram Muthiah | 792e2ad | 2019-04-19 11:19:46 -0700 | [diff] [blame] | 504 | // runtime |
| 505 | } else { |
| 506 | tmp_config_obj.add_kernel_cmdline("androidboot.tombstone_transmit=0"); |
| 507 | } |
| 508 | |
Cody Schuffelen | 1300f12 | 2019-05-28 18:24:34 -0700 | [diff] [blame] | 509 | tmp_config_obj.set_use_bootloader(FLAGS_use_bootloader); |
| 510 | tmp_config_obj.set_bootloader(FLAGS_bootloader); |
| 511 | |
David Anderson | 637bfd6 | 2019-09-26 13:23:21 -0700 | [diff] [blame^] | 512 | if (!FLAGS_boot_slot.empty()) { |
| 513 | tmp_config_obj.set_boot_slot(FLAGS_boot_slot); |
| 514 | } |
| 515 | |
| 516 | if (!FLAGS_use_bootloader) { |
| 517 | std::string slot_suffix; |
| 518 | if (FLAGS_boot_slot.empty()) { |
| 519 | slot_suffix = "_a"; |
| 520 | } else { |
| 521 | slot_suffix = "_" + FLAGS_boot_slot; |
| 522 | } |
| 523 | tmp_config_obj.add_kernel_cmdline("androidboot.slot_suffix=" + slot_suffix); |
| 524 | } |
| 525 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 526 | tmp_config_obj.set_cuttlefish_env_path(GetCuttlefishEnvPath()); |
| 527 | |
| 528 | auto config_file = GetConfigFilePath(tmp_config_obj); |
| 529 | auto config_link = vsoc::GetGlobalConfigFileLink(); |
| 530 | // Save the config object before starting any host process |
| 531 | if (!tmp_config_obj.SaveToFile(config_file)) { |
| 532 | LOG(ERROR) << "Unable to save config object"; |
| 533 | return false; |
| 534 | } |
| 535 | setenv(vsoc::kCuttlefishConfigEnvVarName, config_file.c_str(), true); |
| 536 | if (symlink(config_file.c_str(), config_link.c_str()) != 0) { |
| 537 | LOG(ERROR) << "Failed to create symlink to config file at " << config_link |
| 538 | << ": " << strerror(errno); |
| 539 | return false; |
| 540 | } |
| 541 | |
| 542 | return true; |
| 543 | } |
| 544 | |
| 545 | void SetDefaultFlagsForQemu() { |
| 546 | auto default_mobile_interface = GetPerInstanceDefault("cvd-mbr-"); |
| 547 | SetCommandLineOptionWithMode("mobile_interface", |
| 548 | default_mobile_interface.c_str(), |
| 549 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 550 | auto default_mobile_tap_name = GetPerInstanceDefault("cvd-mtap-"); |
| 551 | SetCommandLineOptionWithMode("mobile_tap_name", |
| 552 | default_mobile_tap_name.c_str(), |
| 553 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 554 | auto default_wifi_tap_name = GetPerInstanceDefault("cvd-wtap-"); |
| 555 | SetCommandLineOptionWithMode("wifi_tap_name", |
| 556 | default_wifi_tap_name.c_str(), |
| 557 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 558 | auto default_instance_dir = |
| 559 | cvd::StringFromEnv("HOME", ".") + "/cuttlefish_runtime"; |
| 560 | SetCommandLineOptionWithMode("instance_dir", |
| 561 | default_instance_dir.c_str(), |
| 562 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | fd1a6b0 | 2019-02-27 16:25:00 -0800 | [diff] [blame] | 563 | SetCommandLineOptionWithMode("hardware_name", "cutf_ivsh", |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 564 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 565 | SetCommandLineOptionWithMode("logcat_mode", cvd::kLogcatSerialMode, |
| 566 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | void SetDefaultFlagsForCrosvm() { |
| 570 | auto default_mobile_interface = GetPerInstanceDefault("cvd-mbr-"); |
| 571 | SetCommandLineOptionWithMode("mobile_interface", |
| 572 | default_mobile_interface.c_str(), |
| 573 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 574 | auto default_mobile_tap_name = GetPerInstanceDefault("cvd-mtap-"); |
| 575 | SetCommandLineOptionWithMode("mobile_tap_name", |
| 576 | default_mobile_tap_name.c_str(), |
| 577 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 578 | auto default_wifi_tap_name = GetPerInstanceDefault("cvd-wtap-"); |
| 579 | SetCommandLineOptionWithMode("wifi_tap_name", |
| 580 | default_wifi_tap_name.c_str(), |
| 581 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 582 | auto default_instance_dir = |
| 583 | cvd::StringFromEnv("HOME", ".") + "/cuttlefish_runtime"; |
| 584 | SetCommandLineOptionWithMode("instance_dir", |
| 585 | default_instance_dir.c_str(), |
| 586 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Greg Hartman | a3c552d | 2019-03-28 18:20:48 -0700 | [diff] [blame] | 587 | SetCommandLineOptionWithMode("wayland_socket", |
Greg Hartman | eb04ac5 | 2019-07-16 16:44:18 -0700 | [diff] [blame] | 588 | "", |
| 589 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
| 590 | SetCommandLineOptionWithMode("x_display", |
| 591 | getenv("DISPLAY"), |
Greg Hartman | a3c552d | 2019-03-28 18:20:48 -0700 | [diff] [blame] | 592 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | fd1a6b0 | 2019-02-27 16:25:00 -0800 | [diff] [blame] | 593 | SetCommandLineOptionWithMode("hardware_name", "cutf_cvm", |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 594 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | 84d93c1 | 2019-02-05 12:02:29 -0800 | [diff] [blame] | 595 | SetCommandLineOptionWithMode("run_e2e_test", "false", |
| 596 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 597 | SetCommandLineOptionWithMode("logcat_mode", cvd::kLogcatVsockMode, |
| 598 | google::FlagSettingMode::SET_FLAGS_DEFAULT); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | bool ParseCommandLineFlags(int* argc, char*** argv) { |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 602 | google::ParseCommandLineNonHelpFlags(argc, argv, true); |
| 603 | bool invalid_manager = false; |
| 604 | if (FLAGS_vm_manager == vm_manager::QemuManager::name()) { |
| 605 | SetDefaultFlagsForQemu(); |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 606 | } else if (FLAGS_vm_manager == vm_manager::CrosvmManager::name()) { |
| 607 | SetDefaultFlagsForCrosvm(); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 608 | } else { |
| 609 | std::cerr << "Unknown Virtual Machine Manager: " << FLAGS_vm_manager |
| 610 | << std::endl; |
| 611 | invalid_manager = true; |
| 612 | } |
| 613 | google::HandleCommandLineHelpFlags(); |
| 614 | if (invalid_manager) { |
| 615 | return false; |
| 616 | } |
| 617 | // Set the env variable to empty (in case the caller passed a value for it). |
| 618 | unsetenv(vsoc::kCuttlefishConfigEnvVarName); |
| 619 | |
| 620 | return ResolveInstanceFiles(); |
| 621 | } |
| 622 | |
| 623 | bool CleanPriorFiles() { |
| 624 | // Everything on the instance directory |
| 625 | std::string prior_files = FLAGS_instance_dir + "/*"; |
| 626 | // The shared memory file |
| 627 | prior_files += " " + FLAGS_mempath; |
| 628 | // The environment file |
| 629 | prior_files += " " + GetCuttlefishEnvPath(); |
| 630 | // The global link to the config file |
| 631 | prior_files += " " + vsoc::GetGlobalConfigFileLink(); |
| 632 | LOG(INFO) << "Assuming prior files of " << prior_files; |
| 633 | std::string fuser_cmd = "fuser " + prior_files + " 2> /dev/null"; |
| 634 | int rval = std::system(fuser_cmd.c_str()); |
| 635 | // fuser returns 0 if any of the files are open |
| 636 | if (WEXITSTATUS(rval) == 0) { |
| 637 | LOG(ERROR) << "Clean aborted: files are in use"; |
| 638 | return false; |
| 639 | } |
| 640 | std::string clean_command = "rm -rf " + prior_files; |
| 641 | rval = std::system(clean_command.c_str()); |
| 642 | if (WEXITSTATUS(rval) != 0) { |
| 643 | LOG(ERROR) << "Remove of files failed"; |
| 644 | return false; |
| 645 | } |
| 646 | return true; |
| 647 | } |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 648 | |
| 649 | bool DecompressKernel(const std::string& src, const std::string& dst) { |
| 650 | cvd::Command decomp_cmd(FLAGS_kernel_decompresser_executable); |
| 651 | decomp_cmd.AddParameter(src); |
| 652 | auto output_file = cvd::SharedFD::Creat(dst.c_str(), 0666); |
| 653 | if (!output_file->IsOpen()) { |
| 654 | LOG(ERROR) << "Unable to create decompressed image file: " |
| 655 | << output_file->StrError(); |
| 656 | return false; |
| 657 | } |
| 658 | decomp_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut, output_file); |
| 659 | auto decomp_proc = decomp_cmd.Start(false); |
| 660 | return decomp_proc.Started() && decomp_proc.Wait() == 0; |
| 661 | } |
Cody Schuffelen | 78824ed | 2019-09-06 17:43:15 -0700 | [diff] [blame] | 662 | |
| 663 | void ValidateAdbModeFlag(const vsoc::CuttlefishConfig& config) { |
| 664 | auto adb_modes = config.adb_mode(); |
| 665 | adb_modes.erase(vsoc::AdbMode::Unknown); |
| 666 | if (adb_modes.size() < 1) { |
| 667 | LOG(INFO) << "ADB not enabled"; |
| 668 | } |
| 669 | } |
| 670 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 671 | } // namespace |
| 672 | |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 673 | namespace { |
| 674 | |
| 675 | std::vector<ImagePartition> disk_config() { |
| 676 | std::vector<ImagePartition> partitions; |
Cody Schuffelen | 4f7e441 | 2019-08-30 16:10:59 -0700 | [diff] [blame] | 677 | partitions.push_back(ImagePartition { |
| 678 | .label = "super", |
| 679 | .image_file_path = FLAGS_super_image, |
| 680 | }); |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 681 | partitions.push_back(ImagePartition { |
| 682 | .label = "userdata", |
| 683 | .image_file_path = FLAGS_data_image, |
| 684 | }); |
| 685 | partitions.push_back(ImagePartition { |
| 686 | .label = "cache", |
| 687 | .image_file_path = FLAGS_cache_image, |
| 688 | }); |
| 689 | partitions.push_back(ImagePartition { |
| 690 | .label = "metadata", |
| 691 | .image_file_path = FLAGS_metadata_image, |
| 692 | }); |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 693 | partitions.push_back(ImagePartition { |
| 694 | .label = "boot", |
| 695 | .image_file_path = FLAGS_boot_image, |
| 696 | }); |
Yifan Hong | 19d713e | 2019-05-01 14:12:07 -0700 | [diff] [blame] | 697 | partitions.push_back(ImagePartition { |
| 698 | .label = "misc", |
| 699 | .image_file_path = FLAGS_misc_image |
| 700 | }); |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 701 | return partitions; |
| 702 | } |
| 703 | |
| 704 | bool ShouldCreateCompositeDisk() { |
| 705 | if (FLAGS_composite_disk.empty()) { |
| 706 | return false; |
| 707 | } |
Cody Schuffelen | c3fd6e5 | 2019-08-30 15:14:07 -0700 | [diff] [blame] | 708 | if (FLAGS_vm_manager == vm_manager::CrosvmManager::name()) { |
| 709 | // The crosvm implementation is very fast to rebuild but also more brittle due to being split |
| 710 | // into multiple files. The QEMU implementation is slow to build, but completely self-contained |
| 711 | // at that point. Therefore, always rebuild on crosvm but check if it is necessary for QEMU. |
| 712 | return true; |
| 713 | } |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 714 | auto composite_age = cvd::FileModificationTime(FLAGS_composite_disk); |
| 715 | for (auto& partition : disk_config()) { |
| 716 | auto partition_age = cvd::FileModificationTime(partition.image_file_path); |
| 717 | if (partition_age >= composite_age) { |
| 718 | LOG(INFO) << "composite disk age was \"" << std::chrono::system_clock::to_time_t(composite_age) << "\", " |
| 719 | << "partition age was \"" << std::chrono::system_clock::to_time_t(partition_age) << "\""; |
| 720 | return true; |
| 721 | } |
| 722 | } |
| 723 | return false; |
| 724 | } |
| 725 | |
Ram Muthiah | 3db0a56 | 2019-08-26 13:35:19 -0700 | [diff] [blame] | 726 | bool ConcatRamdisks(const std::string& new_ramdisk_path, const std::string& ramdisk_a_path, |
| 727 | const std::string& ramdisk_b_path) { |
| 728 | // clear out file of any pre-existing content |
| 729 | std::ofstream new_ramdisk(new_ramdisk_path, std::ios_base::binary | std::ios_base::trunc); |
| 730 | std::ifstream ramdisk_a(ramdisk_a_path, std::ios_base::binary); |
| 731 | std::ifstream ramdisk_b(ramdisk_b_path, std::ios_base::binary); |
Ram Muthiah | aad97c5 | 2019-08-14 17:05:01 -0700 | [diff] [blame] | 732 | |
Ram Muthiah | 3db0a56 | 2019-08-26 13:35:19 -0700 | [diff] [blame] | 733 | if(!new_ramdisk.is_open() || !ramdisk_a.is_open() || !ramdisk_b.is_open()) { |
Ram Muthiah | aad97c5 | 2019-08-14 17:05:01 -0700 | [diff] [blame] | 734 | return false; |
| 735 | } |
| 736 | |
Ram Muthiah | 3db0a56 | 2019-08-26 13:35:19 -0700 | [diff] [blame] | 737 | new_ramdisk << ramdisk_a.rdbuf() << ramdisk_b.rdbuf(); |
Ram Muthiah | aad97c5 | 2019-08-14 17:05:01 -0700 | [diff] [blame] | 738 | return true; |
| 739 | } |
| 740 | |
Cody Schuffelen | c3fd6e5 | 2019-08-30 15:14:07 -0700 | [diff] [blame] | 741 | void CreateCompositeDisk(const vsoc::CuttlefishConfig& config) { |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 742 | if (FLAGS_composite_disk.empty()) { |
| 743 | LOG(FATAL) << "asked to create composite disk, but path was empty"; |
| 744 | } |
Cody Schuffelen | c3fd6e5 | 2019-08-30 15:14:07 -0700 | [diff] [blame] | 745 | if (FLAGS_vm_manager == vm_manager::CrosvmManager::name()) { |
| 746 | std::string header_path = config.PerInstancePath("gpt_header.img"); |
| 747 | std::string footer_path = config.PerInstancePath("gpt_footer.img"); |
| 748 | create_composite_disk(disk_config(), header_path, footer_path, FLAGS_composite_disk); |
| 749 | } else { |
| 750 | aggregate_image(disk_config(), FLAGS_composite_disk); |
| 751 | } |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | } // namespace |
| 755 | |
Cody Schuffelen | 605e685 | 2019-10-16 16:22:24 -0700 | [diff] [blame] | 756 | const vsoc::CuttlefishConfig* InitFilesystemAndCreateConfig( |
Cody Schuffelen | b737ef5 | 2019-09-25 14:54:38 -0700 | [diff] [blame] | 757 | int* argc, char*** argv, cvd::FetcherConfig fetcher_config) { |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 758 | if (!ParseCommandLineFlags(argc, argv)) { |
| 759 | LOG(ERROR) << "Failed to parse command arguments"; |
Cody Schuffelen | e71fa35 | 2019-09-10 16:11:58 -0700 | [diff] [blame] | 760 | exit(AssemblerExitCodes::kArgumentParsingError); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | // Clean up prior files before saving the config file (doing it after would |
| 764 | // delete it) |
| 765 | if (!CleanPriorFiles()) { |
| 766 | LOG(ERROR) << "Failed to clean prior files"; |
Cody Schuffelen | e71fa35 | 2019-09-10 16:11:58 -0700 | [diff] [blame] | 767 | exit(AssemblerExitCodes::kPrioFilesCleanupError); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 768 | } |
| 769 | // Create instance directory if it doesn't exist. |
| 770 | if (!cvd::DirectoryExists(FLAGS_instance_dir.c_str())) { |
| 771 | LOG(INFO) << "Setting up " << FLAGS_instance_dir; |
| 772 | if (mkdir(FLAGS_instance_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) { |
| 773 | LOG(ERROR) << "Failed to create instance directory: " |
| 774 | << FLAGS_instance_dir << ". Error: " << errno; |
Cody Schuffelen | e71fa35 | 2019-09-10 16:11:58 -0700 | [diff] [blame] | 775 | exit(AssemblerExitCodes::kInstanceDirCreationError); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
Jorge E. Moreira | 1e8e2f1 | 2019-10-07 18:09:49 -0700 | [diff] [blame] | 779 | auto internal_dir = FLAGS_instance_dir + "/" + vsoc::kInternalDirName; |
| 780 | if (!cvd::DirectoryExists(internal_dir)) { |
| 781 | if (mkdir(internal_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < |
| 782 | 0) { |
| 783 | LOG(ERROR) << "Failed to create internal instance directory: " |
| 784 | << internal_dir << ". Error: " << errno; |
| 785 | exit(AssemblerExitCodes::kInstanceDirCreationError); |
| 786 | } |
| 787 | } |
| 788 | |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 789 | if (!cvd::FileHasContent(FLAGS_boot_image)) { |
| 790 | LOG(ERROR) << "File not found: " << FLAGS_boot_image; |
| 791 | exit(cvd::kCuttlefishConfigurationInitError); |
| 792 | } |
| 793 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 794 | auto boot_img_unpacker = cvd::BootImageUnpacker::FromImage(FLAGS_boot_image); |
| 795 | |
| 796 | if (!InitializeCuttlefishConfiguration(*boot_img_unpacker)) { |
| 797 | LOG(ERROR) << "Failed to initialize configuration"; |
Cody Schuffelen | e71fa35 | 2019-09-10 16:11:58 -0700 | [diff] [blame] | 798 | exit(AssemblerExitCodes::kCuttlefishConfigurationInitError); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 799 | } |
| 800 | // Do this early so that the config object is ready for anything that needs it |
| 801 | auto config = vsoc::CuttlefishConfig::Get(); |
| 802 | if (!config) { |
| 803 | LOG(ERROR) << "Failed to obtain config singleton"; |
Cody Schuffelen | e71fa35 | 2019-09-10 16:11:58 -0700 | [diff] [blame] | 804 | exit(AssemblerExitCodes::kCuttlefishConfigurationInitError); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | if (!boot_img_unpacker->Unpack(config->ramdisk_image_path(), |
| 808 | config->use_unpacked_kernel() |
| 809 | ? config->kernel_image_path() |
| 810 | : "")) { |
| 811 | LOG(ERROR) << "Failed to unpack boot image"; |
Cody Schuffelen | e71fa35 | 2019-09-10 16:11:58 -0700 | [diff] [blame] | 812 | exit(AssemblerExitCodes::kBootImageUnpackError); |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 813 | } |
| 814 | |
Cody Schuffelen | 9fd9547 | 2019-10-04 13:49:57 -0700 | [diff] [blame] | 815 | if(config->initramfs_path().size() != 0) { |
| 816 | if(!ConcatRamdisks(config->final_ramdisk_path(), config->ramdisk_image_path(), |
| 817 | config->initramfs_path())) { |
Ram Muthiah | aad97c5 | 2019-08-14 17:05:01 -0700 | [diff] [blame] | 818 | LOG(ERROR) << "Failed to concatenate ramdisk and initramfs"; |
Cody Schuffelen | e71fa35 | 2019-09-10 16:11:58 -0700 | [diff] [blame] | 819 | exit(AssemblerExitCodes::kInitRamFsConcatError); |
Ram Muthiah | aad97c5 | 2019-08-14 17:05:01 -0700 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 823 | if (config->decompress_kernel()) { |
| 824 | if (!DecompressKernel(config->kernel_image_path(), |
| 825 | config->decompressed_kernel_image_path())) { |
| 826 | LOG(ERROR) << "Failed to decompress kernel"; |
Cody Schuffelen | e71fa35 | 2019-09-10 16:11:58 -0700 | [diff] [blame] | 827 | exit(AssemblerExitCodes::kKernelDecompressError); |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 831 | ValidateAdbModeFlag(*config); |
| 832 | |
Yifan Hong | 19d713e | 2019-05-01 14:12:07 -0700 | [diff] [blame] | 833 | // Create misc if necessary |
| 834 | if (!InitializeMiscImage(FLAGS_misc_image)) { |
| 835 | exit(cvd::kCuttlefishConfigurationInitError); |
| 836 | } |
| 837 | |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 838 | // Create data if necessary |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 839 | if (!ApplyDataImagePolicy(*config, FLAGS_data_image)) { |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 840 | exit(cvd::kCuttlefishConfigurationInitError); |
| 841 | } |
| 842 | |
Cody Schuffelen | 69c1959 | 2019-05-31 16:00:30 -0700 | [diff] [blame] | 843 | if (!cvd::FileExists(FLAGS_metadata_image)) { |
| 844 | CreateBlankImage(FLAGS_metadata_image, FLAGS_blank_metadata_image_mb, "none"); |
| 845 | } |
Paul Trautrim | ba8f8e9 | 2019-03-12 17:55:48 +0900 | [diff] [blame] | 846 | |
Cody Schuffelen | b737ef5 | 2019-09-25 14:54:38 -0700 | [diff] [blame] | 847 | if (SuperImageNeedsRebuilding(fetcher_config, *config)) { |
| 848 | if (!RebuildSuperImage(fetcher_config, *config, FLAGS_super_image)) { |
| 849 | LOG(ERROR) << "Super image rebuilding requested but could not be completed."; |
| 850 | exit(cvd::kCuttlefishConfigurationInitError); |
| 851 | } |
| 852 | } |
| 853 | |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 854 | if (ShouldCreateCompositeDisk()) { |
Cody Schuffelen | c3fd6e5 | 2019-08-30 15:14:07 -0700 | [diff] [blame] | 855 | CreateCompositeDisk(*config); |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 858 | // Check that the files exist |
Cody Schuffelen | 3c99f5b | 2019-06-14 17:26:01 -0700 | [diff] [blame] | 859 | for (const auto& file : config->virtual_disk_paths()) { |
Alistair Strachan | 050ca93 | 2018-11-27 12:41:19 -0800 | [diff] [blame] | 860 | if (!file.empty() && !cvd::FileHasContent(file.c_str())) { |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 861 | LOG(ERROR) << "File not found: " << file; |
| 862 | exit(cvd::kCuttlefishConfigurationInitError); |
| 863 | } |
| 864 | } |
| 865 | |
Cody Schuffelen | 20ecaca | 2019-01-29 17:43:38 -0800 | [diff] [blame] | 866 | return config; |
| 867 | } |
| 868 | |
| 869 | std::string GetConfigFilePath(const vsoc::CuttlefishConfig& config) { |
| 870 | return config.PerInstancePath("cuttlefish_config.json"); |
| 871 | } |