-
Notifications
You must be signed in to change notification settings - Fork 68
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
Feature: Jlink plugin #150
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
mbed SDK | ||
Copyright (c) 2011-2015 ARM Limited | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
Author: Przemyslaw Wirkus <[email protected]> | ||
""" | ||
|
||
from mbed_os_tools.test.host_tests_plugins.module_copy_jlink import ( | ||
HostTestPluginCopyMethod_Jlink, | ||
load_plugin, | ||
) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||
""" | ||||||
mbed SDK | ||||||
Copyright (c) 2011-2015 ARM Limited | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind updating the copyright year here?
Suggested change
|
||||||
|
||||||
Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
you may not use this file except in compliance with the License. | ||||||
You may obtain a copy of the License at | ||||||
|
||||||
http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|
||||||
Unless required by applicable law or agreed to in writing, software | ||||||
distributed under the License is distributed on an "AS IS" BASIS, | ||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
See the License for the specific language governing permissions and | ||||||
limitations under the License. | ||||||
|
||||||
Author: Przemyslaw Wirkus <[email protected]> | ||||||
""" | ||||||
|
||||||
from mbed_os_tools.test.host_tests_plugins.module_reset_jlink import ( | ||||||
HostTestPluginResetMethod_Jlink, | ||||||
load_plugin, | ||||||
) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,113 @@ | ||||||
# Copyright (c) 2018, Arm Limited and affiliates. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind updating the copyright year here?
Suggested change
|
||||||
# SPDX-License-Identifier: Apache-2.0 | ||||||
# | ||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
# you may not use this file except in compliance with the License. | ||||||
# You may obtain a copy of the License at | ||||||
# | ||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||
# | ||||||
# Unless required by applicable law or agreed to in writing, software | ||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
# See the License for the specific language governing permissions and | ||||||
# limitations under the License. | ||||||
|
||||||
import os | ||||||
import tempfile | ||||||
|
||||||
from .host_test_plugins import HostTestPluginBase | ||||||
|
||||||
|
||||||
COPY_FILE = "copy.jlink" | ||||||
|
||||||
class HostTestPluginCopyMethod_Jlink(HostTestPluginBase): | ||||||
|
||||||
# Plugin interface | ||||||
name = 'HostTestPluginCopyMethod_Jlink' | ||||||
type = 'CopyMethod' | ||||||
capabilities = ['JTAG', 'SWD'] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this plugin is specific to JLink, could you prefix these as follows? We also stick with lower case capabilities across the plugins:
Suggested change
|
||||||
required_parameters = ['image_path', 'mcu'] | ||||||
|
||||||
def is_os_supported(self, os_name=None): | ||||||
"""! In this implementation this plugin only is supporeted under Windows machines | ||||||
""" | ||||||
# If no OS name provided use host OS name | ||||||
if not os_name: | ||||||
os_name = self.mbed_os_support() | ||||||
|
||||||
# This plugin only works on Windows | ||||||
if os_name and os_name.startswith('Windows'): | ||||||
return True | ||||||
return False | ||||||
|
||||||
def setup(self, *args, **kwargs): | ||||||
"""! Configure plugin, this function should be called before plugin execute() method is used. | ||||||
""" | ||||||
#Note you need to have jlink.exe on your system path! | ||||||
self.JLINK = 'JLink.exe' | ||||||
return True | ||||||
|
||||||
def build_jlink_script(self, path, image_path): | ||||||
"""! write a jlink commander file that | ||||||
erase and flash the target | ||||||
|
||||||
@param path the file path of the script we are writing in the function | ||||||
@param image_path path to the binary file to flash | ||||||
""" | ||||||
with open(path, "w") as jlink_script: | ||||||
jlink_script.write("connect\n") | ||||||
jlink_script.write("erase\n") | ||||||
jlink_script.write("loadbin {0} 0x08000000\n".format(image_path)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it is the internal flash address of STM32 microcontrollers. However, there are microcontrollers with different flash addresses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. This plugin is what we use internally, and we only use ST. We definitely need feedback from non-ST future users of the plugin before we can precede. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check the file format of the file under Another issue with The much better alternative in such situations is If the image format is If the Below is fully working jlink script I use to program 32F746GDISCOVERY board (onboard ST-Link upgraded to JLink using https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/) with the
Note that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some questions:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion There isn't any simple way to determine the load address of To generate
You can check which targets do output A bit different approach to the problem, would be to pass the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi everyone, good discussion going on here! Addressing your questions @embeddedteam103:
Htrun doesn't know anything about the build system really, it just knows about targets and binaries. I think just checking the file extension of
I don't really have much of an idea here unfortunately. Htrun doesn't have access to the start address of ROM at the moment. It only initially supported flashing via the Mbed drive (USB MSD) as @desowin mentioned, so this information was never integrated into this tool. One idea we've had for the future is to consolidate around pyocd as our flashing and reset mechanism. It has growing target support. At the moment I believe it supports CMSIS-DAP and ST-Link debuggers. Still no mainline support for JLink, but I think that's being worked on. |
||||||
jlink_script.write("r\n") | ||||||
jlink_script.write("go\n") | ||||||
jlink_script.write("exit\n") | ||||||
|
||||||
|
||||||
def execute(self, capability, *args, **kwargs): | ||||||
"""! Executes capability by name | ||||||
|
||||||
@param capability Capability name | ||||||
@param args Additional arguments | ||||||
@param kwargs Additional arguments | ||||||
|
||||||
@details Each capability e.g. may directly just call some command line program or execute building pythonic function | ||||||
|
||||||
@return Capability call return value | ||||||
""" | ||||||
result = False | ||||||
if self.check_parameters(capability, *args, **kwargs) is True: | ||||||
|
||||||
mcu = os.path.normpath(kwargs['mcu']) | ||||||
image_path = os.path.normpath(kwargs['image_path']) | ||||||
|
||||||
jlink_file_path = os.path.join(tempfile.gettempdir(), COPY_FILE) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there are multiple processes running at once, I believe this it is possible for multiple processes trying to write and read to the same file. I think an alternative to this would be to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. We used the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be great, thanks! |
||||||
|
||||||
self.build_jlink_script(jlink_file_path, image_path) | ||||||
|
||||||
if capability == 'JTAG': | ||||||
cmd = [self.JLINK, | ||||||
"-device", mcu, | ||||||
"-if", "JTAG", | ||||||
"-jtagconf", "-1,-1", | ||||||
"-speed", "1000", | ||||||
"-CommanderScript", jlink_file_path] | ||||||
|
||||||
elif capability == 'SWD': | ||||||
cmd = [self.JLINK, | ||||||
"-device", mcu, | ||||||
"-if", "SWD", | ||||||
"-speed", "1000", | ||||||
"-CommanderScript", jlink_file_path] | ||||||
else: | ||||||
self.print_plugin_error("Unsupported capability") | ||||||
|
||||||
result = self.run_command(cmd) | ||||||
|
||||||
return result | ||||||
|
||||||
|
||||||
def load_plugin(): | ||||||
""" Returns plugin available in this module | ||||||
""" | ||||||
return HostTestPluginCopyMethod_Jlink() |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,108 @@ | ||||||
# Copyright (c) 2018, Arm Limited and affiliates. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind updating the copyright year here?
Suggested change
|
||||||
# SPDX-License-Identifier: Apache-2.0 | ||||||
# | ||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
# you may not use this file except in compliance with the License. | ||||||
# You may obtain a copy of the License at | ||||||
# | ||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||
# | ||||||
# Unless required by applicable law or agreed to in writing, software | ||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
# See the License for the specific language governing permissions and | ||||||
# limitations under the License. | ||||||
|
||||||
import os | ||||||
import tempfile | ||||||
|
||||||
from .host_test_plugins import HostTestPluginBase | ||||||
|
||||||
|
||||||
RESET_FILE = "reset.jlink" | ||||||
|
||||||
class HostTestPluginResetMethod_Jlink(HostTestPluginBase): | ||||||
|
||||||
# Plugin interface | ||||||
name = 'HostTestPluginResetMethod_Jlink' | ||||||
type = 'ResetMethod' | ||||||
capabilities = ['JTAG', 'SWD'] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this plugin is specific to JLink, could you prefix these as follows? We also stick with lower case capabilities across the plugins:
Suggested change
|
||||||
required_parameters = ['mcu'] | ||||||
|
||||||
def is_os_supported(self, os_name=None): | ||||||
"""! In this implementation this plugin only is supporeted under Windows machines | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Little spelling error here:
Suggested change
|
||||||
""" | ||||||
# If no OS name provided use host OS name | ||||||
if not os_name: | ||||||
os_name = self.mbed_os_support() | ||||||
|
||||||
# This plugin only works on Windows | ||||||
if os_name and os_name.startswith('Windows'): | ||||||
return True | ||||||
return False | ||||||
|
||||||
def setup(self, *args, **kwargs): | ||||||
"""! Configure plugin, this function should be called before plugin execute() method is used. | ||||||
""" | ||||||
#Note you need to have jlink.exe on your system path! | ||||||
self.JLINK = 'JLink.exe' | ||||||
return True | ||||||
|
||||||
def build_jlink_script(self, path): | ||||||
"""! write a jlink commander file that | ||||||
reset the target | ||||||
|
||||||
@param path the file path of the script we are writing in the function | ||||||
""" | ||||||
with open(path, "w") as jlink_script: | ||||||
jlink_script.write("r\n") | ||||||
jlink_script.write("go\n") | ||||||
jlink_script.write("exit\n") | ||||||
|
||||||
|
||||||
def execute(self, capability, *args, **kwargs): | ||||||
"""! Executes capability by name | ||||||
|
||||||
@param capability Capability name | ||||||
@param args Additional arguments | ||||||
@param kwargs Additional arguments | ||||||
|
||||||
@details Each capability e.g. may directly just call some command line program or execute building pythonic function | ||||||
|
||||||
@return Capability call return value | ||||||
""" | ||||||
result = False | ||||||
if self.check_parameters(capability, *args, **kwargs) is True: | ||||||
|
||||||
mcu = os.path.normpath(kwargs['mcu']) | ||||||
|
||||||
jlink_file_path = os.path.join(tempfile.gettempdir(), RESET_FILE) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there are multiple processes running at once, I believe this has the opportunity for multiple processes trying to write and read to the same file. I think an alternative to this would be to use |
||||||
|
||||||
self.build_jlink_script(jlink_file_path) | ||||||
|
||||||
if capability == 'JTAG': | ||||||
cmd = [self.JLINK, | ||||||
"-device", mcu, | ||||||
"-if", "JTAG", | ||||||
"-jtagconf", "-1,-1", | ||||||
"-speed", "1000", | ||||||
"-CommanderScript", jlink_file_path] | ||||||
|
||||||
elif capability == 'SWD': | ||||||
cmd = [self.JLINK, | ||||||
"-device", mcu, | ||||||
"-if", "SWD", | ||||||
"-speed", "1000", | ||||||
"-CommanderScript", jlink_file_path] | ||||||
else: | ||||||
self.print_plugin_error("Unsupported capability") | ||||||
|
||||||
result = self.run_command(cmd) | ||||||
|
||||||
return result | ||||||
|
||||||
|
||||||
def load_plugin(): | ||||||
""" Returns plugin available in this module | ||||||
""" | ||||||
return HostTestPluginResetMethod_Jlink() |
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.
Would you mind updating the copyright year here?
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.
Also line 17 to be removed. Plus files should have SPDX identifier (any new file should).