OLD | NEW |
---|---|
(Empty) | |
1 #!/bin/bash | |
2 # Copyright 2012 The Native Client Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can | |
4 # be found in the LICENSE file. | |
5 # | |
6 #@ This script creates the mips trusted SDK. | |
7 #@ It must be run from the native_client directory. | |
8 | |
9 ###################################################################### | |
10 # Config | |
11 ###################################################################### | |
12 | |
13 set -o nounset | |
14 set -o errexit | |
15 | |
16 readonly CS_URL=https://sourcery.mentor.com/sgpp/lite/mips/portal/package9761/pu blic/mips-linux-gnu/mips-2011.09-75-mips-linux-gnu-i686-pc-linux-gnu.tar.bz2 | |
17 | |
18 readonly DOWNLOAD_QEMU_URL="http://download.savannah.gnu.org/releases/qemu/qemu- 0.12.5.tar.gz" | |
19 | |
20 readonly INSTALL_ROOT=$(pwd)/toolchain/linux_mips-trusted | |
21 | |
22 readonly TMP=$(pwd)/toolchain/tmp/crosstool-trusted | |
23 | |
24 readonly PATCH_MIPS32=$(readlink -f ../third_party/qemu/qemu-0.12.5.patch_mips) | |
25 | |
26 readonly CS_ROOT=${INSTALL_ROOT}/mips-release | |
27 | |
28 readonly JAIL_MIPS32=${CS_ROOT}/mips-linux-gnu/libc/el | |
29 | |
30 readonly MAKE_OPTS="-j8" | |
31 # These are simple compiler wrappers to force 32bit builds | |
32 readonly CC32=$(readlink -f pnacl/scripts/mygcc32) | |
33 readonly CXX32=$(readlink -f pnacl/scripts/myg++32) | |
34 ###################################################################### | |
35 # Helper | |
36 ###################################################################### | |
37 | |
38 Banner() { | |
39 echo "######################################################################" | |
40 echo $* | |
41 echo "######################################################################" | |
42 } | |
43 | |
44 SubBanner() { | |
45 echo "......................................................................" | |
46 echo $* | |
47 echo "...................................................................." | |
48 } | |
49 | |
50 Usage() { | |
51 echo | |
52 echo "$0 trusted_sdk" | |
53 echo | |
54 echo "trusted_sdk - Build everything and package it" | |
55 echo | |
56 } | |
57 | |
58 DownloadOrCopy() { | |
59 if [[ -f "$2" ]] ; then | |
60 echo "$2 already in place" | |
61 elif [[ $1 =~ 'http://' || $1 =~ 'https://' ]] ; then | |
62 SubBanner "downloading from $1 -> $2" | |
63 wget $1 -O $2 | |
64 else | |
65 SubBanner "copying from $1" | |
66 cp $1 $2 | |
67 fi | |
68 } | |
69 | |
70 ###################################################################### | |
71 # | |
72 ###################################################################### | |
73 | |
74 # some sanity checks to make sure this script is run from the right place | |
75 # with the right tools | |
76 SanityCheck() { | |
77 Banner "Sanity Checks" | |
78 if [[ $(basename $(pwd)) != "native_client" ]] ; then | |
79 echo "ERROR: run this script from the native_client/ dir" | |
80 exit -1 | |
81 fi | |
82 | |
83 if ! mkdir -p "${INSTALL_ROOT}" ; then | |
84 echo "ERROR: ${INSTALL_ROOT} can't be created." | |
85 exit -1 | |
86 fi | |
87 | |
88 for tool in cleanlinks wget ; do | |
89 if ! which ${tool} ; then | |
90 echo "Required binary $tool not found." | |
91 echo "Exiting." | |
92 exit 1 | |
93 fi | |
94 done | |
95 } | |
96 | |
97 | |
98 ClearInstallDir() { | |
99 Banner "clearing dirs in ${INSTALL_ROOT}" | |
100 rm -rf ${INSTALL_ROOT}/* | |
101 } | |
102 | |
103 | |
104 CreateTarBall() { | |
105 local tarball=$1 | |
106 Banner "creating tar ball ${tarball}" | |
107 tar cfz ${tarball}-mips.tgz -C ${INSTALL_ROOT} . | |
108 } | |
109 | |
110 | |
111 # try to keep the tarball small | |
112 PruneDirs() { | |
113 Banner "pruning code sourcery tree" | |
114 SubBanner "Size before: $(du -msc ${CS_ROOT})" | |
115 rm -rf ${CS_ROOT}/share | |
116 rm -rf ${CS_ROOT}/mips-linux-gnu/lib/uclibc | |
117 rm -rf ${CS_ROOT}/mips-linux-gnu/lib/soft-float | |
118 rm -rf ${CS_ROOT}/mips-linux-gnu/lib/micromips | |
119 | |
120 rm -rf ${CS_ROOT}/mips-linux-gnu/libc/uclibc | |
121 rm -rf ${CS_ROOT}/mips-linux-gnu/libc/soft-float | |
122 rm -rf ${CS_ROOT}/mips-linux-gnu/libc/micromips | |
123 | |
124 rm -rf ${CS_ROOT}/lib/gcc/mips-linux-gnu/4.4.1/uclibc | |
125 rm -rf ${CS_ROOT}/lib/gcc/mips-linux-gnu/4.4.1/soft-float | |
126 rm -rf ${CS_ROOT}/lib/gcc/mips-linux-gnu/4.4.1/micromips | |
127 | |
128 rm -rf ${CS_ROOT}/mips-linux-gnu/include/c++/4.4.1/mips-linux-gnu/uclibc | |
129 rm -rf ${CS_ROOT}/mips-linux-gnu/include/c++/4.4.1/mips-linux-gnu/soft-float | |
130 rm -rf ${CS_ROOT}/mips-linux-gnu/include/c++/4.4.1/mips-linux-gnu/micromips | |
131 | |
132 SubBanner "Size after: $(du -msc ${CS_ROOT})" | |
133 } | |
134 | |
135 | |
136 # Download the codesourcery tarball or use a local copy when available. | |
137 DownloadOrCopyAndInstallCodeSourceryTarball() { | |
138 Banner "Installing Codesourcery Toolchain" | |
139 local tarball="${TMP}/${CS_URL##*/}" | |
140 DownloadOrCopy ${CS_URL} ${tarball} | |
141 | |
142 SubBanner "Untaring ${INSTALL_ROOT}/${tarball}" | |
143 tar jxf ${tarball} -C ${INSTALL_ROOT} | |
144 | |
145 pushd ${INSTALL_ROOT} | |
146 mv mips-* mips-release | |
147 popd | |
148 } | |
149 | |
150 | |
151 InstallTrustedLinkerScript() { | |
152 local trusted_ld_script=${INSTALL_ROOT}/ld_script_mips_trusted | |
153 # We are using the output of "ld --verbose" which contains | |
154 # the linker script delimited by "=========". | |
155 # We are changing the image start address to 70000000 | |
156 # to move the sel_ldr and other images "out of the way" | |
157 Banner "installing trusted linker script to ${trusted_ld_script}" | |
158 | |
159 ${CS_ROOT}/bin/mips-linux-gnu-ld --verbose |\ | |
160 grep -A 10000 "=======" |\ | |
161 grep -v "=======" |\ | |
162 sed -e 's/0400000/70000000/g' > ${trusted_ld_script} | |
163 } | |
164 | |
165 | |
166 InstallMissingHeaders() { | |
167 Banner "installing openssl headers from local system" | |
168 cp -r /usr/include/openssl ${JAIL_MIPS32}/usr/include/ | |
169 } | |
170 | |
171 | |
172 MissingSharedLibCleanup() { | |
173 Banner "Cleanup dangling symlinks" | |
174 } | |
175 | |
176 # ---------------------------------------------------------------------- | |
177 # mips32 deb files to complete our code sourcery jail | |
178 # ---------------------------------------------------------------------- | |
179 | |
180 readonly REPO_DEBIAN=http://ftp.debian.org/debian | |
181 readonly MIPS32_PACKAGES=${REPO_DEBIAN}/dists/squeeze/main/binary-mipsel/Package s.bz2 | |
182 | |
183 readonly TMP_PACKAGELIST_MIPS32=${TMP}/../packagelist_mipsel.tmp | |
184 | |
185 # These are good enough for native client | |
186 readonly BASE_PACKAGES="\ | |
187 libssl0.9.8 \ | |
188 libssl-dev \ | |
189 libx11-6 \ | |
190 libx11-dev \ | |
191 x11proto-core-dev \ | |
192 libxt6 \ | |
193 libxt-dev \ | |
194 zlib1g \ | |
195 zlib1g-dev \ | |
196 libasound2 \ | |
197 libasound2-dev \ | |
198 libaa1 \ | |
199 libaa1-dev \ | |
200 libxau-dev \ | |
201 libxau6 \ | |
202 libxcb1 \ | |
203 libxcb1-dev \ | |
204 libxcb-render0 \ | |
205 libxcb-render0-dev \ | |
206 libxcb-render-util0 \ | |
207 libxcb-render-util0-dev \ | |
208 libxcb-shm0 \ | |
209 libxcb-shm0-dev \ | |
210 libxdmcp6 \ | |
211 libxdmcp-dev \ | |
212 libxss1 \ | |
213 libxss-dev" | |
214 | |
215 GeneratePackageLists() { | |
216 Banner "generating package lists for mips32" | |
217 echo -n > ${TMP_PACKAGELIST_MIPS32} | |
218 DownloadOrCopy ${MIPS32_PACKAGES} ${TMP}/../Packages_mipsel.bz2 | |
219 bzcat ${TMP}/../Packages_mipsel.bz2 | egrep '^(Package:|Filename:)' > ${TMP}/. ./Packages_mipsel | |
robertm
2012/08/07 17:55:19
break line before pipe
| |
220 for pkg in ${BASE_PACKAGES} ; do | |
221 grep -A 1 "${pkg}\$" ${TMP}/../Packages_mipsel | egrep -o "pool/.*" >> ${TM P_PACKAGELIST_MIPS32} | |
robertm
2012/08/07 17:55:19
break line before pipe
| |
222 done | |
223 } | |
224 | |
225 InstallMissingLibraries() { | |
226 readonly DEP_FILES_NEEDED_MIPS32=$(cat ${TMP_PACKAGELIST_MIPS32}) | |
227 for file in ${DEP_FILES_NEEDED_MIPS32} ; do | |
228 local package="${TMP}/${file##*/}" | |
229 Banner "installing ${file}" | |
230 DownloadOrCopy ${REPO_DEBIAN}/${file} ${package} | |
231 SubBanner "extracting to ${JAIL_MIPS32}" | |
232 dpkg --fsys-tarfile ${package}\ | |
233 | tar -xvf - --exclude=./usr/share -C ${JAIL_MIPS32} | |
234 done | |
235 | |
236 Banner "some cleanup" | |
237 | |
238 pushd ${JAIL_MIPS32}/usr/lib/ | |
239 cleanlinks > /dev/null 2> /dev/null | |
240 FixLibs | |
241 popd | |
242 } | |
243 | |
244 FixLibs() { | |
245 Banner "Fixing libraries" | |
246 | |
247 rm -f libbz2.so | |
248 ln -s ../../lib/libbz2.so.1 libbz2.so | |
249 | |
250 rm -f libm.so | |
251 ln -s ../../lib/libm.so.6 libm.so | |
252 | |
253 rm -f libdl.so | |
254 ln -s ../../lib/libdl.so.2 libdl.so | |
255 | |
256 rm -f librt.so | |
257 ln -s ../../lib/librt.so.1 librt.so | |
258 | |
259 rm -f libpcre.so | |
260 ln -s ../../lib/libpcre.so.3 libpcre.so | |
261 | |
262 rm -f libresolv.so | |
263 ln -s ../../lib/libresolv.so.2 libresolv.so | |
264 | |
265 echo "OUTPUT_FORMAT(elf32-tradlittlemips)" > libc.so | |
266 echo "GROUP ( libc.so.6 libc_nonshared.a AS_NEEDED ( ld.so.1 ) )" >> libc.so | |
267 | |
268 echo "OUTPUT_FORMAT(elf32-tradlittlemips)" > libpthread.so | |
269 echo "GROUP ( libpthread.so.0 libpthread_nonshared.a )" >> libpthread.so | |
270 } | |
271 | |
272 BuildAndInstallQemu() { | |
273 local saved_dir=$(pwd) | |
274 local tmpdir="${TMP}/qemu-mips.nacl" | |
275 local tarball="qemu-0.12.5.tar.gz" | |
276 Banner "Building qemu in ${tmpdir}" | |
277 rm -rf ${tmpdir} | |
278 mkdir ${tmpdir} | |
279 cd ${tmpdir} | |
280 SubBanner "Downloading" | |
281 wget -c ${DOWNLOAD_QEMU_URL} | |
282 SubBanner "Untaring" | |
283 tar zxf ${tarball} | |
284 cd qemu-0.12.5 | |
285 SubBanner "Patching" | |
286 patch -p1 < ${PATCH_MIPS32} | |
287 | |
288 echo | |
289 echo "NOTE: on 64 bit systems you will need to the following 32bit libs:" | |
290 echo "lib32z1-dev" | |
291 echo | |
292 | |
293 SubBanner "Configuring" | |
294 env -i PATH=/usr/bin/:/bin \ | |
295 ./configure \ | |
296 --cc=${CC32} \ | |
297 --disable-system \ | |
298 --enable-linux-user \ | |
299 --disable-darwin-user \ | |
300 --disable-bsd-user \ | |
301 --target-list=mipsel-linux-user \ | |
302 --disable-sdl \ | |
303 --disable-linux-aio \ | |
304 --static | |
305 | |
306 SubBanner "Make" | |
307 env -i PATH=/usr/bin/:/bin \ | |
308 make MAKE_OPTS=${MAKE_OPTS} | |
309 | |
310 SubBanner "Install" | |
311 cp mipsel-linux-user/qemu-mipsel ${INSTALL_ROOT}/qemu-mips32 | |
312 cd ${saved_dir} | |
313 cp tools/trusted_cross_toolchains/qemu_tool_mips32.sh ${INSTALL_ROOT} | |
314 ln -sf qemu_tool_mips32.sh ${INSTALL_ROOT}/run_under_qemu_mips32 | |
315 } | |
316 ###################################################################### | |
317 # Main | |
318 ###################################################################### | |
319 | |
320 if [[ $# -eq 0 ]] ; then | |
321 echo "you must specify a mode on the commandline:" | |
322 echo | |
323 Usage | |
324 exit -1 | |
325 | |
326 elif [[ $1 == "trusted_sdk" ]]; then | |
327 mkdir -p ${TMP} | |
328 SanityCheck | |
329 ClearInstallDir | |
330 DownloadOrCopyAndInstallCodeSourceryTarball | |
331 PruneDirs | |
332 GeneratePackageLists | |
333 InstallMissingHeaders | |
334 InstallMissingLibraries | |
335 MissingSharedLibCleanup | |
336 InstallTrustedLinkerScript | |
337 BuildAndInstallQemu | |
338 CreateTarBall $1 | |
339 | |
340 else | |
341 Usage | |
342 exit -1 | |
343 | |
344 fi | |
345 | |
OLD | NEW |