diff mbox series

[meta-swupdate,v2,1/3] swupdate_class: prepare to use SRC_URI in image recipes

Message ID 20210216095258.514-2-agust@denx.de
State Changes Requested
Headers show
Series Extend swupdate class to support swu image fstype | expand

Commit Message

Anatolij Gustschin Feb. 16, 2021, 9:52 a.m. UTC
Enable swuimage task if building 'update-image' recipe of the
meta-swupdate-boards layer or if building usual image recipes
with appended SRC_URI and enabled 'swu' image fstype. Fetch
SRC_URI files if 'swu' image fstype was selected.

This is in preparation of support for 'swu' image type class
(for building .swu images without meta-swupdate-boards layer).

Signed-off-by: Anatolij Gustschin <agust@denx.de>
---
 classes/swupdate.bbclass | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

Comments

Stefano Babic Feb. 17, 2021, 3:28 p.m. UTC | #1
Hi Anatolji,

On 16.02.21 10:52, Anatolij Gustschin wrote:
> Enable swuimage task if building 'update-image' recipe of the
> meta-swupdate-boards layer or if building usual image recipes
> with appended SRC_URI and enabled 'swu' image fstype. Fetch
> SRC_URI files if 'swu' image fstype was selected.
> 
> This is in preparation of support for 'swu' image type class
> (for building .swu images without meta-swupdate-boards layer).
> 
> Signed-off-by: Anatolij Gustschin <agust@denx.de>
> ---
>  classes/swupdate.bbclass | 31 ++++++++++++++++++++++++++++---
>  1 file changed, 28 insertions(+), 3 deletions(-)
> 
> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
> index 2c2430b..c2899be 100644
> --- a/classes/swupdate.bbclass
> +++ b/classes/swupdate.bbclass
> @@ -51,7 +51,10 @@ def swupdate_getdepends(d):
>  
>      depstr = ""
>      for dep in deps:
> -        depstr += " " + dep + ":do_build"
> +        if dep == d.getVar('PN'):
> +            depstr += " " + dep + ":do_image_complete"
> +        else:
> +            depstr += " " + dep + ":do_build"
>      return depstr

mmhhhh..

also, you are checking if 'PN' exists and if it is the same as the name
of your recipe. If this is true, you decide that this is an image, and
it depends on do_image_complete. It looks to me a very indirect way.
Really (I have not checked if and how this can be reached), you want to
know for the dependency "dep" if it has a task called "do_image_complete".

What about if I build a SWU from a package ? This is a use case on my
site. I have to package a file (a license file) into a SWU, and this
will be installed by SWUpdate. It is something like:

SRC_URI = "\
    file://file_to_beput_in_swu \
    file://sw-description \
    file://something_else.lua \
    "

FILES_${PN} = ....
inherit swupdate

....re-enable do_install, do_package,... ---

...


The result is a package (for rootfs) + a SWU (SWU is like another
packaging) to install this alone. Your change above should break this,
because it will add a dep to do_image_complete.

