1 #!/usr/bin/env python2.7
3 # Copyright (c) 2017-2018 Metempsy Technology Consulting
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met: redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer;
10 # redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution;
13 # neither the name of the copyright holders nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 from optparse
import OptionParser
30 from subprocess
import call
31 from platform
import machine
32 from distutils
import spawn
38 def run_cmd(explanation
, working_dir
, cmd
, stdout
= None):
39 print "Running phase '%s'" % explanation
42 # some of the commands need $PWD to be properly set
43 env
= os
.environ
.copy()
44 env
['PWD'] = working_dir
46 return_code
= call(cmd
, cwd
= working_dir
, stdout
= stdout
,
52 print "Error running phase %s. Returncode: %d" % (explanation
, return_code
)
56 kernel_vexpress_gem5_dir
= os
.path
.join(
57 options
.dest_dir
, "linux-kernel-vexpress_gem5")
59 run_cmd("clone linux kernel for VExpress_GEM5_V1 platform",
61 ["git", "clone", "https://gem5.googlesource.com/arm/linux",
62 kernel_vexpress_gem5_dir
])
65 kernel_vexpress_gem5_dir
= os
.path
.join(
66 options
.dest_dir
, "linux-kernel-vexpress_gem5")
68 linux_bin
= os
.path
.join(
69 binaries_dir
, "vmlinux.vexpress_gem5_v1_64")
71 with
open(revisions_dir
+ "/linux", "w+") as rev_file
:
72 run_cmd("write revision of linux-kernel-vexpress_gem5 repo",
73 kernel_vexpress_gem5_dir
,
74 ["git", "rev-parse", "--short", "HEAD"],
77 run_cmd("configure kernel for arm64",
78 kernel_vexpress_gem5_dir
,
79 ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-",
80 "gem5_defconfig", make_jobs_str
])
81 run_cmd("compile kernel for arm64",
82 kernel_vexpress_gem5_dir
,
83 ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-",
85 run_cmd("copy arm64 vmlinux",
86 kernel_vexpress_gem5_dir
,
87 ["cp", "vmlinux", linux_bin
])
88 run_cmd("cleanup arm64 kernel compilation",
89 kernel_vexpress_gem5_dir
,
90 ["make", "distclean"])
93 kernel_vexpress_gem5_dir
= os
.path
.join(
94 options
.dest_dir
, "linux-kernel-vexpress_gem5")
96 linux_bin
= os
.path
.join(
97 binaries_dir
, "vmlinux.vexpress_gem5_v1")
99 run_cmd("configure kernel for arm",
100 kernel_vexpress_gem5_dir
,
101 ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-",
103 run_cmd("compile kernel for arm",
104 kernel_vexpress_gem5_dir
,
105 ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-",
107 run_cmd("copy arm vmlinux",
108 kernel_vexpress_gem5_dir
,
109 ["cp", "vmlinux", linux_bin
])
113 Checkout and build linux kernel for VExpress_GEM5_V1 (arm and arm64)
121 Checkout and build linux kernel and DTB for VExpress_EMM64/EMM
123 kernel_vexpress_emm64_dir
= os
.path
.join(options
.dest_dir
,
124 "linux-kernel-vexpress_emm64")
125 run_cmd("clone linux kernel for VExpress_EMM64 platform",
127 ["git", "clone", "https://gem5.googlesource.com/arm/linux-arm64-legacy",
128 kernel_vexpress_emm64_dir
])
129 with
open(revisions_dir
+ "/linux-arm64-legacy", "w+") as rev_file
:
130 run_cmd("write revision of linux-kernel-vexpress_emm64 repo",
131 kernel_vexpress_emm64_dir
,
132 ["git", "rev-parse", "--short", "HEAD"],
134 run_cmd("configure kernel",
135 kernel_vexpress_emm64_dir
,
136 ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-",
137 "CC=aarch64-linux-gnu-gcc-4.8", "gem5_defconfig"])
138 run_cmd("compile kernel",
139 kernel_vexpress_emm64_dir
,
140 ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-",
141 "CC=aarch64-linux-gnu-gcc-4.8", make_jobs_str
])
142 run_cmd("copy vmlinux",
143 kernel_vexpress_emm64_dir
,
144 ["cp", "vmlinux", binaries_dir
+ "/vmlinux.vexpress_emm64"])
146 kernel_vexpress_emm64_dir
,
147 ["cp", "arch/arm64/boot/dts/aarch64_gem5_server.dtb", binaries_dir
])
149 kernel_vexpress_emm_dir
= options
.dest_dir
+ "/linux-kernel-vexpress_emm"
150 run_cmd("clone linux kernel for VExpress_EMM platform",
152 ["git", "clone", "https://gem5.googlesource.com/arm/linux-arm-legacy",
153 kernel_vexpress_emm_dir
])
154 with
open(revisions_dir
+ "/linux-arm-legacy", "w+") as rev_file
:
155 run_cmd("write revision of linux-kernel-vexpress_emm64 repo",
156 kernel_vexpress_emm_dir
,
157 ["git", "rev-parse", "--short", "HEAD"],
159 run_cmd("configure kernel",
160 kernel_vexpress_emm_dir
,
161 ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-",
162 "CC=arm-linux-gnueabihf-gcc-4.8", "vexpress_gem5_server_defconfig"])
163 run_cmd("compile kernel",
164 kernel_vexpress_emm_dir
,
165 ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-",
166 "CC=arm-linux-gnueabihf-gcc-4.8", make_jobs_str
])
167 run_cmd("copy vmlinux",
168 kernel_vexpress_emm_dir
,
169 ["cp", "vmlinux", binaries_dir
+ "/vmlinux.vexpress_emm"])
170 run_cmd("rename DTB for 1 CPU",
171 kernel_vexpress_emm_dir
,
172 ["cp", "arch/arm/boot/dts/vexpress-v2p-ca15-tc1-gem5.dtb",
173 binaries_dir
+ "/vexpress-v2p-ca15-tc1-gem5_1cpus.dtb"])
175 kernel_vexpress_emm_dir
,
176 ["cp"] + glob(kernel_vexpress_emm_dir
+ "/arch/arm/boot/dts/*gem5_*dtb") +
181 Build DTBs for VExpress_GEM5_V1
183 dt_dir
= gem5_dir
+ "/system/arm/dt"
184 run_cmd("compile DTBs for VExpress_GEM5_V1 platform",
186 ["make", make_jobs_str
])
189 ["cp"] + glob(dt_dir
+ "/*dtb") + [binaries_dir
])
193 Build bootloaders arm64/arm
196 bootloader_arm64_dir
= gem5_dir
+ "/system/arm/bootloader/arm64"
197 run_cmd("compile arm64 bootloader",
198 bootloader_arm64_dir
,
200 run_cmd("copy arm64 bootloader",
201 bootloader_arm64_dir
,
202 ["cp", "boot.arm64", "boot_emm.arm64", "boot_v2.arm64", binaries_dir
])
204 bootloader_arm_dir
= gem5_dir
+ "/system/arm/bootloader/arm"
205 run_cmd("compile arm bootloader",
208 run_cmd("copy arm bootloaders",
210 ["cp", "boot.arm", "boot_emm.arm", binaries_dir
])
216 m5_dir
= gem5_dir
+ "/util/m5"
217 run_cmd("compile arm64 m5",
219 ["make", "-f", "Makefile.aarch64"])
220 run_cmd("copy arm64 m5",
222 ["cp", "m5", binaries_dir
+ "/m5.aarch64"])
223 run_cmd("clean arm64 m5",
225 ["make", "clean", "-f", "Makefile.aarch64"])
226 run_cmd("compile arm m5",
228 ["make", "-f", "Makefile.arm"])
229 run_cmd("copy arm m5",
231 ["cp", "m5", binaries_dir
+ "/m5.aarch32"])
233 script_dir
= os
.path
.dirname(os
.path
.abspath(sys
.argv
[0]))
234 gem5_dir
= os
.path
.dirname(script_dir
)
238 "linux-legacy" : linux_legacy
,
240 "bootloaders" : bootloaders
,
244 parser
= OptionParser()
246 parser
.add_option("--gem5-dir", default
= gem5_dir
,
247 metavar
= "GEM5_DIR",
248 help = "gem5 root directory to be used for bootloader and "
249 "VExpress_GEM5_V1 DTB sources. The default value is the gem5 root "
250 "directory of the executed script (%default)")
251 parser
.add_option("--dest-dir", default
= "/tmp",
252 metavar
= "DEST_DIR",
253 help = "Directory to use for checking out the different kernel "
254 "repositories. Generated files will be copied to "
255 "DEST_DIR/binaries (which must not exist). The default "
257 parser
.add_option("-j", "--make-jobs", type = "int", default
= 1,
258 metavar
= "MAKE_JOBS",
259 help = "Number of jobs to use with the 'make' commands. Default value: "
261 parser
.add_option("-b", "--fs-binaries", action
="append",
262 choices
=all_binaries
.keys(), default
=[],
263 help = "List of FS files to be generated. Defaulting to all")
265 (options
, args
) = parser
.parse_args()
268 print "Unrecognized argument(s) %s." % args
271 if not os
.path
.isdir(options
.dest_dir
):
272 print "Error: %s is not a directory." % options
.dest_dir
275 if not os
.path
.isdir(options
.gem5_dir
):
276 print "Error: %s is not a directory." % options
.gem5_dir
279 if machine() != "x86_64":
280 print "Error: This script should run in a x86_64 machine"
283 binaries_dir
= options
.dest_dir
+ "/binaries"
285 if os
.path
.exists(binaries_dir
):
286 print "Error: %s already exists." % binaries_dir
289 revisions_dir
= options
.dest_dir
+ "/revisions"
291 if os
.path
.exists(revisions_dir
):
292 print "Error: %s already exists." %revisions
_dir
295 os
.mkdir(binaries_dir
);
296 os
.mkdir(revisions_dir
);
298 make_jobs_str
= "-j" + str(options
.make_jobs
)
300 rev_file
= open(revisions_dir
+ "/gem5", "w+")
301 run_cmd("write revision of gem5 repo",
303 ["git", "rev-parse", "--short", "HEAD"],
307 binaries
= options
.fs_binaries
if options
.fs_binaries
else all_binaries
.keys()
308 for fs_binary
in binaries
:
309 all_binaries
[fs_binary
]()
311 print "Done! All the generated files can be found in %s" % binaries_dir