-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup-environment
More file actions
executable file
·222 lines (188 loc) · 7.59 KB
/
setup-environment
File metadata and controls
executable file
·222 lines (188 loc) · 7.59 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
#!/usr/bin/env bash
##############################################################################
#
# Copyright (C) 2013, Linaro Ltd.
# Authored-by: Nicolas Dechesne <nicolas.dechesne@linaro.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################
if [ "$0" = "${BASH_SOURCE}" ]; then
echo -e "\nERROR: This script must not be executed but sourced like below"
echo -e "\n. $0 \nor \nsource $0"
exit 1
fi
if [ -z "$BASH" -a -z "$ZSH_NAME" ] ;then
echo Please source this script in bash or zsh shell
return 1
fi
# check that we are not root!
if [ "$(whoami)" = "root" ]; then
echo -e "\nERROR: do not use the BSP as root. Exiting..."
return 1
fi
OE_CORE_LAYER="openembedded-core"
if [ -d "poky" ];then
OE_CORE_LAYER="poky"
fi
# check that we are where we think we are!
if [ ! -f "$OE_CORE_LAYER/oe-init-build-env" ]; then
echo -e "\nUNABLE TO FIND OPENEMBEDDED !"
return 1
fi
usage () {
cat <<EOF
Usage: [MACHINE=<MACHINE>] source $BASH_SOURCE [BUILDDIR]
If no MACHINE is set, list all possible machines, and ask user to choose.
EOF
}
# Clean up PATH for local dirs starting with .
export PATH="`echo ${PATH} | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
# Clean PATH of any previous oe-core bitbake or scripts directories
export PATH="$(echo $PATH | sed 's!/[^:]\+/$OE_CORE_LAYER/\(bitbake/bin\|scripts\):!!g')"
# only 1 parameter max, <build> folder, or default to build-$machine
_BUILDDIR=
if [ $# -gt 1 ]; then
usage
return 1
elif [ $# -eq 1 ]; then
_BUILDDIR=$1
# check if this <build> folder was already configured
_CONFIGS_FOUND=
if [ -f ${_BUILDDIR}/conf/local.conf ] && \
[ -f ${_BUILDDIR}/conf/bblayers.conf ]; then
_CONFIGS_FOUND="yes"
fi
fi
# if no MACHINE is set, list common machines and ask user.
# Note: filter out meta-linaro and non-x86 qemu machines from this list to
# avoid confusion (it's still possible to select any valid machine manually).
while [ -z "$MACHINE" ] && [ -z "$_CONFIGS_FOUND" ]; do
_options=$(\ls -1 *{,/*}/conf/machine/*.conf 2>/dev/null | grep -v '\(^meta-linaro\|^meta-intel\|/qemumips\|/qemuppc\)')
_options_count=`echo ${_options} | wc -w`
PS3="Please enter your choice of machine [1..${_options_count}]: "
select opt in `echo $_options`
do
if [ -z "$opt" ]; then
echo "Invalid choice"
else
MACHINE=$(echo $opt | sed 's|.*/\(.*\)\.conf|\1|')
break;
fi
done
unset PS3 _options_count _options
done
# Setting CPC_CUSTOM_STAMP in auto.conf
if [ -f "generic/yocto-hooks/$MACHINE/setup-datetime.sh" ]; then
./generic/yocto-hooks/$MACHINE/setup-datetime.sh
fi
# at this point, MACHINE is set, either from env, or explicitely
# BUILDIR is either set from command line, or needs to be set to build-$MACHINE
if [ -z "$_BUILDDIR" ]; then
_BUILDDIR=build-$MACHINE
# check if this build-$MACHINE folder was already configured
if [ -f ${_BUILDDIR}/conf/local.conf ] && \
[ -f ${_BUILDDIR}/conf/bblayers.conf ]
then
_CONFIGS_FOUND="yes"
fi
fi
_PWD_PREV=$(pwd)
# Warning: Sourcing the oe-init-build-env script changes the current directory.
TEMPLATECONF=${_PWD_PREV}/meta-rdk/conf source $OE_CORE_LAYER/oe-init-build-env ${_BUILDDIR}
if [ "$_CONFIGS_FOUND" ]; then
echo -e "\nConfig files already exist in folder ${_BUILDDIR}/conf/, they were not modified."
unset -f usage
unset _BUILDDIR _CONFIGS_FOUND _PWD_PREV MACHINE
return 0
fi
# Determine DISTRO_CODENAME from the bitbake version
# Warning: The RDK has historically combined bitbake 1.28 (ie the version of
# bitbake released with OE 2.0) with OE 1.6. We need to account for that here,
# ie bitbake version 1.28 needs to map to "daisy", not "jethro".
case "$(sed -n 's/^__version__ = "\(.*\)"/\1/p' ${_PWD_PREV}/$OE_CORE_LAYER/bitbake/bin/bitbake)"
in
2.2.*) _DISTRO_CODENAME="kirkstone" ;;
2.0.*) _DISTRO_CODENAME="kirkstone" ;;
1.46.*) _DISTRO_CODENAME="dunfell" ;;
1.37.*|1.38.*) _DISTRO_CODENAME="sumo" ;;
1.35.*|1.36.*) _DISTRO_CODENAME="rocko" ;;
1.34.*) _DISTRO_CODENAME="pyro" ;;
1.32.*) _DISTRO_CODENAME="morty" ;;
1.30.*) _DISTRO_CODENAME="krogoth" ;;
*) _DISTRO_CODENAME="daisy" ;;
esac
sed -e "s/##DISTRO_CODENAME##/$_DISTRO_CODENAME/g" \
-i conf/local.conf
# Check the machine type specified
_VALID_MACHINES=$(\ls -1 ${_PWD_PREV}/*{,/*}/conf/machine/${MACHINE}.conf 2>/dev/null | wc -l)
if [ "$_VALID_MACHINES" -eq 0 ]; then
echo -e "\n##\n## WARNING: No machine configs found for '$MACHINE' !"
echo -e "##\n## That looks very suspicious, you should check your configuration"
echo -e "##\n## Possible alternatives might be:\n##"
( cd ${_PWD_PREV} && \ls -1 *{,/*}/conf/machine/*.conf 2>/dev/null | sed 's|.*/\(.*\)\.conf|## \1|' | sort | uniq )
echo -e "##"
elif [ "$_VALID_MACHINES" -gt 1 ]; then
echo -e "\n##\n## WARNING: Multiple possible machine configs found for '$MACHINE' !\n##"
( cd ${_PWD_PREV} && \ls -1 *{,/*}/conf/machine/${MACHINE}.conf 2>/dev/null | sed 's|^|## |' )
echo -e "##\n## That looks very suspicious, you should check your source tree\n##"
fi
# Change settings according environment
sed -e "s/##MACHINE##/$MACHINE/g" \
-i conf/local.conf
if [ -f ${_PWD_PREV}/auto.conf ]; then
ln -s ${_PWD_PREV}/auto.conf conf/auto.conf
fi
# Append BSP layer to BBLAYERS, if the machine is not from meta-linaro or OE (which are included in BBLAYERS by default)
if [ "$_VALID_MACHINES" -eq 1 ]; then
_MACH_CONF=`find ${_PWD_PREV}/meta-* -name ${MACHINE}.conf`
_BSP_LAYER_REQUIRED=`echo ${_MACH_CONF} | sed -n 's/.*\(meta-.*\)\(\/conf\/machine\/\).*/\1/p'`
_LAYERS=`\grep '^#@NEEDED_BSPLAYERS:' ${_MACH_CONF}`
_BSP=`echo ${_LAYERS} |cut -f 2 -d ':'`
if [ -n "${_BSP}" ]; then
for bsp in $_BSP; do
cat >> conf/bblayers.conf <<EOF
BBLAYERS =+ "\${RDKROOT}/$bsp"
EOF
done
fi
if [ -n "${_BSP_LAYER_REQUIRED}" -a "${_LAYERS#*${_BSP_LAYER_REQUIRED}}" = "${_LAYERS}" ]; then
cat >> conf/bblayers.conf <<EOF
BBLAYERS =+ "\${RDKROOT}/${_BSP_LAYER_REQUIRED}"
EOF
fi
_RDK_FLAVOR=`sed -n '/^#@RDK_FLAVOR:/p' ${_MACH_CONF} | sed -e 's/^#@RDK_FLAVOR:\s//g'`
[ -z "${_RDK_FLAVOR}" ] && _RDK_FLAVOR="rdkv"
sed -e "s|##RDK_FLAVOR##|${_RDK_FLAVOR}|g" -i conf/local.conf
fi
rpi='raspberrypi-rdk-cmc'
if [[ "$MACHINE" == *"$rpi"* ]]; then
source ${PWD}/../meta-rdk/rename_srcrev.sh
fi
cat <<EOF
Configuration files have been created for the following configuration:
DISTRO: ${_RDK_FLAVOR}
MACHINE: $MACHINE
EOF
(
set +e
# Hook for multiconfig build, where we create multiconfig directory under build conf directory and
# copy mc conf files
mul_hooks=$(ls -1 ../*{,/*}/conf/machine/post-builddir-$MACHINE.sh 2>/dev/null)
if [ -f "$mul_hooks" ]; then
echo "running script $mul_hooks"
source $mul_hooks $MACHINE
fi
)
# Since this script is sourced, be careful not to pollute caller's environment with temp variables
unset -f usage
unset _BUILDDIR _CONFIGS_FOUND _PWD_PREV _VALID_MACHINES _NCPU _BSP MACHINE _LAYERS _MACH_CONF _BSP_LAYER_REQUIRED _DISTRO_CODENAME