>  
>  IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-swuimage"
> @@ -76,14 +79,38 @@ do_package_write_ipk[noexec] = "1"
>  do_package_write_deb[noexec] = "1"
>  do_package_write_rpm[noexec] = "1"
>  
> +USING_SWU = "${@bb.utils.contains('IMAGE_FSTYPES', 'swu', '1', '', d)}"
> +
>  python () {
>      deps = " " + swupdate_getdepends(d)
>      d.appendVarFlag('do_swuimage', 'depends', deps)
> +
> +    # add swuimage task if building with swu image type or if
> +    # building via 'update-image' recipe in meta-swupdate-boards
> +    if d.getVar('PN') == 'update-image':

meta-swupdate-boards is just a bunch of examples, and yes the name for
SWU is "update-image", but this class should be unaware of it. There
should be no constrain how to name the recipes for SWUs.

> +        bb.build.addtask('do_swuimage', 'do_build', 'do_unpack do_prepare_recipe_sysroot', d)
> +    elif d.getVar('USING_SWU'):
> +        bb.build.addtask('do_swuimage', 'do_build', 'do_image_complete', d)
>  }
>  
>  python do_swuimage () {
>      import shutil
>  
> +    if d.getVar('USING_SWU'):
> +        src_uri = (d.getVar('SRC_URI') or "").split()
> +        if len(src_uri) == 0:
> +            bb.fatal("SRC_URI (sw-description) required with 'swu' in IMAGE_FSTYPES")
> +
> +        try:
> +            fetcher = bb.fetch2.Fetch(src_uri, d)
> +            fetcher.download()
> +        except bb.fetch2.BBFetchException as e:
> +            bb.fatal(str(e))
> +        try:
> +            fetcher.unpack(d.getVar('WORKDIR'))
> +        except bb.fetch2.BBFetchException as e:
> +            bb.fatal(str(e))
> +
>      workdir = d.getVar('WORKDIR', True)
>      images = (d.getVar('SWUPDATE_IMAGES', True) or "").split()
>      s = d.getVar('S', True)
> @@ -168,5 +195,3 @@ PACKAGE_ARCH = "${MACHINE_ARCH}"
>  
>  INHIBIT_DEFAULT_DEPS = "1"
>  EXCLUDE_FROM_WORLD = "1"
> -
> -addtask do_swuimage after do_unpack do_prepare_recipe_sysroot before do_build
> 

Best regards,
Stefano
diff mbox series

Patch

diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
index 2c2430b..c2899be 100644
--- a/classes/swupdate.bbclass
+++ b/classes/swupdate.bbclass
@@ -51,7 +51,10 @@  def swupdate_getdepends(d):
 
     depstr = ""
     for dep in deps:
-        depstr += " " + dep + ":do_build"
+        if dep == d.getVar('PN'):
+            depstr += " " + dep + ":do_image_complete"
+        else:
+            depstr += " " + dep + ":do_build"
     return depstr
 
 IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-swuimage"
@@ -76,14 +79,38 @@  do_package_write_ipk[noexec] = "1"
 do_package_write_deb[noexec] = "1"
 do_package_write_rpm[noexec] = "1"
 
+USING_SWU = "${@bb.utils.contains('IMAGE_FSTYPES', 'swu', '1', '', d)}"
+
 python () {
     deps = " " + swupdate_getdepends(d)
     d.appendVarFlag('do_swuimage', 'depends', deps)
+
+    # add swuimage task if building with swu image type or if
+    # building via 'update-image' recipe in meta-swupdate-boards
+    if d.getVar('PN') == 'update-image':
+        bb.build.addtask('do_swuimage', 'do_build', 'do_unpack do_prepare_recipe_sysroot', d)
+    elif d.getVar('USING_SWU'):
+        bb.build.addtask('do_swuimage', 'do_build', 'do_image_complete', d)
 }
 
 python do_swuimage () {
     import shutil
 
+    if d.getVar('USING_SWU'):
+        src_uri = (d.getVar('SRC_URI') or "").split()
+        if len(src_uri) == 0:
+            bb.fatal("SRC_URI (sw-description) required with 'swu' in IMAGE_FSTYPES")
+
+        try:
+            fetcher = bb.fetch2.Fetch(src_uri, d)
+            fetcher.download()
+        except bb.fetch2.BBFetchException as e:
+            bb.fatal(str(e))
+        try:
+            fetcher.unpack(d.getVar('WORKDIR'))
+        except bb.fetch2.BBFetchException as e:
+            bb.fatal(str(e))
+
     workdir = d.getVar('WORKDIR', True)
     images = (d.getVar('SWUPDATE_IMAGES', True) or "").split()
     s = d.getVar('S', True)
@@ -168,5 +195,3 @@  PACKAGE_ARCH = "${MACHINE_ARCH}"
 
 INHIBIT_DEFAULT_DEPS = "1"
 EXCLUDE_FROM_WORLD = "1"
-
-addtask do_swuimage after do_unpack do_prepare_recipe_sysroot before do_build