Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1 | # 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 | |
| 20 | import os |
| 21 | import bb |
| 22 | import logging |
| 23 | import argparse |
| 24 | import glob |
| 25 | from devtool import exec_build_env_command, setup_tinfoil, DevtoolError |
| 26 | |
| 27 | logger = logging.getLogger('devtool') |
| 28 | |
| 29 | def runqemu(args, config, basepath, workspace): |
| 30 | """Entry point for the devtool 'runqemu' subcommand""" |
| 31 | |
| 32 | tinfoil = setup_tinfoil(config_only=True, basepath=basepath) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 33 | try: |
| 34 | machine = tinfoil.config_data.getVar('MACHINE', True) |
| 35 | bindir_native = tinfoil.config_data.getVar('STAGING_BINDIR_NATIVE', True) |
| 36 | finally: |
| 37 | tinfoil.shutdown() |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 38 | |
| 39 | if not glob.glob(os.path.join(bindir_native, 'qemu-system-*')): |
| 40 | raise DevtoolError('QEMU is not available within this SDK') |
| 41 | |
| 42 | imagename = args.imagename |
| 43 | if not imagename: |
| 44 | sdk_targets = config.get('SDK', 'sdk_targets', '').split() |
| 45 | if sdk_targets: |
| 46 | imagename = sdk_targets[0] |
| 47 | if not imagename: |
| 48 | raise DevtoolError('Unable to determine image name to run, please specify one') |
| 49 | |
| 50 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 51 | # FIXME runqemu assumes that if OECORE_NATIVE_SYSROOT is set then it shouldn't |
| 52 | # run bitbake to find out the values of various environment variables, which |
| 53 | # isn't the case for the extensible SDK. Work around it for now. |
| 54 | newenv = dict(os.environ) |
| 55 | newenv.pop('OECORE_NATIVE_SYSROOT', '') |
| 56 | exec_build_env_command(config.init_path, basepath, 'runqemu %s %s %s' % (machine, imagename, " ".join(args.args)), watch=True, env=newenv) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 57 | except bb.process.ExecutionError as e: |
| 58 | # We've already seen the output since watch=True, so just ensure we return something to the user |
| 59 | return e.exitcode |
| 60 | |
| 61 | return 0 |
| 62 | |
| 63 | def register_commands(subparsers, context): |
| 64 | """Register devtool subcommands from this plugin""" |
| 65 | if context.fixed_setup: |
| 66 | parser_runqemu = subparsers.add_parser('runqemu', help='Run QEMU on the specified image', |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 67 | description='Runs QEMU to boot the specified image', |
| 68 | group='testbuild', order=-20) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 69 | parser_runqemu.add_argument('imagename', help='Name of built image to boot within QEMU', nargs='?') |
| 70 | parser_runqemu.add_argument('args', help='Any remaining arguments are passed to the runqemu script (pass --help after imagename to see what these are)', |
| 71 | nargs=argparse.REMAINDER) |
| 72 | parser_runqemu.set_defaults(func=runqemu) |