summaryrefslogtreecommitdiffstats
path: root/src/core/gdbserial.c
diff options
context:
space:
mode:
authorMichael Brown2015-06-29 17:43:39 +0200
committerMichael Brown2015-06-29 17:44:16 +0200
commita0f60d26f5780196f75f4b14444dfa8d020a5e00 (patch)
tree1ca4b35752cb30e03faa03e9e3ad084dbba0e57e /src/core/gdbserial.c
parent[ipoib] Attempt to generate ARPs as needed to repopulate REMAC cache (diff)
downloadipxe-a0f60d26f5780196f75f4b14444dfa8d020a5e00.tar.gz
ipxe-a0f60d26f5780196f75f4b14444dfa8d020a5e00.tar.xz
ipxe-a0f60d26f5780196f75f4b14444dfa8d020a5e00.zip
[gdb] Allow gdbstub to be started on an arbitrary serial port
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/gdbserial.c')
-rw-r--r--src/core/gdbserial.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/core/gdbserial.c b/src/core/gdbserial.c
index 802463f4..0983f255 100644
--- a/src/core/gdbserial.c
+++ b/src/core/gdbserial.c
@@ -24,6 +24,8 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <assert.h>
#include <ipxe/uart.h>
#include <ipxe/gdbstub.h>
@@ -54,6 +56,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** GDB serial UART */
static struct uart gdbserial_uart;
+struct gdb_transport serial_gdb_transport __gdb_transport;
+
static size_t gdbserial_recv ( char *buf, size_t len ) {
assert ( len > 0 );
@@ -69,15 +73,27 @@ static void gdbserial_send ( const char *buf, size_t len ) {
}
}
-static int gdbserial_init ( int argc __unused, char **argv __unused ) {
- int rc;
+static int gdbserial_init ( int argc, char **argv ) {
+ unsigned int port;
+ char *endp;
- if ( ( rc = uart_select ( &gdbserial_uart, GDBSERIAL_PORT ) ) != 0 )
- return rc;
+ if ( argc == 0 ) {
+ port = GDBSERIAL_PORT;
+ } else if ( argc == 1 ) {
+ port = strtoul ( argv[0], &endp, 10 );
+ if ( *endp ) {
+ printf ( "serial: invalid port\n" );
+ return 1;
+ }
+ } else {
+ printf ( "serial: syntax <port>\n" );
+ return 1;
+ }
- if ( ( rc = uart_init ( &gdbserial_uart, GDBSERIAL_BAUD,
- GDBSERIAL_LCR ) ) != 0 )
- return rc;
+ if ( ! gdbserial_configure ( port, GDBSERIAL_BAUD, GDBSERIAL_LCR ) ) {
+ printf ( "serial: unable to configure\n" );
+ return 1;
+ }
return 0;
}
@@ -88,3 +104,16 @@ struct gdb_transport serial_gdb_transport __gdb_transport = {
.recv = gdbserial_recv,
.send = gdbserial_send,
};
+
+struct gdb_transport * gdbserial_configure ( unsigned int port,
+ unsigned int baud, uint8_t lcr ) {
+ int rc;
+
+ if ( ( rc = uart_select ( &gdbserial_uart, port ) ) != 0 )
+ return NULL;
+
+ if ( ( rc = uart_init ( &gdbserial_uart, baud, lcr ) ) != 0 )
+ return NULL;
+
+ return &serial_gdb_transport;
+}