diff mbox series

wic: bootimg-partition: Allow root placeholder in custom config

Message ID 20231002121936.133895-1-dse@thaumatec.com
State New
Headers show
Series wic: bootimg-partition: Allow root placeholder in custom config | expand

Commit Message

Daniel Semkowicz Oct. 2, 2023, 12:19 p.m. UTC
Allow using `<<uuid-of-rootfs>>` placeholder in the custom configuration
file. This placeholder is then replaced with the actual UUID of the
root partition, generated during do_image_wic().

This allows making use of dynamically generated partition UUID instead
of hard-coding it in the WKS file.

For consistency, the same root device placeholder tag was used
as in the `fs-uuid.bbclass`.

Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
---
 scripts/lib/wic/engine.py                           | 10 ++++++++++
 scripts/lib/wic/plugins/source/bootimg-partition.py |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)

Comments

Richard Purdie Oct. 2, 2023, 12:23 p.m. UTC | #1
On Mon, 2023-10-02 at 14:19 +0200, Daniel Semkowicz wrote:
> Allow using `<<uuid-of-rootfs>>` placeholder in the custom configuration
> file. This placeholder is then replaced with the actual UUID of the
> root partition, generated during do_image_wic().
> 
> This allows making use of dynamically generated partition UUID instead
> of hard-coding it in the WKS file.
> 
> For consistency, the same root device placeholder tag was used
> as in the `fs-uuid.bbclass`.
> 
> Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
> ---
>  scripts/lib/wic/engine.py                           | 10 ++++++++++
>  scripts/lib/wic/plugins/source/bootimg-partition.py |  4 ++--
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
> index 674ccfc244..c68e5adacb 100644
> --- a/scripts/lib/wic/engine.py
> +++ b/scripts/lib/wic/engine.py
> @@ -626,3 +626,13 @@ def get_custom_config(boot_file):
>          with open(cfg_file, "r") as f:
>              config = f.read()
>          return config
> +
> +def configure_custom_config(config, creator):
> +    """
> +    Replace placeholders in the configuration file with the actual values.
> +    Does nothing if no placeholder is found.
> +    """
> +    rootdev_placeholder = '<<uuid-of-rootfs>>'
> +    if rootdev_placeholder in config:
> +        config = config.replace(rootdev_placeholder, creator.rootdev)
> +    return config
> diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
> index 58f6da72c3..969f99476b 100644
> --- a/scripts/lib/wic/plugins/source/bootimg-partition.py
> +++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
> @@ -19,7 +19,7 @@ import re
>  from glob import glob
>  
>  from wic import WicError
> -from wic.engine import get_custom_config
> +from wic.engine import get_custom_config, configure_custom_config
>  from wic.pluginbase import SourcePlugin
>  from wic.misc import exec_cmd, get_bitbake_var
>  
> @@ -110,7 +110,7 @@ class BootimgPartitionPlugin(SourcePlugin):
>              custom_cfg = get_custom_config(configfile)
>              if custom_cfg:
>                  # Use a custom configuration for extlinux.conf
> -                extlinux_conf = custom_cfg
> +                extlinux_conf = configure_custom_config(custom_cfg, cr)
>                  logger.debug("Using custom configuration file "
>                               "%s for extlinux.conf", configfile)
>              else:

Do we need to add a test case to "oe-selftest -r wic" for this?

Cheers,

Richard
Daniel Semkowicz Oct. 2, 2023, 1:24 p.m. UTC | #2
Hello Richard,


On Mon, Oct 2, 2023 at 2:24 PM Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
>
> On Mon, 2023-10-02 at 14:19 +0200, Daniel Semkowicz wrote:
> > Allow using `<<uuid-of-rootfs>>` placeholder in the custom configuration
> > file. This placeholder is then replaced with the actual UUID of the
> > root partition, generated during do_image_wic().
> >
> > This allows making use of dynamically generated partition UUID instead
> > of hard-coding it in the WKS file.
> >
> > For consistency, the same root device placeholder tag was used
> > as in the `fs-uuid.bbclass`.
> >
> > Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
> > ---
> >  scripts/lib/wic/engine.py                           | 10 ++++++++++
> >  scripts/lib/wic/plugins/source/bootimg-partition.py |  4 ++--
> >  2 files changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
> > index 674ccfc244..c68e5adacb 100644
> > --- a/scripts/lib/wic/engine.py
> > +++ b/scripts/lib/wic/engine.py
> > @@ -626,3 +626,13 @@ def get_custom_config(boot_file):
> >          with open(cfg_file, "r") as f:
> >              config = f.read()
> >          return config
> > +
> > +def configure_custom_config(config, creator):
> > +    """
> > +    Replace placeholders in the configuration file with the actual values.
> > +    Does nothing if no placeholder is found.
> > +    """
> > +    rootdev_placeholder = '<<uuid-of-rootfs>>'
> > +    if rootdev_placeholder in config:
> > +        config = config.replace(rootdev_placeholder, creator.rootdev)
> > +    return config
> > diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
> > index 58f6da72c3..969f99476b 100644
> > --- a/scripts/lib/wic/plugins/source/bootimg-partition.py
> > +++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
> > @@ -19,7 +19,7 @@ import re
> >  from glob import glob
> >
> >  from wic import WicError
> > -from wic.engine import get_custom_config
> > +from wic.engine import get_custom_config, configure_custom_config
> >  from wic.pluginbase import SourcePlugin
> >  from wic.misc import exec_cmd, get_bitbake_var
> >
> > @@ -110,7 +110,7 @@ class BootimgPartitionPlugin(SourcePlugin):
> >              custom_cfg = get_custom_config(configfile)
> >              if custom_cfg:
> >                  # Use a custom configuration for extlinux.conf
> > -                extlinux_conf = custom_cfg
> > +                extlinux_conf = configure_custom_config(custom_cfg, cr)
> >                  logger.debug("Using custom configuration file "
> >                               "%s for extlinux.conf", configfile)
> >              else:
>
> Do we need to add a test case to "oe-selftest -r wic" for this?

This makes sense. I will push v2 with a test case.

>
> Cheers,
>
> Richard

Best regards
Daniel
diff mbox series

Patch

diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 674ccfc244..c68e5adacb 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -626,3 +626,13 @@  def get_custom_config(boot_file):
         with open(cfg_file, "r") as f:
             config = f.read()
         return config
+
+def configure_custom_config(config, creator):
+    """
+    Replace placeholders in the configuration file with the actual values.
+    Does nothing if no placeholder is found.
+    """
+    rootdev_placeholder = '<<uuid-of-rootfs>>'
+    if rootdev_placeholder in config:
+        config = config.replace(rootdev_placeholder, creator.rootdev)
+    return config
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
index 58f6da72c3..969f99476b 100644
--- a/scripts/lib/wic/plugins/source/bootimg-partition.py
+++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
@@ -19,7 +19,7 @@  import re
 from glob import glob
 
 from wic import WicError
-from wic.engine import get_custom_config
+from wic.engine import get_custom_config, configure_custom_config
 from wic.pluginbase import SourcePlugin
 from wic.misc import exec_cmd, get_bitbake_var
 
@@ -110,7 +110,7 @@  class BootimgPartitionPlugin(SourcePlugin):
             custom_cfg = get_custom_config(configfile)
             if custom_cfg:
                 # Use a custom configuration for extlinux.conf
-                extlinux_conf = custom_cfg
+                extlinux_conf = configure_custom_config(custom_cfg, cr)
                 logger.debug("Using custom configuration file "
                              "%s for extlinux.conf", configfile)
             else: