forked from tq-systems/ci-meta-tq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-environment
executable file
·298 lines (251 loc) · 8.46 KB
/
setup-environment
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
#!/bin/bash
#
# Copyright (C) 2012, 2013, 2016 O.S. Systems Software LTDA.
# Authored-by: Otavio Salvador <[email protected]>
#
# Copyright (C) TQ-Systems GmbH
# 2017 - 2021 Markus Niebel <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Add options for the script
# Copyright (C) 2013 Freescale Semiconductor, Inc.
CWD=$(pwd)
PROGNAME="setup-environment"
LIST_TQ_MACHINES=$(${CWD}/ci/ls-machines meta-tq)
DEFAULT_MACHINE=$(echo ${LIST_TQ_MACHINES} | awk '{ print $1 }')
CONFIG_TEMPLATE=minimal
DEFAULT_DISTRO_minimal="poky"
# use for linux-imx based kernel, should this be fsl[c]-wayland?
DEFAULT_DISTRO_imx="poky"
DEFAULT_DISTRO_ls="poky"
DEFAULT_DISTRO_ti="poky"
DEFAULT_DISTRO_rzg2="poky"
usage()
{
echo -e "\nUsage: source ${PROGNAME} <build-dir> <template>
<build-dir>: specifies the build directory location (required)
<template>: template bblayers.conf to use (optional)
If undefined, this script will set \$MACHINE to '${DEFAULT_MACHINE}'.
"
ls sources/*/conf/machine/*.conf > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "
Supported machines: `echo; ls sources/meta-tq/conf/machine/*.conf \
| sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
To build for a machine listed above, run this script as:
MACHINE=<machine> source ${PROGNAME} <build-dir>
"
fi
}
clean_up() {
unset EULA LIST_MACHINES VALID_MACHINE LIST_TQ_MACHINES
unset CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME
unset generated_config updated
unset MACHINE SDKMACHINE DISTRO OEROOT
unset DEFAULT_DISTRO DEFAULT_MACHINE CONFIG_TEMPLATE PROGNAME
unset DEFAULT_DISTRO_imx DEFAULT_DISTRO_minimal DEFAULT_DISTRO_ti
unset BBLAYERS_TEMPLATE VALID_MACHINE FILES
unset DISTRO_VAR
}
handle_eula() {
# Handle EULA setting
local EULA_ACCEPTED=
# EULA has been accepted already (ACCEPT_FSL_EULA is set in local.conf)
if grep -q '^\s*ACCEPT_FSL_EULA\s*=\s*["'\'']..*["'\'']' conf/local.conf; then
EULA_ACCEPTED=1
fi
if grep -q '^\s*ACCEPT_FSL_EULA\s*=\s*["'\'']..*["'\'']' conf/auto.conf; then
EULA_ACCEPTED=1
fi
if [ -z "${EULA_ACCEPTED}" ] && [ -n "${EULA}" ]; then
# The FSL EULA is not set as accepted in local.conf, but the EULA
# variable is set in the environment, so we just configure
# ACCEPT_FSL_EULA in local.conf according to $EULA.
echo "ACCEPT_FSL_EULA = \"${EULA}\"" >> conf/local.conf
elif [ -n "${EULA_ACCEPTED}" ]; then
# The FSL EULA has been accepted once, so ACCEPT_FSL_EULA is set
# in local.conf. No need to do anything.
:
else
# The FSL EULA is not set as accepted in local.conf / auto.conf,
# and EULA is not set in the environment, so we need to ask user
# if he/she accepts the FSL EULA:
cat <<EOF
Some BSPs depend on libraries and packages which are covered by Freescale's
End User License Agreement (EULA). To have the right to use these binaries in
your images, you need to read and accept the following...
EOF
sleep 4
more -d ${CWD}/sources/meta-freescale/EULA
echo
REPLY=
while [ -z "${REPLY}" ]; do
echo -n "Do you accept the EULA you just read? (y/n)"
read REPLY
case "${REPLY}" in
y|Y)
echo "EULA has been accepted."
echo "ACCEPT_FSL_EULA = \"1\"" >> conf/local.conf
;;
n|N)
echo "EULA has not been accepted."
;;
*)
REPLY=
;;
esac
done
fi
}
# get command line options
SHORTOPTS="h"
LONGOPTS="help"
ARGS=$(getopt --options ${SHORTOPTS} \
--longoptions ${LONGOPTS} --name ${PROGNAME} -- "$@" )
# Print the usage menu if invalid options are specified
if [ $? != 0 -o $# -lt 1 ]; then
usage && clean_up
return 1
fi
eval set -- "${ARGS}"
while true;
do
case $1 in
-h|--help)
usage
clean_up
return 0
;;
--)
shift
break
;;
esac
done
if [ "$(whoami)" = "root" ]; then
echo "ERROR: do not use the BSP as root. Exiting..."
fi
if [ -z "${MACHINE}" ]; then
MACHINE=${DEFAULT_MACHINE}
fi
if ! [ -z "${2}" ]; then
CONFIG_TEMPLATE=${2}
fi
BBLAYERS_TEMPLATE=bblayers.conf.${CONFIG_TEMPLATE}
# Check the machine type specified
LIST_MACHINES=$(ls -1 ${CWD}/sources/*/conf/machine)
VALID_MACHINE=$(echo -e "${LIST_MACHINES}" | grep ${MACHINE}.conf$ | wc -l)
if [ -z "${MACHINE}" ] || [ "${VALID_MACHINE}" -eq "0" ]; then
echo -e "\nThe \$MACHINE you have specified (${MACHINE}) is not supported by this build setup"
usage && clean_up
return 1
else
if [ ! -e $1/conf/local.conf.sample ]; then
echo "Configuring for ${MACHINE}"
fi
fi
if [ -z "${SDKMACHINE}" ]; then
SDKMACHINE="i686"
fi
if [ -z "${DISTRO}" ]; then
DISTRO_VAR=DEFAULT_DISTRO_${CONFIG_TEMPLATE}
eval DISTRO=\$$DISTRO_VAR
fi
OEROOT=${CWD}/sources/poky
if [ -e ${CWD}/sources/oe-core ]; then
OEROOT=${CWD}/sources/oe-core
fi
. ${OEROOT}/oe-init-build-env ${CWD}/$1 > /dev/null
# if conf/local.conf not generated, no need to go further
if [ ! -e conf/local.conf ]; then
clean_up && return 1
fi
# Clean up PATH, because if it includes tokens to current directories somehow,
# wrong binaries can be used instead of the expected ones during task execution
export PATH="`echo ${PATH} | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
generated_config=
if [ ! -e conf/local.conf.sample ]; then
mv conf/local.conf conf/local.conf.sample
# Generate the local.conf based on the Yocto defaults, throw away comments
TEMPLATES=${CWD}/sources/template/conf
grep -v '^#\|^$' conf/local.conf.sample > conf/local.conf
echo "link additional includes from ${TEMPLATES} to ./conf/ ..."
FILES=$(find ${TEMPLATES} -maxdepth 1 -type f -name "*.inc")
echo "link ${FILES}"
for f in ${FILES}; do
ln -s ${f} conf/$(basename ${f})
done
echo "link auto.conf templates from ${TEMPLATES} to ./conf/ ..."
FILES=$(find ${TEMPLATES} -maxdepth 1 -type f -name "auto.conf*")
echo "link ${FILES}"
for f in ${FILES}; do
ln -s ${f} conf/$(basename ${f})
done
ln -s ${TEMPLATES}/auto.conf.normal ./conf/auto.conf
! [ -e ./conf/auto.conf ] && "missing auto.conf" && clean_up && return 1
# copy local bblayers.conf templates
if [ -e ${TEMPLATES}/${BBLAYERS_TEMPLATE} ]; then
ln -s ${TEMPLATES}/${BBLAYERS_TEMPLATE} conf/bblayers.conf.tmpl
cp ${TEMPLATES}/${BBLAYERS_TEMPLATE} conf/bblayers.conf
fi
# Change settings according environment
sed -e "s,MACHINE ??=.*,MACHINE ??= \"${MACHINE}\",g" \
-e "s,SDKMACHINE ??=.*,SDKMACHINE ??= \"${SDKMACHINE}\",g" \
-e "s,DISTRO ?=.*,DISTRO ?= \"${DISTRO}\",g" \
-i conf/local.conf
# check for site.conf and create link if available
for s in ${HOME}/.oe ${HOME}/.yocto; do
if [ -e ${s}/site.conf ]; then
echo "Linking ${s}/site.conf to conf/site.conf"
ln -s ${s}/site.conf conf
fi
done
generated_config=1
fi
# call handle_eula if meta-freescale is in conf/bblayers.conf
grep "meta-freescale" conf/bblayers.conf >> /dev/null
[ "$?" -eq "0" ] && handle_eula
# print welcome banner ...
cat <<EOF
Welcome to TQ metalayer test
The Yocto Project has extensive documentation about OE including a
reference manual which can be found at:
http://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
You can now run 'bitbake <target>'
Common targets are:
core-image-minimal
meta-toolchain
meta-toolchain-sdk
adt-installer
meta-ide-support
EOF
# finally give info whether we use an existing buildspace or
# just created a new one ...
if [ -n "${generated_config}" ]; then
cat <<EOF
Your build environment has been configured with:
MACHINE=${MACHINE}
SDKMACHINE=${SDKMACHINE}
DISTRO=${DISTRO}
EULA=${EULA}
EOF
else
echo "Your configuration files at $1 have not been touched."
cmp conf/bblayers.conf conf/bblayers.conf.tmpl > /dev/null
[ "$?" -ne "0" ] && echo "Your conf/bblayers.conf (or the template changed)"
fi
clean_up