|
| 1 | +# Copyright (c) 2021 Gerson Fernando Budke <[email protected]> |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +'''Bouffalo Lab flash tool (blflash) runner for serial boot ROM''' |
| 6 | + |
| 7 | +from runners.core import ZephyrBinaryRunner, RunnerCaps |
| 8 | + |
| 9 | +DEFAULT_BLFLASH_PORT = '/dev/ttyUSB0' |
| 10 | +DEFAULT_BLFLASH_SPEED = '2000000' |
| 11 | + |
| 12 | +class BlFlashBinaryRunner(ZephyrBinaryRunner): |
| 13 | + '''Runner front-end for blflash.''' |
| 14 | + |
| 15 | + def __init__(self, cfg, blflash='blflash', |
| 16 | + port=DEFAULT_BLFLASH_PORT, |
| 17 | + speed=DEFAULT_BLFLASH_SPEED): |
| 18 | + super().__init__(cfg) |
| 19 | + self.blflash = blflash |
| 20 | + self.port = port |
| 21 | + self.speed = speed |
| 22 | + |
| 23 | + @classmethod |
| 24 | + def name(cls): |
| 25 | + return 'blflash' |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def capabilities(cls): |
| 29 | + return RunnerCaps(commands={'flash'}) |
| 30 | + |
| 31 | + @classmethod |
| 32 | + def do_add_parser(cls, parser): |
| 33 | + parser.add_argument('--blflash', default='blflash', |
| 34 | + help='path to blflash, default is blflash') |
| 35 | + parser.add_argument('--port', default=DEFAULT_BLFLASH_PORT, |
| 36 | + help='serial port to use, default is ' + |
| 37 | + str(DEFAULT_BLFLASH_PORT)) |
| 38 | + parser.add_argument('--speed', default=DEFAULT_BLFLASH_SPEED, |
| 39 | + help='serial port speed to use, default is ' + |
| 40 | + DEFAULT_BLFLASH_SPEED) |
| 41 | + |
| 42 | + @classmethod |
| 43 | + def do_create(cls, cfg, args): |
| 44 | + return BlFlashBinaryRunner(cfg, |
| 45 | + blflash=args.blflash, |
| 46 | + port=args.port, |
| 47 | + speed=args.speed) |
| 48 | + |
| 49 | + def do_run(self, command, **kwargs): |
| 50 | + self.require(self.blflash) |
| 51 | + self.ensure_output('bin') |
| 52 | + |
| 53 | + cmd_flash = [self.blflash, |
| 54 | + 'flash', |
| 55 | + '-s', self.speed, |
| 56 | + self.cfg.bin_file, |
| 57 | + '-p', self.port] |
| 58 | + |
| 59 | + self.check_call(cmd_flash) |
0 commit comments