Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suit: Move MPI to sysbuild Kconfig #2289

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion scripts/west_commands/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ def get_runner_cls(runner):
for cls in ZephyrBinaryRunner.get_runners():
if cls.name() == runner:
return cls
raise ValueError('unknown runner "{}"'.format(runner))
raise ValueError(f'unknown runner "{runner}"')

__all__ = ['ZephyrBinaryRunner', 'get_runner_cls']
20 changes: 8 additions & 12 deletions scripts/west_commands/runners/blackmagicprobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,11 @@ def bmp_flash(self, command, **kwargs):

command = (self.gdb +
['-ex', "set confirm off",
'-ex', "target extended-remote {}".format(
self.gdb_serial)] +
'-ex', f"target extended-remote {self.gdb_serial}"] +
self.connect_rst_enable_arg +
['-ex', "monitor swdp_scan",
'-ex', "attach 1",
'-ex', "load {}".format(flash_file),
'-ex', f"load {flash_file}",
'-ex', "kill",
'-ex', "quit",
'-silent'])
Expand All @@ -192,34 +191,31 @@ def bmp_attach(self, command, **kwargs):
if self.elf_file is None:
command = (self.gdb +
['-ex', "set confirm off",
'-ex', "target extended-remote {}".format(
self.gdb_serial)] +
'-ex', f"target extended-remote {self.gdb_serial}"] +
self.connect_rst_disable_arg +
['-ex', "monitor swdp_scan",
'-ex', "attach 1"])
else:
command = (self.gdb +
['-ex', "set confirm off",
'-ex', "target extended-remote {}".format(
self.gdb_serial)] +
'-ex', f"target extended-remote {self.gdb_serial}"] +
self.connect_rst_disable_arg +
['-ex', "monitor swdp_scan",
'-ex', "attach 1",
'-ex', "file {}".format(self.elf_file)])
'-ex', f"file {self.elf_file}"])
self.check_call_ignore_sigint(command)

def bmp_debug(self, command, **kwargs):
if self.elf_file is None:
raise ValueError('Cannot debug; elf file is missing')
command = (self.gdb +
['-ex', "set confirm off",
'-ex', "target extended-remote {}".format(
self.gdb_serial)] +
'-ex', f"target extended-remote {self.gdb_serial}"] +
self.connect_rst_enable_arg +
['-ex', "monitor swdp_scan",
'-ex', "attach 1",
'-ex', "file {}".format(self.elf_file),
'-ex', "load {}".format(self.elf_file)])
'-ex', f"file {self.elf_file}",
'-ex', f"load {self.elf_file}"])
self.check_call_ignore_sigint(command)

def do_run(self, command, **kwargs):
Expand Down
4 changes: 3 additions & 1 deletion scripts/west_commands/runners/bossac.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ def get_image_offset(self, supports_offset):

def is_gnu_coreutils_stty(self):
try:
result = subprocess.run(['stty', '--version'], capture_output=True, text=True, check=True)
result = subprocess.run(
['stty', '--version'], capture_output=True, text=True, check=True
)
return 'coreutils' in result.stdout
except subprocess.CalledProcessError:
return False
Expand Down
59 changes: 32 additions & 27 deletions scripts/west_commands/runners/canopen_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
DEFAULT_PROGRAM_NUMBER = 1

# Program download buffer size in bytes
PROGRAM_DOWNLOAD_BUFFER_SIZE = 1024

# Program download chunk size in bytes
PROGRAM_DOWNLOAD_CHUNK_SIZE = PROGRAM_DOWNLOAD_BUFFER_SIZE // 2
DEFAULT_PROGRAM_DOWNLOAD_BUFFER_SIZE = 1024

