Skip to contentSkip to conversation

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

PATCH In review Daniel Semkowicz 2 participants 3 messages Oct 2, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wic: bootimg-partition: Allow root placeholder in custom config

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.

---
 scripts/lib/wic/engine.py                           | 10 ++++++++++
 scripts/lib/wic/plugins/source/bootimg-partition.py |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)
scripts/lib/wic/engine.py +10 -0
index 674ccfc244..c68e5adacb 100644
@@ -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
scripts/lib/wic/plugins/source/bootimg-partition.py +2 -2
index 58f6da72c3..969f99476b 100644
@@ -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:
Signature · 1 line
2.41.0
#1 lore raw
Quoted 48 lines · Daniel Semkowicz

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.

---
 scripts/lib/wic/engine.py                           | 10 ++++++++++
 scripts/lib/wic/plugins/source/bootimg-partition.py |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)
scripts/lib/wic/engine.py +10 -0
index 674ccfc244..c68e5adacb 100644
@@ -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
scripts/lib/wic/plugins/source/bootimg-partition.py +1 -1
index 58f6da72c3..969f99476b 100644
@@ -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
 

scripts/lib/wic/plugins/source/bootimg-partition.py class BootimgPartitionPlugin(SourcePlugin): · line 116

Quoted 8 lines
scripts/lib/wic/plugins/source/bootimg-partition.py +1 -1
@@ -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

#2 lore raw

Hello Richard,

Quoted 49 lines · Richard Purdie
Quoted 47 lines · Daniel Semkowicz

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.

---
 scripts/lib/wic/engine.py                           | 10 ++++++++++
 scripts/lib/wic/plugins/source/bootimg-partition.py |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)
scripts/lib/wic/engine.py +10 -0
index 674ccfc244..c68e5adacb 100644
@@ -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
scripts/lib/wic/plugins/source/bootimg-partition.py +1 -1
index 58f6da72c3..969f99476b 100644
@@ -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
 
Quoted 11 lines

scripts/lib/wic/plugins/source/bootimg-partition.py class BootimgPartitionPlugin(SourcePlugin): · line 116

Quoted 9 lines
scripts/lib/wic/plugins/source/bootimg-partition.py +1 -1
@@ -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.

Quoted 4 lines

Cheers,

Richard

Best regards
Daniel