|
| 1 | +# Copyright (c) 2024 Advanced Micro Devices, Inc. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +"""Runner for flashing with xsdb CLI, the official programming |
| 6 | + utility from AMD platforms. |
| 7 | +""" |
| 8 | +import argparse |
| 9 | +import os |
| 10 | +from runners.core import ZephyrBinaryRunner, RunnerCaps, RunnerConfig |
| 11 | + |
| 12 | +class XSDBBinaryRunner(ZephyrBinaryRunner): |
| 13 | + def __init__(self, cfg: RunnerConfig, config=None, bitstream=None, |
| 14 | + fsbl=None): |
| 15 | + super(XSDBBinaryRunner, self).__init__(cfg) |
| 16 | + self.elf_file = cfg.elf_file |
| 17 | + if not config: |
| 18 | + cfgfile_path = os.path.join(cfg.board_dir, 'support') |
| 19 | + default = os.path.join(cfgfile_path, 'xsdb.cfg') |
| 20 | + if os.path.exists(default): |
| 21 | + config = default |
| 22 | + self.xsdb_cfg_file = config |
| 23 | + self.bitstream = bitstream |
| 24 | + self.fsbl = fsbl |
| 25 | + |
| 26 | + @classmethod |
| 27 | + def name(cls): |
| 28 | + return 'xsdb' |
| 29 | + |
| 30 | + @classmethod |
| 31 | + def capabilities(cls): |
| 32 | + return RunnerCaps(flash_addr=True) |
| 33 | + |
| 34 | + @classmethod |
| 35 | + def do_add_parser(cls, parser): |
| 36 | + parser.add_argument('--config', help='if given, override default config file') |
| 37 | + parser.add_argument('--bitstream', help='path to the bitstream file') |
| 38 | + parser.add_argument('--fsbl', help='path to the fsbl elf file') |
| 39 | + |
| 40 | + @classmethod |
| 41 | + def do_create( |
| 42 | + cls, cfg: RunnerConfig, args: argparse.Namespace |
| 43 | + ) -> "XSDBBinaryRunner": |
| 44 | + return XSDBBinaryRunner(cfg, config=args.config, |
| 45 | + bitstream=args.bitstream, fsbl=args.fsbl) |
| 46 | + |
| 47 | + def do_run(self, command, **kwargs): |
| 48 | + if self.bitstream and self.fsbl: |
| 49 | + cmd = ['xsdb', self.xsdb_cfg_file, self.elf_file, self.bitstream, self.fsbl] |
| 50 | + elif self.bitstream: |
| 51 | + cmd = ['xsdb', self.xsdb_cfg_file, self.elf_file, self.bitstream] |
| 52 | + elif self.fsbl: |
| 53 | + cmd = ['xsdb', self.xsdb_cfg_file, self.elf_file, self.fsbl] |
| 54 | + else: |
| 55 | + cmd = ['xsdb', self.xsdb_cfg_file] |
| 56 | + self.check_call(cmd) |
0 commit comments