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
)
55 script_dir
= os
.path
.dirname(os
.path
.abspath(sys
.argv
[0]))
56 gem5_dir
= os
.path
.dirname(script_dir
)
58 parser
= OptionParser()
60 parser
.add_option("--gem5-dir", default
= gem5_dir
,
62 help = "gem5 root directory to be used for bootloader and "
63 "VExpress_GEM5_V1 DTB sources. The default value is the gem5 root "
64 "directory of the executed script (%default)")
65 parser
.add_option("--dest-dir", default
= "/tmp",
67 help = "Directory to use for checking out the different kernel "
68 "repositories. Generated files will be copied to "
69 "DEST_DIR/binaries (which must not exist). The default "
71 parser
.add_option("--make-jobs", type = "int", default
= 1,
72 metavar
= "MAKE_JOBS",
73 help = "Number of jobs to use with the 'make' commands. Default value: "
76 (options
, args
) = parser
.parse_args()
79 print "Unrecognized argument(s) %s." % args
82 if not os
.path
.isdir(options
.dest_dir
):
83 print "Error: %s is not a directory." % options
.dest_dir
86 if not os
.path
.isdir(options
.gem5_dir
):
87 print "Error: %s is not a directory." % options
.gem5_dir
90 if machine() != "x86_64":
91 print "Error: This script should run in a x86_64 machine"
94 binaries_dir
= options
.dest_dir
+ "/binaries"
96 if os
.path
.exists(binaries_dir
):
97 print "Error: %s already exists." % binaries_dir
100 revisions_dir
= options
.dest_dir
+ "/revisions"
102 if os
.path
.exists(revisions_dir
):
103 print "Error: %s already exists." %revisions
_dir
106 # Some basic dependency checking
109 "aarch64-linux-gnu-gcc",
110 "arm-linux-gnueabihf-gcc",
111 "aarch64-linux-gnu-gcc-4.8",
112 "arm-linux-gnueabihf-gcc-4.8",
116 "arm-linux-gnueabi-gcc"
119 for program
in needed_programs
:
120 if not spawn
.find_executable(program
):
121 print "Error: command %s not found in $PATH" % program
122 print ("If running on an Debian-based linux, please try the following "
123 "cmd to get all the necessary packages: ")
124 print ("sudo apt-get install -y make gcc bc gcc-aarch64-linux-gnu "
125 "gcc-4.8-aarch64-linux-gnu gcc-4.8-arm-linux-gnueabihf "
126 "gcc-arm-linux-gnueabihf device-tree-compiler "
127 "gcc-arm-linux-gnueabi")
130 os
.mkdir(binaries_dir
);
131 os
.mkdir(revisions_dir
);
133 make_jobs_str
= "-j" + str(options
.make_jobs
)
135 rev_file
= open(revisions_dir
+ "/gem5", "w+")
136 run_cmd("write revision of gem5 repo",
138 ["git", "rev-parse", "--short", "HEAD"],
142 # Checkout and build linux kernel for VExpress_GEM5_V1 (arm and arm64)
143 kernel_vexpress_gem5_dir
= options
.dest_dir
+ "/linux-kernel-vexpress_gem5"
144 run_cmd("clone linux kernel for VExpress_GEM5_V1 platform",
146 ["git", "clone", "https://gem5.googlesource.com/arm/linux",
147 kernel_vexpress_gem5_dir
])
148 rev_file
= open(revisions_dir
+ "/linux", "w+")
149 run_cmd("write revision of linux-kernel-vexpress_gem5 repo",
150 kernel_vexpress_gem5_dir
,
151 ["git", "rev-parse", "--short", "HEAD"],
154 run_cmd("configure kernel for arm64",
155 kernel_vexpress_gem5_dir
,
156 ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-",
157 "gem5_defconfig", make_jobs_str
])
158 run_cmd("compile kernel for arm64",
159 kernel_vexpress_gem5_dir
,
160 ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-", make_jobs_str
])
161 run_cmd("copy arm64 vmlinux",
162 kernel_vexpress_gem5_dir
,
163 ["cp", "vmlinux", binaries_dir
+ "/vmlinux.vexpress_gem5_v1_64"])
164 run_cmd("cleanup arm64 kernel compilation",
165 kernel_vexpress_gem5_dir
,
166 ["make", "distclean"])
167 run_cmd("configure kernel for arm",
168 kernel_vexpress_gem5_dir
,
169 ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-",
171 run_cmd("compile kernel for arm",
172 kernel_vexpress_gem5_dir
,
173 ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-", make_jobs_str
])
174 run_cmd("copy arm vmlinux",
175 kernel_vexpress_gem5_dir
,
176 ["cp", "vmlinux", binaries_dir
+ "/vmlinux.vexpress_gem5_v1"])
178 # Checkout and build linux kernel and DTB for VExpress_EMM64
179 kernel_vexpress_emm64_dir
= options
.dest_dir
+ "/linux-kernel-vexpress_emm64"
180 run_cmd("clone linux kernel for VExpress_EMM64 platform",
182 ["git", "clone", "https://gem5.googlesource.com/arm/linux-arm64-legacy",
183 kernel_vexpress_emm64_dir
])
184 rev_file
= open(revisions_dir
+ "/linux-arm64-legacy", "w+")
185 run_cmd("write revision of linux-kernel-vexpress_emm64 repo",
186 kernel_vexpress_emm64_dir
,
187 ["git", "rev-parse", "--short", "HEAD"],
190 run_cmd("configure kernel",
191 kernel_vexpress_emm64_dir
,
192 ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-",
193 "CC=aarch64-linux-gnu-gcc-4.8", "gem5_defconfig"])
194 run_cmd("compile kernel",
195 kernel_vexpress_emm64_dir
,
196 ["make", "ARCH=arm64", "CROSS_COMPILE=aarch64-linux-gnu-",
197 "CC=aarch64-linux-gnu-gcc-4.8", make_jobs_str
])
198 run_cmd("copy vmlinux",
199 kernel_vexpress_emm64_dir
,
200 ["cp", "vmlinux", binaries_dir
+ "/vmlinux.vexpress_emm64"])
202 kernel_vexpress_emm64_dir
,
203 ["cp", "arch/arm64/boot/dts/aarch64_gem5_server.dtb", binaries_dir
])
205 # Checkout and build linux kernel and DTBs for VExpress_EMM
206 kernel_vexpress_emm_dir
= options
.dest_dir
+ "/linux-kernel-vexpress_emm"
207 run_cmd("clone linux kernel for VExpress_EMM platform",
209 ["git", "clone", "https://gem5.googlesource.com/arm/linux-arm-legacy",
210 kernel_vexpress_emm_dir
])
211 rev_file
= open(revisions_dir
+ "/linux-arm-legacy", "w+")
212 run_cmd("write revision of linux-kernel-vexpress_emm64 repo",
213 kernel_vexpress_emm_dir
,
214 ["git", "rev-parse", "--short", "HEAD"],
217 run_cmd("configure kernel",
218 kernel_vexpress_emm_dir
,
219 ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-",
220 "CC=arm-linux-gnueabihf-gcc-4.8", "vexpress_gem5_server_defconfig"])
221 run_cmd("compile kernel",
222 kernel_vexpress_emm_dir
,
223 ["make", "ARCH=arm", "CROSS_COMPILE=arm-linux-gnueabihf-",
224 "CC=arm-linux-gnueabihf-gcc-4.8", make_jobs_str
])
225 run_cmd("copy vmlinux",
226 kernel_vexpress_emm_dir
,
227 ["cp", "vmlinux", binaries_dir
+ "/vmlinux.vexpress_emm"])
228 run_cmd("rename DTB for 1 CPU",
229 kernel_vexpress_emm_dir
,
230 ["cp", "arch/arm/boot/dts/vexpress-v2p-ca15-tc1-gem5.dtb",
231 binaries_dir
+ "/vexpress-v2p-ca15-tc1-gem5_1cpus.dtb"])
233 kernel_vexpress_emm_dir
,
234 ["cp"] + glob(kernel_vexpress_emm_dir
+ "/arch/arm/boot/dts/*gem5_*dtb") +
237 # Build DTBs for VExpress_GEM5_V1
238 dt_dir
= gem5_dir
+ "/system/arm/dt"
239 run_cmd("compile DTBs for VExpress_GEM5_V1 platform",
241 ["make", make_jobs_str
])
244 ["cp"] + glob(dt_dir
+ "/*dtb") + [binaries_dir
])
246 # Build bootloaders arm64
247 bootloader_arm64_dir
= gem5_dir
+ "/system/arm/bootloader/arm64"
248 run_cmd("compile arm64 bootloader",
249 bootloader_arm64_dir
,
251 run_cmd("copy arm64 bootloader",
252 bootloader_arm64_dir
,
253 ["cp", "boot.arm64", "boot_emm.arm64", "boot_v2.arm64", binaries_dir
])
255 # Build bootloaders arm
256 bootloader_arm_dir
= gem5_dir
+ "/system/arm/bootloader/arm"
257 run_cmd("compile arm bootloader",
260 run_cmd("copy arm bootloaders",
262 ["cp", "boot.arm", "boot_emm.arm", binaries_dir
])
265 m5_dir
= gem5_dir
+ "/util/m5"
266 run_cmd("compile arm64 m5",
268 ["make", "-f", "Makefile.aarch64"])
269 run_cmd("copy arm64 m5",
271 ["cp", "m5", binaries_dir
+ "/m5.aarch64"])
272 run_cmd("clean arm64 m5",
274 ["make", "clean", "-f", "Makefile.aarch64"])
275 run_cmd("compile arm m5",
277 ["make", "-f", "Makefile.arm"])
278 run_cmd("copy arm m5",
280 ["cp", "m5", binaries_dir
+ "/m5.aarch32"])
282 print "Done! All the generated files can be found in %s" % binaries_dir