-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·139 lines (112 loc) · 3.76 KB
/
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#! /bin/env bash
# THEJAS32 SDK setup script
# Author - Arif B <arif.dev@pm.me>
if [ ! -f $PWD/config ];then
echo "Configuration file absent, aborting installation!"
exit 1
fi
source $PWD/config
set -e
# Check if running as root
if [[ "$EUID" != 0 ]]
then
echo "${MAGENTA}Please run the script with administrator privileges!${NORMAL}"
echo "Try sudo $0"
exit
fi
# Install dependencies
if command -v apt &> /dev/null; then
apt-get -y install make tar xz-utils git minicom gcc
elif command -v yum &> /dev/null; then
yum install -y make tar xz git minicom gcc ncurses
elif command -v pacman &> /dev/null; then
pacman -Sy make tar xz git minicom gcc
else
printf "${RED}Unsupported Distro! Please make sure the following packages are installed:${NORMAL}"
printf "make\ntar\ngit\nxz\nminicom\ngcc\n"
printf "${YELLOW}Continue? (Y/n) :${NORMAL}"
read input
if [ ${input^^} = "N" ]; then
exit
fi
fi
# Copy header files
mkdir -p "$HEADER_PATH"
cp "$SETUP_PATH"/hal/include/* "$HEADER_PATH"
# Copy libraries
mkdir -p "$SDK_PATH"
cp hal/thejas32/* "$SDK_PATH"
cp -r "$SETUP_PATH"/hal/drivers "$SDK_PATH"
cp -r "$SETUP_PATH"/hal/libs "$SDK_PATH"
gcc "$SETUP_PATH"/tools/xmodem.c -o "$SDK_PATH"/xmodem
# Add sdk directory to PATH variable
case "$DEFAULT_SHELL" in
"bash")
RC_FILE=/home/$SUDO_USER/.bashrc
;;
"zsh")
RC_FILE=/home/$SUDO_USER/.zshrc
;;
*)
printf "Unsupported shell: %s
Manually export the environment variable VEGA_SDK_PATH in your shell profile
export VEGA_SDK_PATH=%s",$DEFAULT_SHELL,$VEGA_SDK_PATH
;;
esac
echo "export VEGA_SDK_PATH=$SDK_PATH" >> $RC_FILE
# Download RISC-V cross-toolchain
# WIP, Downloading a fixed release for Linux currently
printf "\nIf this is your first time running the script, you might want to download pre-compiled RISC-V toolchain\n"
printf "\n${YELLOW}Download RISC-V Toolchain? ([Y]/n) :${NORMAL} "
read -r input
if [ -z "$input" ] || [ "${input^^}" = "Y" ]; then
if [ "$HOST_ARCH" = "x86_64" ];then
TOOLCHAIN_URL=https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-x64.tar.gz
flag=1
elif [ "$HOST_ARCH" = "aarch64" ];then
TOOLCHAIN_URL=https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v13.2.0-2/xpack-riscv-none-elf-gcc-13.2.0-2-linux-arm64.tar.gz
flag=1
else
printf "${MAGENTA}Unsupported host architecture! Please create a pull request${NORMAL}"
flag=0
fi
if [ "$flag" = 1 ];then
mkdir -p $RISCV_TOOLCHAIN_PATH
pushd $RISCV_TOOLCHAIN_PATH
curl -OL "$TOOLCHAIN_URL"
tar xzf *.tar.gz
rm *.tar.gz
extracted_dir=$(find . -maxdepth 1 -type d -name "xpack-*" -print -quit)
if [ -n "$extracted_dir" ]; then
bin_path="$(realpath "$extracted_dir")/bin"
echo "export PATH=\$PATH:$bin_path" >> $RC_FILE
popd
fi
fi
fi
# Create minicom config
printf "
# THEJAS32 Minicom Configuration
pu port /dev/ttyUSB0
pu baudrate 115200
pu bits 8
pu parity N
pu stopbits 1
pu rtscts No
" > $MINICOM_CONFIG
# Add user to dialout group
usermod -aG dialout $SUDO_USER
# Add udev rules
echo '
# CP2102 on ARIESv3
SUBSYSTEM=="usb", SYSFS{idVendor}=="0x10c4", SYSFS{idProduct}=="0xea60", ACTION=="add", GROUP="dialout", MODE="0664"
# FT230X on ARIESv2
SUBSYSTEM=="usb", SYSFS{idVendor}=="0404", SYSFS{idProduct} =="6015", ACTION=="add", GROUP="dialout", MODE="0664"
' > $UDEV_CONFIG
# Reload rules
udevadm control --reload-rules && udevadm trigger
echo "${GREEN}
------------------------------
Successfully Installed the SDK
------------------------------
${NORMAL}"