Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "host/commands/run_cvd/kernel_args.h" |
| 18 | |
| 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
| 22 | #include "host/commands/run_cvd/launch.h" |
| 23 | #include "host/commands/run_cvd/runner_defs.h" |
| 24 | #include "host/libs/config/cuttlefish_config.h" |
| 25 | #include "host/libs/vm_manager/vm_manager.h" |
| 26 | |
| 27 | template<typename T> |
| 28 | static void AppendVector(std::vector<T>* destination, const std::vector<T>& source) { |
| 29 | destination->insert(destination->end(), source.begin(), source.end()); |
| 30 | } |
| 31 | |
| 32 | template<typename S, typename T> |
| 33 | static std::string concat(const S& s, const T& t) { |
| 34 | std::ostringstream os; |
| 35 | os << s << t; |
| 36 | return os.str(); |
| 37 | } |
| 38 | |
| 39 | std::vector<std::string> KernelCommandLineFromConfig(const vsoc::CuttlefishConfig& config) { |
Cody Schuffelen | 47c5785 | 2019-12-13 13:50:50 -0800 | [diff] [blame] | 40 | auto instance = config.ForDefaultInstance(); |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 41 | std::vector<std::string> kernel_cmdline; |
| 42 | |
| 43 | AppendVector(&kernel_cmdline, config.boot_image_kernel_cmdline()); |
| 44 | AppendVector(&kernel_cmdline, |
| 45 | vm_manager::VmManager::ConfigureGpuMode(config.vm_manager(), config.gpu_mode())); |
| 46 | AppendVector(&kernel_cmdline, vm_manager::VmManager::ConfigureBootDevices(config.vm_manager())); |
| 47 | |
Cody Schuffelen | 47c5785 | 2019-12-13 13:50:50 -0800 | [diff] [blame] | 48 | kernel_cmdline.push_back(concat("androidboot.serialno=", instance.serial_number())); |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 49 | kernel_cmdline.push_back(concat("androidboot.lcd_density=", config.dpi())); |
| 50 | if (config.logcat_mode() == cvd::kLogcatVsockMode) { |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 51 | } |
| 52 | kernel_cmdline.push_back(concat( |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 53 | "androidboot.setupwizard_mode=", config.setupwizard_mode())); |
| 54 | if (!config.use_bootloader()) { |
| 55 | std::string slot_suffix; |
| 56 | if (config.boot_slot().empty()) { |
| 57 | slot_suffix = "_a"; |
| 58 | } else { |
| 59 | slot_suffix = "_" + config.boot_slot(); |
| 60 | } |
| 61 | kernel_cmdline.push_back(concat("androidboot.slot_suffix=", slot_suffix)); |
| 62 | } |
| 63 | kernel_cmdline.push_back(concat("loop.max_part=", config.loop_max_part())); |
| 64 | if (config.guest_enforce_security()) { |
| 65 | kernel_cmdline.push_back("enforcing=1"); |
| 66 | } else { |
| 67 | kernel_cmdline.push_back("enforcing=0"); |
| 68 | kernel_cmdline.push_back("androidboot.selinux=permissive"); |
| 69 | } |
| 70 | if (config.guest_audit_security()) { |
| 71 | kernel_cmdline.push_back("audit=1"); |
| 72 | } else { |
| 73 | kernel_cmdline.push_back("audit=0"); |
| 74 | } |
Alistair Delva | 33b861f | 2019-12-26 12:23:59 -0800 | [diff] [blame] | 75 | if (config.guest_force_normal_boot()) { |
| 76 | kernel_cmdline.push_back("androidboot.force_normal_boot=1"); |
| 77 | } |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 78 | |
| 79 | AppendVector(&kernel_cmdline, config.extra_kernel_cmdline()); |
| 80 | |
| 81 | return kernel_cmdline; |
| 82 | } |
| 83 | |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 84 | std::vector<std::string> KernelCommandLineFromStreamer( |
| 85 | const StreamerLaunchResult& streamer_launch) { |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 86 | std::vector<std::string> kernel_args; |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 87 | if (streamer_launch.frames_server_vsock_port) { |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 88 | kernel_args.push_back(concat("androidboot.vsock_frames_port=", |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 89 | *streamer_launch.frames_server_vsock_port)); |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 90 | } |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 91 | if (streamer_launch.touch_server_vsock_port) { |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 92 | kernel_args.push_back(concat("androidboot.vsock_touch_port=", |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 93 | *streamer_launch.touch_server_vsock_port)); |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 94 | } |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 95 | if (streamer_launch.keyboard_server_vsock_port) { |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 96 | kernel_args.push_back(concat("androidboot.vsock_keyboard_port=", |
Jorge E. Moreira | e049b79 | 2019-12-18 18:17:48 -0800 | [diff] [blame] | 97 | *streamer_launch.keyboard_server_vsock_port)); |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 98 | } |
| 99 | return kernel_args; |
| 100 | } |
| 101 | |
| 102 | std::vector<std::string> KernelCommandLineFromTombstone(const TombstoneReceiverPorts& tombstone) { |
| 103 | if (!tombstone.server_vsock_port) { |
| 104 | return { "androidboot.tombstone_transmit=0" }; |
| 105 | } |
| 106 | return { |
| 107 | "androidboot.tombstone_transmit=1", |
| 108 | concat("androidboot.vsock_tombstone_port=", *tombstone.server_vsock_port), |
| 109 | }; |
| 110 | } |
Cody Schuffelen | c9183ba | 2019-12-05 15:23:46 -0800 | [diff] [blame] | 111 | |
| 112 | std::vector<std::string> KernelCommandLineFromConfigServer(const ConfigServerPorts& config_server) { |
| 113 | if (!config_server.server_vsock_port) { |
| 114 | return {}; |
| 115 | } |
| 116 | return { |
| 117 | concat("androidboot.cuttlefish_config_server_port=", *config_server.server_vsock_port), |
| 118 | }; |
| 119 | } |
Cody Schuffelen | eb5c215 | 2019-12-05 15:44:49 -0800 | [diff] [blame] | 120 | |
| 121 | std::vector<std::string> KernelCommandLineFromLogcatServer(const LogcatServerPorts& logcat_server) { |
| 122 | if (!logcat_server.server_vsock_port) { |
| 123 | return {}; |
| 124 | } |
| 125 | return { |
| 126 | concat("androidboot.vsock_logcat_port=", *logcat_server.server_vsock_port), |
| 127 | }; |
| 128 | } |