jamieiles
Posts: 3
Joined: Wed Sep 19, 2012 10:38 am

Project announce: GDB remote serial protocol stub

Wed Oct 10, 2012 7:50 pm

Hi all,

I thought I'd share something that I've been working on (Raspberry Pi GDB remote serial protocol stub) which is an implementation of a gdb stub that runs on bare metal and talks over the serial port. This should be useful to anyone doing bare metal development that doesn't have a JTAG.

It's still early days but "release early, release often"! It'll happily load a bunch of dwelch's examples and allow you to step through those though so it's in a usable state. At the moment it's configured to sit 16MB into RAM so if you have a particularly large project it'll need a tweak to the ldscript and loader which should eventually be a little more configurable.

Jamie

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: Project announce: GDB remote serial protocol stub

Fri Oct 12, 2012 7:46 pm

Sounds interesting! If I have some time this weekend, I'm going to try it.

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: Project announce: GDB remote serial protocol stub

Sat Oct 13, 2012 11:53 am

Here's my initial results.

I use a Mac for most of my development. This probably isn't an issue with your code, but the Yagarto ARM gdb was not able to open the serial port. I can successfully use the serial port from serial terminal software. I could see data coming back from the Pi in the serial terminal so that (and the slow blinking onboard LED) tells me the Pi-side code was running and able to communicate. That causes me to suspect it's an issue with gdb on the Mac side.

I then fired up a Linux virtual machine running CodeSourcery and I was able to connect to the Pi. I loaded David Welch's blinker05 code and it stopped at the _start assembly code entry point. (By the way, for others, use the blinker05.elf file as the "binary" file and modify the make file to add the '-g' flag to tell the compiler to add debug information.) When I tried to stepi from _start I had the following problem.

Code: Select all

(gdb) where
#0  _start () at vectors.s:7
(gdb) list
1	
2	//-------------------------------------------------------------------------
3	//-------------------------------------------------------------------------
4	
5	extern void PUT32 ( unsigned int, unsigned int );
6	extern unsigned int GET32 ( unsigned int );
7	extern void dummy ( unsigned int );
8	extern void enable_irq ( void );
9	extern void enable_fiq ( void );
10	
(gdb) stepi
warning: Invalid remote reply: 
^C
gdb) continue
Continuing.

Breakpoint 1, notmain () at blinker05.c:55
55	    PUT32(IRQ_DISABLE_BASIC,1);
(gdb) where
#0  notmain () at blinker05.c:55
#1  0x00008080 in reset () at vectors.s:52
Backtrace stopped: frame did not save the PC
(gdb) step
warning: Invalid remote reply: 
next
^C
Breakpoint 1, Quit
(gdb) next
warning: Invalid remote reply: 
The line numbers don't seem to match up with the actual code. In any case, gdb hangs at this point and the onboard LED stops blinking on the Pi. I typed ^C and then 'continue' and the code ran to a breakpoint I had set at the notmain function. However, after that, every time I typed 'step' or 'next' I received the "warning: Invalid remote reply:" message. Any ideas?

jamieiles
Posts: 3
Joined: Wed Sep 19, 2012 10:38 am

Re: Project announce: GDB remote serial protocol stub

Sat Oct 13, 2012 12:16 pm

Hi Steverino,

Thanks for giving it a go!
Steverino wrote: I then fired up a Linux virtual machine running CodeSourcery and I was able to connect to the Pi. I loaded David Welch's blinker05 code and it stopped at the _start assembly code entry point. (By the way, for others, use the blinker05.elf file as the "binary" file and modify the make file to add the '-g' flag to tell the compiler to add debug information.) When I tried to stepi from _start I had the following problem.
It's often worth using -ggdb3 as that'll give even more debug info (things like macros etc).
Steverino wrote: The line numbers don't seem to match up with the actual code. In any case, gdb hangs at this point and the onboard LED stops blinking on the Pi. I typed ^C and then 'continue' and the code ran to a breakpoint I had set at the notmain function. However, after that, every time I typed 'step' or 'next' I received the "warning: Invalid remote reply:" message. Any ideas?
Okay, the problem with it hanging is that this example disables FIQ's which is what I use as the NMI for the UART. The patch below is a short term fix for this specific example:

Code: Select all

diff --git i/blinker05/vectors.s w/blinker05/vectors.s
index 9f0aeb8..8d436b4 100644
--- i/blinker05/vectors.s
+++ w/blinker05/vectors.s
@@ -40,8 +40,8 @@ reset:
     msr cpsr_c,r0
     mov sp,#0x4000
 
-    ;@ (PSR_SVC_MODE|PSR_FIQ_DIS|PSR_IRQ_DIS)
-    mov r0,#0xD3
+    ;@ (PSR_SVC_MODE|PSR_IRQ_DIS)
+    mov r0,#0x93
     msr cpsr_c,r0
     mov sp,#0x8000000
Longer term I plan to have the debugee run in non-secure mode and so it won't actually be able to disable FIQ's, but that'll take a bit more time :)

If you still see problems with an invalid remote reply, try running 'set debug remote 1' in your gdbscript and that may give me some extra clues.

Jamie