# Default timeouts and retries
DEFAULT_TIMEOUT = 10.0 # seconds
Expand Down Expand Up @@ -58,7 +55,7 @@ def __init__(self, cfg, dev_id, can_context=DEFAULT_CAN_CONTEXT,
program_number=DEFAULT_PROGRAM_NUMBER, confirm=True,
confirm_only=True, timeout=DEFAULT_TIMEOUT,
sdo_retries=DEFAULT_SDO_RETRIES, sdo_timeout=DEFAULT_SDO_TIMEOUT,
block_transfer=False):
download_buffer_size=DEFAULT_PROGRAM_DOWNLOAD_BUFFER_SIZE, block_transfer=False):
if MISSING_REQUIREMENTS:
raise RuntimeError('one or more Python dependencies were missing; '
"see the getting started guide for details on "
Expand All @@ -76,7 +73,9 @@ def __init__(self, cfg, dev_id, can_context=DEFAULT_CAN_CONTEXT,
program_number=program_number,
sdo_retries=sdo_retries,
sdo_timeout=sdo_timeout,
block_transfer=block_transfer)
download_buffer_size=download_buffer_size,
block_transfer=block_transfer,
)

@classmethod
def name(cls):
Expand Down Expand Up @@ -113,6 +112,10 @@ def do_add_parser(cls, parser):
parser.add_argument('--sdo-timeout', type=float, default=DEFAULT_SDO_TIMEOUT,
help=f'''CANopen SDO response timeout in seconds
(default: {DEFAULT_SDO_TIMEOUT})''')
parser.add_argument('--download-buffer-size', type=int,
default=DEFAULT_PROGRAM_DOWNLOAD_BUFFER_SIZE,
help=f'''Program download buffer size in bytes
(default: {DEFAULT_PROGRAM_DOWNLOAD_BUFFER_SIZE})''')
parser.add_argument('--block-transfer', default=False, action='store_true',
help='Use SDO block transfers (experimental, default: no)')

Expand All @@ -128,6 +131,7 @@ def do_create(cls, cfg, args):
timeout=args.timeout,
sdo_retries=args.sdo_retries,
sdo_timeout=args.sdo_timeout,
download_buffer_size=args.download_buffer_size,
block_transfer=args.block_transfer)

def do_run(self, command, **kwargs):
Expand All @@ -149,8 +153,8 @@ def flash(self, **kwargs):
if status == 0:
self.downloader.swid()
else:
self.logger.warning('Flash status 0x{:02x}, '
'skipping software identification'.format(status))
self.logger.warning(f'Flash status 0x{status:02x}, '
'skipping software identification')

self.downloader.enter_pre_operational()

Expand All @@ -170,7 +174,7 @@ def flash(self, **kwargs):
status = self.downloader.wait_for_flash_status_ok(self.timeout)
if status != 0:
raise ValueError('Program download failed: '
'flash status 0x{:02x}'.format(status))
f'flash status 0x{status:02x}')

