gen_arm_fs_files.py revision 13540
113540Sandrea.mondelli@ucf.edu#!/usr/bin/env python2.7 212123Spau.cabre@metempsy.com 312643Spau.cabre@metempsy.com# Copyright (c) 2017-2018 Metempsy Technology Consulting 412123Spau.cabre@metempsy.com# All rights reserved. 512123Spau.cabre@metempsy.com# 612123Spau.cabre@metempsy.com# Redistribution and use in source and binary forms, with or without 712123Spau.cabre@metempsy.com# modification, are permitted provided that the following conditions are 812123Spau.cabre@metempsy.com# met: redistributions of source code must retain the above copyright 912123Spau.cabre@metempsy.com# notice, this list of conditions and the following disclaimer; 1012123Spau.cabre@metempsy.com# redistributions in binary form must reproduce the above copyright 1112123Spau.cabre@metempsy.com# notice, this list of conditions and the following disclaimer in the 1212123Spau.cabre@metempsy.com# documentation and/or other materials provided with the distribution; 1312123Spau.cabre@metempsy.com# neither the name of the copyright holders nor the names of its 1412123Spau.cabre@metempsy.com# contributors may be used to endorse or promote products derived from 1512123Spau.cabre@metempsy.com# this software without specific prior written permission. 1612123Spau.cabre@metempsy.com# 1712123Spau.cabre@metempsy.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1812123Spau.cabre@metempsy.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1912123Spau.cabre@metempsy.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2012123Spau.cabre@metempsy.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2112123Spau.cabre@metempsy.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2212123Spau.cabre@metempsy.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2312123Spau.cabre@metempsy.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2412123Spau.cabre@metempsy.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2512123Spau.cabre@metempsy.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2612123Spau.cabre@metempsy.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2712123Spau.cabre@metempsy.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2812123Spau.cabre@metempsy.com# 2912123Spau.cabre@metempsy.com# Authors: Pau Cabre 3012123Spau.cabre@metempsy.com 3112123Spau.cabre@metempsy.comfrom optparse import OptionParser 3212123Spau.cabre@metempsy.comfrom subprocess import call 3312123Spau.cabre@metempsy.comfrom platform import machine 3412123Spau.cabre@metempsy.comfrom distutils import spawn 3512123Spau.cabre@metempsy.comfrom glob import glob 3612123Spau.cabre@metempsy.com 3712123Spau.cabre@metempsy.comimport sys 3812123Spau.cabre@metempsy.comimport os 3912123Spau.cabre@metempsy.com 4012643Spau.cabre@metempsy.comdef run_cmd(explanation, working_dir, cmd, stdout = None): 4112123Spau.cabre@metempsy.com print "Running phase '%s'" % explanation 4212643Spau.cabre@metempsy.com sys.stdout.flush() 4312643Spau.cabre@metempsy.com 4412643Spau.cabre@metempsy.com # some of the commands need $PWD to be properly set 4512643Spau.cabre@metempsy.com env = os.environ.copy() 4612643Spau.cabre@metempsy.com env['PWD'] = working_dir 4712643Spau.cabre@metempsy.com 4812643Spau.cabre@metempsy.com return_code = call(cmd, cwd = working_dir, stdout = stdout, 4912643Spau.cabre@metempsy.com env = env) 5012643Spau.cabre@metempsy.com 5112123Spau.cabre@metempsy.com if return_code == 0: 5212123Spau.cabre@metempsy.com return 5312643Spau.cabre@metempsy.com 5412123Spau.cabre@metempsy.com print "Error running phase %s. Returncode: %d" % (explanation, return_code) 5512123Spau.cabre@metempsy.com sys.exit(1) 5612123Spau.cabre@metempsy.com 5712123Spau.cabre@metempsy.comscript_dir = os.path.dirname(os.path.abspath(sys.argv[0])) 5812123Spau.cabre@metempsy.comgem5_dir = os.path.dirname(script_dir) 5912123Spau.cabre@metempsy.com 6012123Spau.cabre@metempsy.comparser = OptionParser() 6112123Spau.cabre@metempsy.com 6212123Spau.cabre@metempsy.comparser.add_option("--gem5-dir", default = gem5_dir, 6312123Spau.cabre@metempsy.com metavar = "GEM5_DIR", 6412123Spau.cabre@metempsy.com help = "gem5 root directory to be used for bootloader and " 6512123Spau.cabre@metempsy.com "VExpress_GEM5_V1 DTB sources. The default value is the gem5 root " 6612123Spau.cabre@metempsy.com "directory of the executed script (%default)") 6712123Spau.cabre@metempsy.comparser.add_option("--dest-dir", default = "/tmp", 6812123Spau.cabre@metempsy.com metavar = "DEST_DIR", 6912123Spau.cabre@metempsy.com help = "Directory to use for checking out the different kernel " 7012123Spau.cabre@metempsy.com "repositories. Generated files will be copied to " 7112123Spau.cabre@metempsy.com "DEST_DIR/binaries (which must not exist). The default " 7212123Spau.cabre@metempsy.com "value is %default") 7312643Spau.cabre@metempsy.comparser.add_option("--make-jobs", type = "int", default = 1, 7412643Spau.cabre@metempsy.com metavar = "MAKE_JOBS", 7512643Spau.cabre@metempsy.com help = "Number of jobs to use with the 'make' commands. Default value: " 7612643Spau.cabre@metempsy.com "%default") 7712123Spau.cabre@metempsy.com 7812123Spau.cabre@metempsy.com(options, args) = parser.parse_args() 7912123Spau.cabre@metempsy.com 8012123Spau.cabre@metempsy.comif args: 8112123Spau.cabre@metempsy.com print "Unrecognized argument(s) %s." % args 8212123Spau.cabre@metempsy.com sys.exit(1) 8312123Spau.cabre@metempsy.com 8412123Spau.cabre@metempsy.comif not os.path.isdir(options.dest_dir): 8512123Spau.cabre@metempsy.com print "Error: %s is not a directory." % options.dest_dir 8612123Spau.cabre@metempsy.com sys.exit(1) 8712123Spau.cabre@metempsy.com 8812643Spau.cabre@metempsy.comif not os.path.isdir(options.gem5_dir): 8912643Spau.cabre@metempsy.com print "Error: %s is not a directory." % options.gem5_dir 9012643Spau.cabre@metempsy.com sys.exit(1) 9112643Spau.cabre@metempsy.com 9212643Spau.cabre@metempsy.comif machine() != "x86_64": 9312643Spau.cabre@metempsy.com print "Error: This script should run in a x86_64 machine" 9412643Spau.cabre@metempsy.com sys.exit(1) 9512643Spau.cabre@metempsy.com 9612123Spau.cabre@metempsy.combinaries_dir = options.dest_dir + "/binaries" 9712123Spau.cabre@metempsy.com 9812123Spau.cabre@metempsy.comif os.path.exists(binaries_dir): 9912123Spau.cabre@metempsy.com print "Error: %s already exists." % binaries_dir 10012123Spau.cabre@metempsy.com sys.exit(1) 10112123Spau.cabre@metempsy.com 10212643Spau.cabre@metempsy.comrevisions_dir = options.dest_dir + "/revisions" 10312643Spau.cabre@metempsy.com 10412643Spau.cabre@metempsy.comif os.path.exists(revisions_dir): 10512643Spau.cabre@metempsy.com print "Error: %s already exists." %revisions_dir 10612123Spau.cabre@metempsy.com sys.exit(1) 10712123Spau.cabre@metempsy.com 10812123Spau.cabre@metempsy.com# Some basic dependency checking 10912123Spau.cabre@metempsy.comneeded_programs = [ 11012123Spau.cabre@metempsy.com "make", 11112123Spau.cabre@metempsy.com "aarch64-linux-gnu-gcc", 11212123Spau.cabre@metempsy.com "arm-linux-gnueabihf-gcc", 11312123Spau.cabre@metempsy.com "aarch64-linux-gnu-gcc-4.8", 11412123Spau.cabre@metempsy.com "arm-linux-gnueabihf-gcc-4.8", 11512123Spau.cabre@metempsy.com "gcc", 11612123Spau.cabre@metempsy.com "bc", 11712123Spau.cabre@metempsy.com "dtc", 11812123Spau.cabre@metempsy.com "arm-linux-gnueabi-gcc" 11912123Spau.cabre@metempsy.com] 12012123Spau.cabre@metempsy.com 12112123Spau.cabre@metempsy.comfor program in needed_programs: 12212123Spau.cabre@metempsy.com if not spawn.find_executable(program): 12312123Spau.cabre@metempsy.com print "Error: command %s not found in $PATH" % program 12412123Spau.cabre@metempsy.com print ("If running on an Debian-based linux, please try the following " 12512123Spau.cabre@metempsy.com "cmd to get all the necessary packages: ") 12612123Spau.cabre@metempsy.com print ("sudo apt-get install -y make gcc bc gcc-aarch64-linux-gnu " 12712123Spau.cabre@metempsy.com "gcc-4.8-aarch64-linux-gnu gcc-4.8-arm-linux-gnueabihf " 12812123Spau.cabre@metempsy.com "gcc-arm-linux-gnueabihf device-tree-compiler " 12912123Spau.cabre@metempsy.com "gcc-arm-linux-gnueabi") 13012123Spau.cabre@metempsy.com sys.exit(1) 13112123Spau.cabre@metempsy.com 13212123Spau.cabre@metempsy.comos.mkdir(binaries_dir); 13312643Spau.cabre@metempsy.comos.mkdir(revisions_dir); 13412643Spau.cabre@metempsy.com 13512643Spau.cabre@metempsy.commake_jobs_str = "-j" + str(options.make_jobs) 13612643Spau.cabre@metempsy.com 13712643Spau.cabre@metempsy.comrev_file = open(revisions_dir + "/gem5", "w+") 13812643Spau.cabre@metempsy.comrun_cmd("write revision of gem5 repo", 13912643Spau.cabre@metempsy.com gem5_dir, 14012643Spau.cabre@metempsy.com ["git", "rev-parse", "--short", "HEAD"], 14112643Spau.cabre@metempsy.com rev_file) 14212643Spau.cabre@metempsy.comrev_file.close() 14312123Spau.cabre@metempsy.com 14412123Spau.cabre@metempsy.com# Checkout and build linux kernel for VExpress_GEM5_V1 (arm and arm64) 14512123Spau.cabre@metempsy.comkernel_vexpress_gem5_dir = options.dest_dir + "/linux-kernel-vexpress_gem5" 14612123Spau.cabre@metempsy.comrun_cmd("clone linux kernel for VExpress_GEM5_V1 platform", 14712123Spau.cabre@metempsy.com options.dest_dir, 14812643Spau.cabre@metempsy.com ["git", "clone", "https://gem5.googlesource.com/arm/linux", 14912643Spau.cabre@metempsy.com kernel_vexpress_gem5_dir]) 15012643Spau.cabre@metempsy.comrev_file = open(revisions_dir + "/linux", "w+") 15112643Spau.cabre@metempsy.comrun_cmd("write revision of linux-kernel-vexpress_gem5 repo", 15212643Spau.cabre@metempsy.com kernel_vexpress_gem5_dir, 15312643Spau.cabre@metempsy.com ["git", "rev-parse", "--short", "HEAD"], 15412643Spau.cabre@metempsy.com rev_file) 15512643Spau.cabre@metempsy.comrev_file.close() 15612123Spau.cabre@metempsy.comrun_cmd("configure kernel for arm64", 15712123Spau.cabre@metempsy.com kernel_vexpress_gem5_dir, 15812123Spau.cabre@metempsy.com ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-", 15912643Spau.cabre@metempsy.com "gem5_defconfig", make_jobs_str]) 16012123Spau.cabre@metempsy.comrun_cmd("compile kernel for arm64", 16112123Spau.cabre@metempsy.com kernel_vexpress_gem5_dir, 16212643Spau.cabre@metempsy.com ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-", make_jobs_str]) 16312123Spau.cabre@metempsy.comrun_cmd("copy arm64 vmlinux", 16412123Spau.cabre@metempsy.com kernel_vexpress_gem5_dir, 16512123Spau.cabre@metempsy.com ["cp", "vmlinux", binaries_dir + "/vmlinux.vexpress_gem5_v1_64"]) 16612123Spau.cabre@metempsy.comrun_cmd("cleanup arm64 kernel compilation", 16712123Spau.cabre@metempsy.com kernel_vexpress_gem5_dir, 16812123Spau.cabre@metempsy.com ["make", "distclean"]) 16912123Spau.cabre@metempsy.comrun_cmd("configure kernel for arm", 17012123Spau.cabre@metempsy.com kernel_vexpress_gem5_dir, 17112123Spau.cabre@metempsy.com ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-", 17212123Spau.cabre@metempsy.com "gem5_defconfig"]) 17312123Spau.cabre@metempsy.comrun_cmd("compile kernel for arm", 17412123Spau.cabre@metempsy.com kernel_vexpress_gem5_dir, 17512643Spau.cabre@metempsy.com ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-", make_jobs_str]) 17612123Spau.cabre@metempsy.comrun_cmd("copy arm vmlinux", 17712123Spau.cabre@metempsy.com kernel_vexpress_gem5_dir, 17812123Spau.cabre@metempsy.com ["cp", "vmlinux", binaries_dir + "/vmlinux.vexpress_gem5_v1"]) 17912123Spau.cabre@metempsy.com 18012123Spau.cabre@metempsy.com# Checkout and build linux kernel and DTB for VExpress_EMM64 18112123Spau.cabre@metempsy.comkernel_vexpress_emm64_dir = options.dest_dir + "/linux-kernel-vexpress_emm64" 18212123Spau.cabre@metempsy.comrun_cmd("clone linux kernel for VExpress_EMM64 platform", 18312123Spau.cabre@metempsy.com options.dest_dir, 18412643Spau.cabre@metempsy.com ["git", "clone", "https://gem5.googlesource.com/arm/linux-arm64-legacy", 18512123Spau.cabre@metempsy.com kernel_vexpress_emm64_dir]) 18612643Spau.cabre@metempsy.comrev_file = open(revisions_dir + "/linux-arm64-legacy", "w+") 18712643Spau.cabre@metempsy.comrun_cmd("write revision of linux-kernel-vexpress_emm64 repo", 18812643Spau.cabre@metempsy.com kernel_vexpress_emm64_dir, 18912643Spau.cabre@metempsy.com ["git", "rev-parse", "--short", "HEAD"], 19012643Spau.cabre@metempsy.com rev_file) 19112643Spau.cabre@metempsy.comrev_file.close() 19212123Spau.cabre@metempsy.comrun_cmd("configure kernel", 19312123Spau.cabre@metempsy.com kernel_vexpress_emm64_dir, 19412123Spau.cabre@metempsy.com ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-", 19512123Spau.cabre@metempsy.com "CC=aarch64-linux-gnu-gcc-4.8", "gem5_defconfig"]) 19612123Spau.cabre@metempsy.comrun_cmd("compile kernel", 19712123Spau.cabre@metempsy.com kernel_vexpress_emm64_dir, 19812123Spau.cabre@metempsy.com ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-", 19912643Spau.cabre@metempsy.com "CC=aarch64-linux-gnu-gcc-4.8", make_jobs_str]) 20012123Spau.cabre@metempsy.comrun_cmd("copy vmlinux", 20112123Spau.cabre@metempsy.com kernel_vexpress_emm64_dir, 20212123Spau.cabre@metempsy.com ["cp", "vmlinux", binaries_dir + "/vmlinux.vexpress_emm64"]) 20312123Spau.cabre@metempsy.comrun_cmd("copy DTB", 20412123Spau.cabre@metempsy.com kernel_vexpress_emm64_dir, 20512123Spau.cabre@metempsy.com ["cp", "arch/arm64/boot/dts/aarch64_gem5_server.dtb", binaries_dir]) 20612123Spau.cabre@metempsy.com 20712123Spau.cabre@metempsy.com# Checkout and build linux kernel and DTBs for VExpress_EMM 20812123Spau.cabre@metempsy.comkernel_vexpress_emm_dir = options.dest_dir + "/linux-kernel-vexpress_emm" 20912123Spau.cabre@metempsy.comrun_cmd("clone linux kernel for VExpress_EMM platform", 21012123Spau.cabre@metempsy.com options.dest_dir, 21112643Spau.cabre@metempsy.com ["git", "clone", "https://gem5.googlesource.com/arm/linux-arm-legacy", 21212643Spau.cabre@metempsy.com kernel_vexpress_emm_dir]) 21312643Spau.cabre@metempsy.comrev_file = open(revisions_dir + "/linux-arm-legacy", "w+") 21412643Spau.cabre@metempsy.comrun_cmd("write revision of linux-kernel-vexpress_emm64 repo", 21512643Spau.cabre@metempsy.com kernel_vexpress_emm_dir, 21612643Spau.cabre@metempsy.com ["git", "rev-parse", "--short", "HEAD"], 21712643Spau.cabre@metempsy.com rev_file) 21812643Spau.cabre@metempsy.comrev_file.close() 21912123Spau.cabre@metempsy.comrun_cmd("configure kernel", 22012123Spau.cabre@metempsy.com kernel_vexpress_emm_dir, 22112123Spau.cabre@metempsy.com ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-", 22212123Spau.cabre@metempsy.com "CC=arm-linux-gnueabihf-gcc-4.8", "vexpress_gem5_server_defconfig"]) 22312123Spau.cabre@metempsy.comrun_cmd("compile kernel", 22412123Spau.cabre@metempsy.com kernel_vexpress_emm_dir, 22512123Spau.cabre@metempsy.com ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-", 22612643Spau.cabre@metempsy.com "CC=arm-linux-gnueabihf-gcc-4.8", make_jobs_str]) 22712123Spau.cabre@metempsy.comrun_cmd("copy vmlinux", 22812123Spau.cabre@metempsy.com kernel_vexpress_emm_dir, 22912123Spau.cabre@metempsy.com ["cp", "vmlinux", binaries_dir + "/vmlinux.vexpress_emm"]) 23012643Spau.cabre@metempsy.comrun_cmd("rename DTB for 1 CPU", 23112123Spau.cabre@metempsy.com kernel_vexpress_emm_dir, 23212123Spau.cabre@metempsy.com ["cp", "arch/arm/boot/dts/vexpress-v2p-ca15-tc1-gem5.dtb", 23312123Spau.cabre@metempsy.com binaries_dir + "/vexpress-v2p-ca15-tc1-gem5_1cpus.dtb"]) 23412643Spau.cabre@metempsy.comrun_cmd("copy DTBs", 23512123Spau.cabre@metempsy.com kernel_vexpress_emm_dir, 23612643Spau.cabre@metempsy.com ["cp"] + glob(kernel_vexpress_emm_dir + "/arch/arm/boot/dts/*gem5_*dtb") + 23712643Spau.cabre@metempsy.com [binaries_dir]) 23812123Spau.cabre@metempsy.com 23912123Spau.cabre@metempsy.com# Build DTBs for VExpress_GEM5_V1 24012123Spau.cabre@metempsy.comdt_dir = gem5_dir + "/system/arm/dt" 24112123Spau.cabre@metempsy.comrun_cmd("compile DTBs for VExpress_GEM5_V1 platform", 24212123Spau.cabre@metempsy.com dt_dir, 24312643Spau.cabre@metempsy.com ["make", make_jobs_str]) 24412123Spau.cabre@metempsy.comrun_cmd("copy DTBs", 24512123Spau.cabre@metempsy.com dt_dir, 24612123Spau.cabre@metempsy.com ["cp"] + glob(dt_dir + "/*dtb") + [binaries_dir]) 24712123Spau.cabre@metempsy.com 24812123Spau.cabre@metempsy.com# Build bootloaders arm64 24912123Spau.cabre@metempsy.combootloader_arm64_dir = gem5_dir + "/system/arm/aarch64_bootloader" 25012123Spau.cabre@metempsy.comrun_cmd("compile arm64 bootloader", 25112123Spau.cabre@metempsy.com bootloader_arm64_dir, 25212123Spau.cabre@metempsy.com ["make"]) 25312123Spau.cabre@metempsy.comrun_cmd("copy arm64 bootloader", 25412123Spau.cabre@metempsy.com bootloader_arm64_dir, 25512123Spau.cabre@metempsy.com ["cp", "boot_emm.arm64", binaries_dir]) 25612123Spau.cabre@metempsy.com 25712123Spau.cabre@metempsy.com# Build bootloaders arm 25812123Spau.cabre@metempsy.combootloader_arm_dir = gem5_dir + "/system/arm/simple_bootloader" 25912123Spau.cabre@metempsy.comrun_cmd("compile arm bootloader", 26012123Spau.cabre@metempsy.com bootloader_arm_dir, 26112123Spau.cabre@metempsy.com ["make"]) 26212123Spau.cabre@metempsy.comrun_cmd("copy arm bootloaders", 26312123Spau.cabre@metempsy.com bootloader_arm_dir, 26412123Spau.cabre@metempsy.com ["cp", "boot.arm", "boot_emm.arm", binaries_dir]) 26512123Spau.cabre@metempsy.com 26612643Spau.cabre@metempsy.com# Build m5 binaries 26712643Spau.cabre@metempsy.comm5_dir = gem5_dir + "/util/m5" 26812643Spau.cabre@metempsy.comrun_cmd("compile arm64 m5", 26912643Spau.cabre@metempsy.com m5_dir, 27012643Spau.cabre@metempsy.com ["make", "-f", "Makefile.aarch64"]) 27112643Spau.cabre@metempsy.comrun_cmd("copy arm64 m5", 27212643Spau.cabre@metempsy.com m5_dir, 27312643Spau.cabre@metempsy.com ["cp", "m5", binaries_dir + "/m5.aarch64"]) 27412643Spau.cabre@metempsy.comrun_cmd("clean arm64 m5", 27512643Spau.cabre@metempsy.com m5_dir, 27612643Spau.cabre@metempsy.com ["make", "clean", "-f", "Makefile.aarch64"]) 27712643Spau.cabre@metempsy.comrun_cmd("compile arm m5", 27812643Spau.cabre@metempsy.com m5_dir, 27912643Spau.cabre@metempsy.com ["make", "-f", "Makefile.arm"]) 28012643Spau.cabre@metempsy.comrun_cmd("copy arm m5", 28112643Spau.cabre@metempsy.com m5_dir, 28212643Spau.cabre@metempsy.com ["cp", "m5", binaries_dir + "/m5.aarch32"]) 28312643Spau.cabre@metempsy.com 28412123Spau.cabre@metempsy.comprint "Done! All the generated files can be found in %s" % binaries_dir 28512123Spau.cabre@metempsy.com 28612643Spau.cabre@metempsy.comsys.exit(0) 28712643Spau.cabre@metempsy.com 288