-
Notifications
You must be signed in to change notification settings - Fork 29
/
setup-environment-internal
481 lines (415 loc) · 17.4 KB
/
setup-environment-internal
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#!/bin/bash
# -*- mode: shell-script-mode; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# Copyright (C) 2012-13 O.S. Systems Software LTDA.
# Copyright (C) 2017-2018 Foundries.io
# Authored-by: Otavio Salvador <otavio@ossystems.com.br>
# Adopted to Angstrom: Khem Raj <raj.khem@gmail.com>
#
# 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.
#
env_cleanup() {
unset MACHINETABLE MACHLAYERS DISTRO_DIRNAME OEROOT
unset ITEM MANIFESTS EULA EULA_MACHINE REPLY READ_EULA
unset usage oldmach
if [ -n "$BUILDDIR" ]; then
export BUILDDIR
fi
}
trap env_cleanup RETURN
if [ "$(whoami)" = "root" ]; then
echo "ERROR: do not build LMP as root. Exiting..."
return
fi
OEROOT=$(readlink -f $(pwd))
cd "$OEROOT"
if [ -n "$ZSH_VERSION" ]; then
setopt sh_word_split
setopt clobber
elif [ -n "$BASH_VERSION" ]; then
set +o noclobber
fi
# Set default distro to Linux microPlatform
DISTRO="${DISTRO-lmp}"
usage () {
cat <<EOF
Usage: [MACHINE=<MACHINE>] source ${BASH_SOURCE[0]} [BUILDDIR]
If no MACHINE is set, list all possible machines, and ask user to choose.
If no BUILDIR is set, it will be set to build-$DISTRO.
EOF
}
if [ $# -gt 1 ]; then
usage
return 1
fi
# Create a common list of "<machine>(<layer>)", sorted by <machine>
# Blacklist OE-core and meta-linaro, we only want BSP layers
MACHLAYERS=$(find layers -print | grep "conf/machine/.*\.conf" |
grep -v scripts | grep -v openembedded-core | grep -v meta-linaro |
sed -e 's/\.conf//g' -e 's/layers\///' |
awk -F'/conf/machine/' '{print $NF "(" $1 ")"}' | LANG=C sort)
if [ -z "${MACHINE}" ]; then
# whiptail
which whiptail > /dev/null 2>&1
if [ $? -eq 0 ]; then
MACHINETABLE=
for ITEM in $MACHLAYERS; do
MACHINETABLE="${MACHINETABLE} $(echo "$ITEM" | cut -d'(' -f1) \
$(echo "$ITEM" | cut -d'(' -f2 | cut -d')' -f1)"
done
MACHINE=$(whiptail --title "Available Machines" --menu \
"Please choose a machine" 0 0 20 \
${MACHINETABLE} 3>&1 1>&2 2>&3)
fi
# dialog
if [ -z "$MACHINE" ]; then
which dialog > /dev/null 2>&1
if [ $? -eq 0 ]; then
MACHINETABLE=
for ITEM in $MACHLAYERS; do
MACHINETABLE="$MACHINETABLE $(echo "$ITEM" | cut -d'(' -f1) \
$(echo "$ITEM" | cut -d'(' -f2 | cut -d')' -f1)"
done
MACHINE=$(dialog --title "Available Machines" --menu \
"Please choose a machine" 0 0 20 $MACHINETABLE \
3>&1 1>&2 2>&3)
fi
fi
fi
# guard against Ctrl-D or cancel
if [ -z "$MACHINE" ]; then
echo "To choose a machine interactively please install whiptail or dialog."
echo "To choose a machine non-interactively please use the following:"
echo " MACHINE=<your-machine> . ./setup-environment"
echo ""
echo "Press <ENTER> to see a list of your choices"
read -r
echo "$MACHLAYERS" | sed -e 's/(/ (/g' | sed -e 's/)/)\n/g' |
sed -e 's/^ */\t/g'
return
fi
if [ -z "${SDKMACHINE}" ]; then
SDKMACHINE='x86_64'
fi
MANIFESTS="${OEROOT}"/.repo/manifests
# We can be called with only 1 parameter max (build folder)
BUILDDIR=build-$DISTRO
if [ $# -eq 1 ]; then
BUILDDIR=$1
fi
BUILDDIR=$OEROOT/$BUILDDIR
# 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/:.\?$//')
export PATH="${OEROOT}/bitbake/bin:${OEROOT}/.repo/repo:${PATH}"
export PATH="${OEROOT}/layers/openembedded-core/scripts:${PATH}"
# Remove duplicate path entries
export PATH=$(echo "$PATH" |
awk -F: '{for (i=1;i<=NF;i++) { if ( !x[$i]++ ) printf("%s:",$i); }}' |
sed 's/:$//')
# Make sure Bitbake doesn't filter out the following variables from our env
export BB_ENV_PASSTHROUGH_ADDITIONS="MACHINE DISTRO TCLIBC TCMODE GIT_PROXY_COMMAND \
http_proxy ftp_proxy https_proxy all_proxy ALL_PROXY no_proxy \
SSH_AGENT_PID SSH_AUTH_SOCK BB_SRCREV_POLICY SDKMACHINE \
BB_NUMBER_THREADS BB_LOGCONFIG BB_CONSOLELOG"
mkdir -p "${BUILDDIR}"/conf && cd "${BUILDDIR}"
if [ -f "conf/auto.conf" ]; then
oldmach=$(grep -E "^MACHINE" "conf/auto.conf" |
sed -e 's%^MACHINE ?= %%' | sed -e 's/^"//' -e 's/"$//')
fi
if [ -e conf/checksum ] && [ "${MACHINE}" = "$oldmach" ]; then
sha512sum --quiet -c conf/checksum > /dev/null 2>&1
if [ $? -eq 0 ]; then
return
fi
fi
# Evaluate new checksum and regenerate the conf files
sha512sum "${MANIFESTS}"/setup-environment-internal 2>&1 > conf/checksum
if [ ! -f "conf/local.conf" ]; then
cp "${MANIFESTS}"/conf/local.conf conf/local.conf
fi
# Copy default development keys if not set by the user
if [ -d "${MANIFESTS}"/conf/keys ]; then
mkdir -p conf/keys
if [ ! -f "conf/keys/dev.key" ] && [ ! -f "conf/keys/dev.crt" ]; then
ln -sf "${MANIFESTS}"/conf/keys/dev.key conf/keys/dev.key
ln -sf "${MANIFESTS}"/conf/keys/dev.crt conf/keys/dev.crt
fi
# Copy default SPL development keys if not set by the user
if [ ! -f "conf/keys/spldev.key" ] && [ ! -f "conf/keys/spldev.crt" ]; then
ln -sf "${MANIFESTS}"/conf/keys/spldev.key conf/keys/spldev.key
ln -sf "${MANIFESTS}"/conf/keys/spldev.crt conf/keys/spldev.crt
fi
# Copy default u-boot development keys if not set by the user
if [ ! -f "conf/keys/ubootdev.key" ] && [ ! -f "conf/keys/ubootdev.crt" ]; then
ln -sf "${MANIFESTS}"/conf/keys/ubootdev.key conf/keys/ubootdev.key
ln -sf "${MANIFESTS}"/conf/keys/ubootdev.crt conf/keys/ubootdev.crt
fi
# Copy default optee development keys if not set by the user
if [ ! -f "conf/keys/opteedev.key" ] && [ ! -f "conf/keys/opteedev.crt" ]; then
ln -sf "${MANIFESTS}"/conf/keys/opteedev.key conf/keys/opteedev.key
ln -sf "${MANIFESTS}"/conf/keys/opteedev.crt conf/keys/opteedev.crt
fi
# Copy default module kernel development keys if not set by the user
if [ ! -f "conf/keys/privkey_modsign.pem" ] && [ ! -f "conf/keys/x509_modsign.crt" ]; then
ln -sf "${MANIFESTS}"/conf/keys/privkey_modsign.pem conf/keys/privkey_modsign.pem
ln -sf "${MANIFESTS}"/conf/keys/x509_modsign.crt conf/keys/x509_modsign.crt
fi
# Link default TF-A development keys if not set by the user
if [ ! -d "conf/keys/tf-a" ]; then
ln -sf "${MANIFESTS}"/conf/keys/tf-a conf/keys/tf-a
fi
# Link default UEFI development keys and certificates if not set by the user
if [ ! -d "conf/keys/uefi" ]; then
ln -sf "${MANIFESTS}"/conf/keys/uefi conf/keys/uefi
fi
# Link default TI K3 RoT keys if not set by the user
if [ ! -d "conf/keys/platform" ]; then
ln -sf "${MANIFESTS}"/conf/keys/platform conf/keys/platform
fi
# Link Composefs keys
if [ ! -d "conf/keys/cfs" ]; then
ln -sf "${MANIFESTS}"/conf/keys/cfs conf/keys/cfs
fi
fi
# Factory specific keys (unique per factory)
if [ -d "${MANIFESTS}"/factory-keys ]; then
mkdir -p conf/factory-keys
# Copy default factory SPL development keys if not set by the user
if [ ! -f "conf/factory-keys/spldev.key" ] && [ ! -f "conf/factory-keys/spldev.crt" ]; then
ln -sf "${MANIFESTS}"/factory-keys/spldev.key conf/factory-keys/spldev.key
ln -sf "${MANIFESTS}"/factory-keys/spldev.crt conf/factory-keys/spldev.crt
fi
# Copy default factory u-boot development keys if not set by the user
if [ ! -f "conf/factory-keys/ubootdev.key" ] && [ ! -f "conf/factory-keys/ubootdev.crt" ]; then
ln -sf "${MANIFESTS}"/factory-keys/ubootdev.key conf/factory-keys/ubootdev.key
ln -sf "${MANIFESTS}"/factory-keys/ubootdev.crt conf/factory-keys/ubootdev.crt
fi
# Copy default factory optee development keys if not set by the user
if [ ! -f "conf/factory-keys/opteedev.key" ] && [ ! -f "conf/factory-keys/opteedev.crt" ]; then
ln -sf "${MANIFESTS}"/factory-keys/opteedev.key conf/factory-keys/opteedev.key
ln -sf "${MANIFESTS}"/factory-keys/opteedev.crt conf/factory-keys/opteedev.crt
fi
# Copy default factory module kernel development keys if not set by the user
if [ ! -f "conf/factory-keys/privkey_modsign.pem" ] && [ ! -f "conf/factory-keys/x509_modsign.crt" ]; then
ln -sf "${MANIFESTS}"/factory-keys/privkey_modsign.pem conf/factory-keys/privkey_modsign.pem
ln -sf "${MANIFESTS}"/factory-keys/x509_modsign.crt conf/factory-keys/x509_modsign.crt
fi
# Link custom TF-A development keys set by the user
if [ -d "${MANIFESTS}"/factory-keys/tf-a ] && [ ! -d "conf/factory-keys/tf-a" ]; then
ln -sf "${MANIFESTS}"/factory-keys/tf-a conf/factory-keys/tf-a
fi
# Link custom UEFI development keys and certificates set by the user
if [ -d "${MANIFESTS}"/factory-keys/uefi ] && [ ! -d "conf/factory-keys/uefi" ]; then
ln -sf "${MANIFESTS}"/factory-keys/uefi conf/factory-keys/uefi
fi
# Link default TI K3 RoT keys if not set by the user
if [ -d "${MANIFESTS}"/factory-keys/platform ] && [ ! -d "conf/factory-keys/platform" ]; then
ln -sf "${MANIFESTS}"/factory-keys/platform conf/factory-keys/platform
fi
# Link Composefs keys if not set by the user
if [ -d "${MANIFESTS}"/factory-keys/cfs ] && [ ! -d "conf/factory-keys/cfs" ]; then
ln -sf "${MANIFESTS}"/factory-keys/cfs conf/factory-keys/cfs
fi
fi
ln -sf "${MANIFESTS}"/conf/bblayers.conf conf/bblayers.conf
ln -sf "${MANIFESTS}"/conf/bblayers-base.inc conf/bblayers-base.inc
ln -sf "${MANIFESTS}"/conf/bblayers-bsp.inc conf/bblayers-bsp.inc
if [ -f "${MANIFESTS}"/conf/bblayers-factory.inc ]; then
ln -sf "${MANIFESTS}"/conf/bblayers-factory.inc conf/bblayers-factory.inc
fi
if [ -f "${MANIFESTS}"/conf/bblayers-partner.inc ]; then
ln -sf "${MANIFESTS}"/conf/bblayers-partner.inc conf/bblayers-partner.inc
fi
ln -sf "${MANIFESTS}"/README.md README.md
ln -sf "${MANIFESTS}" "${OEROOT}"/layers/
DISTRO_DIRNAME=$(echo "${DISTRO}" | sed 's#[.-]#_#g')
LMP_TAG="$(git --git-dir ${MANIFESTS}/.git describe HEAD --tags --abbrev=0)"
# We want to truncate the value and still use the major version cache
# (e.g. for 94.1 use 94. The .1 part of the sstate cache is
# actually in the 95 bucket. 94.1 is small enough so this doesn't matter).
# If we ever have a minor release that causes sufficient cache
# invalidation, then we'll need to re-think how to produce the cache better.
LMP_TAG="$(echo $LMP_TAG | sed 's/\.[0-9]*$//')"
if [[ ! $LMP_TAG =~ ^[[:digit:]] ]]; then
LMP_TAG_ARR=(${LMP_TAG//-/ })
LMP_PARTNER_NAME="${LMP_TAG_ARR[0]}"
LMP_VERSION_CACHE_TMP="${LMP_TAG_ARR[1]}"
else
LMP_VERSION_CACHE_TMP="${LMP_TAG}"
fi
if [ -z "$LMP_VERSION_CACHE" ]; then
LMP_VERSION_CACHE="${LMP_VERSION_CACHE_TMP}"
if [ -v LMP_VERSION_CACHE_DEV ]; then
# to use the development version of the cache the user need to define the LMP_VERSION_CACHE_DEV env
LMP_VERSION_CACHE=$(( $LMP_VERSION_CACHE + 1 ))
fi
fi
if [[ ! -z "$LMP_PARTNER_NAME" ]]; then
SSTATE_MIRRORS="file://.* https://storage.googleapis.com/lmp-cache/$LMP_PARTNER_NAME/v$LMP_VERSION_CACHE-sstate-cache/PATH"
else
SSTATE_MIRRORS="file://.* https://storage.googleapis.com/lmp-cache/v$LMP_VERSION_CACHE-sstate-cache/PATH"
fi
cat > conf/auto.conf <<EOF
DISTRO ?= "${DISTRO}"
MACHINE ?= "${MACHINE}"
SDKMACHINE ?= "${SDKMACHINE}"
# Use public state cache mirror if no other is defined
SSTATE_MIRRORS ??= "$SSTATE_MIRRORS"
# Extra options that can be changed by the user
INHERIT += "rm_work"
INHERIT += "buildstats buildstats-summary"
INHERIT += "buildhistory"
BUILDHISTORY_COMMIT = "1"
EOF
# LMP_VERSION_CACHE was required in some other places on CI so
# we need to proper check for the existence of LMP_VERSION,
# which is only available on CI, to safely remove the LMP_VERSION_CACHE
# on local builds
if [ ! -v LMP_VERSION ]; then
# we don't need this anymore
unset LMP_VERSION_CACHE
fi
if [ ! -e conf/site.conf ]; then
cat > conf/site.conf <<_EOF
SCONF_VERSION = "1"
# Where to store sources
DL_DIR ?= "${OEROOT}/downloads"
# Where to save shared state
SSTATE_DIR ?= "${OEROOT}/sstate-cache"
# Where to save the build system work output
TMPDIR = "${BUILDDIR}/tmp-${DISTRO_DIRNAME}"
# Where to save the packages and images
DEPLOY_DIR = "${BUILDDIR}/deploy"
# Go through the Firewall
#HTTP_PROXY = "http://${PROXYHOST}:${PROXYPORT}/"
_EOF
# LmP default mirrors cache location
LMP_LOCAL_SSTATE_MIRRORS="${LMP_LOCAL_SSTATE_MIRRORS:-/yocto/lmp/cache/sstate-mirrors}"
LMP_LOCAL_PRE_MIRRORS="${LMP_LOCAL_PRE_MIRRORS:-/yocto/lmp/cache/downloads-mirrors}"
if [ -d "${LMP_LOCAL_SSTATE_MIRRORS}" ]; then
cat >> conf/site.conf <<_EOF
# State cache mirror is available locally on the file system
SSTATE_MIRRORS += "file://.* file://${LMP_LOCAL_SSTATE_MIRRORS}/PATH"
_EOF
fi
if [ -d "${LMP_LOCAL_PRE_MIRRORS}" ]; then
cat >> conf/site.conf <<_EOF
# Download mirror is available locally on the file system
PREMIRRORS += " \
git://.*/.* file://${LMP_LOCAL_PRE_MIRRORS} \
ftp://.*/.* file://${LMP_LOCAL_PRE_MIRRORS} \
http://.*/.* file://${LMP_LOCAL_PRE_MIRRORS} \
https://.*/.* file://${LMP_LOCAL_PRE_MIRRORS} \
"
_EOF
fi
fi
# Handle EULA , if needed. This is a generic method to handle BSPs
# that might (or not) come with a EULA. If a machine has a EULA, we
# assume that its corresponding layers has conf/EULA/$MACHINE file
# with the EULA text, which we will display to the user and request
# for acceptance. If accepted, the variable ACCEPT_EULA:$MACHINE is
# set to 1 in auto.conf, which can later be used by the BSP.
# If the env variable EULA_$MACHINE is set it is used by default,
# without prompting the user.
# FIXME: there is a potential issue if the same $MACHINE is set in
# more than one layer.. but we should assert that earlier
EULA=$(find ../layers -path "*/conf/eula/$MACHINE" -print | grep -v scripts |
grep -v openembedded-core | grep -v meta-linaro || true)
if [ -n "$EULA" ]; then
# remove '-' since we are constructing a bash variable name here
EULA_MACHINE="EULA_$(echo "$MACHINE" | sed 's/-//g')"
# NOTE: indirect reference / dynamic variable
if [ -n "${!EULA_MACHINE}" ]; then
# the EULA_$MACHINE variable is set in the environment, so we just
# configure # ACCEPT_EULA:$MACHINE in auto.conf
echo "ACCEPT_EULA:$MACHINE = \"${!EULA_MACHINE}\"" >> conf/auto.conf
else
# so we need to ask user if he/she accepts the EULA:
cat <<EOF
The BSP for $MACHINE depends on packages and firmware which are covered by an
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
echo
REPLY=
while [ -z "$REPLY" ]; do
echo -n "Would you like to read the EULA ? (y/n) "
read -r REPLY
case "$REPLY" in
y|Y)
READ_EULA=1
;;
n|N)
READ_EULA=0
;;
*)
REPLY=
;;
esac
done
if [ "$READ_EULA" = 1 ]; then
more -d "${EULA}"
echo
REPLY=
while [ -z "$REPLY" ]; do
echo -n "Do you accept the EULA you just read? (y/n) "
read -r REPLY
case "$REPLY" in
y|Y)
echo "EULA has been accepted."
echo "ACCEPT_EULA:$MACHINE = \"1\"" >> conf/auto.conf
;;
n|N)
echo "EULA has not been accepted."
;;
*)
REPLY=
;;
esac
done
fi
fi
fi
cat <<EOF
Welcome to Foundries.io Linux microPlatform (FIO LMP)
For more information about Linux microPlatform see:
https://app.foundries.io/docs/latest/
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
Your build environment has been configured with:
MACHINE = ${MACHINE}
DISTRO = ${DISTRO}
You can now run 'bitbake <target>'
Some common targets are:
EOF
if [ "${DISTRO}" = 'lmp-mfgtool' ]; then
if [[ "${MACHINE}" == *"stm32mp1"* ]]; then
cat <<EOF
stm32-mfgtool-files - MFGTOOL Support Files and Binaries for board flashing and provisioning (STM32MP1 machines)
EOF
else
cat <<EOF
mfgtool-files - MFGTOOL Support Files and Binaries for board flashing and provisioning
EOF
fi
else
cat <<EOF
lmp-mini-image - minimal OSTree + OTA capable image
lmp-base-console-image - mini-image + Docker container runtime
lmp-gateway-image - base-console-image + edge gateway related utilities
lmp-factory-image - default (and only available) at FoundriesFactory
EOF
fi