Steverino
Posts: 23
Joined: Sun Aug 19, 2012 2:44 pm

Re: Project announce: GDB remote serial protocol stub

Mon Oct 22, 2012 10:18 pm

Hi Jamie,

Sorry, I didn't click the "watch" button on the topic so I didn't see your earlier reply. I've tried again using your suggestions and I did get farther. I'm able to hit the breakpoint at 'notmain' in blinker05 but when I use 'next' I see the following reply (with 'set debug remote 1'):

Code: Select all

(gdb) n
Sending packet: $vCont;s#b8...Ack
Packet received: 
warning: Invalid remote reply: 
I double-checked the compiled code listing to be sure the FIQ was not disabled and it appears ok.

gvech
Posts: 4
Joined: Thu Jun 22, 2017 10:19 am

Re: Project announce: GDB remote serial protocol stub

Thu Jun 22, 2017 10:24 am

Hi guys, can anyone explain me how can i run this? The makefile copies the kernel.img to tftpboot, do i need a loader like u-boot running in the raspberry? I know this post is too old but if anyone can answer me will help me a lot. Sorry for my english. Regards.

dwelch67
Posts: 835
Joined: Sat May 26, 2012 5:32 pm

Re: Project announce: GDB remote serial protocol stub

Thu Jun 22, 2017 4:48 pm

you just copy the kernel.img file to the sd card along with bootcode.bin and start.elf which you get from the raspberry pi github site https://github.com/raspberrypi in the firmware repo (dont check out the whole repo just those two files).

Depending on how your kernel.img is linked (for address 0x8000 or 0x0000) you may need a config.txt to adjust it (0x8000 no config.txt for a pi1).

While cool sounding understand that rom monitors (for lack of a better term) run on the same processor they are just code that your code has to cooperate with, if your code hangs or crashes in certain ways you might not be able to recover the system through the rom monitor . I have a 200 line bootloader and added a reset button and use that instead of jtag which I have a solution for as well...at least for loading and I dont use gdb for anything ever so dont miss single stepping features or monitoring memory locations, etc...Anyway point being the program you are debugging has to be somewhat behaved for all of this to work...

gvech
Posts: 4
Joined: Thu Jun 22, 2017 10:19 am

Re: Project announce: GDB remote serial protocol stub

Mon Jul 10, 2017 11:09 am

dwelch67 wrote:you just copy the kernel.img file to the sd card along with bootcode.bin and start.elf which you get from the raspberry pi github site https://github.com/raspberrypi in the firmware repo (dont check out the whole repo just those two files).

Depending on how your kernel.img is linked (for address 0x8000 or 0x0000) you may need a config.txt to adjust it (0x8000 no config.txt for a pi1).

While cool sounding understand that rom monitors (for lack of a better term) run on the same processor they are just code that your code has to cooperate with, if your code hangs or crashes in certain ways you might not be able to recover the system through the rom monitor . I have a 200 line bootloader and added a reset button and use that instead of jtag which I have a solution for as well...at least for loading and I dont use gdb for anything ever so dont miss single stepping features or monitoring memory locations, etc...Anyway point being the program you are debugging has to be somewhat behaved for all of this to work...
Hi, thanks for your answer, when i try to connect gdb show me this "Remote replied unexpectedly to 'vMustReplyEmpty': timeout". Why this happens? Maybe is the gdb version? Which version do you use? Does this work for any rpi? I use rpi model A 2.0 v2011.12. Best regards.

LdB
Posts: 568
Joined: Wed Dec 07, 2016 2:29 pm

Re: Project announce: GDB remote serial protocol stub

Mon Jul 10, 2017 4:34 pm

The code wont work on a Pi2 it is hard coded to a Pi1 (The post is very old).

I immediately saw
#define IRQC_BASE 0x2000B000

On a Pi2 that should be
#define IRQC_BASE 0x3F00B000

I also can't see anywhere it sets the FIQ stack pointer yet it's uses the FIQ so if any FIQ code uses the stack it will be interesting.

If you need it I can have a go at fixing it.

However
https://github.com/turboscrew/rpi_stub
Is setup for a Pi1 and Pi2 and sets the stacks up properly and you have options like choosing irq/fiq for the debugger etc. It's a bigger stub but it does a lot more.

gvech
Posts: 4
Joined: Thu Jun 22, 2017 10:19 am

Re: Project announce: GDB remote serial protocol stub

Wed Jul 26, 2017 9:09 am

LdB wrote:
Mon Jul 10, 2017 4:34 pm
However
https://github.com/turboscrew/rpi_stub
Is setup for a Pi1 and Pi2 and sets the stacks up properly and you have options like choosing irq/fiq for the debugger etc. It's a bigger stub but it does a lot more.
Does this work on Pi1? I only see code for Pi2.

ranchu
Posts: 1
Joined: Mon Sep 11, 2017 10:12 pm

Re: Project announce: GDB remote serial protocol stub

Mon Sep 11, 2017 10:14 pm

Hello,

I would like to ask if these projects can be used with any arm, or is it hardcoded (specific registers) for Pi only.

Thank you,
Ran

Return to “Bare metal”

Who is online

Users browsing this forum: jspeccy and 3 guests