Skip to content

Commit 5c995a4

Browse files
committed
feat(debug): Add top-level JTAG assets for Pi 5
Adds the necessary infrastructure for a JTAG-based debugging workflow on the Raspberry Pi 5. This includes a new 'debug/pi5' directory with OpenOCD and GDB configuration files, and a new 'X2_pi5_jtag_halt_stub' project that compiles a simple assembly stub to halt the CPU for debugging. This lays the foundation for the Pi 5 BSP and debugging targets in the tutorial Makefiles. Co-authored-by: Devansh Lodha <[email protected]>
1 parent 644474c commit 5c995a4

File tree

7 files changed

+100
-0
lines changed

7 files changed

+100
-0
lines changed

X2_pi5_jtag_halt_stub/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-License-Identifier: MIT OR Apache-2.0
2+
#
3+
# Copyright (c) 2025 Devansh Lodha <[email protected]>
4+
5+
# This Makefile is designed to be called from the parent directory's
6+
# Docker environment, which provides the aarch64-elf toolchain.
7+
8+
CROSS_COMPILE ?= aarch64-elf-
9+
OBJCOPY = $(CROSS_COMPILE)objcopy
10+
AS = $(CROSS_COMPILE)as
11+
LD = $(CROSS_COMPILE)ld
12+
13+
IMG_NAME = halt_stub.img
14+
ELF_NAME = halt_stub.elf
15+
OBJ_NAME = start.o
16+
17+
.PHONY: all clean
18+
19+
all: $(IMG_NAME)
20+
21+
$(IMG_NAME): $(ELF_NAME)
22+
@echo "--- Building Halt Stub Image ---"
23+
@$(OBJCOPY) -O binary $(ELF_NAME) $(IMG_NAME)
24+
25+
$(ELF_NAME): $(OBJ_NAME)
26+
@$(LD) -T linker.ld -o $(ELF_NAME) $(OBJ_NAME)
27+
28+
$(OBJ_NAME): start.s
29+
@$(AS) -o $(OBJ_NAME) start.s
30+
31+
clean:
32+
@rm -f $(IMG_NAME) $(ELF_NAME) $(OBJ_NAME)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_ ����

X2_pi5_jtag_halt_stub/linker.ld

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* SPDX-License-Identifier: MIT OR Apache-2.0
3+
*
4+
* Copyright (c) 2025 Devansh Lodha <[email protected]>
5+
*/
6+
7+
ENTRY(_start)
8+
SECTIONS
9+
{
10+
. = 0x80000;
11+
.text : { *(.text.boot) }
12+
}

X2_pi5_jtag_halt_stub/start.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* SPDX-License-Identifier: MIT OR Apache-2.0
3+
*
4+
* Copyright (c) 2025 Devansh Lodha <[email protected]>
5+
*/
6+
7+
.section ".text.boot"
8+
.global _start
9+
_start:
10+
wfe // Wait for event (low-power idle)
11+
b _start

debug/pi5/cmsis-dap.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: MIT OR Apache-2.0
2+
#
3+
# Copyright (c) 2025 Devansh Lodha <[email protected]>
4+
5+
adapter driver cmsis-dap

debug/pi5/gdb-init.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: MIT OR Apache-2.0
2+
#
3+
# Copyright (c) 2025 Devansh Lodha <[email protected]>
4+
5+
# 1. Connect to the OpenOCD server.
6+
target remote localhost:3333
7+
8+
# 2. Reset the Pi and halt it at the very beginning.
9+
monitor reset init
10+
11+
# 3. Load your program's symbols and code into the Pi's RAM.
12+
load
13+
14+
# 4. Set the Program Counter to the start of our code.
15+
set $pc = 0x80000

debug/pi5/raspberrypi5.cfg

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: MIT OR Apache-2.0
2+
#
3+
# Copyright (c) 2025 Devansh Lodha <[email protected]>
4+
5+
transport select swd
6+
adapter speed 4000
7+
reset_config srst_push_pull srst_only
8+
set _CHIPNAME bcm2712
9+
set _DAP_TAPID 0x4ba00477
10+
set _CHIPCORES 4
11+
swd newdap $_CHIPNAME cpu -expected-id $_DAP_TAPID
12+
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
13+
set _DBGBASE {0x80010000 0x80110000 0x80210000 0x80310000}
14+
set _CTIBASE {0x80020000 0x80120000 0x80220000 0x80320000}
15+
for { set _core 0 } { $_core < $_CHIPCORES } { incr _core } {
16+
set _CTINAME $_CHIPNAME.cti$_core
17+
set _TARGETNAME $_CHIPNAME.cpu$_core
18+
cti create $_CTINAME -dap $_CHIPNAME.dap -ap-num 0 -baseaddr [lindex $_CTIBASE $_core]
19+
target create $_TARGETNAME aarch64 -dap $_CHIPNAME.dap -coreid $_core -dbgbase [lindex $_DBGBASE $_core] -cti $_CTINAME
20+
$_TARGETNAME configure -event gdb-attach { halt }
21+
}
22+
targets $_CHIPNAME.cpu0
23+
init
24+
$_CHIPNAME.cpu0 configure -event reset-init { halt }

0 commit comments

Comments
 (0)