• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #pragma once
17 
18 #include <string>
19 #include <vector>
20 
21 #include "host/libs/vm_manager/vm_manager.h"
22 
23 #include "common/libs/fs/shared_fd.h"
24 
25 namespace cuttlefish {
26 namespace vm_manager {
27 
28 // Starts a guest VM using the gem5 command directly. It requires the host
29 // package to support the gem5 capability.
30 class Gem5Manager : public VmManager {
31  public:
name()32   static std::string name() { return "gem5"; }
33 
34   Gem5Manager(Arch);
35   virtual ~Gem5Manager() = default;
36 
37   bool IsSupported() override;
38   std::vector<std::string> ConfigureGraphics(
39       const CuttlefishConfig& config) override;
40   std::string ConfigureBootDevices(int num_disks) override;
41 
42   std::vector<cuttlefish::Command> StartCommands(
43       const CuttlefishConfig& config) override;
44 
45  private:
46   Arch arch_;
47 };
48 
49 const std::string fs_header = R"CPP_STR_END(import argparse
50 import devices
51 import os
52 import m5
53 from m5.util import addToPath
54 from m5.objects import *
55 from m5.options import *
56 from common import SysPaths
57 from common import ObjectList
58 from common import MemConfig
59 from common.cores.arm import HPI
60 m5.util.addToPath('../..')
61 )CPP_STR_END";
62 
63 const std::string fs_mem_pci = R"CPP_STR_END(
64   MemConfig.config_mem(args, root.system)
65 
66   pci_devices = []
67   pci_devices.append(PciVirtIO(vio=VirtIOConsole(device=Terminal(number=0))))
68   pci_devices.append(PciVirtIO(vio=VirtIOConsole(device=Terminal(number=1, outfile="none"))))
69   pci_devices.append(PciVirtIO(vio=VirtIOConsole(device=Terminal(number=2))))
70   pci_devices.append(PciVirtIO(vio=VirtIOConsole(device=Terminal(number=3, outfile="none"))))
71   pci_devices.append(PciVirtIO(vio=VirtIOConsole(device=Terminal(number=4, outfile="none"))))
72   pci_devices.append(PciVirtIO(vio=VirtIOConsole(device=Terminal(number=5, outfile="none"))))
73   pci_devices.append(PciVirtIO(vio=VirtIOConsole(device=Terminal(number=6, outfile="none"))))
74 
75   for each_item in args.disk_image:
76     disk_image = CowDiskImage()
77     disk_image.child.image_file = SysPaths.disk(each_item)
78     pci_devices.append(PciVirtIO(vio=VirtIOBlock(image=disk_image)))
79 
80   root.system.pci_devices = pci_devices
81   for pci_device in root.system.pci_devices:
82     root.system.attach_pci(pci_device)
83 
84   root.system.connect()
85 )CPP_STR_END";
86 
87 const std::string fs_kernel_cmd = R"CPP_STR_END(
88   kernel_cmd = [
89     "lpj=19988480",
90     "norandmaps",
91     "mem=%s" % args.mem_size,
92     "console=hvc0",
93     "panic=-1",
94     "earlycon=pl011,mmio32,0x1c090000",
95     "audit=1",
96     "printk.devkmsg=on",
97     "firmware_class.path=/vendor/etc/",
98     "kfence.sample_interval=500",
99     "loop.max_part=7",
100     "bootconfig",
101     "androidboot.force_normal_boot=1",
102   ]
103   root.system.workload.command_line = " ".join(kernel_cmd)
104   m5.instantiate()
105   sys.exit(m5.simulate().getCode())
106 )CPP_STR_END";
107 
108 const std::string fs_exe_main = R"CPP_STR_END(
109 if __name__ == "__m5_main__":
110   main()
111 )CPP_STR_END";
112 
113 } // namespace vm_manager
114 } // namespace cuttlefish
115