Lines Matching full:self
29 def __init__(self, message): argument
130 def __init__(self): argument
131 # The self.d saved vars from self.set(), part of them are from qemuboot.conf
132 self.d = {'QB_KERNEL_ROOT': '/dev/vda'}
136 self.env_vars = ('MACHINE',
148 self.qemu_opt = ''
149 self.qemu_opt_script = ''
150 self.qemuparams = ''
151 self.nfs_server = ''
152 self.rootfs = ''
157 self.ovmf_bios = []
161 self.ovmf_secboot_pkkek1 = ''
162 self.qemuboot = ''
163 self.qbconfload = False
164 self.kernel = ''
165 self.bios = ''
166 self.kernel_cmdline = ''
167 self.kernel_cmdline_script = ''
168 self.bootparams = ''
169 self.dtb = ''
170 self.fstype = ''
171 self.kvm_enabled = False
172 self.vhost_enabled = False
173 self.slirp_enabled = False
174 self.net_bridge = None
175 self.nfs_instance = 0
176 self.nfs_running = False
177 self.serialconsole = False
178 self.serialstdio = False
179 self.nographic = False
180 self.sdl = False
181 self.gtk = False
182 self.gl = False
183 self.gl_es = False
184 self.egl_headless = False
185 self.publicvnc = False
186 self.novga = False
187 self.cleantap = False
188 self.saved_stty = ''
189 self.audio_enabled = False
190 self.tcpserial_portnum = ''
191 self.taplock = ''
192 self.taplock_descriptor = None
193 self.portlocks = {}
194 self.bitbake_e = ''
195 self.snapshot = False
196 self.wictypes = ('wic', 'wic.vmdk', 'wic.qcow2', 'wic.vdi', "wic.vhd", "wic.vhdx")
197 self.fstypes = ('ext2', 'ext3', 'ext4', 'jffs2', 'nfs', 'btrfs',
199 self.vmtypes = ('hddimg', 'iso')
200 self.fsinfo = {}
201 self.network_device = "-device e1000,netdev=net0,mac=@MAC@"
202 self.cmdline_ip_slirp = "ip=dhcp"
203 … self.cmdline_ip_tap = "ip=192.168.7.@CLIENT@::192.168.7.@GATEWAY@:255.255.255.0::eth0:off:8.8.8.8"
210 self.mac_tap = "52:54:00:12:34:"
211 self.mac_slirp = "52:54:00:12:35:"
213 self.qemu_environ = os.environ.copy()
214 self.qemuprocess = None
216 self.cleaned = False
218 self.cleanup_files = []
220 def acquire_taplock(self, error=True): argument
221 logger.debug("Acquiring lockfile %s..." % self.taplock)
223 self.taplock_descriptor = open(self.taplock, 'w')
224 fcntl.flock(self.taplock_descriptor, fcntl.LOCK_EX|fcntl.LOCK_NB)
226 msg = "Acquiring lockfile %s failed: %s" % (self.taplock, e)
231 if self.taplock_descriptor:
232 self.taplock_descriptor.close()
233 self.taplock_descriptor = None
237 def release_taplock(self): argument
238 if self.taplock_descriptor:
239 logger.debug("Releasing lockfile for tap device '%s'" % self.tap)
242 # fcntl.flock(self.taplock_descriptor, fcntl.LOCK_UN)
243 self.taplock_descriptor.close()
245 # os.remove(self.taplock)
246 self.taplock_descriptor = None
248 def check_free_port(self, host, port, lockdir): argument
254 if self.acquire_portlock(lockfile):
258 self.release_portlock(lockfile)
266 def acquire_portlock(self, lockfile): argument
270 self.portlocks.update({lockfile: portlock_descriptor})
271 fcntl.flock(self.portlocks[lockfile], fcntl.LOCK_EX|fcntl.LOCK_NB)
275 if lockfile in self.portlocks.keys() and self.portlocks[lockfile]:
276 self.portlocks[lockfile].close()
277 del self.portlocks[lockfile]
281 def release_portlock(self, lockfile=None): argument
286 # fcntl.flock(self.portlocks[lockfile], fcntl.LOCK_UN)
287 self.portlocks[lockfile].close()
290 del self.portlocks[lockfile]
291 elif len(self.portlocks):
292 for lockfile, descriptor in self.portlocks.items():
300 self.portlocks = {}
302 def get(self, key): argument
303 if key in self.d:
304 return self.d.get(key)
310 def set(self, key, value): argument
311 self.d[key] = value
313 def is_deploy_dir_image(self, p): argument
325 def check_arg_fstype(self, fst): argument
327 if fst not in self.fstypes + self.vmtypes + self.wictypes:
329 if not self.fstype or self.fstype == fst:
334 self.fstype = fst
336 raise RunQemuError("Conflicting: FSTYPE %s and %s" % (self.fstype, fst))
338 def set_machine_deploy_dir(self, machine, deploy_dir_image): argument
341 self.set("MACHINE", machine)
343 self.set("DEPLOY_DIR_IMAGE", deploy_dir_image)
345 def check_arg_nfs(self, p): argument
347 self.rootfs = p
350 self.nfs_server = m.group(1)
351 self.rootfs = m.group(2)
352 self.check_arg_fstype('nfs')
354 def check_arg_path(self, p): argument
363 self.qemuboot = p
364 self.qbconfload = True
368 self.kernel = p
370 self.rootfs = p
371 # Check filename against self.fstypes can handle <file>.cpio.gz,
374 for t in self.fstypes:
379 m = re.search('.*\.(.*)$', self.rootfs)
383 self.check_arg_fstype(fst)
384 qb = re.sub('\.' + fst + "$", '', self.rootfs)
387 self.qemuboot = qb
388 self.qbconfload = True
395 if self.is_deploy_dir_image(p):
397 self.set("DEPLOY_DIR_IMAGE", p)
400 self.check_arg_nfs(p)
402 self.ovmf_bios.append(p)
406 def check_arg_machine(self, arg): argument
408 if self.get('MACHINE') == arg:
410 elif self.get('MACHINE') and self.get('MACHINE') != arg:
411 raise RunQemuError("Maybe conflicted MACHINE: %s vs %s" % (self.get('MACHINE'), arg))
423 deploy = self.get('DEPLOY_DIR_IMAGE')
424 bbchild = deploy and self.get('OE_TMPDIR')
426 self.set_machine_deploy_dir(arg, deploy)
430 if self.get('OECORE_NATIVE_SYSROOT'):
431 self.set("MACHINE", arg)
434 self.bitbake_e = self.run_bitbake_env(arg)
438 s = re.search('^DEPLOY_DIR_IMAGE="(.*)"', self.bitbake_e, re.M)
442 raise RunQemuError("bitbake -e %s" % self.bitbake_e)
443 if self.is_deploy_dir_image(deploy_dir_image):
444 self.set_machine_deploy_dir(arg, deploy_dir_image)
447 self.set("MACHINE", arg)
449 def set_dri_path(self): argument
465 self.qemu_environ['LIBGL_DRIVERS_PATH'] = dripath.decode('utf-8').strip()
470 uninative_path = os.path.dirname(self.get("UNINATIVE_LOADER"))
473 self.qemu_environ['LD_PRELOAD'] = " ".join(preload_paths)
475 def check_args(self): argument
487 self.qemu_environ['SDL_RENDER_DRIVER'] = 'software'
488 self.qemu_environ['SDL_FRAMEBUFFER_ACCELERATION'] = 'false'
492 if arg in self.fstypes + self.vmtypes + self.wictypes:
493 self.check_arg_fstype(arg)
495 self.nographic = True
497 self.sdl = True
499 self.gtk = True
501 self.gl = True
503 self.gl_es = True
505 self.egl_headless = True
507 self.novga = True
509 self.serialconsole = True
511 self.serialstdio = True
515 self.audio_enabled = True
517 self.kvm_enabled = True
519 self.vhost_enabled = True
521 self.slirp_enabled = True
523 self.net_bridge = '%s' % arg[len('bridge='):]
525 self.snapshot = True
527 self.publicvnc = True
528 self.qemu_opt_script += ' -vnc :0'
530 self.tcpserial_portnum = '%s' % arg[len('tcpserial='):]
532 self.qemuparams = ' %s' % arg[len('qemuparams='):]
534 self.bootparams = arg[len('bootparams='):]
536 self.check_arg_path(os.path.abspath(arg))
539 self.rootfs = arg
541 self.ovmf_bios.append(arg)
551 if unknown_arg and self.get('MACHINE') != unknown_arg:
552 if self.get('DEPLOY_DIR_IMAGE'):
553 machine = os.path.basename(self.get('DEPLOY_DIR_IMAGE'))
555 self.set("MACHINE", machine)
557 self.check_arg_machine(unknown_arg)
559 if not (self.get('DEPLOY_DIR_IMAGE') or self.qbconfload):
560 self.load_bitbake_env()
561 s = re.search('^DEPLOY_DIR_IMAGE="(.*)"', self.bitbake_e, re.M)
563 self.set("DEPLOY_DIR_IMAGE", s.group(1))
565 def check_kvm(self): argument
567 if not (self.kvm_enabled or self.vhost_enabled):
568 …self.qemu_opt_script += ' %s %s %s' % (self.get('QB_MACHINE'), self.get('QB_CPU'), self.get('QB_SM…
571 if not self.get('QB_CPU_KVM'):
574 …self.qemu_opt_script += ' %s %s %s' % (self.get('QB_MACHINE'), self.get('QB_CPU_KVM'), self.get('Q…
579 if self.qemu_system.endswith(('i386', 'x86_64')):
593 self.qemu_opt_script += ' -enable-kvm'
594 if self.get('MACHINE') == "qemux86":
598 self.kernel_cmdline_script += " clocksource=kvm-clock hpet=disable noapic nolapic"
604 if self.vhost_enabled:
615 def check_fstype(self): argument
617 if not self.fstype:
618 fstype = self.get('QB_DEFAULT_FSTYPE')
620 self.fstype = fstype
626 qb_fsinfo = self.get('QB_FSINFO')
645 if fstype in self.fsinfo:
646 self.fsinfo[fstype].append(fsflag)
648 self.fsinfo[fstype] = [fsflag]
654 self.fstypes = self.fstypes + self.wictypes
656 self.vmtypes = self.vmtypes + self.wictypes
658 def check_rootfs(self): argument
661 if self.fstype == "none":
664 if self.get('ROOTFS'):
665 if not self.rootfs:
666 self.rootfs = self.get('ROOTFS')
667 elif self.get('ROOTFS') != self.rootfs:
668 … raise RunQemuError("Maybe conflicted ROOTFS: %s vs %s" % (self.get('ROOTFS'), self.rootfs))
670 if self.fstype == 'nfs':
673 if self.rootfs and not os.path.exists(self.rootfs):
675 self.rootfs = "%s/%s-%s.%s" % (self.get('DEPLOY_DIR_IMAGE'),
676 self.rootfs, self.get('MACHINE'),
677 self.fstype)
678 elif not self.rootfs:
679 … cmd_name = '%s/%s*.%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_NAME'), self.fstype)
680 … cmd_link = '%s/%s*.%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_LINK_NAME'), self.fstype)
682 self.rootfs = get_first_file(cmds)
683 if not self.rootfs:
686 if not os.path.exists(self.rootfs):
687 raise RunQemuError("Can't find rootfs: %s" % self.rootfs)
689 def setup_pkkek1(self): argument
695 pemcert = '%s/%s' % (self.get('DEPLOY_DIR_IMAGE'), 'OvmfPkKek1.pem')
701 self.ovmf_secboot_pkkek1 = key
706 def check_ovmf(self): argument
709 for index, ovmf in enumerate(self.ovmf_bios):
713 path = '%s/%s.%s' % (self.get('DEPLOY_DIR_IMAGE'), ovmf, suffix)
715 self.ovmf_bios[index] = path
717 self.setup_pkkek1()
722 def check_kernel(self): argument
725 if self.fstype in self.vmtypes:
729 if self.get('KERNEL'):
730 self.kernel = self.get('KERNEL')
733 kernel_name = os.path.basename(self.get('QB_DEFAULT_KERNEL'))
736 if kernel_name == "none" and not self.kernel:
739 deploy_dir_image = self.get('DEPLOY_DIR_IMAGE')
740 if not self.kernel:
742 kernel_match_link = "%s/%s" % (deploy_dir_image, self.get('KERNEL_IMAGETYPE'))
743 kernel_startswith = "%s/%s*" % (deploy_dir_image, self.get('KERNEL_IMAGETYPE'))
745 self.kernel = get_first_file(cmds)
746 if not self.kernel:
749 if not os.path.exists(self.kernel):
750 raise RunQemuError("KERNEL %s not found" % self.kernel)
752 def check_dtb(self): argument
755 if self.get('DEVICE_TREE'):
756 self.dtb = self.get('DEVICE_TREE')
757 if not os.path.exists(self.dtb):
758 raise RunQemuError('Specified DTB not found: %s' % self.dtb)
761 dtb = self.get('QB_DTB')
763 deploy_dir_image = self.get('DEPLOY_DIR_IMAGE')
768 self.dtb = get_first_file(cmds)
769 if not os.path.exists(self.dtb):
772 def check_bios(self): argument
776 if self.get('BIOS'):
777 self.bios = self.get('BIOS')
780 bios_name = os.path.basename(self.get('QB_DEFAULT_BIOS'))
783 if (bios_name == "" or bios_name == "none") and not self.bios:
786 if not self.bios:
787 deploy_dir_image = self.get('DEPLOY_DIR_IMAGE')
788 self.bios = "%s/%s" % (deploy_dir_image, bios_name)
790 if not self.bios:
793 if not os.path.exists(self.bios):
794 raise RunQemuError("BIOS %s not found" % self.bios)
797 def check_mem(self): argument
802 s = re.search('-m +([0-9]+)', self.qemuparams)
804 self.set('QB_MEM', '-m %s' % s.group(1))
805 elif not self.get('QB_MEM'):
807 self.set('QB_MEM', '-m 256')
810 qb_mem = self.get('QB_MEM')
818 self.set('QB_MEM', qb_mem)
820 mach = self.get('MACHINE')
822 … self.kernel_cmdline_script += ' mem=%s' % self.get('QB_MEM').replace('-m','').strip() + 'M'
824 self.qemu_opt_script += ' %s' % self.get('QB_MEM')
826 def check_tcpserial(self): argument
827 if self.tcpserial_portnum:
828 ports = self.tcpserial_portnum.split(':')
830 if self.get('QB_TCPSERIAL_OPT'):
831 self.qemu_opt_script += ' ' + self.get('QB_TCPSERIAL_OPT').replace('@PORT@', port)
833 self.qemu_opt_script += ' -serial tcp:127.0.0.1:%s' % port
837 self.qemu_opt_script += ' -serial tcp:127.0.0.1:%s' % port
839 def check_and_set(self): argument
841 self.validate_paths()
842 if not self.slirp_enabled and not self.net_bridge:
845 if self.audio_enabled:
846 if not self.get('QB_AUDIO_DRV'):
848 if not self.get('QB_AUDIO_OPT'):
851 self.qemu_opt_script += ' %s' % self.get('QB_AUDIO_OPT')
852 os.putenv('QEMU_AUDIO_DRV', self.get('QB_AUDIO_DRV'))
856 self.check_qemu_system()
857 self.check_kvm()
858 self.check_fstype()
859 self.check_rootfs()
860 self.check_ovmf()
861 self.check_kernel()
862 self.check_dtb()
863 self.check_bios()
864 self.check_mem()
865 self.check_tcpserial()
867 def read_qemuboot(self): argument
868 if not self.qemuboot:
869 if self.get('DEPLOY_DIR_IMAGE'):
870 deploy_dir_image = self.get('DEPLOY_DIR_IMAGE')
875 if self.rootfs and not os.path.exists(self.rootfs):
877 machine = self.get('MACHINE')
880 self.qemuboot = "%s/%s-%s.qemuboot.conf" % (deploy_dir_image,
881 self.rootfs, machine)
892 if '-initramfs-' in os.path.basename(qb) and self.fstype != 'cpio.gz':
894 self.qemuboot = qb
896 if not self.qemuboot:
898 self.qemuboot = qbs.split()[0]
899 self.qbconfload = True
901 if not self.qemuboot:
906 if not os.path.exists(self.qemuboot):
907 …Failed to find %s (wrong image name or BSP does not support running under qemu?)." % self.qemuboot)
909 logger.debug('CONFFILE: %s' % self.qemuboot)
912 cf.read(self.qemuboot)
916 v = os.path.abspath(os.path.dirname(self.qemuboot) + "/" + v)
918 v = os.path.dirname(self.qemuboot)
919 self.set(k_upper, v)
921 def validate_paths(self): argument
926 if self.qbconfload:
927 imgdir = os.path.realpath(os.path.dirname(self.qemuboot))
928 if imgdir != os.path.realpath(self.get('DEPLOY_DIR_IMAGE')):
929 … logger.info('Setting DEPLOY_DIR_IMAGE to folder containing %s (%s)' % (self.qemuboot, imgdir))
930 self.set('DEPLOY_DIR_IMAGE', imgdir)
935 havenative = os.path.exists(self.get('STAGING_DIR_NATIVE')) and \
936 os.path.exists(self.get('STAGING_BINDIR_NATIVE'))
939 if not self.bitbake_e:
940 self.load_bitbake_env()
942 if self.bitbake_e:
945 s = re.search('^%s="(.*)"' % nv, self.bitbake_e, re.M)
946 if s and s.group(1) != self.get(nv):
948 self.set(nv, s.group(1))
954 tmpdir = self.get('OE_TMPDIR')
955 oecore_native_sysroot = self.get('OECORE_NATIVE_SYSROOT')
961 self.set('STAGING_DIR_NATIVE', staging_dir_native)
964 self.set('STAGING_DIR_NATIVE', oecore_native_sysroot)
965 if self.get('STAGING_DIR_NATIVE'):
967 staging_bindir_native = '%s/usr/bin' % self.get('STAGING_DIR_NATIVE')
969 self.set('STAGING_BINDIR_NATIVE', '%s/usr/bin' % self.get('STAGING_DIR_NATIVE'))
971 def print_config(self): argument
973 if not self.fstype in self.vmtypes:
974 logoutput.append('KERNEL: [%s]' % self.kernel)
975 if self.bios:
976 logoutput.append('BIOS: [%s]' % self.bios)
977 if self.dtb:
978 logoutput.append('DTB: [%s]' % self.dtb)
979 logoutput.append('MACHINE: [%s]' % self.get('MACHINE'))
981 fstype_flags = ' (' + ', '.join(self.fsinfo[self.fstype]) + ')'
984 logoutput.append('FSTYPE: [%s%s]' % (self.fstype, fstype_flags))
985 if self.fstype == 'nfs':
986 logoutput.append('NFS_DIR: [%s]' % self.rootfs)
988 logoutput.append('ROOTFS: [%s]' % self.rootfs)
989 if self.ovmf_bios:
990 logoutput.append('OVMF: %s' % self.ovmf_bios)
991 if (self.ovmf_secboot_pkkek1):
992 logoutput.append('SECBOOT PKKEK1: [%s...]' % self.ovmf_secboot_pkkek1[0:100])
993 logoutput.append('CONFFILE: [%s]' % self.qemuboot)
997 def setup_nfs(self): argument
998 if not self.nfs_server:
999 if self.slirp_enabled:
1000 self.nfs_server = '10.0.2.2'
1002 self.nfs_server = '192.168.7.1'
1010 self.nfs_instance = int(all_instances.pop()) + 1
1012 nfsd_port = 3049 + 2 * self.nfs_instance
1013 mountd_port = 3048 + 2 * self.nfs_instance
1017 'NFS_INSTANCE': self.nfs_instance,
1025 self.unfs_opts="nfsvers=3,port=%s,tcp,mountport=%s" % (nfsd_port, mountd_port)
1028 if not (self.rootfs and os.path.isdir(self.rootfs)):
1029 src_prefix = '%s/%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_LINK_NAME'))
1033 self.rootfs = dest
1049 self.rootfs = dest
1050 self.cleanup_files.append(self.rootfs)
1051 self.cleanup_files.append('%s.pseudo_state' % self.rootfs)
1054 cmd = ('runqemu-export-rootfs', 'start', self.rootfs)
1059 self.nfs_running = True
1061 def setup_net_bridge(self): argument
1062 …self.set('NETWORK_CMD', '-netdev bridge,br=%s,id=net0,helper=%s -device virtio-net-pci,netdev=net0…
1063 self.net_bridge, os.path.join(self.bindir_native, 'qemu-oe-bridge-helper')))
1065 def setup_slirp(self): argument
1068 if self.fstype == 'nfs':
1069 self.setup_nfs()
1070 netconf = " " + self.cmdline_ip_slirp
1072 self.kernel_cmdline_script += netconf
1075 … qb_slirp_opt_default = "-netdev user,id=net0%s,tftp=%s" % (hostfwd, self.get('DEPLOY_DIR_IMAGE'))
1076 qb_slirp_opt = self.get('QB_SLIRP_OPT') or qb_slirp_opt_default
1095 while not self.check_free_port('localhost', p_new, lockdir):
1105 mac = "%s%02x" % (self.mac_slirp, mac)
1106 self.set('NETWORK_CMD', '%s %s' % (self.network_device.replace('@MAC@', mac), qb_slirp_opt))
1112 def setup_tap(self): argument
1119 self.qemuifup = shutil.which('runqemu-ifup')
1120 self.qemuifdown = shutil.which('runqemu-ifdown')
1124 if not (self.qemuifup and self.qemuifdown and ip):
1125 logger.error("runqemu-ifup: %s" % self.qemuifup)
1126 logger.error("runqemu-ifdown: %s" % self.qemuifdown)
1150 self.taplock = lockfile + '.lock'
1151 if self.acquire_taplock(error=False):
1166 cmd = ('sudo', self.qemuifup, str(uid), str(gid), self.bindir_native)
1173 self.taplock = lockfile + '.lock'
1174 self.acquire_taplock()
1175 self.cleantap = True
1181 self.tap = tap
1185 if self.fstype == 'nfs':
1186 self.setup_nfs()
1187 netconf = " " + self.cmdline_ip_tap
1191 self.kernel_cmdline_script += netconf
1192 mac = "%s%02x" % (self.mac_tap, client)
1193 qb_tap_opt = self.get('QB_TAP_OPT')
1197 qemu_tap_opt = "-netdev tap,id=net0,ifname=%s,script=no,downscript=no" % (self.tap)
1199 if self.vhost_enabled:
1202 self.set('NETWORK_CMD', '%s %s' % (self.network_device.replace('@MAC@', mac), qemu_tap_opt))
1204 def setup_network(self): argument
1205 if self.get('QB_NET') == 'none':
1208 self.saved_stty = subprocess.check_output(("stty", "-g")).decode('utf-8').strip()
1209 self.network_device = self.get('QB_NETWORK_DEVICE') or self.network_device
1210 if self.net_bridge:
1211 self.setup_net_bridge()
1212 elif self.slirp_enabled:
1213 self.cmdline_ip_slirp = self.get('QB_CMDLINE_IP_SLIRP') or self.cmdline_ip_slirp
1214 self.setup_slirp()
1216 self.cmdline_ip_tap = self.get('QB_CMDLINE_IP_TAP') or self.cmdline_ip_tap
1217 self.setup_tap()
1219 def setup_rootfs(self): argument
1220 if self.get('QB_ROOTFS') == 'none':
1222 if 'wic.' in self.fstype:
1223 self.fstype = self.fstype[4:]
1224 … rootfs_format = self.fstype if self.fstype in ('vmdk', 'vhd', 'vhdx', 'qcow2', 'vdi') else 'raw'
1227 if self.snapshot and tmpfsdir:
1228 … newrootfs = os.path.join(tmpfsdir, os.path.basename(self.rootfs)) + "." + str(os.getpid())
1231 shutil.copyfile(self.rootfs, newrootfs)
1233 self.rootfs = newrootfs
1235 self.snapshot = False
1236 self.cleanup_files.append(newrootfs)
1238 qb_rootfs_opt = self.get('QB_ROOTFS_OPT')
1240 self.rootfs_options = qb_rootfs_opt.replace('@ROOTFS@', self.rootfs)
1242 … self.rootfs_options = '-drive file=%s,if=virtio,format=%s' % (self.rootfs, rootfs_format)
1244 qb_rootfs_extra_opt = self.get("QB_ROOTFS_EXTRA_OPT")
1248 if self.fstype in ('cpio.gz', 'cpio'):
1249 self.kernel_cmdline = 'root=/dev/ram0 rw debugshell'
1250 self.rootfs_options = '-initrd %s' % self.rootfs
1253 if self.fstype in self.vmtypes:
1254 if self.fstype == 'iso':
1255 vm_drive = '-drive file=%s,if=virtio,media=cdrom' % self.rootfs
1256 elif self.get('QB_DRIVE_TYPE'):
1257 drive_type = self.get('QB_DRIVE_TYPE')
1261 % (self.rootfs, rootfs_format, qb_rootfs_extra_opt)
1264 vm_drive = "-drive file=%s,format=%s" % (self.rootfs, rootfs_format)
1268 % (self.rootfs, rootfs_format,qb_rootfs_extra_opt)
1276 … vm_drive = '-drive if=virtio,file=%s,format=%s' % (self.rootfs, rootfs_format)
1279 self.rootfs_options = vm_drive
1280 if not self.fstype in self.vmtypes:
1281 self.rootfs_options += ' -no-reboot'
1284 qb_kernel_root = self.get('QB_KERNEL_ROOT')
1288 self.kernel_cmdline = 'root=%s' % qb_kernel_root
1290 if self.fstype == 'nfs':
1291 self.rootfs_options = ''
1292 …k_root = '/dev/nfs nfsroot=%s:%s,%s' % (self.nfs_server, os.path.abspath(self.rootfs), self.unfs_o…
1293 self.kernel_cmdline = 'root=%s rw' % k_root
1295 if self.fstype == 'none':
1296 self.rootfs_options = ''
1298 self.set('ROOTFS_OPTIONS', self.rootfs_options)
1300 def guess_qb_system(self): argument
1302 mach = self.get('MACHINE')
1305 if self.rootfs:
1306 match = re.match(search, self.rootfs)
1309 elif self.kernel:
1310 match = re.match(search, self.kernel)
1347 def check_qemu_system(self): argument
1348 qemu_system = self.get('QB_SYSTEM_NAME')
1350 qemu_system = self.guess_qb_system()
1353 self.qemu_system = qemu_system
1355 def setup_vga(self): argument
1356 if self.nographic == True:
1357 if self.sdl == True:
1359 if self.gtk == True:
1361 self.qemu_opt += ' -nographic'
1363 if self.novga == True:
1364 self.qemu_opt += ' -vga none'
1367 if (self.gl_es == True or self.gl == True) and (self.sdl == False and self.gtk == False):
1373 …if not self.nographic and not self.sdl and not self.gtk and not self.publicvnc and not self.egl_he…
1374 …output = subprocess.check_output([self.qemu_bin, "--help"], universal_newlines=True, env=self.qemu…
1376 self.gtk = True
1378 self.sdl = True
1380 self.qemu_opt += ' -display none'
1382 if self.sdl == True or self.gtk == True or self.egl_headless == True:
1384 if self.qemu_system.endswith(('i386', 'x86_64')):
1385 if self.gl or self.gl_es or self.egl_headless:
1386 self.qemu_opt += ' -device virtio-vga-gl '
1388 self.qemu_opt += ' -device virtio-vga '
1390 self.qemu_opt += ' -display '
1391 if self.egl_headless == True:
1392 self.set_dri_path()
1393 self.qemu_opt += 'egl-headless,'
1395 if self.sdl == True:
1396 self.qemu_opt += 'sdl,'
1397 elif self.gtk == True:
1398 self.qemu_environ['FONTCONFIG_PATH'] = '/etc/fonts'
1399 self.qemu_opt += 'gtk,'
1401 if self.gl == True:
1402 self.set_dri_path()
1403 self.qemu_opt += 'gl=on,'
1404 elif self.gl_es == True:
1405 self.set_dri_path()
1406 self.qemu_opt += 'gl=es,'
1407 self.qemu_opt += 'show-cursor=on'
1409 self.qemu_opt += ' %s' %self.get('QB_GRAPHICS')
1411 def setup_serial(self): argument
1413 …if self.get('SERIAL_CONSOLES') and (self.serialstdio == True or self.serialconsole == True or self…
1414 for entry in self.get('SERIAL_CONSOLES').split(' '):
1415 self.kernel_cmdline_script += ' console=%s' %entry.split(';')[1]
1417 if self.serialstdio == True or self.nographic == True:
1418 self.qemu_opt += " -serial mon:stdio"
1420 self.qemu_opt += " -serial mon:vc"
1421 if self.serialconsole:
1426 self.qemu_opt += " %s" % self.get("QB_SERIAL_OPT")
1432 serial_num = len(re.findall("-serial", self.qemu_opt))
1434 self.qemu_opt += " -serial null"
1436 def find_qemu(self): argument
1437 qemu_bin = os.path.join(self.bindir_native, self.qemu_system)
1444 qemu_bin_tmp = os.path.join(path, self.qemu_system)
1455 self.qemu_bin = qemu_bin
1457 def setup_final(self): argument
1459 self.find_qemu()
1461 …self.qemu_opt = "%s %s %s %s %s" % (self.qemu_bin, self.get('NETWORK_CMD'), self.get('QB_RNG'), se…
1463 for ovmf in self.ovmf_bios:
1467 self.qemu_opt += ' -drive if=pflash,format=%s,file=%s' % (format, ovmf)
1469 self.qemu_opt += ' ' + self.qemu_opt_script
1471 if self.ovmf_secboot_pkkek1:
1475 self.qemu_opt += ' -smbios type=11,value=4e32566d-8e9e-4f52-81d3-5bb9715f9727:' \
1476 + self.ovmf_secboot_pkkek1
1479 if self.qemuparams:
1480 self.qemu_opt += ' ' + self.qemuparams
1482 if self.snapshot:
1483 self.qemu_opt += " -snapshot"
1485 self.setup_serial()
1486 self.setup_vga()
1488 def start_qemu(self): argument
1490 if self.kernel:
1491 kernel_opts = "-kernel %s -append '%s %s %s %s'" % (self.kernel, self.kernel_cmdline,
1492 … self.kernel_cmdline_script, self.get('QB_KERNEL_CMDLINE_APPEND'),
1493 self.bootparams)
1494 if self.dtb:
1495 kernel_opts += " -dtb %s" % self.dtb
1499 if self.bios:
1500 self.qemu_opt += " -bios %s" % self.bios
1502 cmd = "%s %s" % (self.qemu_opt, kernel_opts)
1509 if self.taplock_descriptor:
1510 pass_fds = [self.taplock_descriptor.fileno()]
1511 if len(self.portlocks):
1512 for descriptor in self.portlocks.values():
1514 … process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ)
1515 self.qemuprocess = process
1523 def cleanup(self): argument
1524 if self.cleaned:
1532 if self.qemuprocess:
1535 self.qemuprocess.send_signal(signal.SIGTERM)
1536 self.qemuprocess.communicate(timeout=5)
1538 self.qemuprocess.kill()
1543 if self.cleantap:
1544 cmd = ('sudo', self.qemuifdown, self.tap, self.bindir_native)
1547 self.release_taplock()
1548 self.release_portlock()
1550 if self.nfs_running:
1552 cmd = ("runqemu-export-rootfs", "stop", self.rootfs)
1556 if self.saved_stty:
1557 subprocess.check_call(("stty", self.saved_stty))
1559 if self.cleanup_files:
1560 for ent in self.cleanup_files:
1570 self.cleaned = True
1572 def run_bitbake_env(self, mach=None): argument
1578 mach = self.get('MACHINE')
1580 multiconfig = self.get('MULTICONFIG')
1592 def load_bitbake_env(self, mach=None): argument
1593 if self.bitbake_e:
1597 self.bitbake_e = self.run_bitbake_env(mach=mach)
1599 self.bitbake_e = ''
1602 def validate_combos(self): argument
1603 if (self.fstype in self.vmtypes) and self.kernel:
1604 raise RunQemuError("%s doesn't need kernel %s!" % (self.fstype, self.kernel))
1607 def bindir_native(self): argument
1608 result = self.get('STAGING_BINDIR_NATIVE')
1613 multiconfig = self.get('MULTICONFIG')
1626 self.set('STAGING_BINDIR_NATIVE', result)