-
Notifications
You must be signed in to change notification settings - Fork 21
truner: adding Sparcv8Leon3 target support #334
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
Draft
maska989
wants to merge
1
commit into
master
Choose a base branch
from
maska989/Sparcv8Leon3
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.
Draft
Changes from all commits
Commits
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,139 @@ | ||
| import subprocess | ||
| import time | ||
| from typing import Callable, Optional | ||
|
|
||
| import pexpect | ||
| import pexpect.fdpexpect | ||
| import usb.core | ||
|
|
||
| from trunner.dut import SerialDut | ||
| from trunner.harness import ( | ||
| HarnessBuilder, | ||
| PloPhoenixdAppLoader, | ||
| PloHarness, | ||
| Rebooter, | ||
| ShellHarness, | ||
| FlashError, | ||
| TestStartRunningHarness, | ||
| ) | ||
| from trunner.host import Host | ||
| from trunner.tools import Phoenixd | ||
| from trunner.types import TestResult, TestOptions | ||
| from .base import TargetBase, find_port | ||
|
|
||
|
|
||
| class GR716Rebooter(Rebooter): | ||
| def _reboot_soft(self): | ||
| self._reboot_hard() | ||
| # TODO implement soft restarts after implementing flash memory | ||
| # self.host.set_reset(1) | ||
| # time.sleep(0.5) | ||
| # self.dut.clear_buffer() | ||
| # self.host.set_reset(0) | ||
| # time.sleep(0.25) | ||
|
|
||
| def _reboot_hard(self): | ||
| # Make sure that that reset pin is in low state | ||
| self.host.set_reset(0) | ||
| self.host.set_power(False) | ||
| time.sleep(0.75) | ||
| self.host.set_power(True) | ||
| time.sleep(0.5) | ||
|
|
||
|
|
||
| class GR716Target(TargetBase): | ||
| def __init__(self, host: Host, port: str, baudrate: int = 115200): | ||
| self.dut = SerialDut(port, baudrate, encoding="utf-8", codec_errors="ignore") | ||
| self.rebooter = GR716Rebooter(host, self.dut) | ||
| super().__init__() | ||
|
|
||
| @classmethod | ||
| def from_context(cls, ctx): | ||
| return cls(ctx.host, ctx.port, ctx.baudrate) | ||
|
|
||
| def MimasCustomUpload(self, boot_dir: str, image: str, vid: hex, pid: hex): | ||
| # using usb.core to fully reset device responsible for phoenixd | ||
| usb.core.find(idVendor=vid, idProduct=pid).reset() | ||
|
|
||
| self.rebooter() | ||
|
|
||
| # parsing passed hex values as string for find_port | ||
| port = str(hex(vid))[2:] + ":" + str(hex(pid))[2:] | ||
|
|
||
| subprocess.Popen( | ||
| f"phoenixd -p {find_port(port)} -b 115200 -s {str(boot_dir)}/.", | ||
| shell=True, | ||
| cwd=".", | ||
| start_new_session=True, | ||
| stdin=subprocess.PIPE, | ||
| stdout=subprocess.DEVNULL, | ||
| stderr=subprocess.STDOUT, | ||
| text=True, | ||
| ) | ||
|
|
||
| while True: | ||
| inChar = self.dut.read() | ||
| inChar += inChar | ||
|
|
||
| if "Bootloader" in inChar: | ||
| with open(f"{boot_dir}/{image}", "rb") as fd: | ||
| filebuff = fd.read() | ||
| time.sleep(1) | ||
| self.dut.serial.write(filebuff) | ||
|
|
||
| try: | ||
| self.dut.expect_exact("(psh)%", timeout=80) | ||
| fd.close() | ||
| break | ||
|
|
||
| except pexpect.TIMEOUT as e: | ||
| fd.close() | ||
| raise FlashError( | ||
| msg=str(e), | ||
| output=e.stdout.decode("ascii") if e.stdout else None, | ||
| ) from e | ||
|
|
||
| def flash_dut(self): | ||
| self.MimasCustomUpload( | ||
| boot_dir=self.boot_dir(), image="plo.img", vid=0x067B, pid=0x2303 | ||
| ) | ||
|
|
||
| def build_test(self, test: TestOptions) -> Callable[[TestResult], TestResult]: | ||
| builder = HarnessBuilder() | ||
|
|
||
| if test.should_reboot: | ||
| # TODO implement soft restarts after implementing flash memory | ||
| self.dut.send("\r\n") | ||
mateusz-bloch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if test.bootloader is not None: | ||
| app_loader = None | ||
|
|
||
| if test.bootloader.apps: | ||
| app_loader = PloPhoenixdAppLoader( | ||
| dut=self.dut, | ||
| apps=test.bootloader.apps, | ||
| phoenixd=Phoenixd(directory=self.root_dir() / test.shell.path), | ||
| ) | ||
|
|
||
| builder.add(PloHarness(self.dut, app_loader=app_loader)) | ||
|
|
||
| if test.shell is not None: | ||
| builder.add(ShellHarness(self.dut, self.shell_prompt, test.shell.cmd)) | ||
| else: | ||
| builder.add(TestStartRunningHarness()) | ||
|
|
||
| builder.add(test.harness) | ||
|
|
||
| return builder.get_harness() | ||
|
|
||
|
|
||
| class MimasSparcV8EvkTarget(GR716Target): | ||
|
Member
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. So, if I understand correctly, the target is not Sparcv8Leon3, but GR716, which is based on the Sparcv8Leon3 architecture. So, shouldn't it be the other way around, something like GR716-mimas-EvkTarget(SparcV8Target) |
||
| name = "sparcv8leon3-gr716-mimas" | ||
| rootfs = False | ||
| experimental = True | ||
|
|
||
| def __init__(self, host: Host, port: Optional[str] = None, baudrate: int = 115200): | ||
| if not port: | ||
| port = find_port("10c4:ea60") # vid:pid for communication (PLO usb/uart) | ||
|
|
||
| super().__init__(host, port, baudrate) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
We can simplify this by knowing that dut is a wrapper around pexpect. For example, by expecting the appearance of the Bootloader instead of catching each character.
Example of simplified code that should work:
Remember also that when you use a context manager in Python, it automatically handles the closing of resources opened within it, so you don't need to manually close them with fd.close()