diff mbox series

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

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

Commit Message

Anatolij Gustschin Feb. 11, 2021, 10:38 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 | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

Comments

Stefano Babic Feb. 11, 2021, 12:30 p.m. UTC | #1
Hi Anatolji,

On 11.02.21 11:38, 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 | 24 ++++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
> index 2c2430b..774de01 100644
> --- a/classes/swupdate.bbclass
> +++ b/classes/swupdate.bbclass
> @@ -76,14 +76,36 @@ 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)}"

Name is quite misleading, SWUpdate always "uses" a SWU - another name ?
GEN_SWU, what else ?

> +
>  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('USING_SWU') or d.getVar('PN') == 'update-image':

I gave the name "update-image", maybe a bad choice. But I do not like
that the name of a recipe is hard-coded here. Is it not enought to check
for IMAGE_FSTYPES, that is with USING_SWU ?


> +        bb.build.addtask('do_swuimage', 'do_build', 'do_image_complete', d)

Why is it added at runtime and not statically as before ?

Do we always habe do_image_complete ? In most cases, I have not...

>  }
>  
>  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 +190,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
> 

Regards,
Stefano
Anatolij Gustschin Feb. 11, 2021, 2:17 p.m. UTC | #2
Hi Stefano,

On Thu, 11 Feb 2021 13:30:32 +0100
Stefano Babic sbabic@denx.de wrote:

>Hi Anatolji,
>
>On 11.02.21 11:38, 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 | 24 ++++++++++++++++++++++--
>>  1 file changed, 22 insertions(+), 2 deletions(-)
>> 
>> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
>> index 2c2430b..774de01 100644
>> --- a/classes/swupdate.bbclass
>> +++ b/classes/swupdate.bbclass
>> @@ -76,14 +76,36 @@ 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)}"  
>
>Name is quite misleading, SWUpdate always "uses" a SWU - another name ?
>GEN_SWU, what else ?

This variable indicates that building via swu FSTYPES was enabled,
so I though this name should be okay.

>>  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('USING_SWU') or d.getVar('PN') == 'update-image':  
>
>I gave the name "update-image", maybe a bad choice. But I do not like
>that the name of a recipe is hard-coded here. Is it not enought to check
>for IMAGE_FSTYPES, that is with USING_SWU ?

If both possibilities for generating .swu should be supported (old via
meta-swupdate-boards update-image and new via IMAGE_FSTYPES += "swu"),
then this is not enough, in case of adding the task at runtime.

>> +        bb.build.addtask('do_swuimage', 'do_build', 'do_image_complete', d)  
>
>Why is it added at runtime and not statically as before ?

I wanted to skip running this task if an image recipe inherited
swupdate class, but did not enable 'swu' fstype for some reason.
If the task must always be statically enabled, then I need to add
a check for 'swu' fstype at the beginning of the task and return
early if swu fstype is disabled. Therefore I preferred to add the
task at runtime.

>Do we always habe do_image_complete ? In most cases, I have not...

For image recipes, yes. For usual package recipes there is no
such task. Maybe we need to stay with do_build dependency in case
of building via update-image. I also tested building via update-image
and it worked. I'm not sure yet.

Thanks,
Anatolij
Stefan Herbrechtsmeier Feb. 13, 2021, 3:44 p.m. UTC | #3
Hi Anatolij,

Am 11.02.21 um 11:38 schrieb Anatolij Gustschin:
> 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 | 24 ++++++++++++++++++++++--
>   1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
> index 2c2430b..774de01 100644
> --- a/classes/swupdate.bbclass
> +++ b/classes/swupdate.bbclass
> @@ -76,14 +76,36 @@ 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)}"

Why do you use one file for different use cases instead of one file per 
use case (swupdate.bbclass and image_types_swu.bbclass) and a extra file 
with shared content (swupdate-common.bbclass)?


>   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('USING_SWU') or d.getVar('PN') == 'update-image':
> +        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 +190,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
>
Anatolij Gustschin Feb. 15, 2021, 10:13 p.m. UTC | #4
Hi Stefan,

On Sat, 13 Feb 2021 16:44:03 +0100
Stefan Herbrechtsmeier stefan@herbrechtsmeier.net wrote:
...
>> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
>> index 2c2430b..774de01 100644
>> --- a/classes/swupdate.bbclass
>> +++ b/classes/swupdate.bbclass
>> @@ -76,14 +76,36 @@ 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)}"  
>
>Why do you use one file for different use cases instead of one file per 
>use case (swupdate.bbclass and image_types_swu.bbclass) and a extra file 
>with shared content (swupdate-common.bbclass)?

other layer (meta-swupdate-boards) uses this swupdate.bbclass, I have
to ensure that using this layer still works after applying this series.
But I think I can add separate image_types_swu.bbclass which inherits
swupdate.bbclass. Will fix in v2 series.

Thanks,
Anatolij
Stefano Babic Feb. 16, 2021, 7:23 a.m. UTC | #5
Hi Anatolji,

On 15.02.21 23:13, Anatolij Gustschin wrote:
> Hi Stefan,
> 
> On Sat, 13 Feb 2021 16:44:03 +0100
> Stefan Herbrechtsmeier stefan@herbrechtsmeier.net wrote:
> ...
>>> diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
>>> index 2c2430b..774de01 100644
>>> --- a/classes/swupdate.bbclass
>>> +++ b/classes/swupdate.bbclass
>>> @@ -76,14 +76,36 @@ 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)}"
>>
>> Why do you use one file for different use cases instead of one file per
>> use case (swupdate.bbclass and image_types_swu.bbclass)

+1

This is the common way in OE and it is preferable instead of putting 
everything in a single class.

>> and a extra file
>> with shared content (swupdate-common.bbclass)? >
> other layer (meta-swupdate-boards) uses this swupdate.bbclass, I have
> to ensure that using this layer still works after applying this series.
> But I think I can add separate image_types_swu.bbclass which inherits
> swupdate.bbclass. Will fix in v2 series.
> 
> Thanks,
> Anatolij
> 

Regards,
Stefano
diff mbox series

Patch

diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass
index 2c2430b..774de01 100644
--- a/classes/swupdate.bbclass
+++ b/classes/swupdate.bbclass
@@ -76,14 +76,36 @@  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('USING_SWU') or d.getVar('PN') == 'update-image':
+        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 +190,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