starter_fs.py revision 13609:adc3dd5e3384
1# Copyright (c) 2016-2017 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license 9# terms below provided that you ensure that this notice is replicated 10# unmodified and in its entirety in all distributions of the software, 11# modified or unmodified, in source code or in binary form. 12# 13# Redistribution and use in source and binary forms, with or without 14# modification, are permitted provided that the following conditions are 15# met: redistributions of source code must retain the above copyright 16# notice, this list of conditions and the following disclaimer; 17# redistributions in binary form must reproduce the above copyright 18# notice, this list of conditions and the following disclaimer in the 19# documentation and/or other materials provided with the distribution; 20# neither the name of the copyright holders nor the names of its 21# contributors may be used to endorse or promote products derived from 22# this software without specific prior written permission. 23# 24# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35# 36# Authors: Andreas Sandberg 37# Chuan Zhu 38# Gabor Dozsa 39# 40 41"""This script is the full system example script from the ARM 42Research Starter Kit on System Modeling. More information can be found 43at: http://www.arm.com/ResearchEnablement/SystemModeling 44""" 45 46from __future__ import print_function 47 48import os 49import m5 50from m5.util import addToPath 51from m5.objects import * 52from m5.options import * 53import argparse 54 55m5.util.addToPath('../..') 56 57from common import SysPaths 58from common import MemConfig 59from common.cores.arm import HPI 60 61import devices 62 63 64default_dist_version = '20170616' 65default_kernel = 'vmlinux.vexpress_gem5_v1_64.' + default_dist_version 66default_disk = 'linaro-minimal-aarch64.img' 67 68 69# Pre-defined CPU configurations. Each tuple must be ordered as : (cpu_class, 70# l1_icache_class, l1_dcache_class, walk_cache_class, l2_Cache_class). Any of 71# the cache class may be 'None' if the particular cache is not present. 72cpu_types = { 73 74 "atomic" : ( AtomicSimpleCPU, None, None, None, None), 75 "minor" : (MinorCPU, 76 devices.L1I, devices.L1D, 77 devices.WalkCache, 78 devices.L2), 79 "hpi" : ( HPI.HPI, 80 HPI.HPI_ICache, HPI.HPI_DCache, 81 HPI.HPI_WalkCache, 82 HPI.HPI_L2) 83} 84 85def create_cow_image(name): 86 """Helper function to create a Copy-on-Write disk image""" 87 image = CowDiskImage() 88 image.child.image_file = SysPaths.disk(name) 89 90 return image; 91 92 93def create(args): 94 ''' Create and configure the system object. ''' 95 96 if args.script and not os.path.isfile(args.script): 97 print("Error: Bootscript %s does not exist" % args.script) 98 sys.exit(1) 99 100 cpu_class = cpu_types[args.cpu][0] 101 mem_mode = cpu_class.memory_mode() 102 # Only simulate caches when using a timing CPU (e.g., the HPI model) 103 want_caches = True if mem_mode == "timing" else False 104 105 system = devices.SimpleSystem(want_caches, 106 args.mem_size, 107 mem_mode=mem_mode, 108 kernel=SysPaths.binary(args.kernel), 109 readfile=args.script) 110 111 MemConfig.config_mem(args, system) 112 113 # Add the PCI devices we need for this system. The base system 114 # doesn't have any PCI devices by default since they are assumed 115 # to be added by the configurastion scripts needin them. 116 system.pci_devices = [ 117 # Create a VirtIO block device for the system's boot 118 # disk. Attach the disk image using gem5's Copy-on-Write 119 # functionality to avoid writing changes to the stored copy of 120 # the disk image. 121 PciVirtIO(vio=VirtIOBlock(image=create_cow_image(args.disk_image))), 122 ] 123 124 # Attach the PCI devices to the system. The helper method in the 125 # system assigns a unique PCI bus ID to each of the devices and 126 # connects them to the IO bus. 127 for dev in system.pci_devices: 128 system.attach_pci(dev) 129 130 # Wire up the system's memory system 131 system.connect() 132 133 # Add CPU clusters to the system 134 system.cpu_cluster = [ 135 devices.CpuCluster(system, 136 args.num_cores, 137 args.cpu_freq, "1.0V", 138 *cpu_types[args.cpu]), 139 ] 140 141 # Create a cache hierarchy for the cluster. We are assuming that 142 # clusters have core-private L1 caches and an L2 that's shared 143 # within the cluster. 144 for cluster in system.cpu_cluster: 145 system.addCaches(want_caches, last_cache_level=2) 146 147 # Setup gem5's minimal Linux boot loader. 148 system.realview.setupBootLoader(system.membus, system, SysPaths.binary) 149 150 if args.dtb: 151 system.dtb_filename = args.dtb 152 else: 153 # No DTB specified: autogenerate DTB 154 system.generateDtb(m5.options.outdir, 'system.dtb') 155 156 # Linux boot command flags 157 kernel_cmd = [ 158 # Tell Linux to use the simulated serial port as a console 159 "console=ttyAMA0", 160 # Hard-code timi 161 "lpj=19988480", 162 # Disable address space randomisation to get a consistent 163 # memory layout. 164 "norandmaps", 165 # Tell Linux where to find the root disk image. 166 "root=/dev/vda1", 167 # Mount the root disk read-write by default. 168 "rw", 169 # Tell Linux about the amount of physical memory present. 170 "mem=%s" % args.mem_size, 171 ] 172 system.boot_osflags = " ".join(kernel_cmd) 173 174 return system 175 176 177def run(args): 178 cptdir = m5.options.outdir 179 if args.checkpoint: 180 print("Checkpoint directory: %s" % cptdir) 181 182 while True: 183 event = m5.simulate() 184 exit_msg = event.getCause() 185 if exit_msg == "checkpoint": 186 print("Dropping checkpoint at tick %d" % m5.curTick()) 187 cpt_dir = os.path.join(m5.options.outdir, "cpt.%d" % m5.curTick()) 188 m5.checkpoint(os.path.join(cpt_dir)) 189 print("Checkpoint done.") 190 else: 191 print(exit_msg, " @ ", m5.curTick()) 192 break 193 194 sys.exit(event.getCode()) 195 196 197def main(): 198 parser = argparse.ArgumentParser(epilog=__doc__) 199 200 parser.add_argument("--dtb", type=str, default=None, 201 help="DTB file to load") 202 parser.add_argument("--kernel", type=str, default=default_kernel, 203 help="Linux kernel") 204 parser.add_argument("--disk-image", type=str, 205 default=default_disk, 206 help="Disk to instantiate") 207 parser.add_argument("--script", type=str, default="", 208 help = "Linux bootscript") 209 parser.add_argument("--cpu", type=str, choices=cpu_types.keys(), 210 default="atomic", 211 help="CPU model to use") 212 parser.add_argument("--cpu-freq", type=str, default="4GHz") 213 parser.add_argument("--num-cores", type=int, default=1, 214 help="Number of CPU cores") 215 parser.add_argument("--mem-type", default="DDR3_1600_8x8", 216 choices=MemConfig.mem_names(), 217 help = "type of memory to use") 218 parser.add_argument("--mem-channels", type=int, default=1, 219 help = "number of memory channels") 220 parser.add_argument("--mem-ranks", type=int, default=None, 221 help = "number of memory ranks per channel") 222 parser.add_argument("--mem-size", action="store", type=str, 223 default="2GB", 224 help="Specify the physical memory size") 225 parser.add_argument("--checkpoint", action="store_true") 226 parser.add_argument("--restore", type=str, default=None) 227 228 229 args = parser.parse_args() 230 231 root = Root(full_system=True) 232 root.system = create(args) 233 234 if args.restore is not None: 235 m5.instantiate(args.restore) 236 else: 237 m5.instantiate() 238 239 run(args) 240 241 242if __name__ == "__m5_main__": 243 main() 244