Elffuss BraidHub

kikocis/kleidiai public

main · 4.2 KiB · executableRawPermalink
1#!/bin/bash -eux
2
3#
4# SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
5#
6# SPDX-License-Identifier: Apache-2.0
7#
8
9BUILD_CACHE=${BUILD_CACHE:-${HOME}/.cache/kleidiai}
10download_and_extract()
11{
12 URL="$1"
13 FOLDER="$2"
14 ARCHIVE="${3:-$(basename $1)}"
15
16 wget -cO ${BUILD_CACHE}/${ARCHIVE} "$URL"
17 mkdir -p ${FOLDER}
18 tar -xa -f ${BUILD_CACHE}/${ARCHIVE} --strip-components=1 -C ${FOLDER}
19}
20
21TARGETARCH=${TARGETARCH:-$(if [ "`uname -m`" == "aarch64" ]; then echo "arm64"; else echo "amd64"; fi)}
22
23# This script is used by Dockerfile to create a Linux bootloader with the latest Linux kernel.
24if [ "`uname -s`" = "Darwin" ]; then
25 HOST_ARCH=darwin-arm64
26 TARGETARCH=arm64
27elif [ "${TARGETARCH}" = "amd64" ] ; then
28 HOST_ARCH=x86_64
29elif [ "${TARGETARCH}" = "arm64" ] ; then
30 HOST_ARCH=aarch64
31else
32 echo "Unknown $TARGETARCH" && exit 1
33fi
34
35TOOLCHAIN_VERSION=14.3.rel1
36TOOLCHAIN_TYPE=aarch64-none-elf
37TOOLCHAIN_DIR=$(pwd)/toolchain-${TOOLCHAIN_TYPE}
38CROSS_COMPILE=${TOOLCHAIN_DIR}/bin/${TOOLCHAIN_TYPE}-
39KERNEL_VERSION=6.16
40# Derive DTS version from kernel version
41DTS_VERSION=$(echo $KERNEL_VERSION | cut -d '.' -f 1,2)
42BOOTLOADER_VERSION=785302c1f7b9eceab3b72a8cb3d79eaf526fd2e3
43
44mkdir -p ${BUILD_CACHE}
45
46# Downloads tools and source code.
47# Download Arm toolchain
48download_and_extract \
49 "https://developer.arm.com/-/media/Files/downloads/gnu/${TOOLCHAIN_VERSION}/binrel/arm-gnu-toolchain-${TOOLCHAIN_VERSION}-${HOST_ARCH}-${TOOLCHAIN_TYPE}.tar.xz" \
50 "${TOOLCHAIN_DIR}"
51
52# Download Linux Kernel
53if [[ "${KERNEL_VERSION}" =~ "-rc" ]]; then
54download_and_extract \
55 "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/snapshot/linux-${KERNEL_VERSION}.tar.gz" \
56 "linux-${KERNEL_VERSION}"
57else
58download_and_extract \
59 "https://cdn.kernel.org/pub/linux/kernel/v$(echo $KERNEL_VERSION | cut -d '.' -f 1).x/linux-${KERNEL_VERSION}.tar.xz" \
60 "linux-${KERNEL_VERSION}"
61fi
62
63# Download booloader
64download_and_extract \
65 "https://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git/snapshot/boot-wrapper-aarch64-${BOOTLOADER_VERSION}.tar.gz" \
66 boot-wrapper-aarch64
67
68# Download DTS tooling
69download_and_extract \
70 "https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git/snapshot/devicetree-rebasing-${DTS_VERSION}-dts.tar.gz" \
71 devicetree-rebasing
72
73# Builds the Linux kernel.
74cd linux-${KERNEL_VERSION}
75CCACHE_DIR=${BUILD_CACHE}/ccache make ARCH=arm64 CROSS_COMPILE="ccache ${CROSS_COMPILE}" defconfig
76CCACHE_DIR=${BUILD_CACHE}/ccache make ARCH=arm64 CROSS_COMPILE="ccache ${CROSS_COMPILE}" "-j$(nproc)" Image
77cd ..
78
79# Builds the device tree.
80cd devicetree-rebasing
81# Reduce number of CPUs to 2 and disable second cluster to keep in sync with FVP parameters. In FVP no more
82# than 2 CPUs are needed. cpu0 to run Linux kernel and system services. cpu1 used to run a test program in isolation.
83cat <<EOF > src/arm64/arm/kleidiai_fvp.dts
84/dts-v1/;
85
86#include "fvp-base-revc.dts"
87
88/delete-node/ &cpu2;
89/delete-node/ &cpu3;
90/delete-node/ &cpu4;
91/delete-node/ &cpu5;
92/delete-node/ &cpu6;
93/delete-node/ &cpu7;
94/delete-node/ &C1_L2;
95
96/ {
97 /delete-node/ ete-2;
98 /delete-node/ ete-3;
99 /delete-node/ ete-4;
100 /delete-node/ ete-5;
101 /delete-node/ ete-6;
102 /delete-node/ ete-7;
103};
104EOF
105make CPP=${CROSS_COMPILE}cpp src/arm64/arm/kleidiai_fvp.dtb
106cd ..
107
108# Builds the bootloader.
109cd boot-wrapper-aarch64
110PATH=$(dirname ${CROSS_COMPILE}gcc):$PATH
111export PATH
112autoreconf -i
113# Extra CFLAGS are needed to avoid using standard libraries when using baremetal toolchain
114# -O2 required as otherwise boot-wrapper would not boot
115CFLAGS="-ffreestanding -nostdlib -O2" ./configure --host=${TOOLCHAIN_TYPE} \
116 --enable-psci \
117 --enable-gicv3 \
118 --with-kernel-dir=../linux-${KERNEL_VERSION} \
119 --with-dtb=../devicetree-rebasing/src/arm64/arm/kleidiai_fvp.dtb \
120 --with-cmdline="console=ttyAMA0 earlycon=pl011,0x1c090000 panic=1 root=/dev/vda rw isolcpus=1 init=/bin/bash -- /root/startup"
121make "-j$(nproc)"
122cd ..
123
124mv boot-wrapper-aarch64/linux-system.axf .
125
126# Cleans up.
127rm -rf \
128 ${TOOLCHAIN_DIR} \
129 linux-${KERNEL_VERSION} \
130 devicetree-rebasing \
131 boot-wrapper-aarch64