This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem when debugging via gdb over ethernet


Guenter Ebermann wrote:
Hello,

I would propose the following change in eth_drv.c.

Had the problem when debugging with gdb over ethernet and a diag_printf (which
would then be redirected to the gdb-stub sitting in RedBoot ROMRAM) is used
during the ethernet driver is stopped my system crashed (using FEC driver on
MPC5200).

I found a config option which already exists and is used in the same way in other
files where the ethernet driver is stopped/reconfigured temporary.
I think it should be also used in this case.

The suspeced code is called from my RAM application indirectly from init_net() in
bootp_support.c.

Sorry my patch is against our local CVS repository. Our company restriced cvs access
to the outside. Anyway, I checked the place the code is on dev-head over WebCVS
... snip

What do you think?

I agree that this is a potential problem (just FYI, the notion of having debug I/O happen over the ethernet while the same interface was being configured was not present when I designed/wrote this code originally. It's a happy result, but there are many caveats to consider...)

I think that this protection belongs in the eth_drv_start() and
eth_drv_stop() functions, as they can be called from other places
and the problem you are seeing could potentially exist there
as well.

Can you try the attached patch to see if it works for you?

--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
Index: io/eth/current/src/net/eth_drv.c
===================================================================
--- io/eth/current/src/net/eth_drv.c	(revision 4174)
+++ io/eth/current/src/net/eth_drv.c	(working copy)
@@ -404,13 +404,58 @@
 }
 
 //
+// Helper functions which handle the case where an ethernet interface is
+// being used for debug/console I/O is also the one being meddled with.
+// In this case, calls to the I/O functions (e.g. diag_printf) are not
+// possible while the interface is in transition, such as being initialized
+// or reconfigured.
+//
+#ifdef CYGPKG_NET_FORCE_SERIAL_CONSOLE
+
+static int _orig_console = -1;
+
+static void
+start_safe_io(struct eth_drv_sc *sc)
+{
+    // 
+    // Tell the I/O layer to use a [hard-wired] serial console, rather than
+    // any network pseudo device, as the latter is the only safe alternative
+    // while the ethernet device is being [re]configured
+    //
+    if (orig_console == -1) {
+        orig_console = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
+        CYGACC_CALL_IF_SET_CONSOLE_COMM(0);
+    }
+}
+
+static void
+end_safe_io(struct eth_drv_sc *sc)
+{
+    //
+    // Restore the I/O console to what it was before the device started
+    // [low-level] [re]configuration.
+    //
+    if (orig_console != -1) {
+        CYGACC_CALL_IF_SET_CONSOLE_COMM(orig_console);
+        orig_console = -1;
+    }
+}
+#else
+#define start_safe_io(sc)
+#define end_safe_io(sc)
+#endif
+
+
+//
 // This [internal] function will be called to stop activity on an interface.
 //
 static void
 eth_drv_stop(struct eth_drv_sc *sc)
 {
     sc->state &= ~ETH_DRV_STATE_ACTIVE;
+    start_safe_io(sc);
     (sc->funs->stop)(sc);
+    end_safe_io(sc);
 }
 
 //
@@ -422,7 +467,9 @@
     struct ifnet *ifp = &sc->sc_arpcom.ac_if;
 
     // Perform any hardware initialization
+    start_safe_io(sc);
     (sc->funs->start)(sc, (unsigned char *)&sc->sc_arpcom.ac_enaddr, 0);
+    end_safe_io(sc);
 #ifdef CYGPKG_NET_FREEBSD_STACK
     // resend multicast addresses if present
     if(ifp->if_multiaddrs.lh_first && ifp->if_ioctl) {

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]