diff mbox series

[meta-swupdate,v2,2/2] image_types_swupdate: add swu image type

Message ID 20180517093710.4155-2-raphael.freudiger@siemens.com
State Changes Requested
Headers show
Series [meta-swupdate,v2,1/2] swupdate_class: split out common python functionality | expand

Commit Message

Raphael Freudiger May 17, 2018, 9:37 a.m. UTC
Signed-off-by: Raphael Freudiger <raphael.freudiger@siemens.com>
---
 classes/image_types_swupdate.bbclass | 62 ++++++++++++++++++++++++++++++++++++
 classes/swupdate-common.bbclass      |  4 ++-
 classes/swupdate.bbclass             |  3 +-
 3 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 classes/image_types_swupdate.bbclass

Comments

Stefano Babic June 4, 2018, 7:26 a.m. UTC | #1
On 17/05/2018 11:37, Raphael Freudiger wrote:
> Signed-off-by: Raphael Freudiger <raphael.freudiger@siemens.com>
> ---
>  classes/image_types_swupdate.bbclass | 62 ++++++++++++++++++++++++++++++++++++
>  classes/swupdate-common.bbclass      |  4 ++-
>  classes/swupdate.bbclass             |  3 +-
>  3 files changed, 67 insertions(+), 2 deletions(-)
>  create mode 100644 classes/image_types_swupdate.bbclass
> 
> diff --git a/classes/image_types_swupdate.bbclass b/classes/image_types_swupdate.bbclass
> new file mode 100644
> index 0000000..d86e936
> --- /dev/null
> +++ b/classes/image_types_swupdate.bbclass
> @@ -0,0 +1,62 @@
> +# Define swupdate image type that can be used in images.
> +#
> +# Example Usage:
> +#
> +# IMAGE_FSTYPES += "swu"
> +# IMAGE_TYPEDEP_swu = "ext4.gz"
> +# SWUPDATE_FILES += "${PN}-${MACHINE}.ext4.gz
> +inherit swupdate-common
> +
> +
> +SWUPDATE_FILES ?= " \
> +                sw-description \
> +                ${@ 'sw-description.sig' if d.getVar('SWUPDATE_SIGNING', True) else ''} \
> +                "
> +
> +IMAGE_CMD_swu () {
> +    cd ${S}
> +    for i in ${SWUPDATE_FILES}
> +    do
> +        echo $i
> +    done | cpio -ov -H crc > ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.swu
> +}
> +
> +python do_prepare_swupdate() {
> +    import shutil
> +    s = d.getVar('S', True)
> +    workdir = d.getVar('WORKDIR', True)
> +    deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
> +    imgdeploydir = d.getVar('IMGDEPLOYDIR', True)
> +
> +    swupdate_files = (d.getVar('SWUPDATE_FILES', True) or '').split()
> +
> +    list_for_cpio = []
> +    for file in swupdate_files:
> +        imagename = os.path.basename(file)
> +        src = os.path.join(workdir, imagename)
> +        if not os.path.exists(src):
> +            src = os.path.join(deploydir, imagename)
> +        if not os.path.exists(src):
> +            src = os.path.join(imgdeploydir, imagename)
> +        if not os.path.exists(src):
> +            bb.fatal("File %s does not exist in any of the directories %s, %s or %s."
> +                     % (imagename, workdir, deploydir, imgdeploydir))
> +        dst = os.path.join(s, imagename)
> +        shutil.copyfile(src, dst)
> +        list_for_cpio.append(imagename)
> +    d.setVar('SWUPDATE_FILES', ' '.join(list_for_cpio))
> +
> +    prepare_sw_description(d)
> +}
> +
> +# The image type needs an additional preparation task, but it should only be executed when needed.
> +# Check that swu is in the IMAGE_FSTYPES before adding the task.
> +python () {
> +    fstypes = (d.getVar('IMAGE_FSTYPES', True) or '').split()
> +    dep = (d.getVar('IMAGE_TYPEDEP_swu', True) or '').split()
> +    if 'swu' in fstypes:
> +        # make sure dependencies are build before the preparation
> +        after = ['do_rootfs']
> +        after += ['do_image_%s' % typ.split('.')[0] for typ in dep]
> +        bb.build.addtask('do_prepare_swupdate', 'do_image_swu', ' '.join(after), d)
> +}
> diff --git a/classes/swupdate-common.bbclass b/classes/swupdate-common.bbclass
> index f53c55f..3fa891c 100644
> --- a/classes/swupdate-common.bbclass
> +++ b/classes/swupdate-common.bbclass
> @@ -29,7 +29,9 @@ def swupdate_write_sha256(s, filename, hash):
>          for line in write_lines:
>              f.write(line)
>  
> -def prepare_sw_description(d, list_for_cpio):
> +def prepare_sw_description(d):
> +    list_for_cpio = (d.getVar('SWUPDATE_FILES', True) or '').split()
> +    s = d.getVar('S', True)
>  
>      for file in list_for_cpio:
>          if file != 'sw-description' and swupdate_is_hash_needed(s, file):
> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
> index e24b387..df6b3e5 100644
> --- a/classes/swupdate.bbclass
> +++ b/classes/swupdate.bbclass
> @@ -106,7 +106,8 @@ python do_swuimage () {
>              shutil.copyfile(src, dst)
>              list_for_cpio.append(imagename)
>  
> -    prepare_sw_description(d, list_for_cpio)
> +    d.setVar('SWUPDATE_FILES', ' '.join(list_for_cpio))
> +    prepare_sw_description(d)
>  
>      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)
> 

