forked from seapath/yocto-bsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·303 lines (258 loc) · 7.74 KB
/
build.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
#!/bin/bash
#
# Yocto build system initiator.
#
# Copyright (C) 2019-2020 Savoir-faire Linux, Inc.
# This program is distributed under the Apache 2 license.
# Name: print_usage
# Brief: Print script usage
# Set image to build, default to core-image-minimal
print_usage()
{
echo "This script builds a yocto distribution
./$(basename ${0}) [OPTIONS]
Options:
(-d|--dl-dir) <path> Yocto downloads cache directory
(-i|--image) <image> Yocto target image
(--distro) <distro> Yocto target distribution
(-m|--machine) <machine> Yocto target machine
(-s|--sstate-dir) <path> Yocto build cache directory
(-k|--sdk) Compile the SDK
(-r|--remove-build-dir) Remove Yocto build directory
(-v|--verbose) Verbose mode
(--debug) Print all commands
(--no-layers-update) Don't auto update bblayers.conf
(-h|--help) Display this help message
(--) <command> Command to launch
"
}
# Name: apply_patch
# Brief: Test and apply a patch file if needed
# Param[in]: Patch file
apply_patch()
{
if patch --dry-run --silent -F 0 --strip=1 --force --input ${1} >/dev/null
then
patch --strip=1 -F 0 --force --input ${1}
fi
}
# Name: parse_options
# Brief: Parse options from command line
# Param[in]: Command line parameters
parse_options()
{
ARGS=$(getopt -o "d:i:khm:rs:v" -l "distro:,dl-dir:,help,image:,machine:,no-layers-update,debug,remove-build-dir,sdk,sstate-dir:,verbose" -n "build.sh" -- "$@")
#Bad arguments
if [ $? -ne 0 ]; then
exit 1
fi
eval set -- "${ARGS}"
while true; do
case "$1" in
--distro)
export DISTRO=$2
shift 2
;;
-d|--dl-dir)
if [ ! -d "$2" ]; then
echo "Fatal: specified dl-dir does not exist"
exit 1
fi
export DL_DIR=$(readlink -f $2)
shift 2
;;
--debug)
set -x
shift
;;
-i|--image)
export IMAGE=$2
shift 2
;;
--no-layers-update)
NO_LAYERS_UPDATE=yes
shift
;;
-m|--machine)
export MACHINE=$2
shift 2
;;
-r|--remove-build-dir)
REMOVE_BUILDDIR=1
shift
;;
-k|--sdk)
COMPILE_SDK=1
shift
;;
-s|--sstate-dir)
if [ ! -d "$2" ]; then
echo "Fatal: specified state-dir does not exist"
exit 1
fi
export SSTATE_DIR=$(readlink -f $2)
shift 2
;;
--meta-list-file)
export META_LIST_FILE=$(readlink -f $2)
shift 2
;;
-v|--verbose)
VERBOSE=1
shift
;;
-h|--help)
print_usage
exit 1
shift
break
;;
-|--)
shift
CMD=$@
break
;;
*)
print_usage
exit 1
shift
break
;;
esac
done
}
# Name: run_cmd
# Brief: Run given command with enhanced display and return code checked
# Param[in]: Command description to print
# Param[in]: The command itself
run_cmd()
{
# Description to display
description=$1
print_noln "$description"
# Remove description from parameters
shift
# Launch command
eval $@
# Check command result, exit on error
check_result $?
# Print ok otherwise
print_ok
}
# Name Update layers
# Brief Add layers in bblayers.conf using bitbake-layers add-layer
update_layers()
{
if [ -n "${NO_LAYERS_UPDATE}" ] ; then
return 0
fi
local layers_filter_pattern
if [ -s "${TOPDIR}/layers.blacklist" ] ; then
while read layer
do
layers_filter_pattern="$layers_filter_pattern${sep}${SOURCESDIR}/${layer}"
local sep="|"
done < ${TOPDIR}/layers.blacklist
layers_filter_pattern="($layers_filter_pattern)"
else
layers_filter_pattern="!()"
fi
local layers_to_add=$(find "${SOURCESDIR}"/meta-* \
"${SOURCESDIR}"/poky/meta-* \
-type f \
-path '*/conf/layer.conf' | \
xargs -n1 dirname | \
xargs -n1 dirname | egrep -v "^${layers_filter_pattern}$")
if [ -n "${layers_to_add}" ] ; then
run_cmd "update layers" "bitbake-layers add-layer ${layers_to_add}"
fi
}
##########################
########## MAIN ##########
##########################
# Include scripting tools
. scripts/bash_scripting_tools/functions.sh
#### Local vars ####
# Not verbose by default
export VERBOSE=0
# Keep directory to retrieve tools
TOPDIR=$(dirname $(readlink -f ${0}))
BUILDDIR=${TOPDIR}/build
SOURCESDIR=${TOPDIR}/sources
POKYDIR=$(dirname $(find "${SOURCESDIR}" -name "oe-init-build-env" -print -quit))
# Change to top directory
cd "${TOPDIR}"
# Check for Poky directory
if [ -z "${POKYDIR}" ]; then
print_ko_ "poky directory cannot be found"
exit 1
fi
# Parse options
parse_options "${@}"
# Display VARIABLES
echo "CMD = '$CMD'"
echo "DL_DIR = '$DL_DIR'"
echo "SSTATE_DIR = '$SSTATE_DIR'"
# Init display
init_output $VERBOSE build
# Apply patches
for patch in patches/*
do
apply_patch ${patch}
done
# Set image to build, default to core-image-minimal
export IMAGE=${IMAGE:-"seapath-host-efi-image"}
export MACHINE=${MACHINE:-"votp-host"}
export DISTRO=${DISTRO:-"seapath-host"}
export ACCEPT_FSL_EULA="1"
export LSB_WARN='0'
if [ -f seapath.conf ] ; then
for seapath_env in $(bash -c \
'( source seapath.conf ; set -o posix ; set \
| grep -e "^SEAPATH" )') ; do
seapath_env_key=$(echo ${seapath_env} | cut -d '=' -f 1)
seapath_env_value=$(echo ${seapath_env} | cut -d '=' -f 2-)
if [ -z $(printenv "${seapath_env_key}") ] ; then
export "${seapath_env_key}"="${seapath_env_value}"
fi
BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE ${seapath_env_key}"
done
fi
for seapath_env in $(printenv | grep -e "^SEAPATH") ; do
echo -n "$(echo $seapath_env | cut -d '=' -f 1) = "
echo $seapath_env | cut -d '=' -f 2-
done
# Set variable readable from command line
export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE \
DISTRO \
DL_DIR \
MACHINE \
SSTATE_DIR \
ACCEPT_FSL_EULA \
LSB_WARN \
"
if [ ! -z "$REMOVE_BUILDDIR" ]; then
# Clean directory
run_cmd "Remove build directory" rm -Rf "${BUILDDIR}"
fi
# Clean layers
if [ -z "${NO_LAYERS_UPDATE}" ] ; then
rm -f ${BUILDDIR}/conf/bblayers.conf
fi
# Init poky build
set "${BUILDDIR}"
. "${POKYDIR}"/oe-init-build-env
# Add layers
update_layers
# Build Yocto
if [ ! -z "$CMD" ]; then
run_cmd "Launch custom command (should take a while)..." "$CMD"
elif [ -z "$COMPILE_SDK" ]; then
run_cmd "Build image (should take a while)..." bitbake "$IMAGE"
else
run_cmd "Build sdk (should take a while)..." bitbake "$IMAGE" -c populate_sdk
fi
# Generate the documentation
if [ "$(type -p asciidoctor-pdf)" ]; then
asciidoctor-pdf -o tmp/deploy/images/README.pdf ../README.adoc
fi