OLD | NEW |
---|---|
(Empty) | |
1 #!/bin/sh | |
2 | |
3 # Copyright 2014 Google Inc. | |
4 # | |
5 # Use of this source code is governed by a BSD-style license that can be | |
6 # found in the LICENSE file. | |
7 | |
8 | |
9 usage() { | |
10 cat >&2 <<EOF | |
11 arm64_download - this script downloads the Linaro's ARMv8 Aarch64 | |
12 toolchain and minimal embedded Linux system as well as ARM's | |
13 foundation model. The required files are mirrored on Google Cloud. | |
14 | |
15 If the files are already located in the working directory, the | |
16 download can be skipped if the checksums match. | |
17 | |
18 The script then starts a emulated Arm64 Linux system in the | |
19 background. After the boot is complete, you can SSH into the system | |
20 at port 8022 via user@localhost. The SSH key will be downloaded into | |
21 the working directery as well. | |
22 | |
23 Requires gsutil, xz, tar, and gunzip. | |
24 | |
25 Usage: | |
26 $0 WORKING_DIRECTORY | |
27 ssh-add WORKING_DIRECTORY/key | |
28 ...wait... | |
29 ssh -p 8022 user@localhost | |
30 EOF | |
31 return 1 | |
32 } | |
33 | |
34 try() { | |
35 # print an error on nonzero return code | |
36 "$@" | |
37 local ret=$? | |
38 if [ $ret != 0 ] ; then | |
39 echo "'$@' failed and returned ${ret}." >&2 | |
40 return $ret | |
41 fi | |
42 } | |
43 | |
44 gsutil_check_get() { | |
45 local gurl="$1" | |
46 local file="$2" | |
47 if ! [ -f "$file" ] || \ | |
48 [ "$(gsutil stat "$gurl" | sed -n 's/\W*Hash (md5):\W*//p')" \ | |
49 != "$(md5sum < "$file" | sed 's/\W*-//')" ] ; then | |
50 try gsutil cp "$gurl" "$file" || return | |
51 fi | |
52 } | |
53 | |
54 download_compiler() { | |
55 local working_dir="$1" | |
56 local location="$2" | |
57 local toolchain="$3" | |
58 | |
59 try cd "$working_dir" || return | |
60 | |
61 try gsutil_check_get "gs://${location}/${toolchain}.tar.xz" \ | |
djsollen
2014/02/19 15:40:00
you can do this without requiring gsutil.
http://
hal.canary
2014/02/19 15:43:56
These files have access control.
| |
62 "${working_dir}/${toolchain}.tar.xz" || return | |
63 ( | |
64 cd "$working_dir" | |
65 xz --decompress --stdout < "${toolchain}.tar.xz" | tar xf - | |
66 ) | |
67 local dir="${working_dir}/${toolchain}" | |
68 try test -d "$dir" || return | |
69 try test -x "${dir}/bin/aarch64-linux-gnu-gcc" || return | |
70 try test -x "${dir}/bin/aarch64-linux-gnu-g++" || return | |
71 } | |
72 | |
73 download_runtime() { | |
74 local working_dir="$1" | |
75 local location="$2" | |
76 local firmware="$3" | |
77 local compressed_rootfs="$4" | |
78 local compressed_foundation_model="$5" | |
79 local keyfile="$6" | |
80 | |
81 try gsutil_check_get "gs://${location}/${firmware}" \ | |
82 "${working_dir}/firmware" || return | |
83 | |
84 try gsutil_check_get "gs://${location}/${compressed_rootfs}" \ | |
85 "${working_dir}/${compressed_rootfs}" || return | |
86 | |
87 try xz --decompress --stdout \ | |
88 < "${working_dir}/${compressed_rootfs}" \ | |
89 > "${working_dir}/rootfs" || return | |
90 try test -f "${working_dir}/rootfs" || return | |
91 | |
92 try gsutil_check_get "gs://${location}/${compressed_foundation_model}" \ | |
93 "${working_dir}/${compressed_foundation_model}" || return | |
94 ( | |
95 try cd "$working_dir" || return | |
96 try gunzip -c "$compressed_foundation_model" | try tar xf - || return | |
97 try test -d "Foundation_v8pkg" || return # Assert. | |
98 ) | |
99 | |
100 try gsutil_check_get "gs://${location}/${keyfile}" \ | |
101 "${working_dir}/key" || return | |
102 chmod go= "${working_dir}/key" | |
103 } | |
104 | |
105 start_arm64_image() { | |
106 local working_dir="$1" | |
107 local foundation_dir="${working_dir}/Foundation_v8pkg" | |
108 local foundation="${foundation_dir}/models/Linux64_GCC-4.1/Foundation_v8" | |
109 local firmware="${working_dir}/firmware" | |
110 local rootfs="${working_dir}/rootfs" | |
111 | |
112 try test -d "$foundation_dir" || return | |
113 try test -x "$foundation" || return | |
114 try test -f "$firmware" || return | |
115 try test -f "$rootfs" || return | |
116 | |
117 for PID in $(ps -o 'pid=' -C 'Foundation_v8') ; do | |
118 kill $PID | |
119 done | |
120 | |
121 DISPLAY='' nohup \ | |
122 "$foundation" \ | |
123 --image="${firmware}" \ | |
124 --cores=4 \ | |
125 --block-device="${rootfs}" \ | |
126 --network="nat" \ | |
127 --network-nat-subnet="192.168.31.0/24" \ | |
128 --network-nat-ports="8022=22" \ | |
129 > /dev/null 2>&1 & | |
130 echo 'Listening to SSH on port 8022.' | |
131 } | |
132 | |
133 arm64_download() { | |
134 local working_directory="$1" | |
135 local location="chromium-skia-gm/arm64env" | |
136 try mkdir -p "$working_directory" || return | |
137 | |
138 try download_compiler \ | |
139 "$working_directory" \ | |
140 "$location" \ | |
141 'gcc-linaro-aarch64-linux-gnu-4.8-2013.12_linux' \ | |
142 || return | |
143 | |
144 local rootfs='vexpress64-openembedded_lamp-armv8-gcc-4.8_20131215-557' | |
145 try download_runtime \ | |
146 "$working_directory" \ | |
147 "$location" \ | |
148 'img-foundation.axf' \ | |
149 "${rootfs}.img.CLEAN_AND_CONFIGURED.xz" \ | |
150 'FM000-KT-00035-r0p8-52rel06.tgz' \ | |
151 'CLEAN_AND_CONFIGURED_key' \ | |
152 || return | |
153 | |
154 try start_arm64_image \ | |
155 "$working_directory" \ | |
156 || return | |
157 | |
158 } | |
159 | |
160 for command in gsutil xz tar gunzip; do | |
161 try command -v "$command" > /dev/null || usage || exit | |
162 done | |
163 | |
164 if [ -z "$1" ] ; then | |
165 usage || exit | |
166 fi | |
167 try arm64_download "$1" || exit | |
OLD | NEW |