blob: 23b83a3875801a068fefde7ddf2e74e0c215ce62 [file] [log] [blame]
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -o errtrace
trap 'echo Fatal error: script $0 aborting at line $LINENO, command \"$BASH_COMMAND\" returned $?; exit 1' ERR
snapshot="2021.01.07.200850"
snapshot_year=`echo $snapshot | cut -d . -f 1`
snapshot_month=`echo $snapshot | cut -d . -f 2`
snapshot_day=`echo $snapshot | cut -d . -f 3`
snapshot_time=`echo $snapshot | cut -d . -f 4`
glibc_version=2.27-r20
glibc_upgrade_snapshot="2022.05.02.091243"
glibc_upgrade_version=2.33-r16
glibc_upgrade_version_major=2.33
# Upgrade CrOS toolchain to GCC 4.9.x ${snapshot}
function build_toolchain_arm_none_eabi {
pushd ${SCRIPT_DIR}
rm -rf arm
# 1. Obtain {toolchain,glibc} prebuilts from Chrome OS.
gsutil.py cp gs://chromiumos-sdk/${snapshot_year}/${snapshot_month}/arm-none-eabi-${snapshot}.tar.xz .
gsutil.py cp gs://chromeos-prebuilt/host/amd64/amd64-host/chroot-${snapshot}/packages/cross-arm-none-eabi/newlib-2.2.0.tbz2 .
# 2. Extract downloaded toolchain (overwrite armv7a contents)
rm -rf arm
mkdir arm
tar -C arm -xf arm-none-eabi-${snapshot}.tar.xz
tar -C arm -xf newlib-2.2.0.tbz2
rm arm-none-eabi-${snapshot}.tar.xz newlib-2.2.0.tbz2
# 3. Make copies of libgcc_s.so.1 to fit with chromecast build system.
cp arm/lib/libgcc_s.so.1 arm/usr/arm-none-eabi/lib/
# 4. Add NOTICE files.
curl -L https://www.gnu.org/licenses/lgpl-2.1.txt > arm/usr/arm-none-eabi/NOTICE-eglibc
curl -L https://gnu.org/licenses/gpl-3.0.txt > arm/usr/arm-none-eabi/NOTICE-gdb
# 6. Customize default linker to be bfd, not gold.
sed -i -e "s/-gold//g" arm/bin/arm-none-eabi-ld
popd # ${SCRIPT_DIR}
}
# Upgrade CrOS toolchain to GCC 4.9.x ${snapshot}
function build_toolchain {
pushd ${SCRIPT_DIR}
local readonly arch=${1}
local readonly abi=${2}
rm -rf ${arch}
# 1. Obtain {toolchain,glibc} prebuilts from Chrome OS.
gsutil cp gs://chromiumos-sdk/${snapshot_year}/${snapshot_month}/${arch}-cros-linux-${abi}-${snapshot}.tar.xz .
gsutil cp gs://chromeos-prebuilt/host/amd64/amd64-host/chroot-${snapshot}/packages/cross-${arch}-cros-linux-${abi}/glibc-${glibc_version}.tbz2 .
gsutil cp gs://chromeos-prebuilt/host/amd64/amd64-host/chroot-${glibc_upgrade_snapshot}/packages/cross-${arch}-cros-linux-${abi}/glibc-${glibc_upgrade_version}.tbz2 .
# 2. Extract downloaded toolchain (overwrite armv7a contents)
rm -rf ${arch}
mkdir ${arch}
tar -C ${arch} -xf ${arch}-cros-linux-${abi}-${snapshot}.tar.xz
tar -C ${arch} -xf glibc-${glibc_version}.tbz2
rm ${arch}-cros-linux-${abi}-${snapshot}.tar.xz glibc-${glibc_version}.tbz2
mkdir -p ${arch}/glibc-${glibc_upgrade_version_major}
# The portage binary package format changed. It is now a concatenation of a
# zstd tar archive and the portage manifest. `tar` doesn't know how to unpack
# it.
#
# `q` is a tool built from google3. See the following instructions:
# https://g3doc.corp.google.com/company/teams/nest-localhome/development/code_to_device.md?cl=head
# TODO: Figure out a better way to do this.
q qtbz2 -t glibc-${glibc_upgrade_version}.tbz2
tar -C ${arch}/glibc-${glibc_upgrade_version_major} -axf glibc-${glibc_upgrade_version}.tar.bz2
rm glibc-${glibc_upgrade_version}.tbz2
rm glibc-${glibc_upgrade_version}.tar.bz2
# 3. Make copies of libgcc_s.so.1 to fit with chromecast build system.
cp ${arch}/usr/lib/gcc/${arch}-cros-linux-${abi}/4.9.x/libgcc_s.so.1 ${arch}/lib/
cp ${arch}/usr/lib/gcc/${arch}-cros-linux-${abi}/4.9.x/libgcc_s.so.1 ${arch}/usr/${arch}-cros-linux-${abi}/lib/
# 4. Add NOTICE files.
curl -L https://www.gnu.org/licenses/lgpl-2.1.txt > ${arch}/usr/${arch}-cros-linux-${abi}/NOTICE-eglibc
curl -L https://gnu.org/licenses/gpl-3.0.txt > ${arch}/usr/${arch}-cros-linux-${abi}/NOTICE-gdb
# 8. Apply our patches
# Remove any empty folders created by unzipping the toolchains that are not
# checked into git. Those can be problematic when applying patches.
find . -type d -empty -delete
pushd ${arch}
patch -p1 < ${SCRIPT_DIR}/patches/eureka.patch
popd
if [ -f ${SCRIPT_DIR}/patches/${arch}.patch ]; then
patch -p1 < ${SCRIPT_DIR}/patches/${arch}.patch
fi
popd # ${SCRIPT_DIR}
}
build_toolchain armv7a gnueabihf
build_toolchain aarch64 gnu
build_toolchain x86_64 gnu
build_toolchain_arm_none_eabi