1
1
#! /usr/bin/env bash
2
2
3
- set -x
4
3
CURRENT_DIR=$(
5
4
cd " $( dirname " $0 " ) "
6
5
pwd
7
6
)
8
7
8
+ user=$( stat -c %U " $0 " )
9
+
9
10
SDK_ROOT=/opt/bouffalolab_sdk
10
- # Currently, only setup toolchain under $SDK_ROOT
11
- TOOLCHAIN_SETUP_ROOT=$SDK_ROOT /toolchain
12
11
13
- TOOLCHAIN_SYMBOLIC_LINK_PATH=" "
14
- git -C . rev-parse 2> /dev/null
15
- if [[ " $? " == " 0" ]]; then
16
- # Examples in Bouffalo Lab IOT SDK repo expect toolchain under repo,
17
- # let's create a symbolic link to Bouffalo Lab toolchain,
18
- # if this script runs under repo
19
- TOOLCHAIN_SYMBOLIC_LINK_PATH=$CURRENT_DIR /../toolchain
12
+ echo " Please input path to install toolchain, or type Enter to install under $SDK_ROOT "
13
+ read TOOLCHAIN_SETUP_ROOT
14
+ if [[ ${TOOLCHAIN_SETUP_ROOT} == " " ]]; then
15
+ TOOLCHAIN_SETUP_ROOT=$SDK_ROOT
20
16
fi
17
+ echo " Toolchain will install under $TOOLCHAIN_SETUP_ROOT "
18
+ flash_tool_postfix=
19
+
20
+ flash_tool=BouffaloLabDevCube-v1.9.0
21
+ flash_tool_url=https://dev.bouffalolab.com/media/upload/download/$flash_tool .zip
22
+ thead_toolchain=gcc_t-head_v2.6.1
23
+ thead_toolchain_url=https://codeload.github.com/bouffalolab/toolchain_gcc_t-head_linux/zip/c4afe91cbd01bf7dce525e0d23b4219c8691e8f0
24
+ thead_toolchain_unzip=toolchain_gcc_t-head_linux-c4afe91cbd01bf7dce525e0d23b4219c8691e8f0
21
25
22
26
if [[ " $OSTYPE " == " linux-gnu" * ]]; then
23
27
toolchains_url=(
24
- " riscv/Thead_riscv/Linux_x86_64" " https://dev.bouffalolab.com/media/upload/download/toolchain_riscv_thead_linux64.zip" " toolchain_riscv_thead_linux_x86_64"
25
- " riscv/Linux" " https://dev.bouffalolab.com/media/upload/download/toolchain_riscv_sifive_linux64.zip" " toolchain_riscv_sifive_linux"
28
+ " toolchain/riscv" " https://dev.bouffalolab.com/media/upload/download/toolchain_riscv_sifive_linux64.zip" Linux toolchain_riscv_sifive_linux
29
+ " toolchain/t-head-riscv" " $thead_toolchain_url " " $thead_toolchain " " $thead_toolchain_unzip "
30
+ " flashtool" " $flash_tool_url " " $flash_tool " " "
26
31
)
32
+ flash_tool_postfix=ubuntu
27
33
elif [[ " $OSTYPE " == " darwin" * ]]; then
28
34
toolchains_url=(
29
- " riscv/Darwin" " https://dev.bouffalolab.com/media/upload/download/toolchain_riscv_sifive_macos.zip" " toolchain_riscv_sifive_macos "
35
+ " toolchain/ riscv/Darwin" " https://dev.bouffalolab.com/media/upload/download/toolchain_riscv_sifive_macos.zip"
30
36
)
37
+ flash_tool_postfix=macos
31
38
else
32
39
echo " Not support for " " $OSTYPE "
33
40
fi
@@ -37,30 +44,44 @@ if [ ! -d "$TOOLCHAIN_SETUP_ROOT" ]; then
37
44
fi
38
45
rm -rf " $TOOLCHAIN_SETUP_ROOT " /* .zip
39
46
40
- for (( i = 0 ; i < ${# toolchains_url[@]} ; i += 3 )) ; do
47
+ for (( i = 0 ; i < ${# toolchains_url[@]} ; i += 4 )) ; do
41
48
path=${toolchains_url[i]}
42
49
url=${toolchains_url[i + 1]}
43
- output=${toolchains_url[i + 2]}
50
+ out=${toolchains_url[i + 2]}
51
+ unzip_name=${toolchains_url[i + 3]}
52
+
53
+ if [ -d " $TOOLCHAIN_SETUP_ROOT /$path /$out " ]; then
54
+ continue
55
+ fi
56
+ rm -rf " $TOOLCHAIN_SETUP_ROOT /$path "
57
+ mkdir -p " $TOOLCHAIN_SETUP_ROOT /$path "
44
58
45
59
wget -P " $TOOLCHAIN_SETUP_ROOT " / " $url "
46
60
toolchain_zip=$( basename " $url " )
61
+ toolchain_zip=$( find " $TOOLCHAIN_SETUP_ROOT " -maxdepth 1 -name * " $toolchain_zip " * )
62
+ toolchain_zip=$( basename " $toolchain_zip " )
47
63
if [ ! -f " $TOOLCHAIN_SETUP_ROOT /$toolchain_zip " ]; then
48
64
exit 1
49
65
fi
50
- rm -rf " $TOOLCHAIN_SETUP_ROOT /$path "
51
- mkdir -p " $TOOLCHAIN_SETUP_ROOT /$path "
52
- unzip " $TOOLCHAIN_SETUP_ROOT /$toolchain_zip " -d " $TOOLCHAIN_SETUP_ROOT /$path "
53
- mv " $TOOLCHAIN_SETUP_ROOT /$path /$output " /* " $TOOLCHAIN_SETUP_ROOT /$path "
66
+
67
+ unzip -q " $TOOLCHAIN_SETUP_ROOT /$toolchain_zip " -d " $TOOLCHAIN_SETUP_ROOT /$path /tmp"
68
+ mv " $TOOLCHAIN_SETUP_ROOT /$path /tmp/$unzip_name " " $TOOLCHAIN_SETUP_ROOT /$path /$out "
69
+
70
+ rm -rf " $TOOLCHAIN_SETUP_ROOT /$path " /tmp
54
71
rm -rf " $TOOLCHAIN_SETUP_ROOT /$toolchain_zip "
55
72
56
- if [ -f " $TOOLCHAIN_SETUP_ROOT /$path " /chmod755.sh ]; then
57
- cd " $TOOLCHAIN_SETUP_ROOT /$path " /
73
+ if [ -f " $TOOLCHAIN_SETUP_ROOT /$path " /" $out " / chmod755.sh ]; then
74
+ cd " $TOOLCHAIN_SETUP_ROOT /$path " /" $out "
58
75
bash chmod755.sh
59
76
cd " $CURRENT_DIR "
60
77
fi
61
78
done
62
79
63
- if [[ " $TOOLCHAIN_SYMBOLIC_LINK_PATH " != " " ]]; then
64
- rm -rf " $TOOLCHAIN_SYMBOLIC_LINK_PATH "
65
- ln -s " $TOOLCHAIN_SETUP_ROOT " " $TOOLCHAIN_SYMBOLIC_LINK_PATH "
80
+ chmod +x " $TOOLCHAIN_SETUP_ROOT /flashtool/$flash_tool /BLDevCube-$flash_tool_postfix "
81
+ chmod +x " $TOOLCHAIN_SETUP_ROOT /flashtool/$flash_tool /bflb_iot_tool-$flash_tool_postfix "
82
+
83
+ if [[ " $user " == " root" ]]; then
84
+ chmod a+wr " $TOOLCHAIN_SETUP_ROOT /flashtool/$flash_tool " -R
85
+ else
86
+ chown " $user " " $TOOLCHAIN_SETUP_ROOT /flashtool/$flash_tool " / -R
66
87
fi
0 commit comments