Add Kelvin toolchain download flow
Also simplify the riscv-gnu-toolchain download command git-clone flags
Kelvin's binutil branch has a gas/doc target and is not quite compatible
with the old top riscv-gnu-toolchain. Add a small fix function to patch
the Makefile
Bug: 288969056
Change-Id: Ie816c2e683e16f2ad5c7d241c3ef02f8ddfd250d
diff --git a/download-toolchain.sh b/download-toolchain.sh
index e30eb04..1aac8b9 100755
--- a/download-toolchain.sh
+++ b/download-toolchain.sh
@@ -22,7 +22,7 @@
exit 1
fi
if [[ -z "$1" ]]; then
- echo "Usage: download-toolchain.sh <gcc dir> [<TARGET> | GCC | LLVM]"
+ echo "Usage: download-toolchain.sh <gcc dir> [<TARGET> | GCC | LLVM | KELVIN]"
exit 1
fi
@@ -32,11 +32,12 @@
TOOLCHAIN_SRC="${OUT}/tmp/toolchain"
LLVM_SRC="${TOOLCHAIN_SRC}/llvm-project"
-TOOLCHAINLLVM_TAG="2021.06.18"
+TOOLCHAIN_TAG="2021.06.18"
TOOLCHAINLLVM_BINUTILS_URL="git://sourceware.org/git/binutils-gdb.git"
if [[ ! "${TOOLCHAIN_TARGET}" == "GCC" ]] &&
- [[ ! "${TOOLCHAIN_TARGET}" == "LLVM" ]]; then
+ [[ ! "${TOOLCHAIN_TARGET}" == "LLVM" ]] &&
+ [[ ! "${TOOLCHAIN_TARGET}" == "KELVIN" ]]; then
echo "Unsupported toochain target: ${TOOLCHAIN_TARGET}"
exit 1
fi
@@ -47,29 +48,38 @@
echo "Remove existing ${TOOLCHAIN_GCC_SRC}..."
rm -rf "${TOOLCHAIN_GCC_SRC}"
fi
-mkdir -p "${TOOLCHAIN_GCC_SRC}"
# Download from the http://github.com/riscv/riscv-gnu-toolchain. For proper
# support of GDB symbol rendering, it requires a tag points to gcc 10.2.
-# Use git init and git fetch to avoid creating an extra layer of the source code.
-pushd "${TOOLCHAIN_GCC_SRC}" > /dev/null
-git init
-git remote add origin https://github.com/riscv/riscv-gnu-toolchain
-echo "Downloading the GNU toolchain source code from master"
-git fetch origin --tags
-git reset --hard ${TOOLCHAINLLVM_TAG}
-popd > /dev/null
+echo "Downloading the GNU toolchain source code from tag ${TOOLCHAIN_TAG}"
+git clone https://github.com/riscv/riscv-gnu-toolchain -b "${TOOLCHAIN_TAG}" \
+ "${TOOLCHAIN_GCC_SRC}"
# Update the submodules. The riscv-binutils has to point to upstream binutil-gdb
# regardless of what it is in .gitmodules
pushd "${TOOLCHAIN_GCC_SRC}" > /dev/null
-git submodule update --init --jobs=8 riscv-*
+
+# CentOS7 git does not support parellel jobs.
+if [[ "${TOOLCHAIN_TARGET}" == "KELVIN" ]]; then
+ git submodule update --init riscv-*
+else
+ git submodule update --init --jobs=8 riscv-*
+fi
+
if [[ "${TOOLCHAIN_TARGET}" == "LLVM" ]]; then
cd "riscv-binutils"
git remote set-url origin "${TOOLCHAINLLVM_BINUTILS_URL}"
git pull -f origin master --jobs=8 --depth=1
git checkout FETCH_HEAD
fi
+
+# Update riscv-binutils for kelvin to binutils 2.40
+if [[ "${TOOLCHAIN_TARGET}" == "KELVIN" ]]; then
+ cd "riscv-binutils"
+ git remote set-url origin "${TOOLCHAINLLVM_BINUTILS_URL}"
+ git fetch -f origin binutils-2_40 --depth=1
+ git checkout FETCH_HEAD
+fi
popd > /dev/null
# Download LLVM project if necessary. Always pull from main ToT.
@@ -85,3 +95,12 @@
git pull origin main --jobs=8 --depth=1
popd > /dev/null
fi
+
+# Patch Kelvin custom ops
+if [[ "${TOOLCHAIN_TARGET}" == "KELVIN" ]]; then
+ pushd "${TOOLCHAIN_GCC_SRC}/riscv-binutils" > /dev/null
+ git apply "${ROOTDIR}/build/patches/kelvin/0001-Kelvin-riscv-binutils-patch.patch"
+ cp "${ROOTDIR}/build/patches/kelvin/kelvin-opc.h" "include/opcode/kelvin-opc.h"
+ cp "${ROOTDIR}/build/patches/kelvin/kelvin-opc.c" "opcodes/kelvin-opc.c"
+ popd > /dev/null
+fi
diff --git a/update-toolchain-makefile.sh b/update-toolchain-makefile.sh
new file mode 100755
index 0000000..8afb2f4
--- /dev/null
+++ b/update-toolchain-makefile.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+#
+# Copyright 2021 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Update Makefile generated by riscv-gnu-toolchain configure to make it
+# binutils_2.40 compatible.
+
+MAKEFILE_PATH=$1
+
+sed -i -e "s#mkdir \$(notdir \$@)#mkdir -p \$(notdir \$@)/gas/doc#g" "${MAKEFILE_PATH}"