Skip to content

Commit 0aff0c8

Browse files
committed
scripts: template_setup_posix: Add web-based toolchain installation
This commit adds the feature to download and install individual toolchains from the web release assets if not all toolchains are locally installed (e.g. minimal web install distribution archive). Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent b0979d7 commit 0aff0c8

File tree

1 file changed

+166
-29
lines changed

1 file changed

+166
-29
lines changed

scripts/template_setup_posix

Lines changed: 166 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,65 @@ ask_yn()
1919
local reply
2020

2121
while true; do
22-
read -n 1 -r -p "$1 [y/n]? " reply && echo
22+
read -r -p "$1 [y/n]? " reply
2323

2424
case "${reply}" in
25-
Y | y) return 0 ;;
26-
N | n) return 1 ;;
27-
*) echo "Invalid choice '${reply}'" ;;
25+
Y* | y*) return 0 ;;
26+
N* | n*) return 1 ;;
27+
*) echo "Invalid choice '${reply}'" ;;
2828
esac
2929
done
3030
}
3131

32+
assert_rc()
33+
{
34+
if [[ $? != 0 ]]; then
35+
echo "$1" 1>&2
36+
exit $2
37+
fi
38+
}
39+
40+
# Check if command is available
41+
check_command()
42+
{
43+
which $1 &> /dev/null
44+
if [ $? != 0 ]; then
45+
echo "Zephyr SDK setup requires '$1' to be installed and available in the PATH."
46+
echo "Please install '$1 and run this script again."
47+
exit $2
48+
fi
49+
}
50+
51+
# Check if the current installation is a full SDK with all toolchains
52+
check_full_sdk()
53+
{
54+
for toolchain in ${toolchains[@]}; do
55+
if [ ! -d "${toolchain}" ]; then
56+
return 1
57+
fi
58+
done
59+
60+
return 0
61+
}
62+
3263
# Display script usage
3364
usage()
3465
{
35-
echo "Usage: $(basename $0) [-c] [-t]"
66+
echo "Usage: $(basename $0) [-t <toolchain>] [-h] [-c]"
67+
echo
68+
echo " -t <toolchain> Install specified toolchain"
69+
echo " all Install all toolchains"
70+
echo " -h Install host tools"
71+
echo " -c Register Zephyr SDK CMake package"
3672
echo
37-
echo " -c Register Zephyr SDK CMake package"
38-
echo " -t Install host tools"
73+
echo "Supported Toolchains:"
74+
echo
75+
for toolchain in ${toolchains[@]}; do
76+
echo " ${toolchain}"
77+
done
3978
echo
4079
echo "If no arguments are specified, the setup script runs in the interactive"
4180
echo "mode asking for user inputs."
42-
exit 1
4381
}
4482

4583
# Ask for user inputs (interactive mode)
@@ -50,29 +88,90 @@ user_prompt()
5088
echo "distribution bundle archive."
5189
echo
5290

53-
ask_yn "Register Zephyr SDK CMake package" && do_cmake_pkg="y"
91+
# Toolchains
92+
check_full_sdk
93+
if [ $? != 0 ]; then
94+
ask_yn "Install toolchains for all targets"
95+
if [ $? == 0 ]; then
96+
inst_toolchains=(${toolchains[*]})
97+
else
98+
for toolchain in ${toolchains[@]}; do
99+
if [ ! -d "${toolchain}" ]; then
100+
ask_yn "Install '${toolchain}' toolchain" && inst_toolchains+=("${toolchain}")
101+
fi
102+
done
103+
fi
104+
fi
105+
106+
# Host Tools
54107
ask_yn "Install host tools" && do_hosttools="y"
55108

109+
# Environment Configurations
110+
ask_yn "Register Zephyr SDK CMake package" && do_cmake_pkg="y"
111+
56112
echo
57113
}
58114

59115
# Entry point
60116
pushd "$(dirname "${BASH_SOURCE[0]}")"
61117