self.downloader.swid()
self.downloader.start_program()
Expand All @@ -188,7 +192,7 @@ class CANopenProgramDownloader(object):
def __init__(self, logger, node_id, can_context=DEFAULT_CAN_CONTEXT,
program_number=DEFAULT_PROGRAM_NUMBER,
sdo_retries=DEFAULT_SDO_RETRIES, sdo_timeout=DEFAULT_SDO_TIMEOUT,
block_transfer=False):
download_buffer_size=DEFAULT_PROGRAM_DOWNLOAD_BUFFER_SIZE, block_transfer=False):
super(CANopenProgramDownloader, self).__init__()
self.logger = logger
self.node_id = node_id
Expand All @@ -201,6 +205,7 @@ def __init__(self, logger, node_id, can_context=DEFAULT_CAN_CONTEXT,
self.ctrl_sdo = self.node.sdo[H1F51_PROGRAM_CTRL][self.program_number]
self.swid_sdo = self.node.sdo[H1F56_PROGRAM_SWID][self.program_number]
self.flash_sdo = self.node.sdo[H1F57_FLASH_STATUS][self.program_number]
self.download_buffer_size = download_buffer_size

self.node.sdo.MAX_RETRIES = sdo_retries
self.node.sdo.RESPONSE_TIMEOUT = sdo_timeout
Expand All @@ -211,8 +216,8 @@ def connect(self):
'''Connect to CAN network'''
try:
self.network.connect(context=self.can_context)
except:
raise ValueError('Unable to connect to CAN network')
except Exception as err:
raise ValueError('Unable to connect to CAN network') from err

def disconnect(self):
'''Disconnect from CAN network'''
Expand All @@ -223,15 +228,15 @@ def enter_pre_operational(self):
self.logger.info("Entering pre-operational mode")
try:
self.node.nmt.state = 'PRE-OPERATIONAL'
except:
raise ValueError('Failed to enter pre-operational mode')
except Exception as err:
raise ValueError('Failed to enter pre-operational mode') from err

def _ctrl_program(self, cmd):
'''Write program control command to CANopen object dictionary (0x1f51)'''
try:
self.ctrl_sdo.raw = cmd
except:
raise ValueError('Unable to write control command 0x{:02x}'.format(cmd))
except Exception as err:
raise ValueError(f'Unable to write control command 0x{cmd:02x}') from err

def stop_program(self):
'''Write stop control command to CANopen object dictionary (0x1f51)'''
Expand All @@ -257,17 +262,17 @@ def swid(self):
'''Read software identification from CANopen object dictionary (0x1f56)'''
try:
swid = self.swid_sdo.raw
except:
raise ValueError('Failed to read software identification')
self.logger.info('Program software identification: 0x{:08x}'.format(swid))
except Exception as err:
raise ValueError('Failed to read software identification') from err
self.logger.info(f'Program software identification: 0x{swid:08x}')
return swid

def flash_status(self):
'''Read flash status identification'''
try:
status = self.flash_sdo.raw
except:
raise ValueError('Failed to read flash status identification')
except Exception as err:
raise ValueError('Failed to read flash status identification') from err
return status

def download(self, bin_file):
Expand All @@ -276,18 +281,18 @@ def download(self, bin_file):
try:
size = os.path.getsize(bin_file)
infile = open(bin_file, 'rb')
outfile = self.data_sdo.open('wb', buffering=PROGRAM_DOWNLOAD_BUFFER_SIZE,
outfile = self.data_sdo.open('wb', buffering=self.download_buffer_size,
size=size, block_transfer=self.block_transfer)

progress = Bar('%(percent)d%%', max=size, suffix='%(index)d/%(max)dB')
while True:
chunk = infile.read(PROGRAM_DOWNLOAD_CHUNK_SIZE)
chunk = infile.read(self.download_buffer_size // 2)
if not chunk:
break
outfile.write(chunk)
progress.next(n=len(chunk))
except:
raise ValueError('Failed to download program')
except Exception as err:
raise ValueError('Failed to download program') from err
finally:
progress.finish()
infile.close()
Expand All @@ -298,8 +303,8 @@ def wait_for_bootup(self, timeout=DEFAULT_TIMEOUT):
self.logger.info('Waiting for boot-up message...')
try:
self.node.nmt.wait_for_bootup(timeout=timeout)
except:
raise ValueError('Timeout waiting for boot-up message')
except Exception as err:
raise ValueError('Timeout waiting for boot-up message') from err

def wait_for_flash_status_ok(self, timeout=DEFAULT_TIMEOUT):
'''Wait for flash status ok'''
Expand Down
26 changes: 16 additions & 10 deletions scripts/west_commands/runners/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def __init__(self, cfg: RunnerConfig):
self.cfg = cfg
'''RunnerConfig for this instance.'''

self.logger = logging.getLogger('runners.{}'.format(self.name()))
self.logger = logging.getLogger(f'runners.{self.name()}')
'''logging.Logger for this instance.'''

@staticmethod
Expand Down Expand Up @@ -577,16 +577,22 @@ def add_parser(cls, parser):
else:
parser.add_argument('--elf-file',
metavar='FILE',
action=(partial(depr_action, cls=cls, replacement='-f/--file') if caps.file else None),
help='path to zephyr.elf' if not caps.file else 'Deprecated, use -f/--file instead.')
action=(partial(depr_action, cls=cls,
replacement='-f/--file') if caps.file else None),
help='path to zephyr.elf'
if not caps.file else 'Deprecated, use -f/--file instead.')
parser.add_argument('--hex-file',
metavar='FILE',
action=(partial(depr_action, cls=cls, replacement='-f/--file') if caps.file else None),
help='path to zephyr.hex' if not caps.file else 'Deprecated, use -f/--file instead.')
action=(partial(depr_action, cls=cls,
replacement='-f/--file') if caps.file else None),
help='path to zephyr.hex'
if not caps.file else 'Deprecated, use -f/--file instead.')
parser.add_argument('--bin-file',
metavar='FILE',
action=(partial(depr_action, cls=cls, replacement='-f/--file') if caps.file else None),
help='path to zephyr.bin' if not caps.file else 'Deprecated, use -f/--file instead.')
action=(partial(depr_action, cls=cls,
replacement='-f/--file') if caps.file else None),
help='path to zephyr.bin'
if not caps.file else 'Deprecated, use -f/--file instead.')

