| 1 | # |
| 2 | # SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 3 | # |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | # |
| 6 | |
| 7 | # Ubuntu base version |
| 8 | ARG UBUNTU_VERSION=24.04 |
| 9 | |
| 10 | FROM ubuntu:${UBUNTU_VERSION} |
| 11 | |
| 12 | # These arguments are required to support multi-arch images |
| 13 | ARG BUILDARCH |
| 14 | ARG BUILDPLATFORM |
| 15 | ARG TARGETARCH |
| 16 | ARG TARGETOS |
| 17 | ARG TARGETPLATFORM |
| 18 | |
| 19 | # Component versions |
| 20 | ARG FVP_UBUNTU_VERSION=24.04.3 |
| 21 | ARG BAZEL_BUILD_TOOLS_VER=v8.2.1 |
| 22 | ARG BAZELISK_VERSION=v1.26.0 |
| 23 | ARG NDK_VERSION=r27d |
| 24 | ARG FVP_VERSION=11.29_42 |
| 25 | |
| 26 | ENV XDG_CACHE_HOME=/cache ANDROID_NDK=/opt/devtools/android-ndk BUILD_CACHE=/build_cache |
| 27 | |
| 28 | RUN mkdir -p /opt/devtools ${XDG_CACHE_HOME} |
| 29 | |
| 30 | # Software from base image required during image usage |
| 31 | RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 32 | --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 33 | apt-get update \ |
| 34 | && DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \ |
| 35 | build-essential \ |
| 36 | ca-certificates \ |
| 37 | clang \ |
| 38 | clang-tidy \ |
| 39 | cmake \ |
| 40 | curl \ |
| 41 | e2tools \ |
| 42 | gcovr \ |
| 43 | git \ |
| 44 | llvm \ |
| 45 | libclang-rt-dev \ |
| 46 | ninja-build \ |
| 47 | pre-commit \ |
| 48 | python3 \ |
| 49 | python3-pip \ |
| 50 | reuse \ |
| 51 | unzip \ |
| 52 | wget |
| 53 | |
| 54 | # Software from base image required during image build |
| 55 | RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 56 | --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 57 | apt-get update && \ |
| 58 | DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install \ |
| 59 | autoconf \ |
| 60 | automake \ |
| 61 | device-tree-compiler \ |
| 62 | flex \ |
| 63 | bison \ |
| 64 | bc \ |
| 65 | libssl-dev \ |
| 66 | genext2fs \ |
| 67 | ccache |
| 68 | |
| 69 | WORKDIR /opt/devtools |
| 70 | |
| 71 | # ============================================================================= |
| 72 | # Linux virtual machine on FVP. |
| 73 | # ============================================================================= |
| 74 | |
| 75 | # Downloads the latest Fixed Virtual Platform. |
| 76 | # The links could be found at https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms/Arm%20Architecture%20FVPs |
| 77 | RUN --mount=type=cache,target=${BUILD_CACHE} <<EOF |
| 78 | FVP_NAME=FVP_Base_RevC-2xAEMvA_${FVP_VERSION}_Linux64$(test "${TARGETARCH}" = "arm64" && echo -n "_armv8l") |
| 79 | set -e |
| 80 | # Public URL changes quite frequent and using a different scheme. Try each variant sequentially for a bit of backward compatibility |
| 81 | for FVP_BASE_VERSION in $(echo -n ${FVP_VERSION} | cut -d '_' -f 1) $(echo -n ${FVP_VERSION} | tr '_' '-') ; do |
| 82 | wget -cO ${BUILD_CACHE}/${FVP_NAME}.tgz \ |
| 83 | "https://developer.arm.com/-/cdn-downloads/permalink/FVPs-Architecture/FM-${FVP_BASE_VERSION}/${FVP_NAME}.tgz" && break |
| 84 | done |
| 85 | set +e |
| 86 | mkdir -vp ${FVP_NAME} |
| 87 | tar xzf ${BUILD_CACHE}/${FVP_NAME}.tgz -C ${FVP_NAME} |
| 88 | ln -s /opt/devtools/${FVP_NAME}/Base_RevC_AEMvA_pkg /opt/devtools/fvp_base_aemva |
| 89 | EOF |
| 90 | |
| 91 | # Creates the root filesystem. |
| 92 | RUN --mount=type=cache,target=${BUILD_CACHE},sharing=locked \ |
| 93 | export UBUNTU_DISTRO_VERSION=$(echo -n "$FVP_UBUNTU_VERSION" | cut -d '.' -f 1,2) && \ |
| 94 | wget -cO ${BUILD_CACHE}/ubuntu-base-${FVP_UBUNTU_VERSION}-base-arm64.tar.gz "https://cdimage.ubuntu.com/ubuntu-base/releases/${UBUNTU_DISTRO_VERSION}/release/ubuntu-base-${FVP_UBUNTU_VERSION}-base-arm64.tar.gz" && \ |
| 95 | genext2fs -a ${BUILD_CACHE}/ubuntu-base-${FVP_UBUNTU_VERSION}-base-arm64.tar.gz -B 4096 -b 51200 linux-rootfs.img |
| 96 | |
| 97 | # Compiles the latest Linux kernel, bootloader and root file system for FVP usage |
| 98 | RUN --mount=type=cache,target=${BUILD_CACHE},sharing=locked \ |
| 99 | --mount=type=bind,source=build_linux_bootloader.sh,target=build_linux_bootloader.sh \ |
| 100 | ./build_linux_bootloader.sh |
| 101 | |
| 102 | WORKDIR / |
| 103 | |
| 104 | # Download and install bazelisk |
| 105 | RUN wget "https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_VERSION}/bazelisk-${TARGETOS}-${TARGETARCH}" -O /usr/bin/bazelisk && \ |
| 106 | chmod a+x /usr/bin/bazelisk |
| 107 | |
| 108 | RUN wget "https://github.com/bazelbuild/buildtools/releases/download/${BAZEL_BUILD_TOOLS_VER}/buildifier-${TARGETOS}-${TARGETARCH}" -O /usr/bin/buildifier && \ |
| 109 | wget "https://github.com/bazelbuild/buildtools/releases/download/${BAZEL_BUILD_TOOLS_VER}/buildozer-${TARGETOS}-${TARGETARCH}" -O /usr/bin/buildozer && \ |
| 110 | wget "https://github.com/bazelbuild/buildtools/releases/download/${BAZEL_BUILD_TOOLS_VER}/unused_deps-${TARGETOS}-${TARGETARCH}" -O /usr/bin/unused_deps && \ |
| 111 | chmod a+x /usr/bin/buildifier /usr/bin/buildozer /usr/bin/unused_deps |
| 112 | |
| 113 | # Android NDK for amd64 only |
| 114 | RUN --mount=type=cache,target=${BUILD_CACHE} \ |
| 115 | if [ "${TARGETARCH}" = "amd64" ] ; then \ |
| 116 | wget -cO ${BUILD_CACHE}/android-ndk-${NDK_VERSION}-${TARGETOS}.zip "https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-${TARGETOS}.zip" && \ |
| 117 | unzip ${BUILD_CACHE}/android-ndk-${NDK_VERSION}-${TARGETOS}.zip -d /opt/devtools/ && \ |
| 118 | ln -s /opt/devtools/android-ndk-${NDK_VERSION} ${ANDROID_NDK}; \ |
| 119 | fi |