zephyr/scripts/support/runner/bossac.py

57 lines
1.8 KiB
Python
Raw Normal View History

# Copyright (c) 2017 Linaro Limited.
#
# SPDX-License-Identifier: Apache-2.0
'''bossac-specific runner (flash only) for Atmel SAM microcontrollers.'''
import platform
scripts: runner: use arguments, not environment vars The various runners (flash/debug scripts) use environment variables to take arguments. This is legacy behavior which is not desirable. Use command line arguments instead. Note: this leaves more general environment variables with publicly documented behavior in place for now, for compatibility, e.g.: ZEPHYR_FLASH_OVER_DFU, OPENSDA_FW, ESP_IDF_PATH, PYOCD_DAPARG For example, when using dfu-util to flash arduino_101, instead of setting DFUUTIL_PID, DFUUTIL_ALT, and DFUUTIL_IMG environment variables, have the script invocation look like this: python3 .../zephyr_flash_debug.py dfu-util flash \ [common arguments omitted] \ --pid=8087:0aba --alt=x86_app \ --img=.../build/zephyr/zephyr.bin Make similar changes for other runners (openocd, etc.) and targets (debug, debugserver). To implement this in the scripts: - have the individual scripts/support/runner/some-runner.py files register their own command line arguments - teach them to construct instances from arguments, not the environment - have zephyr_flash_debug.py request runners to register command line argument parsers, and handle arguments In the build system: - add a new board_runner_args() extension function that board.cmake files can use to add to the zephyr_flash_debug.py command line - adjust cmake/flash/CMakeLists.txt to invoke with arguments - add new helper include files for each runner (like boards/common/dfu-util.board.cmake, etc.), which add default options as needed and then add on overrides from board_runner_args() calls - update board.cmake files to use the new includes and extension This implied some tweaking when using openocd to make the CMake string escaping and unescaping work properly. Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-11-17 06:45:38 +08:00
from .core import ZephyrBinaryRunner, RunnerCaps
DEFAULT_BOSSAC_PORT = '/dev/ttyACM0'
class BossacBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for bossac.'''
def __init__(self, bin_name, bossac='bossac',
port=DEFAULT_BOSSAC_PORT, debug=False):
super(BossacBinaryRunner, self).__init__(debug=debug)
self.bin_name = bin_name
self.bossac = bossac
self.port = port
@classmethod
def name(cls):
return 'bossac'
@classmethod
def capabilities(cls):
return RunnerCaps(commands={'flash'})
scripts: runner: use arguments, not environment vars The various runners (flash/debug scripts) use environment variables to take arguments. This is legacy behavior which is not desirable. Use command line arguments instead. Note: this leaves more general environment variables with publicly documented behavior in place for now, for compatibility, e.g.: ZEPHYR_FLASH_OVER_DFU, OPENSDA_FW, ESP_IDF_PATH, PYOCD_DAPARG For example, when using dfu-util to flash arduino_101, instead of setting DFUUTIL_PID, DFUUTIL_ALT, and DFUUTIL_IMG environment variables, have the script invocation look like this: python3 .../zephyr_flash_debug.py dfu-util flash \ [common arguments omitted] \ --pid=8087:0aba --alt=x86_app \ --img=.../build/zephyr/zephyr.bin Make similar changes for other runners (openocd, etc.) and targets (debug, debugserver). To implement this in the scripts: - have the individual scripts/support/runner/some-runner.py files register their own command line arguments - teach them to construct instances from arguments, not the environment - have zephyr_flash_debug.py request runners to register command line argument parsers, and handle arguments In the build system: - add a new board_runner_args() extension function that board.cmake files can use to add to the zephyr_flash_debug.py command line - adjust cmake/flash/CMakeLists.txt to invoke with arguments - add new helper include files for each runner (like boards/common/dfu-util.board.cmake, etc.), which add default options as needed and then add on overrides from board_runner_args() calls - update board.cmake files to use the new includes and extension This implied some tweaking when using openocd to make the CMake string escaping and unescaping work properly. Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-11-17 06:45:38 +08:00
@classmethod
def do_add_parser(cls, parser):
parser.add_argument('--bossac', default='bossac',
help='path to bossac, default is bossac')
parser.add_argument('--bossac-port', default='/dev/ttyACM0',
help='serial port to use, default is /dev/ttyACM0')
scripts: runner: use arguments, not environment vars The various runners (flash/debug scripts) use environment variables to take arguments. This is legacy behavior which is not desirable. Use command line arguments instead. Note: this leaves more general environment variables with publicly documented behavior in place for now, for compatibility, e.g.: ZEPHYR_FLASH_OVER_DFU, OPENSDA_FW, ESP_IDF_PATH, PYOCD_DAPARG For example, when using dfu-util to flash arduino_101, instead of setting DFUUTIL_PID, DFUUTIL_ALT, and DFUUTIL_IMG environment variables, have the script invocation look like this: python3 .../zephyr_flash_debug.py dfu-util flash \ [common arguments omitted] \ --pid=8087:0aba --alt=x86_app \ --img=.../build/zephyr/zephyr.bin Make similar changes for other runners (openocd, etc.) and targets (debug, debugserver). To implement this in the scripts: - have the individual scripts/support/runner/some-runner.py files register their own command line arguments - teach them to construct instances from arguments, not the environment - have zephyr_flash_debug.py request runners to register command line argument parsers, and handle arguments In the build system: - add a new board_runner_args() extension function that board.cmake files can use to add to the zephyr_flash_debug.py command line - adjust cmake/flash/CMakeLists.txt to invoke with arguments - add new helper include files for each runner (like boards/common/dfu-util.board.cmake, etc.), which add default options as needed and then add on overrides from board_runner_args() calls - update board.cmake files to use the new includes and extension This implied some tweaking when using openocd to make the CMake string escaping and unescaping work properly. Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-11-17 06:45:38 +08:00
@classmethod
def create_from_args(command, args):
return BossacBinaryRunner(args.kernel_bin, bossac=args.bossac,
port=args.bossac_port, debug=args.verbose)
def do_run(self, command, **kwargs):
if platform.system() != 'Linux':
msg = 'CAUTION: No flash tool for your host system found!'
raise NotImplementedError(msg)
cmd_stty = ['stty', '-F', self.port, 'raw', 'ispeed', '1200',
'ospeed', '1200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
'eof', '255']
cmd_flash = [self.bossac, '-p', self.port, '-R', '-e', '-w', '-v',
'-b', self.bin_name]
self.check_call(cmd_stty)
self.check_call(cmd_flash)