This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
RedBoot - support ^C during long network operations
- From: Gary Thomas <gary at mlbassoc dot com>
- To: eCos patches <ecos-patches at sources dot redhat dot com>
- Date: 16 Jul 2003 13:10:16 -0600
- Subject: RedBoot - support ^C during long network operations
- Organization: MLB Associates
Now you can abort the initial BOOTP as well as PING - overall
friendlier.
--
Gary Thomas <gary@mlbassoc.com>
MLB Associates
Index: redboot/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.119
diff -u -5 -p -r1.119 ChangeLog
--- redboot/current/ChangeLog 15 Jul 2003 18:53:49 -0000 1.119
+++ redboot/current/ChangeLog 16 Jul 2003 19:08:01 -0000
@@ -1,5 +1,14 @@
+2003-07-16 Gary Thomas <gary@mlbassoc.com>
+
+ * src/net/ping.c:
+ * src/net/bootp.c: Allow ^C to abort.
+
+ * src/io.c:
+ * include/redboot.h: New function _rb_break() used to test for ^C
+ on the console. Used to break out of long operations like BOOTP.
+
2003-07-15 Gary Thomas <gary@mlbassoc.com>
* src/net/bootp.c: Use correct options for DHCP discover. This has
the added bonus that when BOOTP & GATEWAY options are enabled, then
RedBoot can get it's address via normal DHCP. Of course, DHCP leases
Index: redboot/current/include/redboot.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/include/redboot.h,v
retrieving revision 1.27
diff -u -5 -p -r1.27 redboot.h
--- redboot/current/include/redboot.h 24 Aug 2002 11:34:50 -0000 1.27
+++ redboot/current/include/redboot.h 16 Jul 2003 19:06:24 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -137,10 +137,14 @@ externC int _rb_gets_preloaded(char *li
// Result codes from 'gets()'
#define _GETS_TIMEOUT -1
#define _GETS_CTRLC -2
#define _GETS_GDB 0
#define _GETS_OK 1
+// Test for ^C on the console. This function should only be used if any
+// other console input can be discarded, e.g. while performing some long
+// computation, waiting for the network, etc. Returns 'true' if ^C typed.
+externC bool _rb_break(int timeout);
// "console" selection
externC int start_console(void);
externC void end_console(int old_console);
Index: redboot/current/src/io.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/io.c,v
retrieving revision 1.30
diff -u -5 -p -r1.30 io.c
--- redboot/current/src/io.c 20 May 2003 18:43:52 -0000 1.30
+++ redboot/current/src/io.c 16 Jul 2003 19:06:42 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -243,10 +243,26 @@ mon_set_read_char_timeout(int ms)
}
if ((__chan = CYGACC_CALL_IF_DEBUG_PROCS()) != 0) {
CYGACC_COMM_IF_CONTROL(*__chan, __COMMCTL_SET_TIMEOUT, ms);
}
}
+}
+
+//
+// Test for ^C on the console. CAUTION! discards all console input
+//
+bool
+_rb_break(int timeout)
+{
+ char c;
+ mon_set_read_char_timeout(timeout);
+ if (mon_read_char_with_timeout(&c)) {
+ if (c == 0x03) { // Test for ^C
+ return true;
+ }
+ }
+ return false;
}
#ifdef CYGFUN_REDBOOT_BOOT_SCRIPT
#define __STRINGIFY(x) #x
#define _STRINGIFY(x) __STRINGIFY(x)
Index: redboot/current/src/net/bootp.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/bootp.c,v
retrieving revision 1.11
diff -u -5 -p -r1.11 bootp.c
--- redboot/current/src/net/bootp.c 15 Jul 2003 18:53:50 -0000 1.11
+++ redboot/current/src/net/bootp.c 16 Jul 2003 19:07:30 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -60,11 +60,11 @@
extern int net_debug;
#define SHOULD_BE_RANDOM 0x12345555
/* How many milliseconds to wait before retrying the request */
-#define RETRY_TIME 1000
+#define RETRY_TIME 500
#define MAX_RETRIES 30
static bootp_header_t *bp_info;
#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
@@ -153,10 +153,11 @@ __bootp_find_local_ip(bootp_header_t *in
ip_addr_t saved_ip_addr;
#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
unsigned char *p;
#endif
int txSize;
+ bool abort = false;
bp_info = info;
memset(&b, 0, sizeof(b));
@@ -197,12 +198,12 @@ __bootp_find_local_ip(bootp_header_t *in
r.enet_addr[5] = 255;
/* setup a socket listener for bootp replies */
__udp_install_listener(&udp_skt, IPPORT_BOOTPC, bootp_handler);
- retry = MAX_RETRIES;
- while (retry-- > 0) {
+ retry = MAX_RETRIES;
+ while (!abort && (retry-- > 0)) {
start = MS_TICKS();
__udp_send((char *)&b, txSize, &r, IPPORT_BOOTPS, IPPORT_BOOTPC);
do {
@@ -211,11 +212,22 @@ __bootp_find_local_ip(bootp_header_t *in
__local_ip_addr[2] || __local_ip_addr[3]) {
/* success */
__udp_remove_listener(IPPORT_BOOTPC);
return 0;
}
+ if (_rb_break(1)) {
+ // The user typed ^C on the console
+ abort = true;
+ break;
+ }
+ MS_TICKS_DELAY(); // Count for ^C test
} while ((MS_TICKS_DELAY() - start) < RETRY_TIME);
+
+ // Warn the user that we're polling for BOOTP info
+ if (retry == (MAX_RETRIES-1)) {
+ diag_printf("... waiting for BOOTP information\n");
+ }
}
/* timed out */
__udp_remove_listener(IPPORT_BOOTPC);
net_debug = 0;
Index: redboot/current/src/net/ping.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/ping.c,v
retrieving revision 1.10
diff -u -5 -p -r1.10 ping.c
--- redboot/current/src/net/ping.c 16 Jul 2002 16:25:42 -0000 1.10
+++ redboot/current/src/net/ping.c 16 Jul 2003 19:08:02 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2003 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -175,13 +176,14 @@ do_ping(int argc, char *argv[])
inet_ntoa((in_addr_t *)&local_addr));
diag_printf(" to %s\n",
inet_ntoa((in_addr_t *)&host_addr));
received = 0;
__icmp_install_listener(handle_icmp);
+ // Save default "local" address
+ memcpy(hold_addr, __local_ip_addr, sizeof(hold_addr));
for (tries = 0; tries < count; tries++) {
// The network stack uses the global variable '__local_ip_addr'
- memcpy(hold_addr, __local_ip_addr, sizeof(hold_addr));
memcpy(__local_ip_addr, &local_addr, sizeof(__local_ip_addr));
// Build 'ping' request
if ((pkt = __pktbuf_alloc(ETH_MAX_PKTLEN)) == NULL) {
// Give up if no packets - something is wrong
break;
@@ -207,32 +209,40 @@ do_ping(int argc, char *argv[])
__pktbuf_free(pkt);
start_time = MS_TICKS();
timer = start_time + timeout;
icmp_received = false;
- while (!icmp_received && (MS_TICKS_DELAY() < timer)) {
+ while (!icmp_received && (MS_TICKS_DELAY() < timer)) {
+ if (_rb_break(1)) {
+ goto abort;
+ }
+ MS_TICKS_DELAY();
__enet_poll();
}
end_time = MS_TICKS();
timer = MS_TICKS() + rate;
while (MS_TICKS_DELAY() < timer) {
+ if (_rb_break(1)) {
+ goto abort;
+ }
+ MS_TICKS_DELAY();
__enet_poll();
}
- // Clean up
- memcpy(__local_ip_addr, &hold_addr, sizeof(__local_ip_addr));
-
if (icmp_received) {
received++;
if (verbose) {
diag_printf(" seq: %ld, time: %ld (ticks)\n",
ntohs(hold_hdr.seqnum), end_time-start_time);
}
}
}
+ abort:
__icmp_remove_listener();
+ // Clean up
+ memcpy(__local_ip_addr, &hold_addr, sizeof(__local_ip_addr));
// Report
diag_printf("PING - received %ld of %ld expected\n", received, count);
}
#endif //CYGPKG_REDBOOT_NETWORKING