util: Install scons 3.1 from pip in gcn-gpu dockerfile
[gem5.git] / util / gen_arm_fs_files.py
index 76fa21b2906df605a0c8a539816a75c37dbef6e4..ea05fe189db4ca77e163ab34914594e6bd4b5b84 100755 (executable)
@@ -1,5 +1,17 @@
 #!/usr/bin/env python2.7
 
+# Copyright (c) 2020 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder.  You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
 # Copyright (c) 2017-2018 Metempsy Technology Consulting
 # All rights reserved.
 #
@@ -230,6 +242,73 @@ def m5():
         m5_dir,
         ["cp", "m5", binaries_dir + "/m5.aarch32"])
 
+def xen():
+    """
+    Build Xen for aarch64
+    """
+    xen_dir = os.path.join(options.dest_dir, "xen")
+    bootwrapper_dir = os.path.join(options.dest_dir, "bootwrapper")
+    linux_cmdline = "console=hvc0 root=/dev/vda rw mem=1G"
+    xen_cmdline = "dtuart=/uart@1c090000 console=dtuart no-bootscrub " + \
+                  "dom0_mem=1G loglvl=all guest_loglvl=all"
+
+    run_cmd("clone Xen",
+        options.dest_dir,
+        ["git", "clone", "git://xenbits.xen.org/xen.git",
+         xen_dir])
+
+    run_cmd("clone boot-wrapper-aarch64",
+        options.dest_dir,
+        ["git", "clone", "git://git.kernel.org/pub/" +
+            "scm/linux/kernel/git/mark/boot-wrapper-aarch64.git",
+         bootwrapper_dir])
+
+    # Need to compile arm64 Linux
+    linux_dir = os.path.join(options.dest_dir, "linux-kernel-vexpress_gem5")
+    linux_bin = os.path.join(linux_dir,
+        "arch", "arm64", "boot", "Image")
+    if not os.path.exists(linux_bin):
+        linux_clone()
+        linux64()
+
+    # Need to compile DTBs
+    dtb_bin = os.path.join(binaries_dir, "armv8_gem5_v2_1cpu.dtb")
+    if not os.path.exists(dtb_bin):
+        dtbs()
+
+    # Building Xen
+    run_cmd("building xen for aarch64",
+        xen_dir,
+        ["make", "dist-xen", "XEN_TARGET_ARCH=arm64",
+         "CROSS_COMPILE=aarch64-linux-gnu-",
+         "CONFIG_EARLY_PRINTK=vexpress", make_jobs_str])
+
+    # Building boot-wrapper-aarch64
+    run_cmd("autoreconf boot-wrapper-aarch64",
+        bootwrapper_dir, ["autoreconf", "-i"])
+    run_cmd("configure boot-wrapper-aarch64",
+        bootwrapper_dir, ["./configure",
+            "--host=aarch64-linux-gnu",
+            "--with-kernel-dir={}".format(linux_dir),
+            "--with-dtb={}".format(dtb_bin),
+            "--with-cmdline='{}'".format(linux_cmdline),
+            "--with-xen-cmdline='{}'".format(xen_cmdline),
+            "--with-xen={}".format(os.path.join(xen_dir, "xen", "xen")),
+            "--enable-psci",
+            "--enable-gicv3"])
+    run_cmd("build boot-wrapper-aarch64",
+        bootwrapper_dir, ["make"])
+
+    # Copying the final binary
+    run_cmd("copy xen binary",
+        bootwrapper_dir, ["cp", "xen-system.axf", binaries_dir])
+
+    with open(os.path.join(revisions_dir, "xen"), "w+") as rev_file:
+        run_cmd("write revision of xen repo",
+            xen_dir,
+            ["git", "rev-parse", "--short", "HEAD"],
+            rev_file)
+
 script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
 gem5_dir = os.path.dirname(script_dir)
 
@@ -239,6 +318,7 @@ all_binaries = {
     "dtbs" : dtbs,
     "bootloaders" : bootloaders,
     "m5" : m5,
+    "xen" : xen,
 }
 
 parser = OptionParser()
@@ -254,7 +334,7 @@ parser.add_option("--dest-dir", default = "/tmp",
            "repositories. Generated files will be copied to "
            "DEST_DIR/binaries (which must not exist). The default "
            "value is %default")
-parser.add_option("--make-jobs", type = "int", default = 1,
+parser.add_option("-j", "--make-jobs", type = "int", default = 1,
     metavar = "MAKE_JOBS",
     help = "Number of jobs to use with the 'make' commands. Default value: "
            "%default")
@@ -292,30 +372,6 @@ if os.path.exists(revisions_dir):
     print "Error: %s already exists." %revisions_dir
     sys.exit(1)
 
-# Some basic dependency checking
-needed_programs = [
-    "make",
-    "aarch64-linux-gnu-gcc",
-    "arm-linux-gnueabihf-gcc",
-    "aarch64-linux-gnu-gcc-4.8",
-    "arm-linux-gnueabihf-gcc-4.8",
-    "gcc",
-    "bc",
-    "dtc",
-    "arm-linux-gnueabi-gcc"
-]
-
-for program in needed_programs:
-    if not spawn.find_executable(program):
-        print "Error: command %s not found in $PATH" % program
-        print ("If running on an Debian-based linux, please try the following "
-               "cmd to get all the necessary packages: ")
-        print ("sudo apt-get install -y make gcc bc gcc-aarch64-linux-gnu "
-              "gcc-4.8-aarch64-linux-gnu gcc-4.8-arm-linux-gnueabihf "
-              "gcc-arm-linux-gnueabihf device-tree-compiler "
-              "gcc-arm-linux-gnueabi")
-        sys.exit(1)
-
 os.mkdir(binaries_dir);
 os.mkdir(revisions_dir);