diff mbox series

Copy of files listed in SRC_URI

Message ID cd6ff2040a23ff3f5ede76a58ec66d6910f9dc5b.camel@dimonoff.com
State Changes Requested
Delegated to: Stefano Babic
Headers show
Series Copy of files listed in SRC_URI | expand

Commit Message

Hugo Villeneuve Feb. 2, 2023, 4:16 p.m. UTC
Hi,
I was able to successfully add a shell script to my SWU archive, by
listing it in SRC_URI and also in sw-description. The update procedure
went well with that SWU archive.

However, when I decided to modify my update recipe to dynamically
modify my shell script and save it in WORKDIR (like we often do in
yocto/bitbake recipes), I noticed that swupdate didn't take into
account my modified script.

After a few hours of debuging, I found that swupdate copies the
original file from the yocto source layers, instead of copying it from
WORKDIR.

I don't know if there is a specific reason for that behavior, but to me
it seems to be counter-intuitive.

The included patch fixes this behavior.

Thank you,

Hugo Villeneuve

Comments

Topper Feb. 6, 2023, 6:35 a.m. UTC | #1
Use bitbake -f or better bitbake -c [options]

On Thursday, February 2, 2023 at 6:16:21 PM UTC+2 Hugo Villeneuve wrote:

> Hi,
> I was able to successfully add a shell script to my SWU archive, by
> listing it in SRC_URI and also in sw-description. The update procedure
> went well with that SWU archive.
>
> However, when I decided to modify my update recipe to dynamically
> modify my shell script and save it in WORKDIR (like we often do in
> yocto/bitbake recipes), I noticed that swupdate didn't take into
> account my modified script.
>
> After a few hours of debuging, I found that swupdate copies the
> original file from the yocto source layers, instead of copying it from
> WORKDIR.
>
> I don't know if there is a specific reason for that behavior, but to me
> it seems to be counter-intuitive.
>
> The included patch fixes this behavior.
>
> Thank you,
>
> Hugo Villeneuve
>
>
Stefano Babic Feb. 6, 2023, 1:37 p.m. UTC | #2
Hi Hugo,

On 02.02.23 17:16, 'Hugo Villeneuve' via swupdate wrote:
> Hi,
> I was able to successfully add a shell script to my SWU archive, by
> listing it in SRC_URI and also in sw-description. The update procedure
> went well with that SWU archive.
> 
> However, when I decided to modify my update recipe to dynamically
> modify my shell script and save it in WORKDIR (like we often do in
> yocto/bitbake recipes), I noticed that swupdate didn't take into
> account my modified script.
> 
> After a few hours of debuging, I found that swupdate copies the
> original file from the yocto source layers, instead of copying it from
> WORKDIR.
> 
> I don't know if there is a specific reason for that behavior, but to me
> it seems to be counter-intuitive.
> 

It was discussed here:

https://groups.google.com/g/swupdate/c/85ALYtCt7Pc/m/DAJkUr5lDgAJ

I am not currently sure about the side-effects of copying from SRC_URI. 
One concern I have is that it is easier that in a (official) release a 
not wanted file can slip in : a file in WORKDIR can be elaborate in a 
task after do_fetch and before do_swuimage.

> The included patch fixes this behavior.

Best regards,
Stefano Babic
diff mbox series

Patch

From 85590d8b9220eb9d6e3058ca5aed7b612dcf673e Mon Sep 17 00:00:00 2001
From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Date: Thu, 2 Feb 2023 09:55:35 -0500
Subject: [meta-swupdate][PATCH] Copy files listed in SRC_URI from WORKDIR

This allows recipes to add/modify files in WORKDIR prior to generating the SWU
archive.

For example, an update image may add a shell script in SRC_URI (and
also in sw-description). This script can be modified or auto-generated
by the update image recipe before creating the SWU image.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
 classes/swupdate-common.bbclass | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/classes/swupdate-common.bbclass b/classes/swupdate-common.bbclass
index ac45e58..0a919bc 100644
--- a/classes/swupdate-common.bbclass
+++ b/classes/swupdate-common.bbclass
@@ -215,26 +215,27 @@  def swupdate_add_src_uri(d, list_for_cpio):
     import shutil
 
     s = d.getVar('S', True)
+    workdir = d.getVar('WORKDIR', True)
 
     fetch = bb.fetch2.Fetch([], d)
 
     # Add files listed in SRC_URI to the swu file
     for url in fetch.urls:
-        local = fetch.localpath(url)
-        filename = os.path.basename(local)
+        filename = os.path.basename(fetch.localpath(url))
+        src = os.path.join(workdir, "%s" % filename)
         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)):
+        if (filename != 'sw-description') and (os.path.isfile(src)):
             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)
+                swupdate_encrypt_file(src, dst, key, iv)
             else:
-                shutil.copyfile(local, dst)
+                shutil.copyfile(src, dst)
             list_for_cpio.append(filename)
 
 def add_image_to_swu(d, deploydir, imagename, s, encrypt, list_for_cpio):
-- 
2.30.2