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 | |
Ram Muthiah | ed3cfde | 2020-04-17 21:30:15 -0700 | [diff] [blame] | 17 | #include "host/libs/config/kernel_args.h" |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 18 | |
A. Cody Schuffelen | 9a4f45e | 2020-06-03 16:36:37 -0700 | [diff] [blame] | 19 | #include <array> |
| 20 | #include <sstream> |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 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 | |
A. Cody Schuffelen | 9a4f45e | 2020-06-03 16:36:37 -0700 | [diff] [blame] | 39 | static 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 Schuffelen | a4a9f92 | 2020-06-22 22:49:56 +0000 | [diff] [blame] | 48 | std::vector<std::string> KernelCommandLineFromConfig(const cuttlefish::CuttlefishConfig& config) { |
Cody Schuffelen | 47c5785 | 2019-12-13 13:50:50 -0800 | [diff] [blame] | 49 | auto instance = config.ForDefaultInstance(); |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 50 | std::vector<std::string> kernel_cmdline; |
| 51 | |
Alistair Delva | 51d2535 | 2020-07-01 17:13:17 -0700 | [diff] [blame] | 52 | AppendVector(&kernel_cmdline, config.vm_manager_kernel_cmdline()); |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 53 | 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 Schuffelen | 47c5785 | 2019-12-13 13:50:50 -0800 | [diff] [blame] | 58 | kernel_cmdline.push_back(concat("androidboot.serialno=", instance.serial_number())); |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 59 | kernel_cmdline.push_back(concat("androidboot.lcd_density=", config.dpi())); |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 60 | kernel_cmdline.push_back(concat( |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 61 | "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 Delva | 67b81bf | 2020-07-01 15:34:39 -0700 | [diff] [blame] | 72 | if (!config.guest_enforce_security()) { |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 73 | 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 Delva | 33b861f | 2019-12-26 12:23:59 -0800 | [diff] [blame] | 80 | if (config.guest_force_normal_boot()) { |
| 81 | kernel_cmdline.push_back("androidboot.force_normal_boot=1"); |
| 82 | } |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 83 | |
Ram Muthiah | e4fd63b | 2020-04-16 11:14:37 -0700 | [diff] [blame] | 84 | 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 Muthiah | 5de155b | 2020-04-17 00:17:00 -0700 | [diff] [blame] | 91 | if (instance.config_server_port()) { |
| 92 | kernel_cmdline.push_back(concat("androidboot.cuttlefish_config_server_port=", instance.config_server_port())); |
| 93 | } |
| 94 | |
A. Cody Schuffelen | e55e917 | 2020-05-13 13:25:14 -0700 | [diff] [blame] | 95 | if (config.tpm_binary() != "" && instance.tpm_port()) { |
Ram Muthiah | 66e606a | 2020-04-17 00:47:33 -0700 | [diff] [blame] | 96 | kernel_cmdline.push_back(concat("androidboot.tpm_vsock_port=", instance.tpm_port())); |
| 97 | } |
| 98 | |
Ram Muthiah | a7befdd | 2020-04-17 15:48:33 -0700 | [diff] [blame] | 99 | 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 Schuffelen | af4b621 | 2020-05-07 21:52:27 -0700 | [diff] [blame] | 111 | kernel_cmdline.push_back(concat("androidboot.vsock_keymaster_port=", |
| 112 | instance.keymaster_vsock_port())); |
| 113 | |
A. Cody Schuffelen | 9a4f45e | 2020-06-03 16:36:37 -0700 | [diff] [blame] | 114 | // 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 Delva | 4458548 | 2020-06-10 10:08:43 -0700 | [diff] [blame] | 118 | kernel_cmdline.push_back("androidboot.verifiedbootstate=orange"); |
| 119 | |
Cody Schuffelen | e46ae52 | 2019-12-05 12:55:45 -0800 | [diff] [blame] | 120 | AppendVector(&kernel_cmdline, config.extra_kernel_cmdline()); |
| 121 | |
| 122 | return kernel_cmdline; |
| 123 | } |