|
@@ -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
|
+}
|