Skip to content

Commit

Permalink
trunner: armv7a9: change way that plo is loaded to board
Browse files Browse the repository at this point in the history
JIRA: CI-364
  • Loading branch information
maska989 authored and damianloew committed Oct 25, 2023
1 parent 1e20e2d commit a37c915
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
42 changes: 24 additions & 18 deletions trunner/target/armv7a9.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from abc import abstractmethod
import subprocess
import time
from typing import Callable, Optional
Expand All @@ -18,7 +19,7 @@
)
from trunner.harness import TerminalHarness
from trunner.host import Host
from trunner.tools import JLinkGdbServer, Phoenixd
from trunner.tools import Phoenixd, OpenocdGdbServer
from trunner.types import TestResult, TestOptions
from .base import TargetBase, find_port

Expand All @@ -41,13 +42,13 @@ def _set_flash_mode(self, flash):
self.host.set_flash_mode(not flash)


class ZynqGdbPloLoader(TerminalHarness, PloInterface):
class ZynqZedboardGdbPloLoader(TerminalHarness, PloInterface):
def __init__(self, dut: Dut, script: str, cwd: Optional[str] = None):
TerminalHarness.__init__(self)
PloInterface.__init__(self, dut)
self.script = script
self.cwd = cwd
self.gdbserver = JLinkGdbServer("Zynq 7020")
self.gdbserver = OpenocdGdbServer(board="digilent_zedboard")

def __call__(self):
"""Loads plo image to RAM using gdb."""
Expand Down Expand Up @@ -86,22 +87,10 @@ def __init__(self, host: Host, port: str, baudrate: int = 115200):
def from_context(cls, ctx: TestContext):
return cls(ctx.host, ctx.port, ctx.baudrate)

@abstractmethod
def flash_dut(self):
plo_loader = ZynqGdbPloLoader(
dut=self.dut,
script=f"{self._project_dir()}/phoenix-rtos-build/scripts/upload-zynq7000-jlink.gdb",
cwd=self.boot_dir(),
)

loader = PloImageLoader(
dut=self.dut,
rebooter=self.rebooter,
image=self.image,
plo_loader=plo_loader,
phoenixd=Phoenixd(directory=self.boot_dir()),
)

loader()
# for now there is no common flashing approach for all future armv7a9 targets
pass

def build_test(self, test: TestOptions) -> Callable[[TestResult], TestResult]:
builder = HarnessBuilder()
Expand Down Expand Up @@ -141,3 +130,20 @@ def __init__(self, host: Host, port: Optional[str] = None, baudrate: int = 11520
port = find_port("04b4:0008")

super().__init__(host, port, baudrate)

def flash_dut(self):
plo_loader = ZynqZedboardGdbPloLoader(
dut=self.dut,
script=f"{self._project_dir()}/phoenix-rtos-build/scripts/upload-zynq7000-smt2.gdb",
cwd=self.boot_dir(),
)

loader = PloImageLoader(
dut=self.dut,
rebooter=self.rebooter,
image=self.image,
plo_loader=plo_loader,
phoenixd=Phoenixd(directory=self.boot_dir()),
)

loader()
35 changes: 21 additions & 14 deletions trunner/tools/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import signal
from contextlib import contextmanager
from pathlib import Path
from typing import Optional, Union
from typing import Optional, Union, List

import pexpect

Expand Down Expand Up @@ -94,35 +94,42 @@ class OpenocdError(ProcessError):
class OpenocdGdbServer:
"""Handler for OpenocdGdbServer process"""

def __init__(self, interface: str, target: str, extra_args: Optional[list[str]] = None):
def __init__(
self,
interface: Optional[str] = None,
target: Optional[str] = None,
board: Optional[str] = None,
extra_args: Optional[List[str]] = None,
):
self.proc = None
self.target = target
self.interface = interface
self.board = board
self.output = ""
self.logfile = io.StringIO()
self.extra_args = extra_args

if board:
if target or interface:
raise OpenocdError("Target or Interface arguments provided when board is specified")
else:
if not target or not interface:
raise OpenocdError("Target or Interface arguments missing")

@contextmanager
@add_output_to_exception(OpenocdError)
def run(self):
try:
# Use pexpect.spawn to run a process as PTY, so it will flush on a new line
args = [
"-f",
f"interface/{self.interface}.cfg",
"-f",
f"target/{self.target}.cfg",
]
if self.board:
args = ["-f", f"board/{self.board}.cfg"]
else:
args = ["-f", f"interface/{self.interface}.cfg", "-f", f"target/{self.target}.cfg"]

if self.extra_args:
args.extend(self.extra_args)

self.proc = pexpect.spawn(
"openocd",
args,
encoding="ascii",
logfile=self.logfile,
)
self.proc = pexpect.spawn("openocd", args, encoding="ascii", logfile=self.logfile)

try:
self.proc.expect_exact("Info : Listening on port 3333 for gdb connections")
Expand Down

0 comments on commit a37c915

Please sign in to comment.