= Raspberry Pi Debugging with OpenOCD = [[TOC(Debugging/OpenOCD/Raspberry_Pi , depth=2)]] The scripts for OpenOCD debugging can be found in my [https://github.com/ppisa/rpi-utils/tree/master/jtag-debug rpi-utils] GitHUB repo for example. They are listed below as well. I have issues to load application image over JTAG (some data corruption, may it be by overload of bus arbitration). But when application is load over TFTP from U-boot it can be fully debugged. The JTAG interface has to be enabled first. For U-boot based RTEMS image load it can be achieved by U-boot commands {{{ mw.l 0x20200000 0x04a020 mw.l 0x20200008 0x65b6c0 }}} or apply next change to RTEMS sources {{{ --- a/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c +++ b/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c @@ -29,6 +29,15 @@ #include #include +void ll_strout(char *str) +{ + char ch; + while ((ch = *(str++)) != 0) { + if (ch == '\n') + bcm2835_usart_fns.deviceWritePolled(0, '\r'); + bcm2835_usart_fns.deviceWritePolled(0, ch); + } +} void BSP_START_TEXT_SECTION bsp_start_hook_0(void) { @@ -66,6 +75,21 @@ void BSP_START_TEXT_SECTION bsp_start_hook_0(void) /* Clear Secure or Non-secure Vector Base Address Register */ arm_cp15_set_vector_base_address(0); + + /* Enable JTAG */ + rtems_gpio_bsp_select_specific_io(0, 22, RPI_ALT_FUNC_4); + rtems_gpio_bsp_select_specific_io(0, 4, RPI_ALT_FUNC_5); + rtems_gpio_bsp_select_specific_io(0, 27, RPI_ALT_FUNC_4); + rtems_gpio_bsp_select_specific_io(0, 25, RPI_ALT_FUNC_4); + rtems_gpio_bsp_select_specific_io(0, 23, RPI_ALT_FUNC_4); + rtems_gpio_bsp_select_specific_io(0, 24, RPI_ALT_FUNC_4); + + if (1) { + ll_strout("JTAG Enabled and waiting for GDB\n"); + + continue_execution = 0; + while (!continue_execution); + } } void BSP_START_TEXT_SECTION bsp_start_hook_1(void) }}} Start RTEMS, when message appears connect from OpenOCD, setup breakpoints and set continue_execution to one {{{ (gdb) set continue_execution=1 }}} File "rpi-jt_usb5.cfg": {{{ #daemon configuration telnet_port 4444 gdb_port 3333 # tell gdb our flash memory map # and enable flash programming #gdb_memory_map enable #gdb_flash_program enable interface ftdi #ftdi_device_desc "Dual RS232" ftdi_vid_pid 0x0403 0x6010 ftdi_layout_init 0x0cf8 0x0cfb ftdi_layout_signal nTRST -data 0x0010 -noe 0x0800 ftdi_layout_signal nSRST -ndata 0x0040 -noe 0x0400 ftdi_layout_signal nTRST -data 0x0010 ftdi_layout_signal nSRST -ndata 0x0040 ftdi_layout_signal LED -ndata 0x0800 transport select jtag #ftdi_layout_signal SWD_EN -ndata 0x0400 #ftdi_layout_signal SWDIO_OE -alias TMS adapter_khz 500 reset_config none #jtag_nsrst_delay 400 #jtag_ntrst_delay 400 if { [info exists CHIPNAME] } { set _CHIPNAME $CHIPNAME } else { set _CHIPNAME raspi } reset_config none if { [info exists CPU_TAPID ] } { set _CPU_TAPID $CPU_TAPID } else { set _CPU_TAPID 0x07b7617F } jtag newtap $_CHIPNAME arm -irlen 5 -expected-id $_CPU_TAPID set _TARGETNAME $_CHIPNAME.arm target create $_TARGETNAME arm11 -chain-position $_TARGETNAME adapter_khz 500 init #reset halt #wait_halt # check TDO connection #echo 24 > /sys/class/gpio/export #echo out > /sys/class/gpio/gpio24/direction #echo 1 > /sys/class/gpio/gpio24/value }}} File "gdb-openocd.init": {{{ target remote localhost:3333 #load }}} File "rpi-jt_usb5-ddd" {{{ #!/bin/sh SCRIP_DIR="$(dirname "$(readlink -f "$0")")" nc -w 3 -z localhost 4444 if [ $? -ne 0 ] then echo "Starting OpenOCD" openocd -f "$SCRIP_DIR/rpi-jt_usb5.cfg" & OPENOCD_PID=$! nc -w 10 -z localhost 4444 if [ $? -ne 0 ] then echo "OpenOCD start failed" fi fi ddd --debugger arm-elf-gdb -x "$SCRIP_DIR/gdb-openocd.init" "$1" kill $OPENOCD_PID }}}