diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2016-09-18 00:05:33 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-09-20 15:11:08 +0100 |
commit | d8af0f283ae9d3284f1c51f68ba171473192b49a (patch) | |
tree | 1e8bbb8f487dbf54c593a37e389b011d73afcfa3 /scripts | |
parent | 67cb1169f5c5397418c7477874749372e9fb3be7 (diff) | |
download | poky-d8af0f283ae9d3284f1c51f68ba171473192b49a.tar.gz |
runqemu: improve finding of rootfs, kernel and dtb
* Search rootfs in the following order:
- IMAGE_NAME*.FSTYPE
- IMAGE_LINK_NAME*.FSTYPE
* Search kernel in the following order:
- QB_DEFAULT_KERNEL
- KERNEL_IMAGETYPE
- KERNEL_IMAGETYPE*
* Search dtb in the following order:
- QB_DTB
- QB_DTB*
- *.dtb
* Fix DTB, it should only work with "-kernel" option.
[YOCTO #10265]
(From OE-Core rev: 32ff0974ed06f797c6b7d9092a8dc9ae50e9a572)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/runqemu | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/scripts/runqemu b/scripts/runqemu index 30a49590c4..08dc306921 100755 --- a/scripts/runqemu +++ b/scripts/runqemu | |||
@@ -137,6 +137,16 @@ def check_libgl(qemu_bin): | |||
137 | logger.error("Fedora package names are: mesa-libGL-devel mesa-libGLU-devel.") | 137 | logger.error("Fedora package names are: mesa-libGL-devel mesa-libGLU-devel.") |
138 | raise Exception('%s requires libGLU, but not found' % qemu_bin) | 138 | raise Exception('%s requires libGLU, but not found' % qemu_bin) |
139 | 139 | ||
140 | def get_first_file(cmds): | ||
141 | """Return first file found in wildcard cmds""" | ||
142 | for cmd in cmds: | ||
143 | all_files = glob.glob(cmd) | ||
144 | if all_files: | ||
145 | for f in all_files: | ||
146 | if not os.path.isdir(f): | ||
147 | return f | ||
148 | return '' | ||
149 | |||
140 | class BaseConfig(object): | 150 | class BaseConfig(object): |
141 | def __init__(self): | 151 | def __init__(self): |
142 | # Vars can be merged with .qemuboot.conf, use a dict to manage them. | 152 | # Vars can be merged with .qemuboot.conf, use a dict to manage them. |
@@ -157,6 +167,7 @@ class BaseConfig(object): | |||
157 | self.kernel = '' | 167 | self.kernel = '' |
158 | self.kernel_cmdline = '' | 168 | self.kernel_cmdline = '' |
159 | self.kernel_cmdline_script = '' | 169 | self.kernel_cmdline_script = '' |
170 | self.dtb = '' | ||
160 | self.fstype = '' | 171 | self.fstype = '' |
161 | self.kvm_enabled = False | 172 | self.kvm_enabled = False |
162 | self.vhost_enabled = False | 173 | self.vhost_enabled = False |
@@ -446,17 +457,12 @@ class BaseConfig(object): | |||
446 | self.rootfs, self.get('MACHINE'), | 457 | self.rootfs, self.get('MACHINE'), |
447 | self.fstype) | 458 | self.fstype) |
448 | elif not self.rootfs: | 459 | elif not self.rootfs: |
449 | cmd = '%s/%s*.%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_NAME'), self.fstype) | 460 | cmd_name = '%s/%s*.%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_NAME'), self.fstype) |
450 | all_files = glob.glob(cmd) | 461 | cmd_link = '%s/%s*.%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_LINK_NAME'), self.fstype) |
451 | if all_files: | 462 | cmds = (cmd_name, cmd_link) |
452 | self.rootfs = all_files[0] | 463 | self.rootfs = get_first_file(cmds) |
453 | else: | 464 | if not self.rootfs: |
454 | cmd = '%s/%s*.%s' % (self.get('DEPLOY_DIR_IMAGE'), self.get('IMAGE_LINK_NAME'), self.fstype) | 465 | raise Exception("Failed to find rootfs: %s or %s" % cmds) |
455 | all_files = glob.glob(cmd) | ||
456 | if all_files: | ||
457 | self.rootfs = all_files[0] | ||
458 | else: | ||
459 | raise Exception("Failed to find rootfs: %s" % cmd) | ||
460 | 466 | ||
461 | if not os.path.exists(self.rootfs): | 467 | if not os.path.exists(self.rootfs): |
462 | raise Exception("Can't find rootfs: %s" % self.rootfs) | 468 | raise Exception("Can't find rootfs: %s" % self.rootfs) |
@@ -466,28 +472,29 @@ class BaseConfig(object): | |||
466 | # The vm image doesn't need a kernel | 472 | # The vm image doesn't need a kernel |
467 | if self.fstype in self.vmtypes: | 473 | if self.fstype in self.vmtypes: |
468 | return | 474 | return |
469 | kernel = self.kernel | ||
470 | deploy_dir_image = self.get('DEPLOY_DIR_IMAGE') | ||
471 | if not kernel: | ||
472 | kernel = "%s/%s" % (deploy_dir_image, self.get('QB_DEFAULT_KERNEL')) | ||
473 | 475 | ||
474 | if os.path.exists(kernel): | 476 | deploy_dir_image = self.get('DEPLOY_DIR_IMAGE') |
475 | self.kernel = kernel | 477 | if not self.kernel: |
476 | else: | 478 | kernel_match_name = "%s/%s" % (deploy_dir_image, self.get('QB_DEFAULT_KERNEL')) |
477 | kernel = "%s/%s" % (deploy_dir_image, self.get('KERNEL_IMAGETYPE')) | 479 | kernel_match_link = "%s/%s" % (deploy_dir_image, self.get('KERNEL_IMAGETYPE')) |
478 | if kernel != deploy_dir_image and os.path.exists(kernel): | 480 | kernel_startswith = "%s/%s*" % (deploy_dir_image, self.get('KERNEL_IMAGETYPE')) |
479 | self.kernel = kernel | 481 | cmds = (kernel_match_name, kernel_match_link, kernel_startswith) |
480 | else: | 482 | self.kernel = get_first_file(cmds) |
481 | raise Exception("KERNEL %s not found" % kernel) | 483 | if not self.kernel: |
484 | raise Exception('KERNEL not found: %s, %s or %s' % cmds) | ||
485 | |||
486 | if not os.path.exists(self.kernel): | ||
487 | raise Exception("KERNEL %s not found" % self.kernel) | ||
482 | 488 | ||
483 | dtb = self.get('QB_DTB') | 489 | dtb = self.get('QB_DTB') |
484 | if dtb: | 490 | if dtb: |
485 | dtb = "%s/%s" % (self.get('DEPLOY_DIR_IMAGE'), dtb) | 491 | cmd_match = "%s/%s" % (deploy_dir_image, dtb) |
486 | if os.path.exists(dtb): | 492 | cmd_startswith = "%s/%s*" % (deploy_dir_image, dtb) |
487 | self.set('QB_DTB', '-dtb %s' % dtb) | 493 | cmd_wild = "%s/*.dtb" % deploy_dir_image |
488 | else: | 494 | cmds = (cmd_match, cmd_startswith, cmd_wild) |
489 | raise Exception("DTB %s not found" % dtb) | 495 | self.dtb = get_first_file(cmds) |
490 | 496 | if not os.path.exists(self.dtb): | |
497 | raise Exception('DTB not found: %s, %s or %s' % cmds) | ||
491 | 498 | ||
492 | def check_biosdir(self): | 499 | def check_biosdir(self): |
493 | """Check custombiosdir""" | 500 | """Check custombiosdir""" |
@@ -643,6 +650,8 @@ class BaseConfig(object): | |||
643 | logger.info('Continuing with the following parameters:\n') | 650 | logger.info('Continuing with the following parameters:\n') |
644 | if not self.fstype in self.vmtypes: | 651 | if not self.fstype in self.vmtypes: |
645 | print('KERNEL: [%s]' % self.kernel) | 652 | print('KERNEL: [%s]' % self.kernel) |
653 | if self.dtb: | ||
654 | print('DTB: [%s]' % self.dtb) | ||
646 | print('MACHINE: [%s]' % self.get('MACHINE')) | 655 | print('MACHINE: [%s]' % self.get('MACHINE')) |
647 | print('FSTYPE: [%s]' % self.fstype) | 656 | print('FSTYPE: [%s]' % self.fstype) |
648 | if self.fstype == 'nfs': | 657 | if self.fstype == 'nfs': |
@@ -687,7 +696,7 @@ class BaseConfig(object): | |||
687 | elif os.path.exists(src2): | 696 | elif os.path.exists(src2): |
688 | src = src2 | 697 | src = src2 |
689 | if not src: | 698 | if not src: |
690 | raise Exception("No NFS_DIR is set but can't find %s or %s to extract" % (src1, src2)) | 699 | raise Exception("No NFS_DIR is set, and can't find %s or %s to extract" % (src1, src2)) |
691 | logger.info('NFS_DIR not found, extracting %s to %s' % (src, dest)) | 700 | logger.info('NFS_DIR not found, extracting %s to %s' % (src, dest)) |
692 | cmd = 'runqemu-extract-sdk %s %s' % (src, dest) | 701 | cmd = 'runqemu-extract-sdk %s %s' % (src, dest) |
693 | logger.info('Running %s...' % cmd) | 702 | logger.info('Running %s...' % cmd) |
@@ -845,7 +854,7 @@ class BaseConfig(object): | |||
845 | 854 | ||
846 | check_libgl(qemu_bin) | 855 | check_libgl(qemu_bin) |
847 | 856 | ||
848 | self.qemu_opt = "%s %s %s %s %s %s" % (qemu_bin, self.get('NETWORK_CMD'), self.qemu_opt_script, self.get('ROOTFS_OPTIONS'), self.get('QB_DTB'), self.get('QB_OPT_APPEND')) | 857 | self.qemu_opt = "%s %s %s %s %s" % (qemu_bin, self.get('NETWORK_CMD'), self.qemu_opt_script, self.get('ROOTFS_OPTIONS'), self.get('QB_OPT_APPEND')) |
849 | 858 | ||
850 | # Enable virtio RNG else we can run out of entropy in guests | 859 | # Enable virtio RNG else we can run out of entropy in guests |
851 | self.qemu_opt += " -device virtio-rng-pci" | 860 | self.qemu_opt += " -device virtio-rng-pci" |
@@ -877,6 +886,8 @@ class BaseConfig(object): | |||
877 | def start_qemu(self): | 886 | def start_qemu(self): |
878 | if self.kernel: | 887 | if self.kernel: |
879 | kernel_opts = "-kernel %s -append '%s %s %s'" % (self.kernel, self.kernel_cmdline, self.kernel_cmdline_script, self.get('QB_KERNEL_CMDLINE_APPEND')) | 888 | kernel_opts = "-kernel %s -append '%s %s %s'" % (self.kernel, self.kernel_cmdline, self.kernel_cmdline_script, self.get('QB_KERNEL_CMDLINE_APPEND')) |
889 | if self.dtb: | ||
890 | kernel_opts += " -dtb %s" % self.dtb | ||
880 | else: | 891 | else: |
881 | kernel_opts = "" | 892 | kernel_opts = "" |
882 | cmd = "%s %s" % (self.qemu_opt, kernel_opts) | 893 | cmd = "%s %s" % (self.qemu_opt, kernel_opts) |