parser.add_argument('--erase', '--no-erase', nargs=0,
action=_ToggleAction,
Expand All @@ -612,7 +618,8 @@ def add_parser(cls, parser):
if caps.rtt:
parser.add_argument('--rtt-address', dest='rtt_address',
type=lambda x: int(x, 0),
help="address of RTT control block. If not supplied, it will be autodetected if possible")
help="""address of RTT control block. If not supplied,
it will be autodetected if possible""")
else:
parser.add_argument('--rtt-address', help=argparse.SUPPRESS)

Expand Down Expand Up @@ -701,8 +708,7 @@ def run(self, command: str, **kwargs):
This is the main entry point to this runner.'''
caps = self.capabilities()
if command not in caps.commands:
raise ValueError('runner {} does not implement command {}'.format(
self.name(), command))
raise ValueError(f'runner {self.name()} does not implement command {command}')
self.do_run(command, **kwargs)

@abc.abstractmethod
Expand Down
6 changes: 3 additions & 3 deletions scripts/west_commands/runners/dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def __init__(self, cfg, dev_id, alt, img, exe='dfu-util',
self.dev_id = dev_id # Used only for error checking in do_run
self.alt = alt
self.img = img
self.cmd = [exe, '-d,{}'.format(dev_id)]
self.cmd = [exe, f'-d,{dev_id}']
try:
self.list_pattern = ', alt={},'.format(int(self.alt))
self.list_pattern = f', alt={int(self.alt)},'
except ValueError:
self.list_pattern = ', name="{}",'.format(self.alt)
self.list_pattern = f', name="{self.alt}",'

if dfuse_config is None:
self.dfuse = False
Expand Down
3 changes: 1 addition & 2 deletions scripts/west_commands/runners/esp32.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,5 @@ def do_run(self, command, **kwargs):
else:
cmd_flash.extend([self.app_address, self.app_bin])

self.logger.info("Flashing esp32 chip on {} ({}bps)".
format(self.device, self.baud))
self.logger.info(f"Flashing esp32 chip on {self.device} ({self.baud}bps)")
self.check_call(cmd_flash)
4 changes: 3 additions & 1 deletion scripts/west_commands/runners/ezflashcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def program_bin(self):
self.check_call([self.tool] + options + ["image_flash", self.bin_])
else:
load_offset = self.build_conf['CONFIG_FLASH_LOAD_OFFSET']
self.check_call([self.tool] + options + ["write_flash", f'0x{load_offset:x}', self.bin_])
self.check_call(
[self.tool] + options + ["write_flash", f'0x{load_offset:x}', self.bin_]
)

def reset_device(self):
self.logger.info("Resetting...")
Expand Down
3 changes: 2 additions & 1 deletion scripts/west_commands/runners/intel_adsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def do_add_parser(cls, parser):

for old_sign_param in [ '--rimage-tool', '--config-dir', '--default-key', '--key']:
parser.add_argument(old_sign_param, action=SignParamError,
help='do not use, "west sign" is now called from CMake, see "west sign -h"')
help='''do not use, "west sign" is now called from CMake,
see "west sign -h"''')

@classmethod
def tool_opt_help(cls) -> str:
Expand Down
Loading
Loading