diff mbox series

[5/6] wic: extra-partitions: Make extra-files optional

Message ID 20260113144314.3563680-5-adam.duskett@amarulasolutions.com
State New
Headers show
Series [1/6] wic: extra-partition: Small code cleanup | expand

Commit Message

Adam Duskett Jan. 13, 2026, 2:43 p.m. UTC
There are many use cases where a user may need a blank partition of a given
size and format with no extra files added. Such as an empty data partition.

Signed-off-by: Adam Duskett <adam.duskett@amarulasolutions.com>
---
 meta/lib/oeqa/selftest/cases/wic.py           | 10 ++++++++++
 .../lib/wic/plugins/source/extra_partition.py | 20 ++++++++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)

Comments

Pierre-loup GOSSE Jan. 13, 2026, 3:13 p.m. UTC | #1
Hi Adam,

Thanks for your contribution to the plugin.

> 
> There are many use cases where a user may need a blank partition of a
> given
> size and format with no extra files added. Such as an empty data
> partition.
> 

A blank partition can already be created without the extra-partition plugin.

Personally, I use the following example line in my WKS file:

part --fstype=ext4 --label data --fixed-size 500M

This command creates a blank 500MB partition with an ext4 filesystem.

In my opinion, the extra plugin should always requires files, similar to the bootimg partition plugin (on which the extra partition plugin is based).

Pierre-Loup,
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index d7a9b14658..33a6460677 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -1698,6 +1698,16 @@  INITRAMFS_IMAGE = "core-image-initramfs-boot"
 
             self.remove_config(config)
 
+            # Test with a blank formatted partition of 5M with no extra files
+            with NamedTemporaryFile("w", suffix=".wks") as wks:
+                wks.writelines(['part / --source extra_partition --ondisk sda --fstype=ext4 --label foo --align 4 --size 5M\n'])
+                wks.flush()
+                _, wicimg = self._get_wic(wks.name)
+
+                cmd = "wic ls %s | wc -l" % wicimg
+                result = runCmd(cmd)
+                self.assertEqual('2', result.output, msg="Expect 1 partition, not %s" % result.output)
+
         finally:
             os.environ['PATH'] = oldpath
 
diff --git a/scripts/lib/wic/plugins/source/extra_partition.py b/scripts/lib/wic/plugins/source/extra_partition.py
index efe15a4d15..3abd2bfd4c 100644
--- a/scripts/lib/wic/plugins/source/extra_partition.py
+++ b/scripts/lib/wic/plugins/source/extra_partition.py
@@ -55,11 +55,13 @@  class ExtraPartitionPlugin(SourcePlugin):
         """
         Parse the files of which to copy.
         """
+        cls.extra_files_task = []
         deploy_files = []
 
         extra_files = cls._get_extra_vars(part, cls.image_extra_partition_files_var_name)
         if extra_files is None:
-            raise WicError('No extra files defined, %s unset for entry #%d' % (cls.image_extra_partition_files_var_name, part.lineno))
+            logger.debug('No extra files defined, %s unset for entry #%d' % (cls.image_extra_partition_files_var_name, part.lineno))
+            return
 
 
         logger.info('Extra files: %s', extra_files)
@@ -74,7 +76,6 @@  class ExtraPartitionPlugin(SourcePlugin):
             logger.debug('Destination entry: %r', dst_entry)
             deploy_files.append(dst_entry)
 
-        cls.extra_files_task = []
         for deploy_entry in deploy_files:
             src, dst = deploy_entry
             if '*' in src:
@@ -131,13 +132,14 @@  class ExtraPartitionPlugin(SourcePlugin):
             if not kernel_dir:
                 raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
 
-        for task in cls.extra_files_task:
-            src_path, dst_path = task
-            logger.debug('Install %s as %s', src_path, dst_path)
-            install_cmd = "install -m 0644 -D %s %s" \
-                          % (os.path.join(kernel_dir, src_path),
-                             os.path.join(extradir, dst_path))
-            exec_cmd(install_cmd)
+        if cls.extra_files_task:
+            for task in cls.extra_files_task:
+                src_path, dst_path = task
+                logger.debug('Install %s as %s', src_path, dst_path)
+                install_cmd = "install -m 0644 -D %s %s" \
+                              % (os.path.join(kernel_dir, src_path),
+                                 os.path.join(extradir, dst_path))
+                exec_cmd(install_cmd)
 
         logger.debug('Prepare extra partition using rootfs in %s', extradir)
         part.prepare_rootfs(cr_workdir, oe_builddir, extradir,