-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-environment
More file actions
313 lines (272 loc) · 8.52 KB
/
setup-environment
File metadata and controls
313 lines (272 loc) · 8.52 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
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
#!/bin/sh
# -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# Copyright (C) 2012, 2013, 2016 O.S. Systems Software LTDA.
# Authored-by: Otavio Salvador <otavio@ossystems.com.br>
#
# 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="`cd .;pwd`"
PROGNAME=setup-environment
export BSPDIR="$CWD"
export LAYERDIR="${BSPDIR}/layers"
TEMPLATECONF="${LAYERDIR}/base/conf/templates/default"
if [ -z "$BASH_VERSION" ];then
echo "This script must to be run from bash" >&2
return 1
fi
usage()
{
echo -e "
Usage: source $PROGNAME <build-dir>
Enter an existing <build-dir> created by karo-setup-release.sh and
prepare the calling shell for running bitbake.
The build directory configuration is unchanged.
"
shopt -q nullglob && nullglob=false || nullglob=true
$nullglob && shopt -s nullglob
echo -e "
Supported machines: `echo; find ${LAYERDIR} -path '*/conf/machine/*.conf' | \
sed 's:^.*/:\t:;s/\.conf//' | sort`
Supported distros: `echo; find ${LAYERDIR} -path '*/conf/distro/*.conf' | \
sed 's:^.*/:\t:;s/\.conf//' | sort`
To build for a machine listed above, run this script as:
DISTRO=<distro> MACHINE=<machine> source $PROGNAME <build-dir>
"
$nullglob && shopt -u nullglob
return
cat << EOF
No machine configuration files found!
Make sure, to set up your yocto source directory with:
repo init -u git@github.com:karo-electronics/karo-manifest -b master
repo sync
EOF
$nullglob && shopt -u nullglob
return 1
}
clean_up()
{
unset LIST_MACHINES VALID_MACHINE
unset CWD TEMPLATECONF SHORTOPTS LONGOPTS ARGS PROGNAME
unset generated_config updated
unset MACHINE SDKMACHINE DISTRO OEROOT
}
get_timezone() {
local tz
if [ -s /etc/timezone ];then
tz="`cat /etc/timezone`"
elif [ -s /etc/localtime ];then
tz="`readlink /etc/localtime`"
tz="${tz#*zoneinfo/}"
fi
echo "$tz"
}
# 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 yocto as root! Exiting..."
return 1
fi
if [ ! -e "${1}/conf/local.conf" ];then
build_dir_setup_enabled=true
else
build_dir_setup_enabled=false
fi
if $build_dir_setup_enabled;then
if [ -z "$MACHINE" ];then
usage
echo -e "ERROR: You must set MACHINE when creating a new build directory."
clean_up
return 1
fi
if [ -z "$DISTRO" ];then
usage
echo -e "ERROR: You must set DISTRO when creating a new build directory."
clean_up
return 1
fi
# Check the machine type specified
LIST_MACHINES=`find ${LAYERDIR} -path '*/conf/machine/*.conf'`
VALID_MACHINE=`echo "$LIST_MACHINES" | grep "/${MACHINE}.conf$" | wc -l`
if [ "$MACHINE" = "" ] || [ "$VALID_MACHINE" = "0" ];then
echo -e "\nThe \$MACHINE you have specified ($MACHINE) is not supported by this build setup"
usage && clean_up
return 1
fi
echo "Configuring for ${MACHINE}"
case ${MACHINE%-*} in
txmp|qsmp)
EULA_FILE="${EULA_FILE:-${LAYERDIR}/meta-st/meta-st-stm32mp/conf/eula/ST_EULA_SLA}"
if [ ! -e "$EULA_FILE" ];then
echo -e "ERROR: EULA not found at $EULA_FILE."
clean_up
return 1
fi
;;
esac
shopt -q nullglob && nullglob=false || nullglob=true
$nullglob && shopt -s nullglob
distro_dirs="`find ${LAYERDIR} -path "*/conf/distro/${DISTRO}.conf" -printf "%h\n"`"
if [ -z "$distro_dirs" ];then
echo "Unsupported distro: '$DISTRO'" >&2
usage && clean_up
return 1
fi
bitbake_target=""
for d in $distro_dirs;do
dir="`dirname "${d}"`/../recipes-core/images"
[ -d "$dir" ] || continue
distro_images="`cd "$dir" && ls *.bb`"
bitbake_target="${bitbake_target} ${distro_images//.bb/ }"
done
for t in $bitbake_target;do
if [ "${t/-image/}" = "${DISTRO}" ];then
bitbake_target="$t"
break
fi
if [ "$DISTRO" = "karo-wayland" ];then
bitbake_target="karo-image-weston karo-image-qt6"
fi
if [ "$DISTRO" = "karo-xwayland" ];then
bitbake_target="karo-image-weston karo-image-qt6"
fi
done
fi
if [ -z "$SDKMACHINE" ];then
SDKMACHINE=`uname -m`
fi
OEROOT=${LAYERDIR}/poky
if [ -e ${LAYERDIR}/oe-core ];then
OEROOT=${LAYERDIR}/oe-core
fi
# Ensure all files in ${LAYERDIR}/base are kept in sync with project root
updated=false
for f in "${LAYERDIR}/base/"*;do
[ -f "$f" ] || continue
file="$(basename $f)"
if echo "$file" | grep -q '~$';then
continue
fi
if ! cmp -s "$file" "$f";then
updated=true
[ -e "$file" ] && chmod u+w "$file"
cp "$f" "$file"
fi
done
$nullglob && shopt -u nullglob
if $updated;then
echo "The project root content has been updated. Please run '$PROGNAME' again."
return
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 $build_dir_setup_enabled;then
mv conf/local.conf conf/local.conf.sample
# Generate the local.conf based on the Yocto defaults
grep -v '^#\|^$' conf/local.conf.sample > conf/local.conf
if [ "$DISTRO" = "karo-minimal" ];then
echo 'EXTRA_IMAGE_FEATURES += "read-only-rootfs"' >> conf/local.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
if [ -z "$DEFAULT_TIMEZONE" ];then
DEFAULT_TIMEZONE="`get_timezone`"
fi
if [ -n "$DEFAULT_TIMEZONE" ] && ! grep -q 'DEFAULT_TIMEZONE = ' conf/local.conf;then
cat <<EOF >> conf/local.conf
DEFAULT_TIMEZONE = "$DEFAULT_TIMEZONE"
EOF
fi
if [ -n "${KARO_BASEBOARD}" ];then
cat <<EOF >> conf/local.conf
KARO_BASEBOARD = "${KARO_BASEBOARD}"
EOF
fi
cp $TEMPLATECONF/* conf/
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
if [ -n "$EULA_FILE" ];then
if ! bash ${BSPDIR}/handle-eula.sh "${EULA_FILE}";then
clean_up
return 1
fi
fi
cat <<EOF
Welcome to Ka-Ro electronics TX and QS module BSP
The Yocto Project has extensive documentation about OE including a
reference manual which can be found at:
https://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
https://www.openembedded.org/
For a Ka-Ro specific Yocto guide please refer to:
"Getting Started" > "Yocto Guide" in the respective TX module page on
https://www.karo-electronics.com
${bitbake_target:+\
You can start your build now with:\
$(for i in ${bitbake_target:-core-image-minimal};do \
echo -ne "\n bitbake $i";\
done )}
EOF
if [ -n "$generated_config" ];then
cat <<EOF
Your build environment has been configured with:
MACHINE=$MACHINE
SDKMACHINE=$SDKMACHINE
DISTRO=$DISTRO
EOF
else
echo "Your configuration files at $1 have not been touched."
fi
clean_up