From df339ac34258a5c66dfa98fbdad01155472141b3 Mon Sep 17 00:00:00 2001 From: Anton Bondarenko Date: Wed, 11 Jun 2025 18:09:49 +0200 Subject: [PATCH] Add SME/SME2 support for FVP image in CI Update Linux Kernel and bootloader-wrapper to versions supporting SME/SME2. This required to properly handle context switch with SME state preservation and restoration. Also address CPU boot issue by keep in sync number of CPUs used in bootloader/DTS and FVP configuration. Two CPUs used when first used for running system services and second one as isolated to run test programs. Linux Kernel: 6.16-rc2 (update to released version once available) Bootloader wrapper: latest available Signed-off-by: Anton Bondarenko --- .gitlab-ci.yml | 4 +- docker/Dockerfile | 1 + docker/build_linux_bootloader.sh | 65 +++++++++++++++++++++++++------- 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9ca03ac8..33ce35f0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -311,7 +311,9 @@ test-linux-aarch64: -C bp.terminal_2.start_telnet=0 \ -C bp.terminal_3.mode=raw \ -C bp.terminal_3.start_telnet=0 \ - -C cluster0.NUM_CORES=1 \ + -C pctl.startup=*.*.*.* \ + -C cluster1.NUM_CORES=0 \ + -C cluster0.NUM_CORES=2 \ -C cluster0.has_arm_v8-1=1 \ -C cluster0.has_arm_v8-2=1 \ -C cluster0.has_arm_v8-3=1 \ diff --git a/docker/Dockerfile b/docker/Dockerfile index 71ceef6a..7b78b009 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -73,6 +73,7 @@ WORKDIR /opt/devtools # ============================================================================= # Downloads the latest Fixed Virtual Platform. +# The links could be found at https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms/Arm%20Architecture%20FVPs RUN --mount=type=cache,target=${BUILD_CACHE} \ export FVP_NAME=FVP_Base_RevC-2xAEMvA_${FVP_VERSION}_Linux64$(test "${TARGETARCH}" = "arm64" && echo -n "_armv8l") && \ export FVP_BASE_VERSION=$(echo -n ${FVP_VERSION} | cut -d '_' -f 1) && \ diff --git a/docker/build_linux_bootloader.sh b/docker/build_linux_bootloader.sh index c843bd69..ab44c1d6 100755 --- a/docker/build_linux_bootloader.sh +++ b/docker/build_linux_bootloader.sh @@ -18,10 +18,13 @@ download_and_extract() tar -xa -f ${BUILD_CACHE}/${ARCHIVE} --strip-components=1 -C ${FOLDER} } -TARGETARCH=${TARGETARCH:-amd64} +TARGETARCH=${TARGETARCH:-$(if [ "`uname -m`" == "aarch64" ]; then echo "arm64"; else echo "amd64"; fi)} # This script is used by Dockerfile to create a Linux bootloader with the latest Linux kernel. -if [ "${TARGETARCH}" = "amd64" ] ; then +if [ "`uname -s`" = "Darwin" ]; then + HOST_ARCH=darwin-arm64 + TARGETARCH=arm64 +elif [ "${TARGETARCH}" = "amd64" ] ; then HOST_ARCH=x86_64 elif [ "${TARGETARCH}" = "arm64" ] ; then HOST_ARCH=aarch64 @@ -29,34 +32,42 @@ else echo "Unknown $TARGETARCH" && exit 1 fi -TOOLCHAIN_VER=14.2.rel1 +TOOLCHAIN_VERSION=14.2.rel1 TOOLCHAIN_TYPE=aarch64-none-elf -TOOLCHAIN_DIR=$(pwd)/toolchain-${TOOLCHAIN_TYPE}/ +TOOLCHAIN_DIR=$(pwd)/toolchain-${TOOLCHAIN_TYPE} CROSS_COMPILE=${TOOLCHAIN_DIR}/bin/${TOOLCHAIN_TYPE}- -KERNEL_VERSION=6.12.30 +KERNEL_VERSION=6.16-rc2 +# Derive DTS version from kernel version +DTS_VERSION=$(echo $KERNEL_VERSION | cut -d '.' -f 1,2) +BOOTLOADER_VERSION=785302c1f7b9eceab3b72a8cb3d79eaf526fd2e3 mkdir -p ${BUILD_CACHE} # Downloads tools and source code. # Download Arm toolchain download_and_extract \ - "https://developer.arm.com/-/media/Files/downloads/gnu/${TOOLCHAIN_VER}/binrel/arm-gnu-toolchain-${TOOLCHAIN_VER}-${HOST_ARCH}-${TOOLCHAIN_TYPE}.tar.xz" \ + "https://developer.arm.com/-/media/Files/downloads/gnu/${TOOLCHAIN_VERSION}/binrel/arm-gnu-toolchain-${TOOLCHAIN_VERSION}-${HOST_ARCH}-${TOOLCHAIN_TYPE}.tar.xz" \ "${TOOLCHAIN_DIR}" # Download Linux Kernel +if [[ "${KERNEL_VERSION}" =~ "-rc" ]]; then download_and_extract \ - "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${KERNEL_VERSION}.tar.xz" \ + "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/snapshot/linux-${KERNEL_VERSION}.tar.gz" \ "linux-${KERNEL_VERSION}" +else +download_and_extract \ + "https://cdn.kernel.org/pub/linux/kernel/v$(echo $KERNEL_VERSION | cut -d '.' -f 1).x/linux-${KERNEL_VERSION}.tar.xz" \ + "linux-${KERNEL_VERSION}" +fi # Download booloader -# Revision 1fea854771f9aee405c4ae204c0e0f912318da6f supports bare metal gcc, otherwise hosted toolchain should be used download_and_extract \ - "https://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git/snapshot/boot-wrapper-aarch64-1fea854771f9aee405c4ae204c0e0f912318da6f.tar.gz" \ + "https://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git/snapshot/boot-wrapper-aarch64-${BOOTLOADER_VERSION}.tar.gz" \ boot-wrapper-aarch64 # Download DTS tooling download_and_extract \ - "https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git/snapshot/devicetree-rebasing-$(echo $KERNEL_VERSION | cut -d '.' -f 1,2)-dts.tar.gz" \ + "https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git/snapshot/devicetree-rebasing-${DTS_VERSION}-dts.tar.gz" \ devicetree-rebasing # Builds the Linux kernel. @@ -67,7 +78,31 @@ cd .. # Builds the device tree. cd devicetree-rebasing -make CPP=${CROSS_COMPILE}cpp src/arm64/arm/fvp-base-revc.dtb +# Reduce number of CPUs to 2 and disable second cluster to keep in sync with FVP parameters. In FVP no more +# than 2 CPUs are needed. cpu0 to run Linux kernel and system services. cpu1 used to run a test program in isolation. +cat < src/arm64/arm/kleidiai_fvp.dts +/dts-v1/; + +#include "fvp-base-revc.dts" + +/delete-node/ &cpu2; +/delete-node/ &cpu3; +/delete-node/ &cpu4; +/delete-node/ &cpu5; +/delete-node/ &cpu6; +/delete-node/ &cpu7; +/delete-node/ &C1_L2; + +/ { + /delete-node/ ete-2; + /delete-node/ ete-3; + /delete-node/ ete-4; + /delete-node/ ete-5; + /delete-node/ ete-6; + /delete-node/ ete-7; +}; +EOF +make CPP=${CROSS_COMPILE}cpp src/arm64/arm/kleidiai_fvp.dtb cd .. # Builds the bootloader. @@ -75,12 +110,14 @@ cd boot-wrapper-aarch64 PATH=$(dirname ${CROSS_COMPILE}gcc):$PATH export PATH autoreconf -i -./configure --host=${TOOLCHAIN_TYPE} \ +# Extra CFLAGS are needed to avoid using standard libraries when using baremetal toolchain +# -O2 required as otherwise boot-wrapper would not boot +CFLAGS="-ffreestanding -nostdlib -O2" ./configure --host=${TOOLCHAIN_TYPE} \ --enable-psci \ --enable-gicv3 \ --with-kernel-dir=../linux-${KERNEL_VERSION} \ - --with-dtb=../devicetree-rebasing/src/arm64/arm/fvp-base-revc.dtb \ - --with-cmdline="console=ttyAMA0 earlycon=pl011,0x1c090000 panic=1 root=/dev/vda rw init=/bin/bash -- /root/startup" + --with-dtb=../devicetree-rebasing/src/arm64/arm/kleidiai_fvp.dtb \ + --with-cmdline="console=ttyAMA0 earlycon=pl011,0x1c090000 panic=1 root=/dev/vda rw isolcpus=1 init=/bin/bash -- /root/startup" make "-j$(nproc)" cd .. -- GitLab