Browse Source

[gdb] Allow gdbstub to be started on an arbitrary serial port

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
a0f60d26f5
2 changed files with 44 additions and 7 deletions
  1. 36
    7
      src/core/gdbserial.c
  2. 8
    0
      src/include/ipxe/gdbserial.h

+ 36
- 7
src/core/gdbserial.c View File

@@ -24,6 +24,8 @@
24 24
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 25
 
26 26
 #include <stddef.h>
27
+#include <stdio.h>
28
+#include <stdlib.h>
27 29
 #include <assert.h>
28 30
 #include <ipxe/uart.h>
29 31
 #include <ipxe/gdbstub.h>
@@ -54,6 +56,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
54 56
 /** GDB serial UART */
55 57
 static struct uart gdbserial_uart;
56 58
 
59
+struct gdb_transport serial_gdb_transport __gdb_transport;
60
+
57 61
 static size_t gdbserial_recv ( char *buf, size_t len ) {
58 62
 
59 63
 	assert ( len > 0 );
@@ -69,15 +73,27 @@ static void gdbserial_send ( const char *buf, size_t len ) {
69 73
 	}
70 74
 }
71 75
 
72
-static int gdbserial_init ( int argc __unused, char **argv __unused ) {
73
-	int rc;
76
+static int gdbserial_init ( int argc, char **argv ) {
77
+	unsigned int port;
78
+	char *endp;
74 79
 
75
-	if ( ( rc = uart_select ( &gdbserial_uart, GDBSERIAL_PORT ) ) != 0 )
76
-		return rc;
80
+	if ( argc == 0 ) {
81
+		port = GDBSERIAL_PORT;
82
+	} else if ( argc == 1 ) {
83
+		port = strtoul ( argv[0], &endp, 10 );
84
+		if ( *endp ) {
85
+			printf ( "serial: invalid port\n" );
86
+			return 1;
87
+		}
88
+	} else {
89
+		printf ( "serial: syntax <port>\n" );
90
+		return 1;
91
+	}
77 92
 
78
-	if ( ( rc = uart_init ( &gdbserial_uart, GDBSERIAL_BAUD,
79
-				GDBSERIAL_LCR ) ) != 0 )
80
-		return rc;
93
+	if ( ! gdbserial_configure ( port, GDBSERIAL_BAUD, GDBSERIAL_LCR ) ) {
94
+		printf ( "serial: unable to configure\n" );
95
+		return 1;
96
+	}
81 97
 
82 98
 	return 0;
83 99
 }
@@ -88,3 +104,16 @@ struct gdb_transport serial_gdb_transport __gdb_transport = {
88 104
 	.recv = gdbserial_recv,
89 105
 	.send = gdbserial_send,
90 106
 };
107
+
108
+struct gdb_transport * gdbserial_configure ( unsigned int port,
109
+					     unsigned int baud, uint8_t lcr ) {
110
+	int rc;
111
+
112
+	if ( ( rc = uart_select ( &gdbserial_uart, port ) ) != 0 )
113
+		return NULL;
114
+
115
+	if ( ( rc = uart_init ( &gdbserial_uart, baud, lcr ) ) != 0 )
116
+		return NULL;
117
+
118
+	return &serial_gdb_transport;
119
+}

+ 8
- 0
src/include/ipxe/gdbserial.h View File

@@ -9,4 +9,12 @@
9 9
 
10 10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 11
 
12
+#include <stdint.h>
13
+
14
+struct gdb_transport;
15
+
16
+extern struct gdb_transport * gdbserial_configure ( unsigned int port,
17
+						    unsigned int baud,
18
+						    uint8_t lcr );
19
+
12 20
 #endif /* _IPXE_GDBSERIAL_H */

Loading…
Cancel
Save