blob: 6615441b8e27ff88e8d4605a016e0d704e5d703a [file] [log] [blame]
Cody Schuffelene46ae522019-12-05 12:55:45 -08001/*
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
27template<typename T>
28static void AppendVector(std::vector<T>* destination, const std::vector<T>& source) {
29 destination->insert(destination->end(), source.begin(), source.end());
30}
31
32template<typename S, typename T>
33static std::string concat(const S& s, const T& t) {
34 std::ostringstream os;
35 os << s << t;
36 return os.str();
37}
38
39std::vector<std::string> KernelCommandLineFromConfig(const vsoc::CuttlefishConfig& config) {
Cody Schuffelen47c57852019-12-13 13:50:50 -080040 auto instance = config.ForDefaultInstance();
Cody Schuffelene46ae522019-12-05 12:55:45 -080041 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 Schuffelen47c57852019-12-13 13:50:50 -080048 kernel_cmdline.push_back(concat("androidboot.serialno=", instance.serial_number()));
Cody Schuffelene46ae522019-12-05 12:55:45 -080049 kernel_cmdline.push_back(concat("androidboot.lcd_density=", config.dpi()));
50 if (config.logcat_mode() == cvd::kLogcatVsockMode) {
Cody Schuffelene46ae522019-12-05 12:55:45 -080051 }
52 kernel_cmdline.push_back(concat(
Cody Schuffelene46ae522019-12-05 12:55:45 -080053 "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 Delva33b861f2019-12-26 12:23:59 -080075 if (config.guest_force_normal_boot()) {
76 kernel_cmdline.push_back("androidboot.force_normal_boot=1");
77 }
Cody Schuffelene46ae522019-12-05 12:55:45 -080078
79 AppendVector(&kernel_cmdline, config.extra_kernel_cmdline());
80
81 return kernel_cmdline;
82}
83
Jorge E. Moreirae049b792019-12-18 18:17:48 -080084std::vector<std::string> KernelCommandLineFromStreamer(
85 const StreamerLaunchResult& streamer_launch) {
Cody Schuffelene46ae522019-12-05 12:55:45 -080086 std::vector<std::string> kernel_args;
Jorge E. Moreirae049b792019-12-18 18:17:48 -080087 if (streamer_launch.frames_server_vsock_port) {
Cody Schuffelene46ae522019-12-05 12:55:45 -080088 kernel_args.push_back(concat("androidboot.vsock_frames_port=",
Jorge E. Moreirae049b792019-12-18 18:17:48 -080089 *streamer_launch.frames_server_vsock_port));
Cody Schuffelene46ae522019-12-05 12:55:45 -080090 }
Jorge E. Moreirae049b792019-12-18 18:17:48 -080091 if (streamer_launch.touch_server_vsock_port) {
Cody Schuffelene46ae522019-12-05 12:55:45 -080092 kernel_args.push_back(concat("androidboot.vsock_touch_port=",
Jorge E. Moreirae049b792019-12-18 18:17:48 -080093 *streamer_launch.touch_server_vsock_port));
Cody Schuffelene46ae522019-12-05 12:55:45 -080094 }
Jorge E. Moreirae049b792019-12-18 18:17:48 -080095 if (streamer_launch.keyboard_server_vsock_port) {
Cody Schuffelene46ae522019-12-05 12:55:45 -080096 kernel_args.push_back(concat("androidboot.vsock_keyboard_port=",
Jorge E. Moreirae049b792019-12-18 18:17:48 -080097 *streamer_launch.keyboard_server_vsock_port));
Cody Schuffelene46ae522019-12-05 12:55:45 -080098 }
99 return kernel_args;
100}
101
102std::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 Schuffelenc9183ba2019-12-05 15:23:46 -0800111
112std::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 Schuffeleneb5c2152019-12-05 15:44:49 -0800120
121std::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}