瀏覽代碼

[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 9 年之前
父節點
當前提交
a0f60d26f5
共有 2 個檔案被更改,包括 44 行新增7 行删除
  1. 36
    7
      src/core/gdbserial.c
  2. 8
    0
      src/include/ipxe/gdbserial.h

+ 36
- 7
src/core/gdbserial.c 查看文件

24
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
24
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
 
25
 
26
 #include <stddef.h>
26
 #include <stddef.h>
27
+#include <stdio.h>
28
+#include <stdlib.h>
27
 #include <assert.h>
29
 #include <assert.h>
28
 #include <ipxe/uart.h>
30
 #include <ipxe/uart.h>
29
 #include <ipxe/gdbstub.h>
31
 #include <ipxe/gdbstub.h>
54
 /** GDB serial UART */
56
 /** GDB serial UART */
55
 static struct uart gdbserial_uart;
57
 static struct uart gdbserial_uart;
56
 
58
 
59
+struct gdb_transport serial_gdb_transport __gdb_transport;
60
+
57
 static size_t gdbserial_recv ( char *buf, size_t len ) {
61
 static size_t gdbserial_recv ( char *buf, size_t len ) {
58
 
62
 
59
 	assert ( len > 0 );
63
 	assert ( len > 0 );
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
 	return 0;
98
 	return 0;
83
 }
99
 }
88
 	.recv = gdbserial_recv,
104
 	.recv = gdbserial_recv,
89
 	.send = gdbserial_send,
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 查看文件

9
 
9
 
10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
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
 #endif /* _IPXE_GDBSERIAL_H */
20
 #endif /* _IPXE_GDBSERIAL_H */

Loading…
取消
儲存