-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild_setup.sh
More file actions
executable file
·189 lines (159 loc) · 5.54 KB
/
Copy pathbuild_setup.sh
File metadata and controls
executable file
·189 lines (159 loc) · 5.54 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env bash
set -e
TOP_DIR=$(dirname "$0")
echo $TOP_DIR
echo "Start board build_setup ..."
TOOLCHAIN_PATH=$TOP_DIR/../tools
if [ ! -d "$TOOLCHAIN_PATH" ]; then
mkdir -p $TOOLCHAIN_PATH
echo "Toolchain $TOOLCHAIN_PATH not exist"
fi
TOOLCHAIN_NAME=$TOOLCHAIN_PATH/gcc-arm-none-eabi-10.3-2021.10
if [ -d "$TOOLCHAIN_NAME" ]; then
if [ -f "$TOOLCHAIN_NAME/bin/arm-none-eabi-gcc" ]; then
echo "Toolchain $TOOLCHAIN_NAME check Successful"
echo "Run build setup success ..."
exit 0
else
echo "Toolchain $TOOLCHAIN_NAME check Failed"
rm -rf $TOOLCHAIN_NAME
echo "Remove toolchain $TOOLCHAIN_NAME, download again"
fi
fi
echo "Start download toolchain"
# restult=$(curl -m 15 -s http://www.ip-api.com/json)
# country=$(echo $restult | sed 's/.*"country":"\([^"]*\)".*/\1/')
# echo "country: $country"
cd $TOOLCHAIN_PATH
HOST_MACHINE=$(uname -m)
case "$(uname -s)" in
Linux*)
SYSTEM_NAME="Linux"
if [ $HOST_MACHINE = "x86_64" ]; then
TOOLCHAIN_URL=https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
TOOLCHAIN_FILE=gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
TOOLCHAIN_SIZE=157089706
TOOLCHAIN_SHA256=97dbb4f019ad1650b732faffcc881689cedc14e2b7ee863d390e0a41ef16c9a3
elif [ $HOST_MACHINE = "aarch64" ]; then
TOOLCHAIN_URL=https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-aarch64-linux.tar.bz2
TOOLCHAIN_FILE=gcc-arm-none-eabi-10.3-2021.10-aarch64-linux.tar.bz2
TOOLCHAIN_SIZE=168772350
TOOLCHAIN_SHA256=f605b5f23ca898e9b8b665be208510a54a6e9fdd0fa5bfc9592002f6e7431208
else
echo "Toolchain not support, Please download toolchain from https://developer.arm.com/downloads/-/gnu-rm"
exit 1
fi
;;
Darwin*)
SYSTEM_NAME="Apple"
if [ $HOST_MACHINE = "x86_64" ]; then
TOOLCHAIN_URL=https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-mac.tar.bz2
TOOLCHAIN_FILE=gcc-arm-none-eabi-10.3-2021.10-mac.tar.bz2
TOOLCHAIN_SIZE=158961466
TOOLCHAIN_SHA256=fb613dacb25149f140f73fe9ff6c380bb43328e6bf813473986e9127e2bc283b
else
echo "Toolchain not support, Please download toolchain from https://developer.arm.com/downloads/-/gnu-rm"
exit 1
fi
;;
MINGW* | CYGWIN* | MSYS*)
SYSTEM_NAME="Windows"
TOOLCHAIN_URL=https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-win32.zip
TOOLCHAIN_FILE=gcc-arm-none-eabi-10.3-2021.10-win32.zip
TOOLCHAIN_SIZE=200578763
TOOLCHAIN_SHA256=d287439b3090843f3f4e29c7c41f81d958a5323aecefcf705c203bfd8ae3f2e7
;;
*)
SYSTEM_NAME="Unknown"
exit 1
;;
esac
echo "Running on [$SYSTEM_NAME]"
MAX_DOWNLOAD_ATTEMPTS=2
cleanup_toolchain_artifacts() {
rm -rf "$TOOLCHAIN_FILE"
rm -rf "$TOOLCHAIN_NAME"
}
download_toolchain_package() {
wget "$TOOLCHAIN_URL" -O "$TOOLCHAIN_FILE"
if [ $? -ne 0 ]; then
echo "Download toolchain failed"
cleanup_toolchain_artifacts
return 1
fi
return 0
}
verify_toolchain_package() {
if [ "$TOOLCHAIN_SHA256" != "$(sha256sum "$TOOLCHAIN_FILE" | awk '{print $1}')" ]; then
echo "Toolchain file checksum error"
cleanup_toolchain_artifacts
return 1
fi
if [ "$TOOLCHAIN_SIZE" != "$(stat -c %s "$TOOLCHAIN_FILE")" ]; then
echo "Toolchain file size error"
cleanup_toolchain_artifacts
return 1
fi
return 0
}
extract_toolchain_package() {
FILE_EXTENSION=${TOOLCHAIN_FILE##*.}
echo "start decompression"
echo "FILE_EXTENSION: ${FILE_EXTENSION}"
rm -rf "$TOOLCHAIN_NAME"
if [ "$FILE_EXTENSION" = "bz2" ]; then
tar -xvf "$TOOLCHAIN_FILE" -C "$TOOLCHAIN_PATH" || {
echo "Toolchain extract failed"
cleanup_toolchain_artifacts
return 1
}
elif [ "$FILE_EXTENSION" = "zip" ]; then
unzip "$TOOLCHAIN_FILE" || {
echo "Toolchain extract failed"
cleanup_toolchain_artifacts
return 1
}
else
echo "File not support"
cleanup_toolchain_artifacts
return 1
fi
return 0
}
retry_toolchain_prepare() {
local attempt=1
while [ "$attempt" -le "$MAX_DOWNLOAD_ATTEMPTS" ]; do
if [ -f "$TOOLCHAIN_FILE" ]; then
if ! verify_toolchain_package; then
if [ "$attempt" -ge "$MAX_DOWNLOAD_ATTEMPTS" ]; then
return 1
fi
attempt=$((attempt + 1))
echo "Retrying toolchain download: ${attempt}/${MAX_DOWNLOAD_ATTEMPTS}"
continue
fi
else
if ! download_toolchain_package || ! verify_toolchain_package; then
if [ "$attempt" -ge "$MAX_DOWNLOAD_ATTEMPTS" ]; then
return 1
fi
attempt=$((attempt + 1))
echo "Retrying toolchain download: ${attempt}/${MAX_DOWNLOAD_ATTEMPTS}"
continue
fi
fi
if extract_toolchain_package; then
return 0
fi
if [ "$attempt" -ge "$MAX_DOWNLOAD_ATTEMPTS" ]; then
return 1
fi
attempt=$((attempt + 1))
echo "Retrying toolchain download: ${attempt}/${MAX_DOWNLOAD_ATTEMPTS}"
done
return 1
}
if ! retry_toolchain_prepare; then
exit 1
fi
echo "Run build setup success ..."