[meta-oe,v3,3/4] runqemu: support non-bootable wic images

Submitted by Adrian Freihofer on June 8, 2019, 7:59 a.m. | Patch ID: 162060

Details

Message ID 20190608075948.30537-4-adrian.freihofer@siemens.com
State New
Headers show

Commit Message

Adrian Freihofer June 8, 2019, 7:59 a.m.
wic images are handled as vmtype images. Starting qemu with "-kernel"
parameter and an image of type wic is not supported. Especially for
"-machine virt" the combination of wic with -kernel parameter would
be beneficial.

This patch changes the runqemu script to support this. If QB_MACHINE
contains "-machine virt" and the image is of type wic a -kernel
parameter is expected. Otherwise wic images are handled as before.

Example:
QB_DEFAULT_FSTYPE = "wic"
QB_KERNEL_ROOT = "/dev/vda1"
QB_SYSTEM_NAME = "qemu-system-aarch64"
QB_MACHINE = "-machine virt"
...

[YOCTO #13336]

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 scripts/runqemu | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/scripts/runqemu b/scripts/runqemu
index af90c010da..71894c9ca8 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -185,10 +185,11 @@  class BaseConfig(object):
         self.lock_descriptor = None
         self.bitbake_e = ''
         self.snapshot = False
+        self.wic_fs = None
+        self.wictypes = ('wic', 'wic.vmdk', 'wic.qcow2', 'wic.vdi')
         self.fstypes = ('ext2', 'ext3', 'ext4', 'jffs2', 'nfs', 'btrfs',
                         'cpio.gz', 'cpio', 'ramfs', 'tar.bz2', 'tar.gz')
-        self.vmtypes = ('hddimg', 'hdddirect', 'wic', 'wic.vmdk',
-                        'wic.qcow2', 'wic.vdi', 'iso')
+        self.vmtypes = ('hddimg', 'hdddirect', 'iso')
         self.network_device = "-device e1000,netdev=net0,mac=@MAC@"
         # Use different mac section for tap and slirp to avoid
         # conflicts, e.g., when one is running with tap, the other is
@@ -253,7 +254,7 @@  class BaseConfig(object):
 
     def check_arg_fstype(self, fst):
         """Check and set FSTYPE"""
-        if fst not in self.fstypes + self.vmtypes:
+        if fst not in self.fstypes + self.vmtypes + self.wictypes:
             logger.warning("Maybe unsupported FSTYPE: %s" % fst)
         if not self.fstype or self.fstype == fst:
             if fst == 'ramfs':
@@ -300,7 +301,7 @@  class BaseConfig(object):
             # Check filename against self.fstypes can hanlde <file>.cpio.gz,
             # otherwise, its type would be "gz", which is incorrect.
             fst = ""
-            for t in self.fstypes:
+            for t in self.fstypes + self.wictypes:
                 if p.endswith(t):
                     fst = t
                     break
@@ -390,7 +391,7 @@  class BaseConfig(object):
 
         unknown_arg = ""
         for arg in sys.argv[1:]:
-            if arg in self.fstypes + self.vmtypes:
+            if arg in self.fstypes + self.vmtypes + self.wictypes:
                 self.check_arg_fstype(arg)
             elif arg == 'nographic':
                 self.qemu_opt_script += ' -nographic'
@@ -695,6 +696,21 @@  class BaseConfig(object):
 
     def check_and_set(self):
         """Check configs sanity and set when needed"""
+
+        # Decide how wic images are handled: as vm or with -kernel parameter
+        if self.wic_fs is None:
+            self.wic_fs = False
+            try:
+                qbm = self.get('QB_MACHINE')
+                if re.search('\s+virt(?![^ ])', qbm):
+                    self.wic_fs = True
+            except AttributeError:
+                pass
+        if self.wic_fs is True:
+            self.fstypes = self.fstypes + self.wictypes
+        else:
+            self.vmtypes = self.vmtypes + self.wictypes
+
         self.validate_paths()
         if not self.slirp_enabled:
             check_tun()
@@ -832,7 +848,13 @@  class BaseConfig(object):
             if self.dtb:
                 print('DTB: [%s]' % self.dtb)
         print('MACHINE: [%s]' % self.get('MACHINE'))
-        print('FSTYPE: [%s]' % self.fstype)
+        wic_mode = ''
+        if self.fstype == 'wic':
+            if self.wic_fs:
+                wic_mode = ' (fs)'
+            else:
+                wic_mode = ' (vm)'
+        print('FSTYPE: [%s%s]' % (self.fstype, wic_mode))
         if self.fstype  == 'nfs':
             print('NFS_DIR: [%s]' % self.rootfs)
         else:

Comments

Richard Purdie June 8, 2019, 9:19 a.m.
On Sat, 2019-06-08 at 09:59 +0200, Adrian Freihofer wrote:
> wic images are handled as vmtype images. Starting qemu with "-kernel"
> parameter and an image of type wic is not supported. Especially for
> "-machine virt" the combination of wic with -kernel parameter would
> be beneficial.
> 
> This patch changes the runqemu script to support this. If QB_MACHINE
> contains "-machine virt" and the image is of type wic a -kernel
> parameter is expected. Otherwise wic images are handled as before.
> 
> Example:
> QB_DEFAULT_FSTYPE = "wic"
> QB_KERNEL_ROOT = "/dev/vda1"
> QB_SYSTEM_NAME = "qemu-system-aarch64"
> QB_MACHINE = "-machine virt"
> ...
> 
> [YOCTO #13336]
> 
> Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>

I'm afraid I don't like this at all, it feels like a horrible interface
which won't scale. The fact the machine sets QB_MACHINE to use virt has
no real relation to whether the image contains a kernel or not, it just
happens to match the current defaults.

Can we add a specific parameter which controls this explicitly?

Perhaps something like a generic "fsinfo" parameter:

QB_FSINFO = "wic:kernel-in-fs"

with wic specific information in it?

I do much prefer the wic-fs and wic-vm change though as it means more
than "wic-nb" did.

Cheers,

Richard