blob: 814bb0a961e0c9cef8c81478a3d11c98008acd0d [file] [log] [blame]
Martí Bolívar07a40cb2019-10-30 15:21:52 +08001# 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
Daniel Leung2959ed32020-06-23 10:06:59 -070014import argparse
Martí Bolívar07a40cb2019-10-30 15:21:52 +080015
16class MiscFlasher(ZephyrBinaryRunner):
17 '''Runner for handling special purpose flashing commands.'''
18
Martí Bolívar67d8f752020-03-04 08:57:22 -080019 def __init__(self, cfg, cmd, args):
Martí Bolívar07a40cb2019-10-30 15:21:52 +080020 super().__init__(cfg)
Martí Bolívar67d8f752020-03-04 08:57:22 -080021 if not cmd:
Martí Bolívar07a40cb2019-10-30 15:21:52 +080022 # 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')
Martí Bolívar67d8f752020-03-04 08:57:22 -080025 self.cmd = cmd
Martí Bolívar07a40cb2019-10-30 15:21:52 +080026 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):
Martí Bolívar67d8f752020-03-04 08:57:22 -080038 parser.add_argument('cmd',
Martí Bolívar483adc92019-11-13 07:24:18 -080039 help='''command to run; it will be passed the
40 build directory as its first argument''')
Daniel Leung2959ed32020-06-23 10:06:59 -070041 parser.add_argument('args', nargs=argparse.REMAINDER,
Martí Bolívar483adc92019-11-13 07:24:18 -080042 help='''additional arguments to pass after the build
43 directory''')
Martí Bolívar07a40cb2019-10-30 15:21:52 +080044
45 @classmethod
Martí Bolívarf8e8e922020-06-23 13:35:52 -070046 def do_create(cls, cfg, args):
Martí Bolívar67d8f752020-03-04 08:57:22 -080047 return MiscFlasher(cfg, args.cmd, args.args)
Martí Bolívar07a40cb2019-10-30 15:21:52 +080048
Martí Bolívar483adc92019-11-13 07:24:18 -080049 def do_run(self, *args, **kwargs):
Martí Bolívar67d8f752020-03-04 08:57:22 -080050 self.require(self.cmd)
51 self.check_call([self.cmd, self.cfg.build_dir] + self.args)