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="\
69 libc6-dev-armhf-cross \
71 libgomp1-armhf-cross \
72 linux-libc-dev-armhf-cross \
73 libgcc1-dbg-armhf-cross \
74 libgomp1-dbg-armhf-cross \
75 binutils-arm-linux-gnueabihf \
76 cpp-arm-linux-gnueabihf \
77 gcc-arm-linux-gnueabihf \
78 g++-arm-linux-gnueabihf \
79 cpp-4.5-arm-linux-gnueabihf \
80 gcc-4.5-arm-linux-gnueabihf \
81 g++-4.5-arm-linux-gnueabihf \
82 libmudflap0-dbg-armhf-cross
85 # Jail packages: these are good enough for native client
86 # NOTE: the package listing here should be updated using the
87 # GeneratePackageListXXX() functions below
88 readonly ARMEL_BASE_PACKAGES="\
103 # Additional jail packages needed to build chrome
104 # NOTE: the package listing here should be updated using the
105 # GeneratePackageListXXX() functions below
106 readonly ARMEL_BASE_DEP_LIST="${SCRIPT_DIR}/packagelist.precise.armhf.base"
107 readonly ARMEL_BASE_DEP_FILES="$(cat ${ARMEL_BASE_DEP_LIST})"
109 readonly ARMEL_EXTRA_PACKAGES="\
119 libcairo-script-interpreter2 \
143 libgdk-pixbuf2.0-dev \
147 libgnutls-openssl27 \
155 libgnome-keyring-dev \
186 libpulse-mainloop-glib0 \
224 x11proto-composite-dev \
225 x11proto-damage-dev \
230 x11proto-record-dev \
231 x11proto-render-dev \
232 x11proto-scrnsaver-dev \
235 # NOTE: the package listing here should be updated using the
236 # GeneratePackageListXXX() functions below
237 readonly ARMEL_EXTRA_DEP_LIST="${SCRIPT_DIR}/packagelist.precise.armhf.extra"
238 readonly ARMEL_EXTRA_DEP_FILES="$(cat ${ARMEL_EXTRA_DEP_LIST})"
240 ######################################################################
242 ######################################################################
245 echo "######################################################################"
247 echo "######################################################################"
252 echo "......................................................................"
254 echo "......................................................................"
259 egrep "^#@" $0 | cut --bytes=3-
264 if [[ -f "$2" ]] ; then
265 echo "$2 already in place"
266 elif [[ $1 =~ 'http://' ]] ; then
267 SubBanner "downloading from $1 -> $2"
270 SubBanner "copying from $1"
276 # some sanity checks to make sure this script is run from the right place
277 # with the right tools
279 Banner "Sanity Checks"
281 if [[ $(basename $(pwd)) != "native_client" ]] ; then
282 echo "ERROR: run this script from the native_client/ dir"
286 if ! mkdir -p "${INSTALL_ROOT}" ; then
287 echo "ERROR: ${INSTALL_ROOT} can't be created."
291 if ! mkdir -p "${TMP}" ; then
292 echo "ERROR: ${TMP} can't be created."
296 for tool in ${REQUIRED_TOOLS} ; do
297 if ! which ${tool} ; then
298 echo "Required binary $tool not found."
307 # Change direcotry to top 'native_client' directory.
308 cd $(dirname ${BASH_SOURCE})
313 # TODO(robertm): consider wiping all of ${BASE_DIR}
315 Banner "clearing dirs in ${INSTALL_ROOT}"
316 rm -rf ${INSTALL_ROOT}/*
322 Banner "creating tar ball ${tarball}"
323 tar cfz ${tarball} -C ${INSTALL_ROOT} .
326 ######################################################################
327 # One of these has to be run ONCE per machine
328 ######################################################################
331 #@ InstallCrossArmBasePackages
333 #@ Install packages needed for arm cross compilation.
334 InstallCrossArmBasePackages() {
335 sudo apt-get install ${CROSS_ARM_TC_PACKAGES}
338 ######################################################################
340 ######################################################################
343 #@ InstallTrustedLinkerScript
345 #@ This forces the loading address of sel_ldr like programs
346 #@ to higher memory areas where they do not conflict with
347 #@ untrusted binaries.
348 #@ This likely no longer used because of "nacl_helper_bootstrap".
349 InstallTrustedLinkerScript() {
350 local trusted_ld_script=${INSTALL_ROOT}/ld_script_arm_trusted
351 # We are using the output of "ld --verbose" which contains
352 # the linker script delimited by "=========".
353 # We are changing the image start address to 70000000
354 # to move the sel_ldr and other images "out of the way"
355 Banner "installing trusted linker script to ${trusted_ld_script}"
357 arm-linux-gnueabihf-ld --verbose |\
358 grep -A 10000 "=======" |\
360 sed -e 's/00008000/70000000/g' > ${trusted_ld_script}
364 rel_path=toolchain/linux_x86/arm_trusted
365 Banner "Misc Hacks & Patches"
366 # these are linker scripts with absolute pathnames in them
367 # which we rewrite here
368 lscripts="${rel_path}/usr/lib/arm-linux-gnueabihf/libpthread.so \
369 ${rel_path}/usr/lib/arm-linux-gnueabihf/libc.so"
371 SubBanner "Rewriting Linker Scripts"
375 sed -i -e 's|/usr/lib/arm-linux-gnueabihf/||g' ${lscripts}
376 sed -i -e 's|/lib/arm-linux-gnueabihf/||g' ${lscripts}
378 # This is for chrome's ./build/linux/pkg-config-wrapper
379 # which overwrites PKG_CONFIG_PATH internally
380 SubBanner "Package Configs Symlink"
381 mkdir -p ${rel_path}/usr/share
382 ln -s ../lib/arm-linux-gnueabihf/pkgconfig ${rel_path}/usr/share/pkgconfig
386 InstallMissingArmLibrariesAndHeadersIntoJail() {
387 Banner "Install Libs And Headers Into Jail"
389 mkdir -p ${TMP}/armhf-packages
390 mkdir -p ${INSTALL_ROOT}
392 local package="${TMP}/armhf-packages/${file##*/}"
393 Banner "installing ${file}"
394 DownloadOrCopy ${ARMEL_REPO}/pool/${file} ${package}
395 SubBanner "extracting to ${INSTALL_ROOT}"
396 if [[ ! -s ${package} ]] ; then
398 echo "ERROR: bad package ${package}"
401 dpkg --fsys-tarfile ${package}\
402 | tar -xvf - --exclude=./usr/share -C ${INSTALL_ROOT}
407 CleanupJailSymlinks() {
408 Banner "jail symlink cleanup"
410 pushd ${INSTALL_ROOT}
411 find usr/lib -type l -printf '%p %l\n' | while read link target; do
412 # skip links with non-absolute paths
413 if [[ ${target} != /* ]] ; then
416 echo "${link}: ${target}"
418 usr/lib/arm-linux-gnueabihf/*)
419 # Relativize the symlink.
420 ln -snfv "../../..${target}" "${link}"
423 # Relativize the symlink.
424 ln -snfv "../..${target}" "${link}"
429 find usr/lib -type l -printf '%p %l\n' | while read link target; do
430 if [ ! -r "${link}" ]; then
431 echo "ERROR: FOUND BAD LINK ${link}"
439 #@ BuildAndInstallQemu
441 #@ Build ARM emulator including some patches for better tracing
444 # Traditionally we were building static 32 bit images of qemu on a
445 # 64bit system which would run then on both x86-32 and x86-64 systems.
446 # The latest version of qemu contains new dependencies which
447 # currently make it impossible to build such images on 64bit systems
448 # We can build a static 64bit qemu but it does not work with
449 # the sandboxed translators for unknown reason.
450 # So instead we chose to build 32bit shared images.
453 readonly QEMU_TARBALL=$(readlink -f ../third_party/qemu/qemu-1.0.1.tar.gz)
454 readonly QEMU_PATCH=$(readlink -f ../third_party/qemu/qemu-1.0.1.patch_arm)
455 readonly QEMU_DIR=qemu-1.0.1
457 BuildAndInstallQemu() {
458 local saved_dir=$(pwd)
459 local tmpdir="${TMP}/qemu.nacl"
461 Banner "Building qemu in ${tmpdir}"
463 if [[ -z "$QEMU_TARBALL" ]] ; then
464 echo "ERROR: missing qemu tarball: ../third_party/qemu/qemu-1.0.1.tar.gz"
471 SubBanner "Untaring ${QEMU_TARBALL}"
472 tar zxf ${QEMU_TARBALL}
475 SubBanner "Patching ${QEMU_PATCH}"
476 patch -p1 < ${QEMU_PATCH}
478 SubBanner "Configuring"
479 env -i PATH=/usr/bin/:/bin \
481 --extra-cflags="-m32" \
482 --extra-ldflags="-Wl,-rpath=/lib32" \
484 --enable-linux-user \
485 --disable-darwin-user \
487 --target-list=arm-linux-user \
488 --disable-smartcard-nss \
491 # see above for why we can no longer use -static
495 env -i PATH=/usr/bin/:/bin \
496 V=99 make MAKE_OPTS=${MAKE_OPTS}
498 SubBanner "Install ${INSTALL_ROOT}"
499 cp arm-linux-user/qemu-arm ${INSTALL_ROOT}
501 cp tools/trusted_cross_toolchains/qemu_tool_arm.sh ${INSTALL_ROOT}
502 ln -sf qemu_tool_arm.sh ${INSTALL_ROOT}/run_under_qemu_arm
506 #@ BuildJail <tarball-name>
508 #@ Build everything and package it
511 InstallMissingArmLibrariesAndHeadersIntoJail \
512 ${ARMEL_BASE_DEP_FILES} \
513 ${ARMEL_EXTRA_DEP_FILES}
515 InstallTrustedLinkerScript
522 # GeneratePackageList
524 # Looks up package names in ${TMP}/Packages and write list of URLs
527 GeneratePackageList() {
529 echo "Updating: ${output_file}"
530 /bin/rm -f ${output_file}
533 local pkg_full=$(grep -A 1 "${pkg}\$" ${TMP}/Packages | tail -1 | egrep -o "pool/.*")
534 if [[ -z ${pkg_full} ]]; then
535 echo "ERROR: missing package: $pkg"
538 echo $pkg_full | sed "s/^pool\///" >> $output_file
540 # sort -o does an in-place sort of this file
541 sort $output_file -o $output_file
545 #@ UpdatePackageLists
547 #@ Regenerate the armhf package lists such that they contain an up-to-date
548 #@ list of URLs within the ubuntu archive.
550 UpdatePackageLists() {
551 local package_list="${TMP}/Packages.precise.bz2"
552 local package_list2="${TMP}/Packages.precise-security.bz2"
553 DownloadOrCopy ${PACKAGE_LIST} ${package_list}
554 DownloadOrCopy ${PACKAGE_LIST2} ${package_list2}
555 bzcat ${package_list} ${package_list2} | egrep '^(Package:|Filename:)' > ${TMP}/Packages
557 GeneratePackageList ${ARMEL_BASE_DEP_LIST} "${ARMEL_BASE_PACKAGES}"
558 GeneratePackageList ${ARMEL_EXTRA_DEP_LIST} "${ARMEL_EXTRA_PACKAGES}"
561 if [[ $# -eq 0 ]] ; then
562 echo "ERROR: you must specify a mode on the commandline"
566 elif [[ "$(type -t $1)" != "function" ]]; then
567 echo "ERROR: unknown function '$1'." >&2
568 echo "For help, try:"