forked from keystone-enclave/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast-setup.sh
executable file
·100 lines (78 loc) · 2.48 KB
/
fast-setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
set -e
if [ -z "$BITS" ]; then
BITS=64
fi
echo "Fast Setup (RV$BITS)";
DIST=xenial
if [[ $(ldconfig -p | grep "libmpfr.so.6") ]]; then
DIST=bionic
fi
if [ "$BITS" = "64" ]; then
TOOLCHAIN_7Z_FILE=riscv-toolchain-lp64d-rv64gc-2021.01.$DIST.7z
else
TOOLCHAIN_7Z_FILE=riscv-toolchain-ilp32d-rv32gc-2021.01.$DIST.7z
SDK_FLAGS="-DRISCV32=y"
fi
echo "Starting..."
if ( $(command -v riscv$BITS-unknown-linux-gnu-gcc > /dev/null) &&
$(command -v riscv$BITS-unknown-elf-gcc > /dev/null) )
then
echo "RISCV tools are already installed"
else
echo "Downloading Prebuilt RISC-V Toolchain... "
export RISCV=$(pwd)/riscv$BITS
export PATH=$PATH:$RISCV/bin
if [ -f $TOOLCHAIN_7Z_FILE ]; then
rm $TOOLCHAIN_7Z_FILE;
fi
wget https://keystone-enclave.eecs.berkeley.edu/files/$TOOLCHAIN_7Z_FILE
# Check tool integrity
echo "Verifying prebuilt toolchain integrity..."
sha256sum -c .prebuilt_tools_shasums --status --ignore-missing
if [[ $? != 0 ]]; then
echo "Toolchain binary download incomplete or corrupted. You can build the toolchain locally or try again."
exit 1
fi
echo "Extracting Toolchain"
7za x -y $TOOLCHAIN_7Z_FILE -o./riscv$BITS
echo "Toolchain has been installed in $RISCV"
rm $TOOLCHAIN_7Z_FILE
fi
echo "Updating and cloning submodules, this may take a long time"
git config submodule.riscv-gnu-toolchain.update none
# shallow clone submodules ahead of time (Git must be > 2.11)
if [ ! -e linux/.git ]; then
git clone --shallow-since=2020-05-15 https://github.com/torvalds/linux.git linux
fi
if [ ! -e buildroot/.git ]; then
git clone --shallow-since=2020-04-15 https://github.com/buildroot/buildroot.git buildroot
fi
if [ ! -e qemu/.git ]; then
git clone --shallow-since=2020-11-15 https://github.com/qemu/qemu.git qemu
fi
git submodule sync --recursive
git submodule update --init --recursive
# build SDK if not present
if [ -z $KEYSTONE_SDK_DIR ]
then
echo "KEYSTONE_SDK_DIR is not set. Installing from $(pwd)/sdk"
export KEYSTONE_SDK_DIR=$(pwd)/sdk/build$BITS
cd sdk
mkdir -p build
cd build
cmake .. $SDK_FLAGS
make
make install
cd ../..
fi
# update source.sh
echo "export RISCV=$(pwd)/riscv${BITS}" > ./source.sh
echo "export PATH=$RISCV/bin:\$PATH" >> ./source.sh
echo "export KEYSTONE_SDK_DIR=$KEYSTONE_SDK_DIR" >> ./source.sh
echo "RISC-V toolchain and Keystone SDK have been fully setup"
echo ""
echo " * Notice: run the following command to update enviroment variables *"
echo ""
echo " source ./source.sh"
echo ""