• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/libs/config/kernel_args.h"
18 
19 #include <array>
20 #include <sstream>
21 #include <string>
22 #include <vector>
23 
24 #include "common/libs/utils/environment.h"
25 #include "common/libs/utils/files.h"
26 #include "host/libs/config/cuttlefish_config.h"
27 #include "host/libs/vm_manager/qemu_manager.h"
28 #include "host/libs/vm_manager/vm_manager.h"
29 
30 namespace cuttlefish {
31 
32 using vm_manager::QemuManager;
33 
34 namespace {
35 
36 template<typename T>
AppendVector(std::vector<T> * destination,const std::vector<T> & source)37 void AppendVector(std::vector<T>* destination, const std::vector<T>& source) {
38   destination->insert(destination->end(), source.begin(), source.end());
39 }
40 
41 // TODO(schuffelen): Move more of this into host/libs/vm_manager, as a
42 // substitute for the vm_manager comparisons.
VmManagerKernelCmdline(const CuttlefishConfig & config)43 std::vector<std::string> VmManagerKernelCmdline(const CuttlefishConfig& config) {
44   std::vector<std::string> vm_manager_cmdline;
45   if (config.vm_manager() == QemuManager::name()) {
46     vm_manager_cmdline.push_back("console=hvc0");
47     Arch target_arch = config.target_arch();
48     if (target_arch == Arch::Arm64 || target_arch == Arch::Arm) {
49       // To update the pl011 address:
50       // $ qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine dumpdtb=virt.dtb
51       // $ dtc -O dts -o virt.dts -I dtb virt.dtb
52       // In the virt.dts file, look for a uart node
53       vm_manager_cmdline.push_back("earlycon=pl011,mmio32,0x9000000");
54     } else {
55       // To update the uart8250 address:
56       // $ qemu-system-x86_64 -kernel bzImage -serial stdio | grep ttyS0
57       // Only 'io' mode works; mmio and mmio32 do not
58       vm_manager_cmdline.push_back("earlycon=uart8250,io,0x3f8");
59 
60       // crosvm doesn't support ACPI PNP, but QEMU does. We need to disable
61       // it on QEMU so that the ISA serial ports aren't claimed by ACPI, so
62       // we can use serdev with platform devices instead
63       vm_manager_cmdline.push_back("pnpacpi=off");
64 
65       // crosvm sets up the ramoops.xx= flags for us, but QEMU does not.
66       // See external/crosvm/x86_64/src/lib.rs
67       // this feature is not supported on aarch64
68       vm_manager_cmdline.push_back("ramoops.mem_address=0x100000000");
69       vm_manager_cmdline.push_back("ramoops.mem_size=0x200000");
70       vm_manager_cmdline.push_back("ramoops.console_size=0x80000");
71       vm_manager_cmdline.push_back("ramoops.record_size=0x80000");
72       vm_manager_cmdline.push_back("ramoops.dump_oops=1");
73     }
74   }
75 
76   if (config.console() && config.kgdb()) {
77     AppendVector(&vm_manager_cmdline, {"kgdboc_earlycon", "kgdbcon",
78                                        "kgdboc=" + config.console_dev()});
79   }
80   return vm_manager_cmdline;
81 }
82 
83 } // namespace
84 
KernelCommandLineFromConfig(const CuttlefishConfig & config)85 std::vector<std::string> KernelCommandLineFromConfig(
86     const CuttlefishConfig& config) {
87   std::vector<std::string> kernel_cmdline;
88   AppendVector(&kernel_cmdline, VmManagerKernelCmdline(config));
89   AppendVector(&kernel_cmdline, config.extra_kernel_cmdline());
90   return kernel_cmdline;
91 }
92 
93 } // namespace cuttlefish
94