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