blob: e26cf28c2f251a578e6ddfe9a3f963cd6afdcaf5 [file] [log] [blame]
Patrick Williamsf1e5d692016-03-30 15:21:19 -05001# Development tool - runqemu command plugin
2#
3# Copyright (C) 2015 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18"""Devtool runqemu plugin"""
19
20import os
21import bb
22import logging
23import argparse
24import glob
25from devtool import exec_build_env_command, setup_tinfoil, DevtoolError
26
27logger = logging.getLogger('devtool')
28
29def runqemu(args, config, basepath, workspace):
30 """Entry point for the devtool 'runqemu' subcommand"""
31
32 tinfoil = setup_tinfoil(config_only=True, basepath=basepath)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050034 machine = tinfoil.config_data.getVar('MACHINE')
35 bindir_native = os.path.join(tinfoil.config_data.getVar('STAGING_DIR'),
36 tinfoil.config_data.getVar('BUILD_ARCH'),
37 tinfoil.config_data.getVar('bindir_native').lstrip(os.path.sep))
Patrick Williamsc0f7c042017-02-23 20:41:17 -060038 finally:
39 tinfoil.shutdown()
Patrick Williamsf1e5d692016-03-30 15:21:19 -050040
41 if not glob.glob(os.path.join(bindir_native, 'qemu-system-*')):
42 raise DevtoolError('QEMU is not available within this SDK')
43
44 imagename = args.imagename
45 if not imagename:
46 sdk_targets = config.get('SDK', 'sdk_targets', '').split()
47 if sdk_targets:
48 imagename = sdk_targets[0]
49 if not imagename:
50 raise DevtoolError('Unable to determine image name to run, please specify one')
51
52 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060053 # FIXME runqemu assumes that if OECORE_NATIVE_SYSROOT is set then it shouldn't
54 # run bitbake to find out the values of various environment variables, which
55 # isn't the case for the extensible SDK. Work around it for now.
56 newenv = dict(os.environ)
57 newenv.pop('OECORE_NATIVE_SYSROOT', '')
58 exec_build_env_command(config.init_path, basepath, 'runqemu %s %s %s' % (machine, imagename, " ".join(args.args)), watch=True, env=newenv)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050059 except bb.process.ExecutionError as e:
60 # We've already seen the output since watch=True, so just ensure we return something to the user
61 return e.exitcode
62
63 return 0
64
65def register_commands(subparsers, context):
66 """Register devtool subcommands from this plugin"""
67 if context.fixed_setup:
68 parser_runqemu = subparsers.add_parser('runqemu', help='Run QEMU on the specified image',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050069 description='Runs QEMU to boot the specified image',
70 group='testbuild', order=-20)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050071 parser_runqemu.add_argument('imagename', help='Name of built image to boot within QEMU', nargs='?')
72 parser_runqemu.add_argument('args', help='Any remaining arguments are passed to the runqemu script (pass --help after imagename to see what these are)',
73 nargs=argparse.REMAINDER)
74 parser_runqemu.set_defaults(func=runqemu)