-
-
Notifications
You must be signed in to change notification settings - Fork 274
Add support for PyOCD and labgrid-client reset subcommand #1944
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
Open
gumulka
wants to merge
10
commits into
labgrid-project:master
Choose a base branch
from
gumulka:mcu-programming
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1922232
doc: remove ResetProtocol from SerialDriver
gumulka 91524e1
resource: udev: USBDebugger: add keil CMIS-DAPLink
gumulka 0884f65
driver: pyocd: add driver for bootstrapping
gumulka 114363a
tests: add tests for pyocd
gumulka 7479a7f
remote/client: bootstrap: add USBDebugger
gumulka 248f7ff
remote/client: create function to get PowerDriver
gumulka 1bdb5a3
remote/client: create function to get IODriver
gumulka 9ec9974
remote/client: add reset subcommand
gumulka 72b8d92
tests: add test for labgrid-client subcommands
gumulka f2abdc6
driver: pyocd: fix error on multiple load call
gumulka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import attr | ||
|
|
||
| from ..factory import target_factory | ||
| from ..protocol import BootstrapProtocol, ResetProtocol | ||
| from ..step import step | ||
| from ..util.managedfile import ManagedFile | ||
| from ..util.helper import processwrapper | ||
| from .common import Driver | ||
|
|
||
|
|
||
| @target_factory.reg_driver | ||
| @attr.s(eq=False) | ||
| class PyOCDDriver(Driver, BootstrapProtocol, ResetProtocol): | ||
|
|
||
| priorities = {ResetProtocol: 5} | ||
|
|
||
| bindings = { | ||
| "interface": { | ||
| "USBDebugger", | ||
| "NetworkUSBDebugger", | ||
| }, | ||
| } | ||
|
|
||
| image = attr.ib( | ||
| default=None, | ||
| validator=attr.validators.optional(attr.validators.instance_of(str)), | ||
| ) | ||
| load_commands = attr.ib( | ||
| default=None, | ||
| validator=attr.validators.optional(attr.validators.instance_of((str, list))), | ||
| ) | ||
| target_name = attr.ib( | ||
| default=None, | ||
| validator=attr.validators.optional(attr.validators.instance_of(str)), | ||
| ) | ||
| frequency = attr.ib( | ||
| default=None, | ||
| validator=attr.validators.optional(attr.validators.instance_of(str)), | ||
| ) | ||
| config = attr.ib( | ||
| default=None, | ||
| validator=attr.validators.optional(attr.validators.instance_of(str)), | ||
| ) | ||
| serial = attr.ib( | ||
| default=None, | ||
| validator=attr.validators.optional(attr.validators.instance_of(str)), | ||
| ) | ||
|
|
||
| def __attrs_post_init__(self): | ||
| super().__attrs_post_init__() | ||
|
|
||
| # FIXME make sure we always have an environment or config | ||
| if self.target.env: | ||
| self.tool = self.target.env.config.get_tool("pyocd") | ||
| if self.config: | ||
| self.config = self.target.env.config.resolve_path(self.config) | ||
| else: | ||
| self.tool = "pyocd" | ||
|
|
||
| def _run_commands(self, subcommand: str, commands: list | None = None): | ||
| cmd = [self.tool, subcommand] | ||
| if self.serial: | ||
| cmd += ["--uid", self.serial] | ||
| if self.target_name is not None and (not commands or "--target" not in commands): | ||
| cmd += ["--target", self.target_name] | ||
| if self.frequency is not None and (not commands or "--frequency" not in commands): | ||
| cmd += ["--frequency", self.frequency] | ||
|
|
||
| if self.config is not None: | ||
| mconfig = ManagedFile(self.config, self.interface) | ||
| mconfig.sync_to_resource() | ||
| cmd += ["--config", mconfig.get_remote_path()] | ||
| else: | ||
| cmd += ["--no-config"] | ||
|
|
||
| if commands: | ||
| cmd += commands | ||
| processwrapper.check_output( | ||
| command=self.interface.wrap_command(cmd), | ||
| print_on_silent_log=True, | ||
| ) | ||
|
|
||
| @Driver.check_active | ||
| @step(args=["filename"]) | ||
| def load(self, filename=None): | ||
|
|
||
| if filename is None and self.image is not None and self.target.env: | ||
| filename = self.target.env.config.get_image_path(self.image) | ||
|
|
||
| mf = ManagedFile(filename, self.interface) | ||
| mf.sync_to_resource() | ||
|
|
||
| if self.load_commands: | ||
| if isinstance(self.load_commands, str): | ||
| commands = self.load_commands.split() | ||
| else: | ||
| commands = self.load_commands | ||
| else: | ||
| commands = ["-e", "sector"] | ||
|
|
||
| commands.append(mf.get_remote_path()) | ||
|
|
||
| self._run_commands("load", commands) | ||
|
|
||
| @Driver.check_active | ||
| @step() | ||
| def reset(self): | ||
| self._run_commands("reset") | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this while testing two consecutive
load()calls on the samePyOCDDriverinstance with list-basedload_commands.For example:
Then, in a custom test script:
The first call mutates the configured list to:
As a result, the second call invokes:
This does not occur across separate
labgrid-client bootstrapinvocations, since each CLI invocation creates a new process and driver instance. It can occur whenever the same driver object is reused programmatically.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for pointing that out! I just added a new commit, that has a pytest and a fix for it.