-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup-yocto
executable file
·373 lines (317 loc) · 7.9 KB
/
setup-yocto
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
#!/bin/bash
#
# Abbort script on command failure
set -e
VERSION=1.0
YOCTO_MANIFEST="fs-release-manifest.xml"
RELEASE=$(grep '<release' "${YOCTO_MANIFEST}"| grep -Po 'version="\K.*?(?=")')
YOCTO_DOWNLOAD_URL="https://github.com/FSEmbedded/releases-fus"
YOCTO_BRANCH="main"
WORKDIR=$(pwd)
YOCTO_DIR=yocto-fus
META_FUS_DIR=sources/meta-fus/
KERNEL_PATH=recipes-kernel/linux/
UBOOT_PATH=recipes-bsp/u-boot/
DL_DIR="downloads"
# Parse line with $1 and echo the value of $2 from manifest $3
parse_xml_value()
{
entry=$1
value=$2
manifest=$3
result=$(grep "path=\"${entry}\"" "${manifest}"| grep -Po "${value}=\"\K.*?(?=\")")
echo $result
}
# ----- Helper functions ------------------------------------------------------
# Show usage on error
show_usage()
{
echo
echo "Usage: $0 [options] <target>"
echo
echo "Extract the sources (u-boot, linux, yocto, examples) to directory"
echo "<target>. If a dl directory is available in the release, also copy"
echo "the extra packages in it to the download directory."
echo
echo "Options:"
echo "-r | --release <release>"
echo " Use given <release> directory to locate sources"
echo " (default: directory where this script is located)"
echo "-d | --dl <dl> Use <dl> directory as Yocto download directory"
echo " (default: \$DL_DIR or 'downloads' in Yocto's top dir)"
echo "-f | --force Force installation, overwrite files in directories"
echo " <target> and <dl> if they exist; be careful!"
echo "-n | --dry-run Show what would be done, do not change anything"
echo "-h | --help Show this help"
echo
exit 1
}
# If force is on, delete $1 and show type, otherwise just show existing name
do_delete()
{
if [ $force == 1 ] ; then
if [ -L "$1" ] ; then
echo " [DELETE SYMLINK ] $1"
$run /bin/rm -f "$1"
elif [ -d "$1" ] ; then
echo " [DELETE DIRECTORY] $1"
$run /bin/rm -rf "$1"
else
echo " [DELETE FILE ] $1"
$run /bin/rm -f "$1"
fi
else
stop=1
if [ -L "$1" ] ; then
echo "Symlink already exists: $1"
elif [ -d "$1" ] ; then
echo "Directory already exists: $1"
else
echo "File already exists: $1"
fi
fi
}
# Create directory $1
do_mkdir()
{
echo " [CREATE DIRECTORY] $1"
echo
$run /bin/mkdir -p "$1"
}
# Extract $1 to directory $2
do_extract()
{
echo " [EXTRACT ARCHIVE ] $1"
echo " [TO ] $2"
echo
$run /bin/tar xf "$1" -C "$2"
}
do_set_git_credentials()
{
echo " [GIT CREDENTIALS]"
if ! git config --global user.name
then
$run read -p "Please enter the user name that should be used for git: " username
$run git config --global user.name "$username"
fi
if ! git config --global user.email
then
$run read -p "Please enter the email that should be used for git: " email
$run git config --global user.email "$email"
fi
}
# Clone git from $1 to directory $2
# Check out branch $3 commit $4
do_clone_checkout()
{
echo " [CLONING GIT ] $1"
echo " [TO ] $2"
$run git clone "$1" "$2"
echo " [CHECKING OUT] $3 $4"
echo
$run cd "$2"
existed_in_local=$(git branch --list $3)
if [ -z "$existed_in_local" ]; then
$run git checkout --track origin/$3
fi
$run git checkout "$4"
$run cd -
}
# Copy $1 to $2
do_copy()
{
echo " [COPY PACKAGE ] $1"
echo " [TO ] $2"
echo
$run /bin/cp -f "$1" "$2"
}
# Create symlink $1 to point to $2
do_symlink()
{
echo " [CREATE SYMLINK ] $1"
echo " [TO POINT TO ] $2"
echo
$run /bin/ln -s "$2" "$1"
}
# Write SRC_URI $1 and SRCREV $2 to bbappend at $3
do_write_bbappend()
{
if [ "$#" -eq 2 ]; then
echo " [CREATING ] $2"
echo " [FROM ] $1"
$run cp -f $1 $2
elif [ "$#" -eq 3 ]; then
echo " [CREATING ] $3"
echo " [SRC_URI ] $1"
echo " [SRCREV ] $2"
echo
if [ "$run" != ":" ] ; then
echo "SRC_URI = \"${1}\"" > $3
echo "SRCREV = \"${2}\"" >> $3
fi
else
echo "write_bbappend failed"
fi
}
# Write SRC_URI $1 and SRCREV $2 to bbappend at $3
do_yocto_download()
{
echo " [DOWNOAD MANIFEST] $YOCTO_MANIFEST"
echo " [FROM ] $YOCTO_DOWNLOAD_URL"
echo " [TAG ] $RELEASE"
echo
# Create yocto directory if it does not exist yet
if [ ! -d "$YOCTO_DIR" ] ; then
$run do_mkdir "$YOCTO_DIR"
fi
#$run cd $YOCTO_DIR
# Download Yocto
# Download the repo tool that handles the download of several GIT repos
if [ ! -x ./repo ]
then
$run echo "Downloading repo tool"
$run curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > repo
$run chmod a+x repo
fi
# Fakeinit repo so we can copy our local manifest
$run echo "Getting download information (repo init)"
$run ./repo init -u $YOCTO_DOWNLOAD_URL -b $YOCTO_BRANCH -m $YOCTO_MANIFEST
$run cp $WORKDIR/$YOCTO_MANIFEST .repo/manifests/
# Download the GIT repositories:
$run echo "Downloading all Yocto packages (repo sync)"
$run ./repo sync -m $YOCTO_MANIFEST
}
# ----- Parse arguments -------------------------------------------------------
force=0
run=
TARGET=
while [ $# -gt 0 ] ; do
case "${1,,}" in
-r|--release)
if [ -z "$2" ] ; then
echo
echo "ERROR: Option '$1' needs a path parameter"
show_usage
fi
RELEASE="$2"
shift 2
;;
-d|--dl)
if [ -z "$2" ] ; then
echo
echo "ERROR: Option '$1' needs a path parameter"
show_usage
fi
DL_DIR="$2"
shift 2
;;
-h|--help)
show_usage
;;
-f|--force)
force=1
shift
;;
-n|--dry-run)
run=:
shift
;;
-v|--version)
echo $VERSION
exit
shift
;;
-*)
echo
echo "ERROR: Unknown option '$1'"
show_usage
;;
*)
TARGET="$1"
shift
;;
esac
done
if [ -z $RELEASE ] ; then
RELEASE=$(dirname $0)
fi
echo
if [ -z "$TARGET" ] ; then
echo "No target directory given; use . to install to current directory"
show_usage
fi
# OK, let's start. Prepend all delete and installation commands with $run.
# Then they are automatically skipped in case of --dry-run.
if [ "$run" == ":" ] ; then
echo "*** Dry run -- the following actions would be executed ***"
echo
fi
# ----- Remove existing files and directories ---------------------------------
# Check for main target directory
if [ -e "$TARGET" ] ; then
do_delete "$TARGET"
fi
# Check dl directory; package names must not contain blanks
dl_packages=
install_dl_packages=
create_dl_link=1
if [ -z "$DL_DIR" ] ; then
DL_DIR="$TARGET/$DL_DEF_DIR"
create_dl_link=0
fi
if [ -d "$DL_REL_DIR" ] ; then
dl_packages=$(cd "$DL_REL_DIR"; echo *)
fi
if [ -d "$DL_DIR" ] ; then
for package in $dl_packages ; do
dlpackage="$DL_DIR/$package"
if [ -e "$dlpackage" ] ; then
# Skip if existing package is identical
if cmp -s "$DL_REL_DIR/$package" "$dlpackage" ; then
continue
fi
do_delete "$dlpackage"
fi
# Add this package
install_dl_packages="$install_dl_packages $package"
done
else
# Add all packages
install_dl_packages="$dl_packages"
fi
# Stop on problems with existing files
if [ "$stop" == 1 ] ; then
echo
echo "*** Move away the file(s) or use option --force (-f) to delete. ***"
echo
exit 1;
fi
# ----- Unpack archives and set up environment --------------------------------
echo "Setup release $RELEASE"
echo
# Create target directory if it does not exist yet
if [ ! -d "$TARGET" ] ; then
do_mkdir "$TARGET"
fi
do_set_git_credentials
$run cd $TARGET
do_yocto_download
$run cd $YOCTO_DIR
# Create downloads directory if it does not exist yet
if [ ! -d $DL_DIR ] ; then
do_mkdir $DL_DIR
fi
# Print user manual from yocto-f+s-utilities
$run source ./yocto-f+s-utilities
$run print_usage
$run cd $WORKDIR
# Copy extra packages from dl, if any
if [ -d "$DL_REL_DIR" ] ; then
if [ ! -d "$DL_DIR" ] ; then
do_mkdir "$DL_DIR"
fi
for package in $install_dl_packages ; do
do_copy "$DL_REL_DIR/$package" "$DL_DIR/$package"
done
fi
echo