2 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 #@ This script builds the (trusted) cross toolchain for arm.
7 #@ It must be run from the native_client/ directory.
9 #@ The toolchain consists primarily of a jail with arm header and libraries.
10 #@ It also provides additional tools such as QEMU.
11 #@ It does NOT provide the actual cross compiler anymore.
12 #@ The cross compiler is now comming straight from a debian package.
13 #@ So there is a one-time step required for all machines using this TC.
14 #@ Which is especially true for build-bots:
16 #@ tools/trusted_cross_toolchains/trusted-toolchain-creator.armhf.precise.sh InstallCrossArmBasePackages
19 #@ Generally this script is invoked as:
20 #@ tools/trusted_cross_toolchains/trusted-toolchain-creator.armhf.precise.sh <mode> <args>*
21 #@ Available modes are shown below.
23 #@ This Toolchain was tested with Ubuntu Precise
26 #@ compile: arm-linux-gnueabihf-gcc -march=armv7-a -isystem ${JAIL}/usr/include
27 #@ link: arm-linux-gnueabihf-gcc -L${JAIL}/usr/lib -L${JAIL}/usr/lib/arm-linux-gnueabihf
28 #@ -L${JAIL}/lib -L${JAIL}/lib/arm-linux-gnueabihf
35 ######################################################################
37 ######################################################################
42 readonly SCRIPT_DIR=$(dirname $0)
44 # this where we create the ARMEL "jail"
45 readonly INSTALL_ROOT=$(pwd)/toolchain/linux_x86/arm_trusted
47 readonly TMP=/tmp/armhf-crosstool-precise
49 readonly REQUIRED_TOOLS="wget"
51 readonly MAKE_OPTS="-j8"
53 ######################################################################
55 ######################################################################
57 # this where we get the cross toolchain from for the manual install:
58 readonly CROSS_ARM_TC_REPO=http://archive.ubuntu.com/ubuntu
59 # this is where we get all the armhf packages from
60 readonly ARMEL_REPO=http://ports.ubuntu.com/ubuntu-ports
62 readonly PACKAGE_LIST="${ARMEL_REPO}/dists/precise/main/binary-armhf/Packages.bz2"
63 readonly PACKAGE_LIST2="${ARMEL_REPO}/dists/precise-security/main/binary-armhf/Packages.bz2"
65 # Packages for the host system
66 # NOTE: at one point we should get rid of the 4.5 packages
67 readonly CROSS_ARM_TC_PACKAGES="\
68 g++-arm-linux-gnueabihf \
69 libgomp1-dbg-armhf-cross \
70 libgcc1-dbg-armhf-cross \
71 libmudflap0-dbg-armhf-cross
74 # Jail packages: these are good enough for native client
75 # NOTE: the package listing here should be updated using the
76 # GeneratePackageListXXX() functions below
77 readonly ARMEL_BASE_PACKAGES="\
92 # Additional jail packages needed to build chrome
93 # NOTE: the package listing here should be updated using the
94 # GeneratePackageListXXX() functions below
95 readonly ARMEL_BASE_DEP_LIST="${SCRIPT_DIR}/packagelist.precise.armhf.base"
96 readonly ARMEL_BASE_DEP_FILES="$(cat ${ARMEL_BASE_DEP_LIST})"
98 readonly ARMEL_EXTRA_PACKAGES="\
108 libcairo-script-interpreter2 \
132 libgdk-pixbuf2.0-dev \
136 libgnutls-openssl27 \
144 libgnome-keyring-dev \
175 libpulse-mainloop-glib0 \
213 x11proto-composite-dev \
214 x11proto-damage-dev \
219 x11proto-record-dev \
220 x11proto-render-dev \
221 x11proto-scrnsaver-dev \
224 # NOTE: the package listing here should be updated using the
225 # GeneratePackageListXXX() functions below
226 readonly ARMEL_EXTRA_DEP_LIST="${SCRIPT_DIR}/packagelist.precise.armhf.extra"
227 readonly ARMEL_EXTRA_DEP_FILES="$(cat ${ARMEL_EXTRA_DEP_LIST})"
229 ######################################################################
231 ######################################################################
234 echo "######################################################################"
236 echo "######################################################################"
241 echo "......................................................................"
243 echo "......................................................................"
248 egrep "^#@" $0 | cut --bytes=3-
253 if [[ -f "$2" ]] ; then
254 echo "$2 already in place"
255 elif [[ $1 =~ 'http://' ]] ; then
256 SubBanner "downloading from $1 -> $2"
259 SubBanner "copying from $1"
265 # some sanity checks to make sure this script is run from the right place
266 # with the right tools
268 Banner "Sanity Checks"
270 if [[ $(basename $(pwd)) != "native_client" ]] ; then
271 echo "ERROR: run this script from the native_client/ dir"
275 if ! mkdir -p "${INSTALL_ROOT}" ; then
276 echo "ERROR: ${INSTALL_ROOT} can't be created."
280 if ! mkdir -p "${TMP}" ; then
281 echo "ERROR: ${TMP} can't be created."
285 for tool in ${REQUIRED_TOOLS} ; do
286 if ! which ${tool} ; then
287 echo "Required binary $tool not found."
296 # Change direcotry to top 'native_client' directory.
297 cd $(dirname ${BASH_SOURCE})
302 # TODO(robertm): consider wiping all of ${BASE_DIR}
304 Banner "clearing dirs in ${INSTALL_ROOT}"
305 rm -rf ${INSTALL_ROOT}/*
311 Banner "creating tar ball ${tarball}"
312 tar cfz ${tarball} -C ${INSTALL_ROOT} .
315 ######################################################################
316 # One of these has to be run ONCE per machine
317 ######################################################################
320 #@ InstallCrossArmBasePackages
322 #@ Install packages needed for arm cross compilation.
323 InstallCrossArmBasePackages() {
324 sudo apt-get install ${CROSS_ARM_TC_PACKAGES}
327 ######################################################################
329 ######################################################################
332 #@ InstallTrustedLinkerScript
334 #@ This forces the loading address of sel_ldr like programs
335 #@ to higher memory areas where they do not conflict with
336 #@ untrusted binaries.
337 #@ This likely no longer used because of "nacl_helper_bootstrap".
338 InstallTrustedLinkerScript() {
339 local trusted_ld_script=${INSTALL_ROOT}/ld_script_arm_trusted
340 # We are using the output of "ld --verbose" which contains
341 # the linker script delimited by "=========".
342 # We are changing the image start address to 70000000
343 # to move the sel_ldr and other images "out of the way"
344 Banner "installing trusted linker script to ${trusted_ld_script}"
346 arm-linux-gnueabihf-ld --verbose |\
347 grep -A 10000 "=======" |\
349 sed -e 's/00008000/70000000/g' > ${trusted_ld_script}
353 rel_path=toolchain/linux_x86/arm_trusted
354 Banner "Misc Hacks & Patches"
355 # these are linker scripts with absolute pathnames in them
356 # which we rewrite here
357 lscripts="${rel_path}/usr/lib/arm-linux-gnueabihf/libpthread.so \
358 ${rel_path}/usr/lib/arm-linux-gnueabihf/libc.so"
360 SubBanner "Rewriting Linker Scripts"
361 sed -i -e 's|/usr/lib/arm-linux-gnueabihf/||g' ${lscripts}
362 sed -i -e 's|/lib/arm-linux-gnueabihf/||g' ${lscripts}
364 # This is for chrome's ./build/linux/pkg-config-wrapper
365 # which overwrites PKG_CONFIG_PATH internally
366 SubBanner "Package Configs Symlink"
367 mkdir -p ${rel_path}/usr/share
368 ln -s ../lib/arm-linux-gnueabihf/pkgconfig ${rel_path}/usr/share/pkgconfig
372 InstallMissingArmLibrariesAndHeadersIntoJail() {
373 Banner "Install Libs And Headers Into Jail"
375 mkdir -p ${TMP}/armhf-packages
376 mkdir -p ${INSTALL_ROOT}
378 local package="${TMP}/armhf-packages/${file##*/}"
379 Banner "installing ${file}"
380 DownloadOrCopy ${ARMEL_REPO}/pool/${file} ${package}
381 SubBanner "extracting to ${INSTALL_ROOT}"
382 if [[ ! -s ${package} ]] ; then
384 echo "ERROR: bad package ${package}"
387 dpkg --fsys-tarfile ${package}\
388 | tar -xvf - --exclude=./usr/share -C ${INSTALL_ROOT}
393 CleanupJailSymlinks() {
394 Banner "jail symlink cleanup"
396 pushd ${INSTALL_ROOT}
397 find usr/lib -type l -printf '%p %l\n' | while read link target; do
398 # skip links with non-absolute paths
399 if [[ ${target} != /* ]] ; then
402 echo "${link}: ${target}"
404 usr/lib/arm-linux-gnueabihf/*)
405 # Relativize the symlink.
406 ln -snfv "../../..${target}" "${link}"
409 # Relativize the symlink.
410 ln -snfv "../..${target}" "${link}"
415 find usr/lib -type l -printf '%p %l\n' | while read link target; do
416 if [ ! -r "${link}" ]; then
417 echo "ERROR: FOUND BAD LINK ${link}"
425 #@ BuildAndInstallQemu
427 #@ Build ARM emulator including some patches for better tracing
430 # Traditionally we were building static 32 bit images of qemu on a
431 # 64bit system which would run then on both x86-32 and x86-64 systems.
432 # The latest version of qemu contains new dependencies which
433 # currently make it impossible to build such images on 64bit systems
434 # We can build a static 64bit qemu but it does not work with
435 # the sandboxed translators for unknown reason.
436 # So instead we chose to build 32bit shared images.
439 readonly QEMU_TARBALL=$(readlink -f ../third_party/qemu/qemu-1.0.1.tar.gz)
440 readonly QEMU_PATCH=$(readlink -f ../third_party/qemu/qemu-1.0.1.patch_arm)
441 readonly QEMU_DIR=qemu-1.0.1
443 BuildAndInstallQemu() {
444 local saved_dir=$(pwd)
445 local tmpdir="${TMP}/qemu.nacl"
447 Banner "Building qemu in ${tmpdir}"
449 if [[ -z "$QEMU_TARBALL" ]] ; then
450 echo "ERROR: missing qemu tarball: ../third_party/qemu/qemu-1.0.1.tar.gz"
457 SubBanner "Untaring ${QEMU_TARBALL}"
458 tar zxf ${QEMU_TARBALL}
461 SubBanner "Patching ${QEMU_PATCH}"
462 patch -p1 < ${QEMU_PATCH}
464 SubBanner "Configuring"
465 env -i PATH=/usr/bin/:/bin \
467 --extra-cflags="-m32" \
468 --extra-ldflags="-Wl,-rpath=/lib32" \
470 --enable-linux-user \
471 --disable-darwin-user \
473 --target-list=arm-linux-user \
474 --disable-smartcard-nss \
477 # see above for why we can no longer use -static
481 env -i PATH=/usr/bin/:/bin \
482 V=99 make MAKE_OPTS=${MAKE_OPTS}
484 SubBanner "Install ${INSTALL_ROOT}"
485 cp arm-linux-user/qemu-arm ${INSTALL_ROOT}
487 cp tools/trusted_cross_toolchains/qemu_tool_arm.sh ${INSTALL_ROOT}
488 ln -sf qemu_tool_arm.sh ${INSTALL_ROOT}/run_under_qemu_arm
492 #@ BuildJail <tarball-name>
494 #@ Build everything and package it
497 InstallMissingArmLibrariesAndHeadersIntoJail \
498 ${ARMEL_BASE_DEP_FILES} \
499 ${ARMEL_EXTRA_DEP_FILES}
501 InstallTrustedLinkerScript
508 # GeneratePackageList
510 # Looks up package names in ${TMP}/Packages and write list of URLs
513 GeneratePackageList() {
515 echo "Updating: ${output_file}"
516 /bin/rm -f ${output_file}
519 local pkg_full=$(grep -A 1 "${pkg}\$" ${TMP}/Packages | tail -1 | egrep -o "pool/.*")
520 if [[ -z ${pkg_full} ]]; then
521 echo "ERROR: missing package: $pkg"
524 echo $pkg_full | sed "s/^pool\///" >> $output_file
526 # sort -o does an in-place sort of this file
527 sort $output_file -o $output_file
531 #@ UpdatePackageLists
533 #@ Regenerate the armhf package lists such that they contain an up-to-date
534 #@ list of URLs within the ubuntu archive.
536 UpdatePackageLists() {
537 local package_list="${TMP}/Packages.precise.bz2"
538 local package_list2="${TMP}/Packages.precise-security.bz2"
539 DownloadOrCopy ${PACKAGE_LIST} ${package_list}
540 DownloadOrCopy ${PACKAGE_LIST2} ${package_list2}
541 bzcat ${package_list} ${package_list2} | egrep '^(Package:|Filename:)' > ${TMP}/Packages
543 GeneratePackageList ${ARMEL_BASE_DEP_LIST} "${ARMEL_BASE_PACKAGES}"
544 GeneratePackageList ${ARMEL_EXTRA_DEP_LIST} "${ARMEL_EXTRA_PACKAGES}"
547 if [[ $# -eq 0 ]] ; then
548 echo "ERROR: you must specify a mode on the commandline"
552 elif [[ "$(type -t $1)" != "function" ]]; then
553 echo "ERROR: unknown function '$1'." >&2
554 echo "For help, try:"