1# Copyright (c) 2019, Nordic Semiconductor ASA 2# 3# SPDX-License-Identifier: Apache-2.0 4 5'''Catch-all module for miscellaneous devices which can't use a 6generic or widely used tool like J-Link, OpenOCD, etc. 7 8Please use this sparingly and only when your setup is exotic and 9you're willing to handle requests for help. E.g. if your "board" is a 10core on a special-purpose SoC which requires a complicated script to 11network boot.''' 12 13from runners.core import ZephyrBinaryRunner, RunnerCaps 14import argparse 15 16class MiscFlasher(ZephyrBinaryRunner): 17 '''Runner for handling special purpose flashing commands.''' 18 19 def __init__(self, cfg, cmd, args): 20 super().__init__(cfg) 21 if not cmd: 22 # This is a board definition error, not a user error, 23 # so we can do it now and not in do_run(). 24 raise ValueError('no command was given') 25 self.cmd = cmd 26 self.args = args 27 28 @classmethod 29 def name(cls): 30 return 'misc-flasher' 31 32 @classmethod 33 def capabilities(cls): 34 return RunnerCaps(commands={'flash'}) 35 36 @classmethod 37 def do_add_parser(cls, parser): 38 parser.add_argument('cmd', 39 help='''command to run; it will be passed the 40 build directory as its first argument''') 41 parser.add_argument('args', nargs=argparse.REMAINDER, 42 help='''additional arguments to pass after the build 43 directory''') 44 45 @classmethod 46 def do_create(cls, cfg, args): 47 return MiscFlasher(cfg, args.cmd, args.args) 48 49 def do_run(self, *args, **kwargs): 50 self.require(self.cmd) 51 self.check_call([self.cmd, self.cfg.build_dir] + self.args) 52