Applied to -master and -sumo, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/classes/image_types_swupdate.bbclass b/classes/image_types_swupdate.bbclass
new file mode 100644
index 0000000..d86e936
--- /dev/null
+++ b/classes/image_types_swupdate.bbclass
@@ -0,0 +1,62 @@ 
+# Define swupdate image type that can be used in images.
+#
+# Example Usage:
+#
+# IMAGE_FSTYPES += "swu"
+# IMAGE_TYPEDEP_swu = "ext4.gz"
+# SWUPDATE_FILES += "${PN}-${MACHINE}.ext4.gz
+inherit swupdate-common
+
+
+SWUPDATE_FILES ?= " \
+                sw-description \
+                ${@ 'sw-description.sig' if d.getVar('SWUPDATE_SIGNING', True) else ''} \
+                "
+
+IMAGE_CMD_swu () {
+    cd ${S}
+    for i in ${SWUPDATE_FILES}
+    do
+        echo $i
+    done | cpio -ov -H crc > ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.swu
+}
+
+python do_prepare_swupdate() {
+    import shutil
+    s = d.getVar('S', True)
+    workdir = d.getVar('WORKDIR', True)
+    deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
+    imgdeploydir = d.getVar('IMGDEPLOYDIR', True)
+
+    swupdate_files = (d.getVar('SWUPDATE_FILES', True) or '').split()
+
+    list_for_cpio = []
+    for file in swupdate_files:
+        imagename = os.path.basename(file)
+        src = os.path.join(workdir, imagename)
+        if not os.path.exists(src):
+            src = os.path.join(deploydir, imagename)
+        if not os.path.exists(src):
+            src = os.path.join(imgdeploydir, imagename)
+        if not os.path.exists(src):
+            bb.fatal("File %s does not exist in any of the directories %s, %s or %s."
+                     % (imagename, workdir, deploydir, imgdeploydir))
+        dst = os.path.join(s, imagename)
+        shutil.copyfile(src, dst)
+        list_for_cpio.append(imagename)
+    d.setVar('SWUPDATE_FILES', ' '.join(list_for_cpio))
+
+    prepare_sw_description(d)
+}
+
+# The image type needs an additional preparation task, but it should only be executed when needed.
+# Check that swu is in the IMAGE_FSTYPES before adding the task.
+python () {
+    fstypes = (d.getVar('IMAGE_FSTYPES', True) or '').split()
+    dep = (d.getVar('IMAGE_TYPEDEP_swu', True) or '').split()
+    if 'swu' in fstypes:
+        # make sure dependencies are build before the preparation
+        after = ['do_rootfs']
+        after += ['do_image_%s' % typ.split('.')[0] for typ in dep]
+        bb.build.addtask('do_prepare_swupdate', 'do_image_swu', ' '.join(after), d)
+}
diff --git a/classes/swupdate-common.bbclass b/classes/swupdate-common.bbclass
index f53c55f..3fa891c 100644
--- a/classes/swupdate-common.bbclass
+++ b/classes/swupdate-common.bbclass
@@ -29,7 +29,9 @@  def swupdate_write_sha256(s, filename, hash):
         for line in write_lines:
             f.write(line)
 
-def prepare_sw_description(d, list_for_cpio):
+def prepare_sw_description(d):
+    list_for_cpio = (d.getVar('SWUPDATE_FILES', True) or '').split()
+    s = d.getVar('S', True)
 
     for file in list_for_cpio:
         if file != 'sw-description' and swupdate_is_hash_needed(s, file):
diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
index e24b387..df6b3e5 100644
--- a/classes/swupdate.bbclass
+++ b/classes/swupdate.bbclass
@@ -106,7 +106,8 @@  python do_swuimage () {
             shutil.copyfile(src, dst)
             list_for_cpio.append(imagename)
 
-    prepare_sw_description(d, list_for_cpio)
+    d.setVar('SWUPDATE_FILES', ' '.join(list_for_cpio))
+    prepare_sw_description(d)
 
     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)