-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxtensa-toolchain.sh
executable file
·355 lines (290 loc) · 6.98 KB
/
xtensa-toolchain.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/bin/bash
clean_up() {
local root_dir=${1}
if [ ${#} -ne 1 ]
then
echo -e "${FUNCNAME[0]}: incorrect parameter number ${#}"
return 1
fi
cd ${root_dir}
echo -e "Cleaning up old repositories..."
if [ -e "xtensa-overlay" ]
then
echo -e " remove old xtensa-overlay folder"
rm -rf xtensa-overlay
fi
if [ -e "crosstool-ng" ]
then
echo -e " remove old crosstool-ng folder"
rm -rf crosstool-ng
fi
if [ -e "newlib-xtensa" ]
then
echo -e " remove old newlib-xtensa folder"
rm -rf newlib-xtensa
fi
return 0
}
clone_repositories() {
local root_dir=${1}
if [ ${#} -ne 1 ]
then
echo -e "${FUNCNAME[0]}: incorrect parameter number ${#}"
return 1
fi
echo -e "Cloning new repositories..."
# Clone both repos and check out the sof-gcc8.1 branch.
cd ${root_dir}
git clone https://github.com/thesofproject/xtensa-overlay.git
cd ${root_dir}/xtensa-overlay
git checkout sof-gcc8.1
GITHASH_XTENSA=$(git log --format=%H -n 1)
cd ${root_dir}
git clone https://github.com/thesofproject/crosstool-ng.git
cd ${root_dir}/crosstool-ng
git checkout sof-gcc8.1
GITHASH_CROSSTOOL=$(git log --format=%H -n 1)
# Clone the header repository.
cd ${root_dir}
git clone https://github.com/jcmvbkbc/newlib-xtensa.git
cd ${root_dir}/newlib-xtensa
git checkout -b xtensa origin/xtensa
GITHASH_NEWLIB=$(git log --format=%H -n 1)
echo -e "Cloning success:"
echo -e "GITHASH_XTENSA = ${GITHASH_XTENSA}"
echo -e "GITHASH_CROSSTOOL = ${GITHASH_CROSSTOOL}"
echo -e "GITHASH_NEWLIB = ${GITHASH_NEWLIB}\n"
return 0
}
build_toolchain() {
local root_dir=${1}
if [ ${#} -ne 1 ]
then
echo -e "${FUNCNAME[0]}: incorrect parameter number ${#}"
return 1
fi
echo -e "Building toolchain..."
# Build and install the ct-ng tools in the local folder.
cd ${root_dir}/crosstool-ng
./bootstrap
./configure --prefix=`pwd`
make
make install
CONFIG=("config-byt-gcc8.1-gdb8.1" "config-hsw-gcc8.1-gdb8.1" "config-apl-gcc8.1-gdb8.1" "config-cnl-gcc8.1-gdb8.1" "config-imx-gcc8.1-gdb8.1")
TARGET=("xtensa-byt-elf" "xtensa-hsw-elf" "xtensa-apl-elf" "xtensa-cnl-elf" "xtensa-imx-elf")
# Copy the config files to .config and build the cross compiler for your target platforms.
for ((idx=0; idx<${#CONFIG[@]}; ++idx)); do
cp ${CONFIG[idx]} .config
./ct-ng build
export PATH=${root_dir}/crosstool-ng/builds/${TARGET[idx]}/bin/:${PATH}
done
# Build and install the headers for each platform.
cd ${root_dir}/newlib-xtensa
for ((idx=0; idx<${#TARGET[@]}; ++idx)); do
./configure --target=${TARGET[idx]} --prefix=${root_dir}/crosstool-ng/builds/xtensa-root
make
make install
rm -fr rm etc/config.cache
done
return 0
}
make_deb_package() {
local root_dir=${1}
if [ ${#} -ne 1 ]
then
echo -e "${FUNCNAME[0]}: incorrect parameter number ${#}"
return 1
fi
echo -e "Making deb package..."
MAJOR_VERSION=$(date +%Y)
MINOR_VERSION=$(date +%m%d)
PACKAGE_REVISION="1"
PACKAGE_NAME="xtensa-toolchain"
PACKAGE_ROOT="${PACKAGE_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}-${PACKAGE_REVISION}"
# Make a simple package for it
cd ${root_dir}
mkdir -p ${PACKAGE_ROOT}/opt
mkdir -p ${PACKAGE_ROOT}/DEBIAN
mv ${root_dir}/crosstool-ng/builds ${PACKAGE_ROOT}/opt/${PACKAGE_NAME}
cat >> ${PACKAGE_ROOT}/DEBIAN/control << EOF
Package: ${PACKAGE_NAME}
Version: ${MAJOR_VERSION}.${MINOR_VERSION}-${PACKAGE_REVISION}
Section: devel
Priority: optional
Architecture: amd64
Depends:
Maintainer: Brent Lu <[email protected]>
Description: Toolchain for SOF firmware
Git commits:
crosstool-ng: ${GITHASH_CROSSTOOL}
xtensa-overlay: ${GITHASH_XTENSA}
newlib-xtensa: ${GITHASH_NEWLIB}
EOF
dpkg-deb --build ${PACKAGE_ROOT}
return 0
}
read_deb_file() {
local root_dir=${1}
local deb_file=${2}
if [ ${#} -ne 2 ]
then
echo -e "${FUNCNAME[0]}: incorrect parameter number ${#}"
return 1
fi
local info
cd ${root_dir}
echo -e "Reading deb file..."
info=$(dpkg --info ${deb_file})
while IFS= read -r line
do
if [[ "${line}" == *"crosstool-ng:"* ]]
then
DEB_FILE_CROSSTOOL=${line##*:}
DEB_FILE_CROSSTOOL=${DEB_FILE_CROSSTOOL##*[[:blank:]]}
fi
if [[ "${line}" == *"xtensa-overlay:"* ]]
then
DEB_FILE_XTENSA=${line##*:}
DEB_FILE_XTENSA=${DEB_FILE_XTENSA##*[[:blank:]]}
fi
if [[ "${line}" == *"newlib-xtensa:"* ]]
then
DEB_FILE_NEWLIB=${line##*:}
DEB_FILE_NEWLIB=${DEB_FILE_NEWLIB##*[[:blank:]]}
fi
done <<< "${info}"
echo -e "Reading success:"
echo -e "DEB_FILE_XTENSA = ${DEB_FILE_XTENSA}"
echo -e "DEB_FILE_CROSSTOOL = ${DEB_FILE_CROSSTOOL}"
echo -e "DEB_FILE_NEWLIB = ${DEB_FILE_NEWLIB}\n"
return 0
}
main() {
local action=${1}
if [ ${#} -eq 0 ]
then
echo -e "ERROR: No action specified"
show_usage
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: show_usage fail"
return 1
fi
return 1
fi
local root_dir=$(pwd)
local deb_file=""
echo -e "Action '${action}'"
shift
while getopts p: option
do
case "${option}" in
"p")
echo -e "Option found, deb file: '${OPTARG}'"
deb_file="${OPTARG}"
;;
*)
echo -e "ERROR: Unknown option '${OPTARG}'"
;;
esac
done
case "${action}" in
"check")
if [[ -z "${deb_file}" ]]
then
echo -e "ERROR: No deb file specified"
return 1
fi
if [ ! -e ${deb_file} ]
then
echo -e "ERROR: deb file not exist"
return 1
fi
clean_up "${root_dir}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: clean_up fail"
return 1
fi
clone_repositories "${root_dir}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: clone_repositories fail"
return 1
fi
read_deb_file "${root_dir}" "${deb_file}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: read_deb_file fail"
return 1
fi
if [[ "${DEB_FILE_CROSSTOOL}" == "${GITHASH_CROSSTOOL}" ]] &&
[[ "${DEB_FILE_XTENSA}" == "${GITHASH_XTENSA}" ]] &&
[[ "${DEB_FILE_NEWLIB}" == "${GITHASH_NEWLIB}" ]]
then
echo -e "The toolchain is up-to-date\n"
else
echo -e "The toolchain in out-of-date\n"
fi
# clean up again
clean_up "${root_dir}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: clean_up fail"
return 1
fi
;;
"download")
clean_up "${root_dir}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: clean_up fail"
return 1
fi
clone_repositories "${root_dir}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: clone_repositories fail"
return 1
fi
;;
"build")
clean_up "${root_dir}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: clean_up fail"
return 1
fi
clone_repositories "${root_dir}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: clone_repositories fail"
return 1
fi
build_toolchain "${root_dir}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: build_toolchain fail"
return 1
fi
make_deb_package "${root_dir}"
if [ $? -ne 0 ]
then
echo -e "${FUNCNAME[0]}: make_deb_package fail"
return 1
fi
;;
*)
echo -e "ERROR: Unknown action '${action}', should be 'check', 'download' or 'build'"
;;
esac
return 0
}
# call main funcion
main "$@"
if [ $? -ne 0 ]
then
echo -e "\nScript Fail"
exit 1
fi
echo -e "\nScript Success"