118+
# Initialise toolchain list
119+
toolchains=(
120+
"aarch64-zephyr-elf"
121+
"arc64-zephyr-elf"
122+
"arc-zephyr-elf"
123+
"arm-zephyr-eabi"
124+
"mips-zephyr-elf"
125+
"nios2-zephyr-elf"
126+
"riscv64-zephyr-elf"
127+
"sparc-zephyr-elf"
128+
"x86_64-zephyr-elf"
129+
"xtensa-espressif_esp32_zephyr-elf"
130+
"xtensa-espressif_esp32s2_zephyr-elf"
131+
"xtensa-intel_apl_adsp_zephyr-elf"
132+
"xtensa-intel_bdw_adsp_zephyr-elf"
133+
"xtensa-intel_byt_adsp_zephyr-elf"
134+
"xtensa-intel_s1000_zephyr-elf"
135+
"xtensa-nxp_imx_adsp_zephyr-elf"
136+
"xtensa-nxp_imx8m_adsp_zephyr-elf"
137+
"xtensa-sample_controller_zephyr-elf"
138+
)
139+
140+
# Initialise list of toolchains to install
141+
inst_toolchains=()
142+
62143
# Parse arguments
63144
if [ $# == "0" ]; then
64145
interactive="y"
65146
else
66147
while [ "$1" != "" ]; do
67148
case $1 in
149+
-t)
150+
shift
151+
if [[ "$1" = "all" ]]; then
152+
inst_toolchains=(${toolchains[*]})
153+
else
154+
if [[ " ${toolchains[*]} " =~ " $1 " ]]; then
155+
inst_toolchains+=("$1")
156+
else
157+
echo "ERROR: Unknown toolchain '$1'"
158+
exit 2
159+
fi
160+
fi
161+
;;
162+
-h)
163+
do_hosttools="y"
164+
;;
68165
-c)
69166
do_cmake_pkg="y"
70167
;;
71-
-t)
72-
do_hosttools="y"
168+
'-?')
169+
usage
170+
exit 0
73171
;;
74172
*)
75173
echo "Invalid argument '$1'"
174+
echo
76175
usage
77176
exit 1
78177
;;
@@ -84,49 +183,87 @@ fi
84183
# Read bundle version from file
85184
version=$(<sdk_version)
86185

186+
# Resolve host type
187+
case ${OSTYPE} in
188+
linux-gnu*) host="linux-${HOSTTYPE}" ;;
189+
darwin*) host="macos-${HOSTTYPE}" ;;
190+
*)
191+
echo "ERROR: Unsupported host operating system"
192+
exit 5
193+
;;
194+
esac
195+
196+
# Resolve release download base URI
197+
dl_rel_base="https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}"
198+
dl_toolchain_filename='toolchain_${host}_${toolchain}.tar.gz'
199+
87200
# Print banner
88201
echo "Zephyr SDK ${version} Setup"
89202
echo
90203

91204
# Check dependencies
92-
which cmake &> /dev/null
93-
if [ $? != 0 ]; then
94-
echo "Zephyr SDK setup requires CMake to be installed and available in the PATH."
95-
echo "Please install CMake and run this script again."
96-
exit 90
97-
fi
205+
check_command cmake 90
206+
check_command wget 91
98207

99208
# Ask for user inputs if no argument is specified
100209
if [ "${interactive}" = "y" ]; then
101210
interactive="y"
102211
user_prompt
103212
fi
104213

105-
# Register Zephyr SDK CMake package
106-
if [ "${do_cmake_pkg}" = "y" ]; then
107-
echo "Registering Zephyr SDK CMake package ..."
108-
cmake -P cmake/zephyr_sdk_export.cmake
214+
# Install toolchains
215+
for toolchain in ${inst_toolchains[@]}; do
216+
eval toolchain_filename="${dl_toolchain_filename}"
217+
toolchain_uri="${dl_rel_base}/${toolchain_filename}"
218+
219+
# Skip if toolchain directory already exists
220+
if [ -d "${toolchain}" ]; then
221+
continue
222+
fi
223+
224+
echo "Installing '${toolchain}' toolchain ..."
225+
226+
# Download toolchain archive
227+
wget -q --show-progress -N -O "${toolchain_filename}" "${toolchain_uri}"
228+
if [ $? != 0 ]; then
229+
rm -f "${toolchain_filename}"
230+
echo "ERROR: Toolchain download failed"
231+
exit 20
232+
fi
233+
234+
# Extract archive
235+
tar xf "${toolchain_filename}"
236+
assert_rc "ERROR: Toolchain archive extraction failed" 21
237+
238+
# Remove archive
239+
rm -f "${toolchain_filename}"
240+
109241
echo
110-
fi
242+
done
111243

112244
# Install host tools
113245
if [ "${do_hosttools}" = "y" ]; then
114246
echo "Installing host tools ..."
115-
case ${OSTYPE} in
116-
linux-gnu*)
247+
case ${host} in
248+
linux-*)
117249
./zephyr-sdk-${HOSTTYPE}-hosttools-standalone-0.9.sh -y -d .
250+
assert_rc "ERROR: Host tools installation failed" 30
118251
;;
119-
darwin*)
252+
macos-*)
120253
echo "SKIPPED: macOS host tools are not available yet."
121254
;;
122-
*)
123-
echo "SKIPPED: Unsupported host operating system"
124-
exit 2
125-
;;
126255
esac
127256
echo
128257
fi
129258

259+
# Register Zephyr SDK CMake package
260+
if [ "${do_cmake_pkg}" = "y" ]; then
261+
echo "Registering Zephyr SDK CMake package ..."
262+
cmake -P cmake/zephyr_sdk_export.cmake
263+
assert_rc "ERROR: CMake package registration failed" 40
264+
echo
265+
fi
266+
130267
echo "All done."
131268
if [ "${interactive}" = "y" ]; then
132269
read -n 1 -s -r -p "Press any key to exit ..."

0 commit comments

Comments
 (0)