runqemu.py 3.3 KB

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