Skip to content

Commit

Permalink
rtt: fix cb not found (#1583)
Browse files Browse the repository at this point in the history
Search only for the length of control block ID.

Fixes #1533
  • Loading branch information
tdasika authored Aug 5, 2023
1 parent 37c8efb commit 6dcd439
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pyocd/debug/rtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (C) 2021 Simon D. Levy <[email protected]>
# Copyright (C) 2022 Johan Carlsson <[email protected]>
# Copyright (c) 2022 Samuel Dewan
# Copyright (C) 2023 Tejaswini Dasika <[email protected]>
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -387,7 +388,7 @@ class GenericRTTControlBlock(RTTControlBlock):

target: SoCTarget
_cb_search_address: int
_cb_search_size_words: int
_cb_search_size_bytes: int
_control_block_id: Sequence[int]

def __init__(self, target: SoCTarget, address: int = None,
Expand Down Expand Up @@ -418,17 +419,14 @@ def __init__(self, target: SoCTarget, address: int = None,
if size is None:
# Address was specified, but size was not. Assume that the control
# block is located exactly at the provided address.
self._cb_search_size_words = 0
self._cb_search_size_bytes = 0
else:
self._cb_search_size_words = size // 4

extra_id_bytes = SEGGER_RTT_CB.acID.size - len(control_block_id)
control_block_bytes = control_block_id + b'\0' * extra_id_bytes
self._control_block_id = struct.unpack("<IIII", control_block_bytes)
self._cb_search_size_bytes = size
self._control_block_id = control_block_id

def _find_control_block(self) -> Optional[int]:
addr: int = self._cb_search_address & ~0x3
search_size: int = self._cb_search_size_words
search_size: int = self._cb_search_size_bytes
if search_size < len(self._control_block_id):
search_size = len(self._control_block_id)

Expand All @@ -437,19 +435,19 @@ def _find_control_block(self) -> Optional[int]:

while search_size:
read_size = min(search_size, 32)
data = self.target.read_memory_block32(addr, read_size)
data = self.target.read_memory_block8(addr, read_size)

if not data:
break

for word in data:
if word == self._control_block_id[offset]:
for byte in data:
if byte == self._control_block_id[offset]:
offset += 1
if offset == id_len:
break
else:
num_skip_words = (offset + 1)
addr += (num_skip_words * 4)
addr += (num_skip_words * 1)
search_size -= num_skip_words
offset = 0

Expand Down

0 comments on commit 6dcd439

Please sign in to comment.