Skip to content
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

RTT: search for RTT control block in smaller chunks #1375

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions pyocd/subcommands/rtt_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) 2021 mikisama
# Copyright (C) 2021 Ciro Cattuto <ciro.cattuto@gmail.com>
# Copyright (C) 2021 Simon D. Levy <simon.d.levy@gmail.com>
# Copyright (C) 2022 Johan Carlsson <johan.carlsson@teenage.engineering>
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -128,16 +129,25 @@ def invoke(self) -> int:

LOG.info(f"RTT control block search range [{rtt_range_start:#08x}, {rtt_range_size:#08x}]")

data = target.read_memory_block8(rtt_range_start, rtt_range_size)
pos = bytes(data).find(b"SEGGER RTT")

if pos == -1:
rtt_cb_addr = -1
data = bytearray(b'0000000000')
chunk_size = 1024
while rtt_range_size > 0:
read_size = min(chunk_size, rtt_range_size)
data += bytearray(target.read_memory_block8(rtt_range_start, read_size))
pos = data[-(read_size + 10):].find(b"SEGGER RTT")
if pos != -1:
rtt_cb_addr = rtt_range_start + pos - 10
break
rtt_range_start += read_size
rtt_range_size -= read_size

if rtt_cb_addr == -1:
LOG.error("No RTT control block available")
return 1

rtt_cb_addr = rtt_range_start + pos

rtt_cb = SEGGER_RTT_CB.from_buffer(bytearray(data[pos:]))
data = target.read_memory_block8(rtt_cb_addr, sizeof(SEGGER_RTT_CB))
rtt_cb = SEGGER_RTT_CB.from_buffer(bytearray(data))
up_addr = rtt_cb_addr + SEGGER_RTT_CB.aUp.offset
down_addr = up_addr + sizeof(SEGGER_RTT_BUFFER_UP) * rtt_cb.MaxNumUpBuffers

Expand Down