Skip to content

Commit

Permalink
tools: lists: update probe listing to use board info and fix issues (p…
Browse files Browse the repository at this point in the history
…yocd#1401)

Fixes issues caused by creating a session for each probe, such as
having an unknown target type set for a probe config. This is done
by switching to use the probe's associated board info instead of
getting that info through a session.

Adds 'board_vendor' key to probe info dict, and bumps probe list
data version to 1.1. json_lists_test.py is updated to expect this
version.
  • Loading branch information
flit authored May 30, 2022
1 parent bd445ca commit 0663876
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
47 changes: 30 additions & 17 deletions pyocd/tools/lists.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pyOCD debugger
# Copyright (c) 2018-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# Copyright (c) 2021-2022 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -26,7 +26,6 @@
from ..target.builtin import BUILTIN_TARGETS
from ..board.board_ids import BOARD_ID_TO_INFO
from ..target.pack import pack_target

from ..probe.debug_probe import DebugProbe

class StubProbe(DebugProbe):
Expand All @@ -41,37 +40,49 @@ def list_probes():
Output version history:
- 1.0, initial version
- 1.1, add 'board_vendor' key for each probe
"""
status = 0
error = ""
try:
all_mbeds = ConnectHelper.get_sessions_for_all_connected_probes(blocking=False)
probes = ConnectHelper.get_all_connected_probes(blocking=False)
except Exception as e:
all_mbeds = []
probes = []
status = 1
error = str(e)

boards = []
probes_info_list = []
obj = {
'pyocd_version' : __version__,
'version' : { 'major' : 1, 'minor' : 0 },
'version' : { 'major' : 1, 'minor' : 1 },
'status' : status,
'boards' : boards,
'boards' : probes_info_list,
}

if status != 0:
obj['error'] = error

for mbed in all_mbeds:
for probe in probes:
board_info = probe.associated_board_info
target_type_name = board_info.target if board_info else None
board_name = board_info.name if board_info else "Generic"
board_vendor = board_info.vendor if board_info else None

if board_info and board_info.name:
desc = f"{board_vendor} {board_name}" if board_vendor else board_name
else:
desc = f"{probe.vendor_name} {probe.product_name}"

d = {
'unique_id' : mbed.probe.unique_id,
'info' : mbed.board.description,
'board_name' : mbed.board.name,
'target' : mbed.board.target_type,
'vendor_name' : mbed.probe.vendor_name,
'product_name' : mbed.probe.product_name,
'unique_id' : probe.unique_id,
'info' : desc,
'board_vendor': board_vendor,
'board_name' : board_name,
'target' : target_type_name or "cortex_m",
'vendor_name' : probe.vendor_name,
'product_name' : probe.product_name,
}
boards.append(d)
probes_info_list.append(d)

return obj

Expand Down Expand Up @@ -109,8 +120,10 @@ def list_boards(name_filter=None):
'name' : info.name,
'target': info.target,
'binary' : info.binary,
'is_target_builtin': (info.target.lower() in builtin_target_names),
'is_target_supported': (info.target.lower() in target_names or info.target in managed_targets)
'is_target_builtin': (info.target.lower() in builtin_target_names) \
if info.target else False,
'is_target_supported': (info.target.lower() in target_names \
or info.target in managed_targets) if info.target else False,
}
boards.append(d)

Expand Down
2 changes: 1 addition & 1 deletion test/json_lists_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def validate_targets(data):
out = subprocess.check_output(['pyocd', 'json', '--probes'])
data = json.loads(out)
test_count += 2
if validate_basic_keys(data):
if validate_basic_keys(data, minor_version=1):
test_pass_count += 1
if validate_boards(data):
test_pass_count += 1
Expand Down

0 comments on commit 0663876

Please sign in to comment.