-
-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathbundle.bbclass
More file actions
617 lines (544 loc) · 25.2 KB
/
Copy pathbundle.bbclass
File metadata and controls
617 lines (544 loc) · 25.2 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
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# Class for creating RAUC bundles
#
# See https://rauc.readthedocs.io/en/latest/integration.html for general
# information on how to integrate RAUC into your platform.
#
# An example bundle recipe can look as follows:
#
# inherit bundle
# [...]
#
# RAUC_BUNDLE_COMPATIBLE ?= "My Super Product"
#
# RAUC_BUNDLE_FORMAT = "verity"
#
# RAUC_BUNDLE_SLOTS ?= "bootloader kernel rootfs"
#
# RAUC_SLOT_rootfs ?= "core-image-minimal"
#
# RAUC_SLOT_kernel ?= "linux-yocto"
# RAUC_SLOT_kernel[type] ?= "kernel"
#
# RAUC_SLOT_bootloader ?= "barebox"
# RAUC_SLOT_bootloader[type] ?= "boot"
#
# Additional bundle information can be set using 'RAUC_BUNDLE_COMPATIBLE',
# 'RAUC_BUNDLE_VERSION', 'RAUC_BUNDLE_DESCRIPTION', and 'RAUC_BUNDLE_BUILD'.
# See https://rauc.readthedocs.io/en/latest/reference.html#update-section
# for the meaning of the individual fields.
#
# With 'RAUC_BUNDLE_SLOTS' you list the slot classes the bundle should contain
# an image for.
# With the RAUC_SLOT_<slotclass> entries, you specify which recipe provides the
# file/image. Additional configuration can be done using varflags like 'name',
# 'type', 'imagetype', 'file', or 'hooks'.
#
# To use a hook script, add it to the SRC_URI and let RAUC_BUNDLE_HOOKS point
# to it:
#
# SRC_URI += "file://hook.sh"
# RAUC_BUNDLE_HOOKS[file] ?= "hook.sh"
#
# For (global) install hooks, use the RAUC_BUNDLE_HOOKS 'hooks' varflag:
#
# RAUC_BUNDLE_HOOKS[hooks] ?= "install-check"
#
# For slot hooks, use the 'hooks' varflag of the corresponding slot. E.g.:
#
# RAUC_SLOT_rootfs[hooks] ?= "pre-install;post-install"
#
# To use a different name for the image section in the bundle manifest (e.g. to
# distinguish slot variants), use the 'name' varflag.
# RAUC_SLOT_dtb ?= linux-yocto
# RAUC_SLOT_dtb[name] ?= "dtb.my,compatible"
# RAUC_SLOT_dtb[type] ?= "file"
# RAUC_SLOT_dtb[file] ?= "${MACHINE}-variant1.dtb"
#
# To include the slot image under a different file name in the bundle, use the
# 'rename' varflag:
# RAUC_SLOT_rootfs ?= "core-image-minimal"
# RAUC_SLOT_rootfs[rename] ?= "rootfs.ext4"
#
# RAUC also accepts image sections without an actual image file, e.g. for
# 'install' hooks. These can be specified using the 'none' type:
# RAUC_SLOT_datafs[type] ?= "none"
# RAUC_SLOT_datafs[hooks] ?= "install"
#
# To explicitly set the image 'type' in the manifest, use 'imagetype'.
# When using this option, the filename extension can be chosen freely.
# RAUC_SLOT_bootloader ?= "u-boot"
# RAUC_SLOT_bootloader[imagetype] ?= "raw"
# RAUC_SLOT_bootloader[file] ?= "u-boot.bin"
#
# RAUC_SLOT_data[imagetype] ?= "emptyfs"
#
# To generate an artifact image, use <repo>/<artifact> as the image name:
# RAUC_BUNDLE_SLOTS += "containers/test"
# RAUC_SLOT_containers/test ?= "container-test-image"
# RAUC_SLOT_containers/test[fstype] = "tar.gz"
# RAUC_SLOT_containers/test[convert] = "tar-extract;composefs"
#
# To prepend an offset to a bootloader image, set the following parameter in bytes.
# Optionally you can use units allowed by 'dd' e.g. 'K','kB','MB'.
# If the offset is negative, bytes will not be added, but removed.
# RAUC_SLOT_bootloader[offset] ?= "0"
#
# To unpack before writing the image in the bundle, use 'unpack'. Possible
# values are 'bzip2', 'gzip', 'xz' and 'zst'. 'unpack' requires 'file' to be set
# and is not compatible with 'offset'.
# RAUC_SLOT_rootfs ?= "core-image-minimal"
# RAUC_SLOT_rootfs[file] = "core-image-minimal-qemuarm64.rootfs.ext4.zst"
# RAUC_SLOT_rootfs[unpack] = "zst"
#
# Enable building verity format bundles with
#
# RAUC_BUNDLE_FORMAT = "verity"
#
# To add additional files to the bundle you can use RAUC_BUNDLE_EXTRA_FILES
# and RAUC_BUNDLE_EXTRA_DEPENDS.
# For files from the UNPACKDIR (fetched using SRC_URI) you can write:
#
# SRC_URI += "file://myfile"
# RAUC_BUNDLE_EXTRA_FILES += "myfile"
#
# For files from the DEPLOY_DIR_IMAGE (generated by another recipe) you can write:
#
# RAUC_BUNDLE_EXTRA_DEPENDS += "myfile-recipe-pn"
# RAUC_BUNDLE_EXTRA_FILES += "myfile.img"
#
# Extra arguments may be passed to the bundle command with BUNDLE_ARGS eg:
# BUNDLE_ARGS += ' --mksquashfs-args="-comp zstd -Xcompression-level 22" '
#
# Likewise, extra arguments can be passed to the convert command with
# CONVERT_ARGS.
#
# Additionally you need to provide a certificate and a key file
#
# RAUC_KEY_FILE ?= "development-1.key.pem"
# RAUC_CERT_FILE ?= "development-1.cert.pem"
#
# For bundle signature verification a keyring file must be provided
#
# RAUC_KEYRING_FILE ?= "ca.cert.pem"
#
# To encrypt manifests of 'crypt' format bundles (RAUC_BUNDLE_FORMAT = "crypt")
# during the BSP build already, set
#
# RAUC_ENCRYPT_CRYPT_BUNDLE = "1"
#
# and set a corresponding certificate file of the recipient(s):
#
# RAUC_RECIPIENTS_CERT_FILE ?= "recipient-certs.pem"
#
# This requires RAUC_KEYRING_FILE to be set.
#
# Note that encrypting the bundle during BSP builds only fits development or
# 'single shared key' scenarios that don't support key revocation! For all other
# cases, per-device (re)encryption should happen outside the BSP.
#
# Enable building casync bundles with
#
# RAUC_CASYNC_BUNDLE = "1"
#
# To define custom manifest 'meta' sections, you may use
# 'RAUC_META_SECTIONS' as follows:
#
# RAUC_META_SECTIONS = "mydata foo"
#
# RAUC_META_mydata[release-type] = "beta"
# RAUC_META_mydata[release-notes] = "a few notes here"
#
# RAUC_META_foo[bar] = "baz"
#
# Adding any sort of additional lines to the manifest can be done with the
# RAUC_MANIFEST_EXTRA_LINES variable (using '\n' to indicate newlines):
#
# RAUC_MANIFEST_EXTRA_LINES = "[section]\nkey=value\n"
LICENSE ?= "MIT"
PACKAGE_ARCH = "${MACHINE_ARCH}"
inherit nopackages
PACKAGES = ""
INHIBIT_DEFAULT_DEPS = "1"
# [""] is added to avoid "list index out of range" error with empty IMAGE_FSTYPES
RAUC_IMAGE_FSTYPE ??= "${@(d.getVar('IMAGE_FSTYPES').split() + [""])[0]}"
RAUC_IMAGE_FSTYPE[doc] = "Specifies the default file name extension to expect for collecting images. Defaults to first element set in IMAGE_FSTYPES."
do_patch[noexec] = "1"
do_compile[noexec] = "1"
do_install[noexec] = "1"
deltask do_populate_sysroot
RAUC_BUNDLE_COMPATIBLE ??= "${MACHINE}${TARGET_VENDOR}"
RAUC_BUNDLE_VERSION ??= "${PV}"
RAUC_BUNDLE_DESCRIPTION ??= "${SUMMARY}"
RAUC_BUNDLE_BUILD ??= "${DATETIME}"
RAUC_BUNDLE_BUILD[vardepsexclude] = "DATETIME"
RAUC_BUNDLE_COMPATIBLE[doc] = "Specifies the mandatory bundle compatible string. See RAUC documentation for more details."
RAUC_BUNDLE_VERSION[doc] = "Specifies the bundle version string. See RAUC documentation for more details."
RAUC_BUNDLE_DESCRIPTION[doc] = "Specifies the bundle description string. See RAUC documentation for more details."
RAUC_BUNDLE_BUILD[doc] = "Specifies the bundle build stamp. See RAUC documentation for more details."
RAUC_BUNDLE_SLOTS[doc] = "Space-separated list of slot classes to include in bundle (manifest)"
RAUC_BUNDLE_HOOKS[doc] = "Allows to specify an additional hook executable and bundle hooks (via varflags '[file'] and ['hooks'])"
RAUC_BUNDLE_EXTRA_FILES[doc] = "Specifies list of additional files to add to bundle. Files must either be located in UNPACKDIR (added by SRC_URI) or DEPLOY_DIR_IMAGE (assured by RAUC_BUNDLE_EXTRA_DEPENDS)"
RAUC_BUNDLE_EXTRA_DEPENDS[doc] = "Specifies list of recipes that create files in DEPLOY_DIR_IMAGE. For recipes not depending on do_deploy task also <recipename>:do_<taskname> notation is supported"
RAUC_ENCRYPT_CRYPT_BUNDLE ??= "0"
RAUC_CASYNC_BUNDLE ??= "0"
RAUC_BUNDLE_FORMAT ??= ""
RAUC_BUNDLE_FORMAT[doc] = "Specifies the bundle format to be used (plain/verity/crypt)."
RAUC_VARFLAGS_SLOTS = "name type fstype imagetype file hooks adaptive rename offset depends convert"
RAUC_VARFLAGS_HOOKS = "file hooks"
# Create dependency list from images
python __anonymous() {
for slot in (d.getVar('RAUC_BUNDLE_SLOTS') or "").split():
slot_varflags = d.getVar('RAUC_VARFLAGS_SLOTS').split()
slotflags = d.getVarFlags('RAUC_SLOT_%s' % slot, expand=slot_varflags) or {}
# emptyfs manifest image type doesn't support/require dependencies
if slotflags.get('imagetype') == 'emptyfs':
continue
imgtype = slotflags.get('type')
if not imgtype:
bb.debug(1, "No [type] given for slot '%s', defaulting to 'image'" % slot)
imgtype = 'image'
image = d.getVar('RAUC_SLOT_%s' % slot)
if not image and imgtype != 'none':
bb.fatal("No image set for slot '%s'. Specify via 'RAUC_SLOT_%s = \"<recipe-name>\"'" % (slot, slot))
return
d.appendVarFlag('do_unpack', 'vardeps', ' RAUC_SLOT_%s' % slot)
depends = slotflags.get('depends')
if depends:
d.appendVarFlag('do_unpack', 'depends', ' ' + depends)
continue
if imgtype == 'image':
d.appendVarFlag('do_unpack', 'depends', ' ' + image + ':do_image_complete')
d.appendVarFlag('do_rm_work_all', 'depends', ' ' + image + ':do_rm_work_all')
elif imgtype == 'none':
pass
else:
d.appendVarFlag('do_unpack', 'depends', ' ' + image + ':do_deploy')
extension = slotflags.get('unpack')
if extension:
decompressor = {
"bz2": " bzip2-native ",
"gz": " gzip-native ",
"xz": " xz-native ",
"zst": " zstd-native ",
}.get(extension)
if not decompressor:
bb.error("Not supported compressor filename extension: %s" % extension)
return
d.appendVar('DEPENDS', decompressor)
for image in (d.getVar('RAUC_BUNDLE_EXTRA_DEPENDS') or "").split():
imagewithdep = image.split(':')
deptask = imagewithdep[1] if len(imagewithdep) > 1 else 'do_deploy'
d.appendVarFlag('do_unpack', 'depends', ' %s:%s' % (imagewithdep[0], deptask))
bb.note('adding extra dependency %s:%s' % (imagewithdep[0], deptask))
}
S = "${UNPACKDIR}"
B = "${WORKDIR}/build"
BUNDLE_DIR = "${S}/bundle"
RAUC_KEY_FILE ??= ""
RAUC_KEY_FILE[doc] = "Specifies the path to the RAUC key file used for signing. Use COREBASE to reference files located in any shared BSP folder."
RAUC_CERT_FILE ??= ""
RAUC_CERT_FILE[doc] = "Specifies the path to the RAUC cert file used for signing. Use COREBASE to reference files located in any shared BSP folder."
RAUC_RECIPIENTS_CERT_FILE ??= ""
RAUC_RECIPIENTS_CERT_FILE[doc] = "Specifies the path to the RAUC cert file used for encryption. Use COREBASE to reference files located in any shared BSP folder."
RAUC_KEYRING_FILE ??= ""
RAUC_KEYRING_FILE[doc] = "Specifies the path to the RAUC keyring file used for bundle signature verification. Use COREBASE to reference files located in any shared BSP folder."
BUNDLE_ARGS ??= ""
BUNDLE_ARGS[doc] = "Specifies any extra arguments to pass to the rauc bundle command."
CONVERT_ARGS ??= ""
CONVERT_ARGS[doc] = "Specifies any extra arguments to pass to the rauc convert command."
DEPENDS = "rauc-native squashfs-tools-native"
DEPENDS += "${@bb.utils.contains('RAUC_CASYNC_BUNDLE', '1', 'virtual/fakeroot-native casync-native', '', d)}"
inherit image-artifact-names
def write_manifest(d):
def decompress_image(src, dst, extension):
import subprocess
decompressor = {
"bz2": "bzip2",
"gz": "gzip",
"xz": "xz",
"zst": "zstd -f",
}.get(extension)
if not decompressor:
raise bb.fatal("Not supported compressor filename extension: %s" % extension)
cmd = "%s -dc %s > %s" % (decompressor, src, dst)
subprocess.check_call(cmd, shell=True)
import shutil
import subprocess
from pathlib import PurePath
machine = d.getVar('MACHINE')
bundle_path = d.expand("${BUNDLE_DIR}")
bb.utils.mkdirhier(bundle_path)
try:
manifest = open('%s/manifest.raucm' % bundle_path, 'w')
except OSError:
bb.fatal('Unable to open manifest.raucm')
manifest.write('[update]\n')
manifest.write(d.expand('compatible=${RAUC_BUNDLE_COMPATIBLE}\n'))
manifest.write(d.expand('version=${RAUC_BUNDLE_VERSION}\n'))
manifest.write(d.expand('description=${RAUC_BUNDLE_DESCRIPTION}\n'))
manifest.write(d.expand('build=${RAUC_BUNDLE_BUILD}\n'))
manifest.write('\n')
bundle_format = d.getVar('RAUC_BUNDLE_FORMAT')
if not bundle_format:
bb.warn('No RAUC_BUNDLE_FORMAT set. This will default to using legacy \'plain\' format.'
'\nIf you are unsure, set RAUC_BUNDLE_FORMAT = "verity" for new projects.'
'\nRefer to https://rauc.readthedocs.io/en/latest/reference.html#sec-ref-formats for more information about RAUC bundle formats.')
elif bundle_format != "plain":
manifest.write('[bundle]\n')
manifest.write(d.expand('format=${RAUC_BUNDLE_FORMAT}\n'))
manifest.write('\n')
hooks_varflags = d.getVar('RAUC_VARFLAGS_HOOKS').split()
hooksflags = d.getVarFlags('RAUC_BUNDLE_HOOKS', expand=hooks_varflags) or {}
have_hookfile = False
if 'file' in hooksflags:
have_hookfile = True
manifest.write('[hooks]\n')
manifest.write("filename=%s\n" % hooksflags.get('file'))
if 'hooks' in hooksflags:
manifest.write("hooks=%s\n" % hooksflags.get('hooks'))
manifest.write('\n')
elif 'hooks' in hooksflags:
bb.warn("Suspicious use of RAUC_BUNDLE_HOOKS[hooks] without RAUC_BUNDLE_HOOKS[file]")
for slot in (d.getVar('RAUC_BUNDLE_SLOTS') or "").split():
slot_varflags = d.getVar('RAUC_VARFLAGS_SLOTS').split()
slotflags = d.getVarFlags('RAUC_SLOT_%s' % slot, expand=slot_varflags) or {}
slotname = slotflags.get('name', slot)
manifest.write('[image.%s]\n' % slotname)
if 'hooks' in slotflags:
if not have_hookfile:
bb.warn("A hook is defined for slot %s, but RAUC_BUNDLE_HOOKS[file] is not defined" % slot)
manifest.write("hooks=%s\n" % slotflags.get('hooks'))
if 'adaptive' in slotflags:
manifest.write("adaptive=%s\n" % slotflags.get('adaptive'))
if 'convert' in slotflags:
manifest.write("convert=%s\n" % slotflags.get('convert'))
manifest_imagetype = slotflags.get('imagetype', None)
if manifest_imagetype:
manifest.write("type=%s\n" % manifest_imagetype)
# emptyfs image type can skip image file handling
if manifest_imagetype == "emptyfs":
continue
imgtype = slotflags.get('type', 'image')
if imgtype == 'none':
continue
elif imgtype == 'image':
fallback = "%s%s%s.%s" % (
d.getVar('RAUC_SLOT_%s' % slot),
d.getVar('IMAGE_MACHINE_SUFFIX'),
d.getVar('IMAGE_NAME_SUFFIX'),
slotflags.get('fstype', d.getVar('RAUC_IMAGE_FSTYPE')))
imgname = imgsource = slotflags.get('file', fallback)
elif imgtype == 'kernel':
# TODO: Add image type support
fallback = "%s-%s.bin" % ("zImage", machine)
imgsource = slotflags.get('file', fallback)
imgname = "%s.%s" % (imgsource, "img")
elif imgtype == 'boot':
imgname = imgsource = slotflags.get('file', 'barebox.img')
elif imgtype == 'file':
imgsource = slotflags.get('file')
if not imgsource:
bb.fatal('Image type "file" requires [file] varflag to be set for slot %s' % slot)
imgname = "%s.%s" % (imgsource, "img")
else:
bb.fatal('Unknown image type: %s' % imgtype)
# Remove the last matching suffix when unpack is set (keep the .img)
if 'unpack' in slotflags:
imgname = "".join(imgname.rsplit(".%s" % slotflags.get('unpack'), 1))
imgname = slotflags.get('rename', imgname)
if 'offset' in slotflags:
padding = 'seek'
imgoffset = slotflags.get('offset')
if imgoffset:
sign, magnitude = imgoffset[:1], imgoffset[1:]
if sign == '+':
padding = 'seek'
imgoffset = magnitude
elif sign == '-':
padding = 'skip'
imgoffset = magnitude
if imgoffset == '':
imgoffset = '0'
# Keep only the image name in case the image is in a $DEPLOY_DIR_IMAGE subdirectory
imgname = PurePath(imgname).name
manifest.write("filename=%s\n" % imgname)
manifest.write("\n")
bundle_imgpath = "%s/%s" % (bundle_path, imgname)
bb.note("adding image to bundle dir: '%s'" % imgname)
searchpath = d.expand("${DEPLOY_DIR_IMAGE}/%s") % imgsource
if os.path.isfile(searchpath):
if imgtype == 'boot' and 'offset' in slotflags and imgoffset != '0':
if 'unpack' in slotflags:
bb.fatal("unpack not supported for image type boot with offset")
subprocess.call(['dd', 'if=%s' % searchpath,
'of=%s' % bundle_imgpath,
'iflag=skip_bytes', 'oflag=seek_bytes',
'%s=%s' % (padding, imgoffset)])
elif 'unpack' in slotflags:
decompress_image(searchpath, bundle_imgpath, slotflags.get('unpack'))
else:
shutil.copy(searchpath, bundle_imgpath)
else:
searchpath = d.expand("${UNPACKDIR}/%s") % imgsource
if os.path.isfile(searchpath):
if 'unpack' in slotflags:
decompress_image(searchpath, bundle_imgpath, slotflags.get('unpack'))
else:
shutil.copy(searchpath, bundle_imgpath)
else:
raise bb.fatal('Failed to find source %s' % imgsource)
if not os.path.exists(bundle_imgpath):
raise bb.fatal("Failed adding image '%s' to bundle: not present in DEPLOY_DIR_IMAGE or UNPACKDIR" % imgsource)
for meta_section in (d.getVar('RAUC_META_SECTIONS') or "").split():
manifest.write("[meta.%s]\n" % meta_section)
for meta_key in d.getVarFlags('RAUC_META_%s' % meta_section):
meta_value = d.getVarFlag('RAUC_META_%s' % meta_section, meta_key)
manifest.write("%s=%s\n" % (meta_key, meta_value))
manifest.write("\n");
manifest.write((d.getVar('RAUC_MANIFEST_EXTRA_LINES') or "").replace(r'\n', '\n'))
manifest.close()
def try_searchpath(file, d):
searchpath = d.expand("${DEPLOY_DIR_IMAGE}/%s") % file
if os.path.isfile(searchpath):
bb.note("adding extra file from deploy dir to bundle dir: '%s'" % file)
return searchpath
elif os.path.isdir(searchpath):
bb.note("adding extra directory from deploy dir to bundle dir: '%s'" % file)
return searchpath
searchpath = d.expand("${UNPACKDIR}/%s") % file
if os.path.isfile(searchpath):
bb.note("adding extra file from workdir to bundle dir: '%s'" % file)
return searchpath
elif os.path.isdir(searchpath):
bb.note("adding extra directory from workdir to bundle dir: '%s'" % file)
return searchpath
return None
python do_configure() {
import shutil
import os
import stat
import subprocess
write_manifest(d)
hooks_varflags = d.getVar('RAUC_VARFLAGS_HOOKS').split()
hooksflags = d.getVarFlags('RAUC_BUNDLE_HOOKS', expand=hooks_varflags) or {}
if 'file' in hooksflags:
hf = hooksflags.get('file')
if not os.path.exists(d.expand("${UNPACKDIR}/%s" % hf)):
bb.error("hook file '%s' does not exist in UNPACKDIR" % hf)
return
dsthook = d.expand("${BUNDLE_DIR}/%s" % hf)
bb.note("adding hook file to bundle dir: '%s'" % hf)
shutil.copy(d.expand("${UNPACKDIR}/%s" % hf), dsthook)
st = os.stat(dsthook)
os.chmod(dsthook, st.st_mode | stat.S_IEXEC)
for file in (d.getVar('RAUC_BUNDLE_EXTRA_FILES') or "").split():
bundledir = d.getVar('BUNDLE_DIR')
searchpath = try_searchpath(file, d)
if not searchpath:
bb.fatal("extra file '%s' neither found in workdir nor in deploy dir!" % file)
destdir = '.'
# strip leading and trailing slashes to prevent installing into wrong location
file = file.rstrip('/').lstrip('/')
if "/" in file:
destdir = file.rsplit("/", 1)[0] + '/'
bb.utils.mkdirhier("%s/%s" % (bundledir, destdir))
bb.note("Unpacking %s to %s/" % (file, bundledir))
subprocess.check_call('cp -fpPRH "%s" "%s"' % (searchpath, destdir), shell=True, cwd=bundledir)
}
do_configure[cleandirs] = "${BUNDLE_DIR}"
do_configure[vardeps] += "RAUC_BUNDLE_HOOKS[file] RAUC_BUNDLE_HOOKS[hooks]"
BUNDLE_BASENAME ??= "${PN}"
BUNDLE_BASENAME[doc] = "Specifies desired output base name of generated RAUC bundle."
BUNDLE_NAME ??= "${BUNDLE_BASENAME}-${MACHINE}-${DATETIME}"
BUNDLE_NAME[doc] = "Specifies desired full output name of generated RAUC bundle."
# Don't include the DATETIME variable in the sstate package signatures
BUNDLE_NAME[vardepsexclude] = "DATETIME"
BUNDLE_LINK_NAME ??= "${BUNDLE_BASENAME}-${MACHINE}"
BUNDLE_EXTENSION ??= ".raucb"
BUNDLE_EXTENSION[doc] = "Specifies desired custom filename extension of generated RAUC bundle."
ENCRYPTED_BUNDLE_BASENAME ??= "encrypted-${BUNDLE_BASENAME}"
ENCRYPTED_BUNDLE_BASENAME[doc] = "Specifies desired output base name of generated RAUC crypt bundle."
ENCRYPTED_BUNDLE_NAME ??= "${ENCRYPTED_BUNDLE_BASENAME}-${MACHINE}-${DATETIME}"
ENCRYPTED_BUNDLE_NAME[doc] = "Specifies desired full output name of generated RAUC crypt bundle."
# Don't include the DATETIME variable in the sstate package signatures
ENCRYPTED_BUNDLE_NAME[vardepsexclude] = "DATETIME"
ENCRYPTED_BUNDLE_LINK_NAME ??= "${ENCRYPTED_BUNDLE_BASENAME}-${MACHINE}"
ENCRYPTED_BUNDLE_EXTENSION ??= "${BUNDLE_EXTENSION}"
ENCRYPTED_BUNDLE_EXTENSION[doc] = "Specifies desired custom filename extension of generated RAUC bundle."
CASYNC_BUNDLE_BASENAME ??= "casync-${BUNDLE_BASENAME}"
CASYNC_BUNDLE_BASENAME[doc] = "Specifies desired output base name of generated RAUC casync bundle."
CASYNC_BUNDLE_NAME ??= "${CASYNC_BUNDLE_BASENAME}-${MACHINE}-${DATETIME}"
CASYNC_BUNDLE_NAME[doc] = "Specifies desired full output name of generated RAUC casync bundle."
# Don't include the DATETIME variable in the sstate package signatures
CASYNC_BUNDLE_NAME[vardepsexclude] = "DATETIME"
CASYNC_BUNDLE_LINK_NAME ??= "${CASYNC_BUNDLE_BASENAME}-${MACHINE}"
CASYNC_BUNDLE_EXTENSION ??= "${BUNDLE_EXTENSION}"
CASYNC_BUNDLE_EXTENSION[doc] = "Specifies desired custom filename extension of generated RAUC casync bundle."
fakeroot do_bundle() {
if [ -z "${RAUC_KEY_FILE}" ]; then
bbfatal "'RAUC_KEY_FILE' not set. Please set to a valid key file location."
fi
if [ -z "${RAUC_CERT_FILE}" ]; then
bbfatal "'RAUC_CERT_FILE' not set. Please set to a valid certificate file location."
fi
${STAGING_BINDIR_NATIVE}/rauc bundle \
--debug \
--cert="${RAUC_CERT_FILE}" \
--key="${RAUC_KEY_FILE}" \
${BUNDLE_ARGS} \
${BUNDLE_DIR} \
${B}/bundle.raucb
if [ ${RAUC_ENCRYPT_CRYPT_BUNDLE} -eq 1 ]; then
if [ "${RAUC_BUNDLE_FORMAT}" != "crypt" ]; then
bbfatal "'RAUC_BUNDLE_FORMAT' is not 'crypt'. In order to encrypt bundles during building, please use the 'crypt' bundle format."
fi
if [ -z "${RAUC_RECIPIENTS_CERT_FILE}" ]; then
bbfatal "'RAUC_RECIPIENTS_CERT_FILE' not set. Please set a valid recipient certificate file location."
fi
if [ -z "${RAUC_KEYRING_FILE}" ]; then
bbfatal "'RAUC_KEYRING_FILE' not set. Please set a valid keyring file location."
fi
${STAGING_BINDIR_NATIVE}/rauc encrypt \
--debug \
--to="${RAUC_RECIPIENTS_CERT_FILE}" \
--keyring="${RAUC_KEYRING_FILE}" \
${B}/bundle.raucb \
${B}/encrypted-bundle.raucb
fi
if [ ${RAUC_CASYNC_BUNDLE} -eq 1 ]; then
if [ -z "${RAUC_KEYRING_FILE}" ]; then
bbfatal "'RAUC_KEYRING_FILE' not set. Please set a valid keyring file location."
fi
${STAGING_BINDIR_NATIVE}/rauc convert \
--debug \
--trust-environment \
--cert=${RAUC_CERT_FILE} \
--key=${RAUC_KEY_FILE} \
--keyring=${RAUC_KEYRING_FILE} \
${CONVERT_ARGS} \
${B}/bundle.raucb \
${B}/casync-bundle.raucb
fi
}
do_bundle[dirs] = "${B}"
do_bundle[cleandirs] = "${B}"
do_bundle[file-checksums] += "${RAUC_CERT_FILE}:False ${RAUC_KEY_FILE}:False"
addtask bundle after do_configure
inherit deploy
SSTATE_SKIP_CREATION:task-deploy = '1'
do_deploy() {
install -d ${DEPLOYDIR}
install -m 0644 ${B}/bundle.raucb ${DEPLOYDIR}/${BUNDLE_NAME}${BUNDLE_EXTENSION}
ln -sf ${BUNDLE_NAME}${BUNDLE_EXTENSION} ${DEPLOYDIR}/${BUNDLE_LINK_NAME}${BUNDLE_EXTENSION}
if [ ${RAUC_ENCRYPT_CRYPT_BUNDLE} -eq 1 ]; then
install -m 0644 ${B}/encrypted-bundle.raucb ${DEPLOYDIR}/${ENCRYPTED_BUNDLE_NAME}${ENCRYPTED_BUNDLE_EXTENSION}
ln -sf ${ENCRYPTED_BUNDLE_NAME}${ENCRYPTED_BUNDLE_EXTENSION} ${DEPLOYDIR}/${ENCRYPTED_BUNDLE_LINK_NAME}${ENCRYPTED_BUNDLE_EXTENSION}
fi
if [ ${RAUC_CASYNC_BUNDLE} -eq 1 ]; then
install -m 0644 ${B}/casync-bundle.raucb ${DEPLOYDIR}/${CASYNC_BUNDLE_NAME}${CASYNC_BUNDLE_EXTENSION}
cp -r ${B}/casync-bundle.castr ${DEPLOYDIR}/${CASYNC_BUNDLE_NAME}.castr
ln -sf ${CASYNC_BUNDLE_NAME}${CASYNC_BUNDLE_EXTENSION} ${DEPLOYDIR}/${CASYNC_BUNDLE_LINK_NAME}${CASYNC_BUNDLE_EXTENSION}
ln -sf ${CASYNC_BUNDLE_NAME}.castr ${DEPLOYDIR}/${CASYNC_BUNDLE_LINK_NAME}.castr
fi
}
addtask deploy after do_bundle before do_build