How to support patching files from SRC_URI before adding to cpio archive

18 views
Skip to first unread message

Klinke, Tobias Alexander

unread,
Apr 4, 2025, 11:08:03 AM4/4/25
to swup...@googlegroups.com
Internal

Hi,

I'm generating a .swu archive by inheriting from swupdate-image.bbclass and I add some additional files to the archive by listing them in SRC_URI.
For one of those files (my sw-versions file) I want to modify it before adding it to the cpio archive by replacing some placeholders in do_unpack:append() with information from my CI build.
Here is the relevant code (using kirkstone, but should be applicable to newer branches as well):

SRC_URI += " \
file://sw-versions \
file://some-other-script.sh \
"

# Replace @VERSION@ in sw-versions
python do_unpack:append() {
from pathlib import Path
sw_versions_path = Path(f"{d.getVar('WORKDIR')}/sw-versions")
sw_versions_template = sw_versions_path.read_text()
version = d.getVar('SOME_CI_STUFF', True)
sw_versions_content = sw_versions_template.replace("@VERSION@", version)
sw_versions_path.write_text(sw_versions_content)
}
inherit swupdate-image


However, the resulting .swu keeps containing the original unmodified file from the source directory.
I suspect the reason is that in swupdate-common.bbclass the swupdate_create_cpio() function copies the files from S directory.
Is there any reason why they are not taken from WORKDIR to allow patching in do_unpack() as above?
Or is there another mechanism to add additional generated files to the .swu archive?

Best regards,
Tobias Klinke
---
This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthaelt vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfaenger dieser E-mail sein, senden Sie bitte diese an den Absender zurueck und loeschen Sie die E-mail aus Ihrem System.

Stefano Babic

unread,
Apr 4, 2025, 11:38:33 AM4/4/25
to Klinke, Tobias Alexander, swup...@googlegroups.com
Hallo Tobias,

On 4/4/25 17:02, 'Klinke, Tobias Alexander' via swupdate wrote:
> Internal
>

???

> Hi,
>
> I'm generating a .swu archive by inheriting from swupdate-image.bbclass and I add some additional files to the archive by listing them in SRC_URI.
> For one of those files (my sw-versions file) I want to modify it before adding it to the cpio archive by replacing some placeholders in do_unpack:append() with information from my CI build.
> Here is the relevant code (using kirkstone, but should be applicable to newer branches as well):
>
> SRC_URI += " \
> file://sw-versions \
> file://some-other-script.sh \
> "
>
> # Replace @VERSION@ in sw-versions

Variable substitution is supported out-of-the-box in sw-description only.

> python do_unpack:append() {
> from pathlib import Path
> sw_versions_path = Path(f"{d.getVar('WORKDIR')}/sw-versions")
> sw_versions_template = sw_versions_path.read_text()
> version = d.getVar('SOME_CI_STUFF', True)
> sw_versions_content = sw_versions_template.replace("@VERSION@", version)
> sw_versions_path.write_text(sw_versions_content)
> }
> inherit swupdate-image
>
>
> However, the resulting .swu keeps containing the original unmodified file from the source directory.
> I suspect the reason is that in swupdate-common.bbclass the swupdate_create_cpio() function copies the files from S directory.

Or even that you append() does not run at all, because this is an image
and not a package , and do_unpack() runs just for packages....

The layer fetches the files in SRC_URI and there is no support for vars
substitution. Files are then copied into ${S}.


> Is there any reason why they are not taken from WORKDIR to allow patching in do_unpack() as above?
> Or is there another mechanism to add additional generated files to the .swu archive?

You should generate them in a package and put the generated files into
${DEPLOY_DIR_IMAGE}.

Best regards,
Stefano Babic

Klinke, Tobias Alexander

unread,
Apr 8, 2025, 11:08:03 AM4/8/25
to Stefano Babic, swup...@googlegroups.com
Hi Stefano,

thanks for the quick reply.
Indeed ${DEPLOY_DIR_IMAGE} is what I've been looking for.
I now have a recipe that deploys my generated sw-versions file to ${DEPLOY_DIR_IMAGE} and in my image recipe I added it to ${SWUPDATE_IMAGES}:

SWUPDATE_IMAGES += "sw-versions"

For me, the documentation in https://sbabic.github.io/swupdate/building-with-yocto.html#the-swupdate-class was not clear that you can add literally anything to ${SWUPDATE_IMAGES} - not just images - as long as it is in ${DEPLOY_DIR_IMAGE}.

I'd be happy to contribute a patch to documentation - if you think that it makes sense.

Best regards,
Tobias
________________________________________
Von: Stefano Babic <stefan...@swupdate.org>
Gesendet: Freitag, 4. April 2025 17:38
An: Klinke, Tobias Alexander <tobiasalexa...@draeger.com>; swup...@googlegroups.com <swup...@googlegroups.com>
Betreff: [External] Re: [swupdate] How to support patching files from SRC_URI before adding to cpio archive

Stefano Babic

unread,
Apr 8, 2025, 11:56:40 AM4/8/25
to Klinke, Tobias Alexander, Stefano Babic, swup...@googlegroups.com
Hi Tobias,

On 08.04.25 17:07, 'Klinke, Tobias Alexander' via swupdate wrote:
> Hi Stefano,
>
> thanks for the quick reply.
> Indeed ${DEPLOY_DIR_IMAGE} is what I've been looking for.
> I now have a recipe that deploys my generated sw-versions file to ${DEPLOY_DIR_IMAGE} and in my image recipe I added it to ${SWUPDATE_IMAGES}:
>
> SWUPDATE_IMAGES += "sw-versions"
>
> For me, the documentation in https://sbabic.github.io/swupdate/building-with-yocto.html#the-swupdate-class was not clear that you can add literally anything to ${SWUPDATE_IMAGES} - not just images - as long as it is in ${DEPLOY_DIR_IMAGE}.
>
> I'd be happy to contribute a patch to documentation - if you think that it makes sense.

Please sned your patch to make the topic more clear - because I
developed it, it is to me often clear out-of-the-box, and my doc can
have some "implicit" things. I am happy to receive patches to make
documentation better.

Best regards,
Stefano
Reply all
Reply to author
Forward
0 new messages