This is as preparation to introduce other classes in the layer.
classes/swupdate-common.bbclass | 117 ++++++++++++++++++++++++++++++++
classes/swupdate.bbclass | 117 +-------------------------------
2 files changed, 118 insertions(+), 116 deletions(-)
diff --git a/classes/swupdate-common.bbclass b/classes/swupdate-common.bbclass
index 8cfd11b..0c08ca9 100644
--- a/classes/swupdate-common.bbclass
+++ b/classes/swupdate-common.bbclass
@@ -1,3 +1,20 @@
+DEPENDS += "${@ 'openssl-native' if d.getVar('SWUPDATE_SIGNING', True) else ''}"
+do_swuimage[umask] = "022"
+SSTATETASKS += "do_swuimage"
+SSTATE_SKIP_CREATION_task-swuimage = '1'
+IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-swuimage"
+
+do_swuimage[dirs] = "${TOPDIR}"
+do_swuimage[cleandirs] += "${S} ${IMGDEPLOYDIR}"
+do_swuimage[sstate-inputdirs] = "${IMGDEPLOYDIR}"
+do_swuimage[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
+do_swuimage[stamp-extra-info] = "${MACHINE}"
+
+python () {
+ deps = " " + swupdate_getdepends(d)
+ d.appendVarFlag('do_swuimage', 'depends', deps)
+}
+
def swupdate_is_hash_needed(s, filename):
with open(os.path.join(s, "sw-description"), 'r') as f:
for line in f:
@@ -5,6 +22,22 @@ def swupdate_is_hash_needed(s, filename):
return True
return False
+def swupdate_getdepends(d):
+ def adddep(depstr, deps):
+ for i in (depstr or "").split():
+ if i not in deps:
+ deps.append(i)
+
+ deps = []
+ images = (d.getVar('IMAGE_DEPENDS', True) or "").split()
+ for image in images:
+ adddep(image , deps)
+
+ depstr = ""
+ for dep in deps:
+ depstr += " " + dep + ":do_build"
+ return depstr
+
def swupdate_get_sha256(s, filename):
import hashlib
@@ -228,3 +261,87 @@ def prepare_sw_description(d, s, list_for_cpio):
bb.fatal("Failed to sign sw-description with %s" % (privkey))
else:
bb.fatal("Unrecognized SWUPDATE_SIGNING mechanism.");
+
+python do_swuimage () {
+ import shutil
+
+ workdir = d.getVar('WORKDIR', True)
+ images = (d.getVar('SWUPDATE_IMAGES', True) or "").split()
+ s = d.getVar('S', True)
+ shutil.copyfile(os.path.join(workdir, "sw-description"), os.path.join(s, "sw-description"))
+ fetch = bb.fetch2.Fetch([], d)
+ list_for_cpio = ["sw-description"]
+
+ if d.getVar('SWUPDATE_SIGNING', True):
+ list_for_cpio.append('sw-description.sig')
+
+ # Add files listed in SRC_URI to the swu file
+ for url in fetch.urls:
+ local = fetch.localpath(url)
+ filename = os.path.basename(local)
+ aes_file = d.getVar('SWUPDATE_AES_FILE', True)
+ if aes_file:
+ key,iv = swupdate_extract_keys(d.getVar('SWUPDATE_AES_FILE', True))
+ if (filename != 'sw-description') and (os.path.isfile(local)):
+ encrypted = (d.getVarFlag("SWUPDATE_IMAGES_ENCRYPTED", filename, True) or "")
+ dst = os.path.join(s, "%s" % filename )
+ if encrypted == '1':
+ bb.note("Encryption requested for %s" %(filename))
+ if not key or not iv:
+ bb.fatal("Encryption required, but no key found")
+ swupdate_encrypt_file(local, dst, key, iv)
+ else:
+ shutil.copyfile(local, dst)
+ list_for_cpio.append(filename)
+
+ def add_image_to_swu(deploydir, imagename, s, encrypt):
+ src = os.path.join(deploydir, imagename)
+ if not os.path.isfile(src):
+ return False
+ target_imagename = os.path.basename(imagename) # allow images in subfolders of DEPLOY_DIR_IMAGE
+ dst = os.path.join(s, target_imagename)
+ if encrypt == '1':
+ key,iv = swupdate_extract_keys(d.getVar('SWUPDATE_AES_FILE', True))
+ bb.note("Encryption requested for %s" %(imagename))
+ swupdate_encrypt_file(src, dst, key, iv)
+ else:
+ shutil.copyfile(src, dst)
+ list_for_cpio.append(target_imagename)
+ return True
+
+ # Search for images listed in SWUPDATE_IMAGES in the DEPLOY directory.
+ deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
+ imgdeploydir = d.getVar('IMGDEPLOYDIR', True)
+ for image in images:
+ fstypes = (d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", image, True) or "").split()
+ encrypted = (d.getVarFlag("SWUPDATE_IMAGES_ENCRYPTED", image, True) or "")
+ if fstypes:
+ noappend_machine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True)
+ if noappend_machine == "0": # Search for a file explicitly with MACHINE
+ imagebases = [ image + '-' + d.getVar('MACHINE', True) ]
+ elif noappend_machine == "1": # Search for a file explicitly without MACHINE
+ imagebases = [ image ]
+ else: # None, means auto mode. Just try to find an image file with MACHINE or without MACHINE
+ imagebases = [ image + '-' + d.getVar('MACHINE', True), image ]
+ for fstype in fstypes:
+ image_found = False
+ for imagebase in imagebases:
+ image_found = add_image_to_swu(deploydir, imagebase + fstype, s, encrypted)
+ if image_found:
+ break
+ if not image_found:
+ bb.fatal("swupdate cannot find image file: %s" % os.path.join(deploydir, imagebase + fstype))
+ else: # Allow also complete entries like "image.ext4.gz" in SWUPDATE_IMAGES
+ if not add_image_to_swu(deploydir, image, s, encrypted):
+ bb.fatal("swupdate cannot find %s image file" % image)
+
+ prepare_sw_description(d, s, list_for_cpio)
+
+ line = 'for i in ' + ' '.join(list_for_cpio) + '; do echo $i;done | cpio -ov -H crc >' + os.path.join(imgdeploydir,d.getVar('IMAGE_NAME', True) + '.swu')
+ os.system("cd " + s + ";" + line)
+
+ line = 'ln -sf ' + d.getVar('IMAGE_NAME', True) + '.swu ' + d.getVar('IMAGE_LINK_NAME', True) + '.swu'
+ os.system("cd " + imgdeploydir + "; " + line)
+}
+
+
diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
index f2f50e7..44542d9 100644
--- a/classes/swupdate.bbclass
+++ b/classes/swupdate.bbclass
@@ -1,4 +1,4 @@
-# Copyright (C) 2015 Stefano Babic <
sba...@denx.de>
+# Copyright (C) 2015-2021 Stefano Babic <
sba...@denx.de>
#
# Some parts from the patch class
#
@@ -36,36 +36,8 @@ inherit image-artifact-names
S = "${WORKDIR}/${PN}"
-DEPENDS += "${@ 'openssl-native' if d.getVar('SWUPDATE_SIGNING', True) else ''}"
IMAGE_DEPENDS ?= ""
-def swupdate_getdepends(d):
- def adddep(depstr, deps):
- for i in (depstr or "").split():
- if i not in deps:
- deps.append(i)
-
- deps = []
- images = (d.getVar('IMAGE_DEPENDS', True) or "").split()
- for image in images:
- adddep(image , deps)
-
- depstr = ""
- for dep in deps:
- depstr += " " + dep + ":do_build"
- return depstr
-
-IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-swuimage"
-
-do_swuimage[dirs] = "${TOPDIR}"
-do_swuimage[cleandirs] += "${S} ${IMGDEPLOYDIR}"
-do_swuimage[umask] = "022"
-SSTATETASKS += "do_swuimage"
-SSTATE_SKIP_CREATION_task-swuimage = '1'
-do_swuimage[sstate-inputdirs] = "${IMGDEPLOYDIR}"
-do_swuimage[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
-do_swuimage[stamp-extra-info] = "${MACHINE}"
-
do_configure[noexec] = "1"
do_compile[noexec] = "1"
do_install[noexec] = "1"
@@ -77,93 +49,6 @@ do_package_write_ipk[noexec] = "1"
do_package_write_deb[noexec] = "1"
do_package_write_rpm[noexec] = "1"
-python () {
- deps = " " + swupdate_getdepends(d)
- d.appendVarFlag('do_swuimage', 'depends', deps)
-}
-
-python do_swuimage () {
- import shutil
-
- workdir = d.getVar('WORKDIR', True)
- images = (d.getVar('SWUPDATE_IMAGES', True) or "").split()
- s = d.getVar('S', True)
- shutil.copyfile(os.path.join(workdir, "sw-description"), os.path.join(s, "sw-description"))
- fetch = bb.fetch2.Fetch([], d)
- list_for_cpio = ["sw-description"]
-
- if d.getVar('SWUPDATE_SIGNING', True):
- list_for_cpio.append('sw-description.sig')
-
- # Add files listed in SRC_URI to the swu file
- for url in fetch.urls:
- local = fetch.localpath(url)
- filename = os.path.basename(local)
- aes_file = d.getVar('SWUPDATE_AES_FILE', True)
- if aes_file:
- key,iv = swupdate_extract_keys(d.getVar('SWUPDATE_AES_FILE', True))
- if (filename != 'sw-description') and (os.path.isfile(local)):
- encrypted = (d.getVarFlag("SWUPDATE_IMAGES_ENCRYPTED", filename, True) or "")
- dst = os.path.join(s, "%s" % filename )
- if encrypted == '1':
- bb.note("Encryption requested for %s" %(filename))
- if not key or not iv:
- bb.fatal("Encryption required, but no key found")
- swupdate_encrypt_file(local, dst, key, iv)
- else:
- shutil.copyfile(local, dst)
- list_for_cpio.append(filename)
-
- def add_image_to_swu(deploydir, imagename, s, encrypt):
- src = os.path.join(deploydir, imagename)
- if not os.path.isfile(src):
- return False
- target_imagename = os.path.basename(imagename) # allow images in subfolders of DEPLOY_DIR_IMAGE
- dst = os.path.join(s, target_imagename)
- if encrypt == '1':
- key,iv = swupdate_extract_keys(d.getVar('SWUPDATE_AES_FILE', True))
- bb.note("Encryption requested for %s" %(imagename))
- swupdate_encrypt_file(src, dst, key, iv)
- else:
- shutil.copyfile(src, dst)
- list_for_cpio.append(target_imagename)
- return True
-
- # Search for images listed in SWUPDATE_IMAGES in the DEPLOY directory.
- deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
- imgdeploydir = d.getVar('IMGDEPLOYDIR', True)
- for image in images:
- fstypes = (d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", image, True) or "").split()
- encrypted = (d.getVarFlag("SWUPDATE_IMAGES_ENCRYPTED", image, True) or "")
- if fstypes:
- noappend_machine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True)
- if noappend_machine == "0": # Search for a file explicitly with MACHINE
- imagebases = [ image + '-' + d.getVar('MACHINE', True) ]
- elif noappend_machine == "1": # Search for a file explicitly without MACHINE
- imagebases = [ image ]
- else: # None, means auto mode. Just try to find an image file with MACHINE or without MACHINE
- imagebases = [ image + '-' + d.getVar('MACHINE', True), image ]
- for fstype in fstypes:
- image_found = False
- for imagebase in imagebases:
- image_found = add_image_to_swu(deploydir, imagebase + fstype, s, encrypted)
- if image_found:
- break
- if not image_found:
- bb.fatal("swupdate cannot find image file: %s" % os.path.join(deploydir, imagebase + fstype))
- else: # Allow also complete entries like "image.ext4.gz" in SWUPDATE_IMAGES
- if not add_image_to_swu(deploydir, image, s, encrypted):
- bb.fatal("swupdate cannot find %s image file" % image)
-
- prepare_sw_description(d, s, list_for_cpio)
-
- line = 'for i in ' + ' '.join(list_for_cpio) + '; do echo $i;done | cpio -ov -H crc >' + os.path.join(imgdeploydir,d.getVar('IMAGE_NAME', True) + '.swu')
- os.system("cd " + s + ";" + line)
-
- line = 'ln -sf ' + d.getVar('IMAGE_NAME', True) + '.swu ' + d.getVar('IMAGE_LINK_NAME', True) + '.swu'
- os.system("cd " + imgdeploydir + "; " + line)
-}
-
COMPRESSIONTYPES = ""
PACKAGE_ARCH = "${MACHINE_ARCH}"
--
2.25.1