blob: 8853fd3034922caabb33bc5aae8b8bd7b05f6b87 [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
Ram Muthiahed3cfde2020-04-17 21:30:15 -070017#include "host/libs/config/kernel_args.h"
Cody Schuffelene46ae522019-12-05 12:55:45 -080018
A. Cody Schuffelen9a4f45e2020-06-03 16:36:37 -070019#include <array>
20#include <sstream>
Cody Schuffelene46ae522019-12-05 12:55:45 -080021#include <string>
22#include <vector>
23
Cody Schuffelene46ae522019-12-05 12:55:45 -080024#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
A. Cody Schuffelen9a4f45e2020-06-03 16:36:37 -070039static std::string mac_to_str(const std::array<unsigned char, 6>& mac) {
40 std::ostringstream stream;
41 stream << std::hex << (int) mac[0];
42 for (int i = 1; i < 6; i++) {
43 stream << ":" << std::hex << (int) mac[i];
44 }
45 return stream.str();
46}
47
A. Cody Schuffelena4a9f922020-06-22 22:49:56 +000048std::vector<std::string> KernelCommandLineFromConfig(const cuttlefish::CuttlefishConfig& config) {
Cody Schuffelen47c57852019-12-13 13:50:50 -080049 auto instance = config.ForDefaultInstance();
Cody Schuffelene46ae522019-12-05 12:55:45 -080050 std::vector<std::string> kernel_cmdline;
51
Alistair Delva51d25352020-07-01 17:13:17 -070052 AppendVector(&kernel_cmdline, config.vm_manager_kernel_cmdline());
Cody Schuffelene46ae522019-12-05 12:55:45 -080053 AppendVector(&kernel_cmdline, config.boot_image_kernel_cmdline());
54 AppendVector(&kernel_cmdline,
55 vm_manager::VmManager::ConfigureGpuMode(config.vm_manager(), config.gpu_mode()));
56 AppendVector(&kernel_cmdline, vm_manager::VmManager::ConfigureBootDevices(config.vm_manager()));
57
Cody Schuffelen47c57852019-12-13 13:50:50 -080058 kernel_cmdline.push_back(concat("androidboot.serialno=", instance.serial_number()));
Cody Schuffelene46ae522019-12-05 12:55:45 -080059 kernel_cmdline.push_back(concat("androidboot.lcd_density=", config.dpi()));
Cody Schuffelene46ae522019-12-05 12:55:45 -080060 kernel_cmdline.push_back(concat(
Cody Schuffelene46ae522019-12-05 12:55:45 -080061 "androidboot.setupwizard_mode=", config.setupwizard_mode()));
62 if (!config.use_bootloader()) {
63 std::string slot_suffix;
64 if (config.boot_slot().empty()) {
65 slot_suffix = "_a";
66 } else {
67 slot_suffix = "_" + config.boot_slot();
68 }
69 kernel_cmdline.push_back(concat("androidboot.slot_suffix=", slot_suffix));
70 }
71 kernel_cmdline.push_back(concat("loop.max_part=", config.loop_max_part()));
Alistair Delva67b81bf2020-07-01 15:34:39 -070072 if (!config.guest_enforce_security()) {
Cody Schuffelene46ae522019-12-05 12:55:45 -080073 kernel_cmdline.push_back("androidboot.selinux=permissive");
74 }
75 if (config.guest_audit_security()) {
76 kernel_cmdline.push_back("audit=1");
77 } else {
78 kernel_cmdline.push_back("audit=0");
79 }
Alistair Delva33b861f2019-12-26 12:23:59 -080080 if (config.guest_force_normal_boot()) {
81 kernel_cmdline.push_back("androidboot.force_normal_boot=1");
82 }
Cody Schuffelene46ae522019-12-05 12:55:45 -080083
Ram Muthiahe4fd63b2020-04-16 11:14:37 -070084 if (config.enable_tombstone_receiver() && instance.tombstone_receiver_port()) {
85 kernel_cmdline.push_back("androidboot.tombstone_transmit=1");
86 kernel_cmdline.push_back(concat("androidboot.vsock_tombstone_port=", instance.tombstone_receiver_port()));
87 } else {
88 kernel_cmdline.push_back("androidboot.tombstone_transmit=0");
89 }
90
Ram Muthiah5de155b2020-04-17 00:17:00 -070091 if (instance.config_server_port()) {
92 kernel_cmdline.push_back(concat("androidboot.cuttlefish_config_server_port=", instance.config_server_port()));
93 }
94
A. Cody Schuffelene55e9172020-05-13 13:25:14 -070095 if (config.tpm_binary() != "" && instance.tpm_port()) {
Ram Muthiah66e606a2020-04-17 00:47:33 -070096 kernel_cmdline.push_back(concat("androidboot.tpm_vsock_port=", instance.tpm_port()));
97 }
98
Ram Muthiaha7befdd2020-04-17 15:48:33 -070099 if (instance.keyboard_server_port()) {
100 kernel_cmdline.push_back(concat("androidboot.vsock_keyboard_port=", instance.keyboard_server_port()));
101 }
102
103 if (instance.touch_server_port()) {
104 kernel_cmdline.push_back(concat("androidboot.vsock_touch_port=", instance.touch_server_port()));
105 }
106
107 if (instance.frames_server_port()) {
108 kernel_cmdline.push_back(concat("androidboot.vsock_frames_port=", instance.frames_server_port()));
109 }
110
A. Cody Schuffelenaf4b6212020-05-07 21:52:27 -0700111 kernel_cmdline.push_back(concat("androidboot.vsock_keymaster_port=",
112 instance.keymaster_vsock_port()));
113
A. Cody Schuffelen9a4f45e2020-06-03 16:36:37 -0700114 // TODO(b/158131610): Set this in crosvm instead
115 kernel_cmdline.push_back(concat("androidboot.wifi_mac_address=",
116 mac_to_str(instance.wifi_mac_address())));
117
Alistair Delva44585482020-06-10 10:08:43 -0700118 kernel_cmdline.push_back("androidboot.verifiedbootstate=orange");
119
Cody Schuffelene46ae522019-12-05 12:55:45 -0800120 AppendVector(&kernel_cmdline, config.extra_kernel_cmdline());
121
122 return kernel_cmdline;
123}