summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2017-04-11 02:21:25 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-04-12 15:09:57 +0100
commitf6aaba31cf12d339d76ac12f37efcd074312245d (patch)
treefcd642cf7858c6ed5efb029836bafcfb76da00f9 /scripts
parentb283b10d5363b4d86f2a18fce6a6aa37325fb5f2 (diff)
downloadpoky-f6aaba31cf12d339d76ac12f37efcd074312245d.tar.gz
runqemu: support env vars explicitly
Use self.env_vars to support get vars from environment explicity. The MACHINE, ROOTFS and KERNEL was supported by shell based runqemu, and the help text says support them from env vars, so add them back. [YOCTO #11141] (From OE-Core rev: 20008d0bfe2cacecba77e11b0a0faf3d959eaf1e) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/runqemu71
1 files changed, 42 insertions, 29 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index b696202871..6234e811a7 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -163,12 +163,18 @@ def check_free_port(host, port):
163 163
164class BaseConfig(object): 164class BaseConfig(object):
165 def __init__(self): 165 def __init__(self):
166 # Vars can be merged with .qemuboot.conf, use a dict to manage them. 166 # The self.d saved vars from self.set(), part of them are from qemuboot.conf
167 self.d = { 167 self.d = {'QB_KERNEL_ROOT': '/dev/vda'}
168 'MACHINE': '', 168
169 'DEPLOY_DIR_IMAGE': '', 169 # Supported env vars, add it here if a var can be got from env,
170 'QB_KERNEL_ROOT': '/dev/vda', 170 # and don't use os.getenv in the code.
171 } 171 self.env_vars = ('MACHINE',
172 'ROOTFS',
173 'KERNEL',
174 'DEPLOY_DIR_IMAGE',
175 'OE_TMPDIR',
176 'OECORE_NATIVE_SYSROOT',
177 )
172 178
173 self.qemu_opt = '' 179 self.qemu_opt = ''
174 self.qemu_opt_script = '' 180 self.qemu_opt_script = ''
@@ -238,6 +244,8 @@ class BaseConfig(object):
238 def get(self, key): 244 def get(self, key):
239 if key in self.d: 245 if key in self.d:
240 return self.d.get(key) 246 return self.d.get(key)
247 elif os.getenv(key):
248 return os.getenv(key)
241 else: 249 else:
242 return '' 250 return ''
243 251
@@ -338,10 +346,13 @@ class BaseConfig(object):
338 346
339 def check_arg_machine(self, arg): 347 def check_arg_machine(self, arg):
340 """Check whether it is a machine""" 348 """Check whether it is a machine"""
341 if self.get('MACHINE') and self.get('MACHINE') != arg or re.search('/', arg): 349 if self.get('MACHINE') == arg:
342 raise Exception("Unknown arg: %s" % arg)
343 elif self.get('MACHINE') == arg:
344 return 350 return
351 elif self.get('MACHINE') and self.get('MACHINE') != arg:
352 raise Exception("Maybe conflicted MACHINE: %s vs %s" % (self.get('MACHINE'), arg))
353 elif re.search('/', arg):
354 raise Exception("Unknown arg: %s" % arg)
355
345 logger.info('Assuming MACHINE = %s' % arg) 356 logger.info('Assuming MACHINE = %s' % arg)
346 357
347 # if we're running under testimage, or similarly as a child 358 # if we're running under testimage, or similarly as a child
@@ -350,14 +361,14 @@ class BaseConfig(object):
350 # FIXME: testimage.bbclass exports these two variables into env, 361 # FIXME: testimage.bbclass exports these two variables into env,
351 # are there other scenarios in which we need to support being 362 # are there other scenarios in which we need to support being
352 # invoked by bitbake? 363 # invoked by bitbake?
353 deploy = os.environ.get('DEPLOY_DIR_IMAGE') 364 deploy = self.get('DEPLOY_DIR_IMAGE')
354 bbchild = deploy and os.environ.get('OE_TMPDIR') 365 bbchild = deploy and self.get('OE_TMPDIR')
355 if bbchild: 366 if bbchild:
356 self.set_machine_deploy_dir(arg, deploy) 367 self.set_machine_deploy_dir(arg, deploy)
357 return 368 return
358 # also check whether we're running under a sourced toolchain 369 # also check whether we're running under a sourced toolchain
359 # environment file 370 # environment file
360 if os.environ.get('OECORE_NATIVE_SYSROOT'): 371 if self.get('OECORE_NATIVE_SYSROOT'):
361 self.set("MACHINE", arg) 372 self.set("MACHINE", arg)
362 return 373 return
363 374
@@ -430,20 +441,15 @@ class BaseConfig(object):
430 if unknown_arg: 441 if unknown_arg:
431 if self.get('MACHINE') == unknown_arg: 442 if self.get('MACHINE') == unknown_arg:
432 return 443 return
433 if not self.get('DEPLOY_DIR_IMAGE'): 444 if self.get('DEPLOY_DIR_IMAGE'):
434 # Trying to get DEPLOY_DIR_IMAGE from env. 445 machine = os.path.basename(self.get('DEPLOY_DIR_IMAGE'))
435 p = os.getenv('DEPLOY_DIR_IMAGE') 446 if unknown_arg == machine:
436 if p and self.is_deploy_dir_image(p): 447 self.set("MACHINE", machine)
437 machine = os.path.basename(p) 448 return
438 if unknown_arg == machine: 449
439 self.set_machine_deploy_dir(machine, p)
440 return
441 else:
442 logger.info('DEPLOY_DIR_IMAGE: %s' % p)
443 self.set("DEPLOY_DIR_IMAGE", p)
444 self.check_arg_machine(unknown_arg) 450 self.check_arg_machine(unknown_arg)
445 451
446 if not (self.get('MACHINE') or self.get('DEPLOY_DIR_IMAGE')): 452 if not self.get('DEPLOY_DIR_IMAGE'):
447 self.load_bitbake_env() 453 self.load_bitbake_env()
448 s = re.search('^DEPLOY_DIR_IMAGE="(.*)"', self.bitbake_e, re.M) 454 s = re.search('^DEPLOY_DIR_IMAGE="(.*)"', self.bitbake_e, re.M)
449 if s: 455 if s:
@@ -505,7 +511,16 @@ class BaseConfig(object):
505 def check_rootfs(self): 511 def check_rootfs(self):
506 """Check and set rootfs""" 512 """Check and set rootfs"""
507 513
508 if self.fstype == 'nfs' or self.fstype == "none": 514 if self.fstype == "none":
515 return
516
517 if self.get('ROOTFS'):
518 if not self.rootfs:
519 self.rootfs = self.get('ROOTFS')
520 elif self.get('ROOTFS') != self.rootfs:
521 raise Exception("Maybe conflicted ROOTFS: %s vs %s" % (self.get('ROOTFS'), self.rootfs))
522
523 if self.fstype == 'nfs':
509 return 524 return
510 525
511 if self.rootfs and not os.path.exists(self.rootfs): 526 if self.rootfs and not os.path.exists(self.rootfs):
@@ -642,8 +657,6 @@ class BaseConfig(object):
642 if not self.qemuboot: 657 if not self.qemuboot:
643 if self.get('DEPLOY_DIR_IMAGE'): 658 if self.get('DEPLOY_DIR_IMAGE'):
644 deploy_dir_image = self.get('DEPLOY_DIR_IMAGE') 659 deploy_dir_image = self.get('DEPLOY_DIR_IMAGE')
645 elif os.getenv('DEPLOY_DIR_IMAGE'):
646 deploy_dir_image = os.getenv('DEPLOY_DIR_IMAGE')
647 else: 660 else:
648 logger.info("Can't find qemuboot conf file, DEPLOY_DIR_IMAGE is NULL!") 661 logger.info("Can't find qemuboot conf file, DEPLOY_DIR_IMAGE is NULL!")
649 return 662 return
@@ -720,8 +733,8 @@ class BaseConfig(object):
720 # be able to call `bitbake -e`, then try: 733 # be able to call `bitbake -e`, then try:
721 # - get OE_TMPDIR from environment and guess paths based on it 734 # - get OE_TMPDIR from environment and guess paths based on it
722 # - get OECORE_NATIVE_SYSROOT from environment (for sdk) 735 # - get OECORE_NATIVE_SYSROOT from environment (for sdk)
723 tmpdir = os.environ.get('OE_TMPDIR', None) 736 tmpdir = self.get('OE_TMPDIR', None)
724 oecore_native_sysroot = os.environ.get('OECORE_NATIVE_SYSROOT', None) 737 oecore_native_sysroot = self.get('OECORE_NATIVE_SYSROOT', None)
725 if tmpdir: 738 if tmpdir:
726 logger.info('Setting STAGING_DIR_NATIVE and STAGING_BINDIR_NATIVE relative to OE_TMPDIR (%s)' % tmpdir) 739 logger.info('Setting STAGING_DIR_NATIVE and STAGING_BINDIR_NATIVE relative to OE_TMPDIR (%s)' % tmpdir)
727 hostos, _, _, _, machine = os.uname() 740 hostos, _, _, _, machine = os.uname()