Skip to contentSkip to conversation

netconsole: various improvements

PATCH RESEND In review Tony Dinh 3 participants 13 messages Apr 3, 2023 – May 9, 2023

Subsystems (2)
lore
Share & tools
lore

Tony Dinh

author
#0 lore raw

PATCH RESEND v2 1/1 netconsole: various improvements

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

---

Changes in v2:
- Select CONFIG_CONSOLE_MUX if CONFIG_NETCONSOLE is enabled
- Add new functions in netconsole driver to support CONSOLE_MUX
- Add new function to encapsulate the process of stopping netconsole from bootm
- Remove unecessary net_timeout initial value = 1
- Resend to correct missing <stdio_dev.h> include in bootm.c

 boot/bootm.c             | 14 +++++++---
 drivers/net/Kconfig      | 10 +++++++
 drivers/net/netconsole.c | 60 ++++++++++++++++++++++++++++++++++++++++
 include/stdio_dev.h      |  1 +
 4 files changed, 81 insertions(+), 4 deletions(-)
boot/bootm.c +10 -4
index 2eec60ec7b..1b2542b570 100644
@@ -18,6 +18,7 @@
 #include <malloc.h>
 #include <mapmem.h>
 #include <net.h>
+#include <stdio_dev.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -472,11 +473,16 @@ ulong bootm_disable_interrupts(void)
 	 * recover from any failures any more...
 	 */
 	iflag = disable_interrupts();
-#ifdef CONFIG_NETCONSOLE
-	/* Stop the ethernet stack if NetConsole could have left it up */
-	eth_halt();
-#endif
 
+	if (IS_ENABLED(CONFIG_NETCONSOLE)) {
+		/*
+		 * Make sure that the starting kernel message printed out,
+		 * stop netconsole and the ethernet stack
+		 */
+		printf("\n\nStarting kernel ...\n\n");
+		drv_nc_stop();
+		eth_halt();
+	}
 #if defined(CONFIG_CMD_USB)
 	/*
 	 * turn off USB to prevent the host controller from writing to the
drivers/net/Kconfig +10 -0
index ceadee98a1..0661059dfa 100644
@@ -945,4 +945,14 @@ config MDIO_MUX_MESON_G12A
 	  This driver is used for the MDIO mux found on the Amlogic G12A & compatible
 	  SoCs.
 
+config NETCONSOLE
+	bool "Enable netconsole"
+	select CONSOLE_MUX
+	help
+	  NetConsole requires CONSOLE_MUX, i.e. at least one default console such
+	  must be specified in addition to nc console. For example, for boards that
+	  the main console is serial, set each of the envs stdin/stdout/stderr to serial,nc.
+	  See CONFIG_CONSOLE_MUX and CONFIG_SYS_CONSOLE_IS_IN_ENV help for detailed
+	  description of usage.
+
 endif # NETDEVICES
drivers/net/netconsole.c +60 -0

93 lines not on this page · raw message

include/stdio_dev.h +1 -0
index 3105928970..9d2375a67e 100644
@@ -112,6 +112,7 @@ int drv_keyboard_init(void);
 int drv_usbtty_init(void);
 int drv_usbacm_init(void);
 int drv_nc_init(void);
+void drv_nc_stop(void);
 int drv_jtag_console_init(void);
 int cbmemc_init(void);
 
Signature · 1 line
2.30.2
author
#1 lore raw

Hi Ramon,
Hi Joe,

Any comments on this patch?

Thanks,
Tony

Quoted 194 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

---

Changes in v2:
- Select CONFIG_CONSOLE_MUX if CONFIG_NETCONSOLE is enabled
- Add new functions in netconsole driver to support CONSOLE_MUX
- Add new function to encapsulate the process of stopping netconsole from bootm
- Remove unecessary net_timeout initial value = 1
- Resend to correct missing <stdio_dev.h> include in bootm.c

 boot/bootm.c             | 14 +++++++---
 drivers/net/Kconfig      | 10 +++++++
 drivers/net/netconsole.c | 60 ++++++++++++++++++++++++++++++++++++++++
 include/stdio_dev.h      |  1 +
 4 files changed, 81 insertions(+), 4 deletions(-)
boot/bootm.c +10 -4
index 2eec60ec7b..1b2542b570 100644
@@ -18,6 +18,7 @@
 #include <malloc.h>
 #include <mapmem.h>
 #include <net.h>
+#include <stdio_dev.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -472,11 +473,16 @@ ulong bootm_disable_interrupts(void)
         * recover from any failures any more...
         */
        iflag = disable_interrupts();
-#ifdef CONFIG_NETCONSOLE
-       /* Stop the ethernet stack if NetConsole could have left it up */
-       eth_halt();
-#endif
 
+       if (IS_ENABLED(CONFIG_NETCONSOLE)) {
+               /*
+                * Make sure that the starting kernel message printed out,
+                * stop netconsole and the ethernet stack
+                */
+               printf("\n\nStarting kernel ...\n\n");
+               drv_nc_stop();
+               eth_halt();
+       }
 #if defined(CONFIG_CMD_USB)
        /*
         * turn off USB to prevent the host controller from writing to the
drivers/net/Kconfig +10 -0
index ceadee98a1..0661059dfa 100644
@@ -945,4 +945,14 @@ config MDIO_MUX_MESON_G12A
          This driver is used for the MDIO mux found on the Amlogic G12A & compatible
          SoCs.
 
+config NETCONSOLE
+       bool "Enable netconsole"
+       select CONSOLE_MUX
+       help
+         NetConsole requires CONSOLE_MUX, i.e. at least one default console such
+         must be specified in addition to nc console. For example, for boards that
+         the main console is serial, set each of the envs stdin/stdout/stderr to serial,nc.
+         See CONFIG_CONSOLE_MUX and CONFIG_SYS_CONSOLE_IS_IN_ENV help for detailed
+         description of usage.
+
 endif # NETDEVICES
drivers/net/netconsole.c +60 -0
index 151bc55e07..bb92d2e130 100644
@@ -7,6 +7,7 @@
 #include <common.h>
 #include <command.h>
 #include <env.h>
+#include <iomux.h>
 #include <log.h>
 #include <stdio_dev.h>
 #include <net.h>
@@ -33,6 +34,12 @@ static int output_packet_len;
  */
 enum proto_t net_loop_last_protocol = BOOTP;
 
+/*
+ * Net console helpers
+ */
+static void usage(void);
+static void remove_nc_from(const int console);
+
 static void nc_wait_arp_handler(uchar *pkt, unsigned dest,
                                 struct in_addr sip, unsigned src,
                                 unsigned len)
@@ -111,6 +118,21 @@ static int refresh_settings_from_env(void)
        return 0;
 }
 
+static void remove_nc_from(const int console)
+{
+       int ret;
+
+       ret = iomux_replace_device(console, "nc", "nulldev");
+       if (ret) {
+               printf("\n*** Warning: Cannot remove nc from %s Error=%d\n",
+                       stdio_names[console], ret);
+               printf("%s=", stdio_names[console]);
+               iomux_printdevs(console);
+               usage();
+               flush();
+       }
+}
+
 /**
  * Called from net_loop in net/net.c before each packet
  */
@@ -241,6 +263,29 @@ static int nc_stdio_start(struct stdio_dev *dev)
        return 0;
 }
 
+void nc_stdio_stop(void)
+{
+       if (IS_ENABLED(CONFIG_CONSOLE_MUX)) {
+               int ret;
+               struct stdio_dev *sdev;
+
+               /* Remove nc from each stdio file  */
+               remove_nc_from(stdin);
+               remove_nc_from(stderr);
+               remove_nc_from(stdout);
+
+               /* Deregister nc device */
+               sdev = stdio_get_by_name("nc");
+               ret = stdio_deregister_dev(sdev, true);
+               if (ret)
+                       printf("\nWarning: Cannot deregister nc console Error=%d\n", ret);
+       } else {
+               printf("\n*** Warning: CONFIG_CONSOLE_MUX must be enabled for netconsole\n"
+                       "to work properly. The nc console will be removed when\n"
+                       "netconsole driver stops\n");
+       }
+}
+
 static void nc_stdio_putc(struct stdio_dev *dev, char c)
 {
        if (output_recursion)
@@ -316,6 +361,16 @@ static int nc_stdio_tstc(struct stdio_dev *dev)
        return input_size != 0;
 }
 
+static void usage(void)
+{
+       printf("USAGE:\n"
+               "NetConsole requires CONFIG_CONSOLE_MUX. At least one default console\n"
+               "must be specified in addition to nc console. For example, for boards\n"
+               "that the main console is serial, set the each of envs stdin/stdout/stderr\n"
+               "to serial,nc. Some kernel might fail to boot when nc is the only device in\n"
+               "stdout list\n");
+}
+
 int drv_nc_init(void)
 {
        struct stdio_dev dev;
@@ -335,3 +390,8 @@ int drv_nc_init(void)
 
        return (rc == 0) ? 1 : rc;
 }
+
+void drv_nc_stop(void)
+{
+       nc_stdio_stop();
+}
include/stdio_dev.h +1 -1
index 3105928970..9d2375a67e 100644
@@ -112,6 +112,7 @@ int drv_keyboard_init(void);
 int drv_usbtty_init(void);
 int drv_usbacm_init(void);
 int drv_nc_init(void);
+void drv_nc_stop(void);
 int drv_jtag_console_init(void);
 int cbmemc_init(void);
 
--

2.30.2

#2 lore raw
In reply to Tony Dinh

Hi Tony,

Quoted 18 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

---

Changes in v2:
- Select CONFIG_CONSOLE_MUX if CONFIG_NETCONSOLE is enabled
- Add new functions in netconsole driver to support CONSOLE_MUX
- Add new function to encapsulate the process of stopping netconsole from bootm
- Remove unecessary net_timeout initial value = 1
- Resend to correct missing <stdio_dev.h> include in bootm.c

Quoted 5 lines
 boot/bootm.c             | 14 +++++++---
 drivers/net/Kconfig      | 10 +++++++
 drivers/net/netconsole.c | 60 ++++++++++++++++++++++++++++++++++++++++
 include/stdio_dev.h      |  1 +
 4 files changed, 81 insertions(+), 4 deletions(-)

This seems OK to me but for a few thoughts below.

But can we use this opportunity to move this to driver model? The netconsole driver could be bound in eth_post_bind() and the code in netconsole.c converted to be a driver.

I think that would be better than building on an out-of-date driver.

Quoted 132 lines
boot/bootm.c +10 -4
index 2eec60ec7b..1b2542b570 100644
@@ -18,6 +18,7 @@
 #include <malloc.h>
 #include <mapmem.h>
 #include <net.h>
+#include <stdio_dev.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -472,11 +473,16 @@ ulong bootm_disable_interrupts(void)
         * recover from any failures any more...
         */
        iflag = disable_interrupts();
-#ifdef CONFIG_NETCONSOLE
-       /* Stop the ethernet stack if NetConsole could have left it up */
-       eth_halt();
-#endif
 
+       if (IS_ENABLED(CONFIG_NETCONSOLE)) {
+               /*
+                * Make sure that the starting kernel message printed out,
+                * stop netconsole and the ethernet stack
+                */
+               printf("\n\nStarting kernel ...\n\n");
+               drv_nc_stop();
+               eth_halt();
+       }
 #if defined(CONFIG_CMD_USB)
        /*
         * turn off USB to prevent the host controller from writing to the
drivers/net/Kconfig +10 -0
index ceadee98a1..0661059dfa 100644
@@ -945,4 +945,14 @@ config MDIO_MUX_MESON_G12A
          This driver is used for the MDIO mux found on the Amlogic G12A & compatible
          SoCs.
 
+config NETCONSOLE
+       bool "Enable netconsole"
+       select CONSOLE_MUX
+       help
+         NetConsole requires CONSOLE_MUX, i.e. at least one default console such
+         must be specified in addition to nc console. For example, for boards that
+         the main console is serial, set each of the envs stdin/stdout/stderr to serial,nc.
+         See CONFIG_CONSOLE_MUX and CONFIG_SYS_CONSOLE_IS_IN_ENV help for detailed
+         description of usage.
+
 endif # NETDEVICES
drivers/net/netconsole.c +45 -0
index 151bc55e07..bb92d2e130 100644
@@ -7,6 +7,7 @@
 #include <common.h>
 #include <command.h>
 #include <env.h>
+#include <iomux.h>
 #include <log.h>
 #include <stdio_dev.h>
 #include <net.h>
@@ -33,6 +34,12 @@ static int output_packet_len;
  */
 enum proto_t net_loop_last_protocol = BOOTP;
 
+/*
+ * Net console helpers
+ */
+static void usage(void);
+static void remove_nc_from(const int console);
+
 static void nc_wait_arp_handler(uchar *pkt, unsigned dest,
                                 struct in_addr sip, unsigned src,
                                 unsigned len)
@@ -111,6 +118,21 @@ static int refresh_settings_from_env(void)
        return 0;
 }
 
+static void remove_nc_from(const int console)
+{
+       int ret;
+
+       ret = iomux_replace_device(console, "nc", "nulldev");
+       if (ret) {
+               printf("\n*** Warning: Cannot remove nc from %s Error=%d\n",
+                       stdio_names[console], ret);
+               printf("%s=", stdio_names[console]);
+               iomux_printdevs(console);
+               usage();
+               flush();
+       }
+}
+
 /**
  * Called from net_loop in net/net.c before each packet
  */
@@ -241,6 +263,29 @@ static int nc_stdio_start(struct stdio_dev *dev)
        return 0;
 }
 
+void nc_stdio_stop(void)
+{
+       if (IS_ENABLED(CONFIG_CONSOLE_MUX)) {
+               int ret;
+               struct stdio_dev *sdev;
+
+               /* Remove nc from each stdio file  */
+               remove_nc_from(stdin);
+               remove_nc_from(stderr);
+               remove_nc_from(stdout);
+
+               /* Deregister nc device */
+               sdev = stdio_get_by_name("nc");
+               ret = stdio_deregister_dev(sdev, true);
+               if (ret)
+                       printf("\nWarning: Cannot deregister nc console Error=%d\n", ret);
+       } else {
+               printf("\n*** Warning: CONFIG_CONSOLE_MUX must be enabled for netconsole\n"
+                       "to work properly. The nc console will be removed when\n"
+                       "netconsole driver stops\n");
+       }
+}
+
 static void nc_stdio_putc(struct stdio_dev *dev, char c)
 {
        if (output_recursion)
@@ -316,6 +361,16 @@ static int nc_stdio_tstc(struct stdio_dev *dev)
        return input_size != 0;

drivers/net/netconsole.c static int nc_stdio_tstc(struct stdio_dev *dev) · line 371

Quoted 10 lines
drivers/net/netconsole.c +8 -0
 }
 
+static void usage(void)
+{
+       printf("USAGE:\n"
+               "NetConsole requires CONFIG_CONSOLE_MUX. At least one default console\n"
+               "must be specified in addition to nc console. For example, for boards\n"
+               "that the main console is serial, set the each of envs stdin/stdout/stderr\n"
+               "to serial,nc. Some kernel might fail to boot when nc is the only device in\n"
+               "stdout list\n");

How about creating a doc/ file with info about net console? This is a bit too much text to put in a user message.

Quoted 19 lines
drivers/net/netconsole.c +7 -0
+}
+
 int drv_nc_init(void)
 {
        struct stdio_dev dev;
@@ -335,3 +390,8 @@ int drv_nc_init(void)
 
        return (rc == 0) ? 1 : rc;
 }
+
+void drv_nc_stop(void)
+{
+       nc_stdio_stop();
+}
include/stdio_dev.h +0 -0
index 3105928970..9d2375a67e 100644

include/stdio_dev.h int drv_keyboard_init(void); · line 115

Quoted 4 lines
include/stdio_dev.h +1 -0
@@ -112,6 +112,7 @@ int drv_keyboard_init(void);
 int drv_usbtty_init(void);
 int drv_usbacm_init(void);
 int drv_nc_init(void);
+void drv_nc_stop(void);

Once this is a driver we won't need this.

include/stdio_dev.h int drv_keyboard_init(void); · line 117

Quoted 2 lines
include/stdio_dev.h +0 -0
 int drv_jtag_console_init(void);
 int cbmemc_init(void);

Regards,
Simon

author
#3 lore raw

HI Simon,

Quoted 28 lines · Simon Glass

Hi Tony,

Quoted 18 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

---

Changes in v2:
- Select CONFIG_CONSOLE_MUX if CONFIG_NETCONSOLE is enabled
- Add new functions in netconsole driver to support CONSOLE_MUX
- Add new function to encapsulate the process of stopping netconsole from bootm
- Remove unecessary net_timeout initial value = 1
- Resend to correct missing <stdio_dev.h> include in bootm.c

Quoted 5 lines
 boot/bootm.c             | 14 +++++++---
 drivers/net/Kconfig      | 10 +++++++
 drivers/net/netconsole.c | 60 ++++++++++++++++++++++++++++++++++++++++
 include/stdio_dev.h      |  1 +
 4 files changed, 81 insertions(+), 4 deletions(-)
Quoted 7 lines

This seems OK to me but for a few thoughts below.

But can we use this opportunity to move this to driver model? The netconsole driver could be bound in eth_post_bind() and the code in netconsole.c converted to be a driver.

I think that would be better than building on an out-of-date driver.

I'd agree that converting to a driver model is the logical next step. My motivation is to fix the booting problem for the Linux kernel first (I'm having problems booting some kernels without this patch). And then in the next go round, I'll convert netconsole to a driver. Most of the code in this small patch will be needed whether it is an old driver or DM anyway.

Quoted 135 lines
Quoted 135 lines
boot/bootm.c +10 -4
index 2eec60ec7b..1b2542b570 100644
@@ -18,6 +18,7 @@
 #include <malloc.h>
 #include <mapmem.h>
 #include <net.h>
+#include <stdio_dev.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -472,11 +473,16 @@ ulong bootm_disable_interrupts(void)
         * recover from any failures any more...
         */
        iflag = disable_interrupts();
-#ifdef CONFIG_NETCONSOLE
-       /* Stop the ethernet stack if NetConsole could have left it up */
-       eth_halt();
-#endif
 
+       if (IS_ENABLED(CONFIG_NETCONSOLE)) {
+               /*
+                * Make sure that the starting kernel message printed out,
+                * stop netconsole and the ethernet stack
+                */
+               printf("\n\nStarting kernel ...\n\n");
+               drv_nc_stop();
+               eth_halt();
+       }
 #if defined(CONFIG_CMD_USB)
        /*
         * turn off USB to prevent the host controller from writing to the
drivers/net/Kconfig +10 -0
index ceadee98a1..0661059dfa 100644
@@ -945,4 +945,14 @@ config MDIO_MUX_MESON_G12A
          This driver is used for the MDIO mux found on the Amlogic G12A & compatible
          SoCs.
 
+config NETCONSOLE
+       bool "Enable netconsole"
+       select CONSOLE_MUX
+       help
+         NetConsole requires CONSOLE_MUX, i.e. at least one default console such
+         must be specified in addition to nc console. For example, for boards that
+         the main console is serial, set each of the envs stdin/stdout/stderr to serial,nc.
+         See CONFIG_CONSOLE_MUX and CONFIG_SYS_CONSOLE_IS_IN_ENV help for detailed
+         description of usage.
+
 endif # NETDEVICES
drivers/net/netconsole.c +45 -0
index 151bc55e07..bb92d2e130 100644
@@ -7,6 +7,7 @@
 #include <common.h>
 #include <command.h>
 #include <env.h>
+#include <iomux.h>
 #include <log.h>
 #include <stdio_dev.h>
 #include <net.h>
@@ -33,6 +34,12 @@ static int output_packet_len;
  */
 enum proto_t net_loop_last_protocol = BOOTP;
 
+/*
+ * Net console helpers
+ */
+static void usage(void);
+static void remove_nc_from(const int console);
+
 static void nc_wait_arp_handler(uchar *pkt, unsigned dest,
                                 struct in_addr sip, unsigned src,
                                 unsigned len)
@@ -111,6 +118,21 @@ static int refresh_settings_from_env(void)
        return 0;
 }
 
+static void remove_nc_from(const int console)
+{
+       int ret;
+
+       ret = iomux_replace_device(console, "nc", "nulldev");
+       if (ret) {
+               printf("\n*** Warning: Cannot remove nc from %s Error=%d\n",
+                       stdio_names[console], ret);
+               printf("%s=", stdio_names[console]);
+               iomux_printdevs(console);
+               usage();
+               flush();
+       }
+}
+
 /**
  * Called from net_loop in net/net.c before each packet
  */
@@ -241,6 +263,29 @@ static int nc_stdio_start(struct stdio_dev *dev)
        return 0;
 }
 
+void nc_stdio_stop(void)
+{
+       if (IS_ENABLED(CONFIG_CONSOLE_MUX)) {
+               int ret;
+               struct stdio_dev *sdev;
+
+               /* Remove nc from each stdio file  */
+               remove_nc_from(stdin);
+               remove_nc_from(stderr);
+               remove_nc_from(stdout);
+
+               /* Deregister nc device */
+               sdev = stdio_get_by_name("nc");
+               ret = stdio_deregister_dev(sdev, true);
+               if (ret)
+                       printf("\nWarning: Cannot deregister nc console Error=%d\n", ret);
+       } else {
+               printf("\n*** Warning: CONFIG_CONSOLE_MUX must be enabled for netconsole\n"
+                       "to work properly. The nc console will be removed when\n"
+                       "netconsole driver stops\n");
+       }
+}
+
 static void nc_stdio_putc(struct stdio_dev *dev, char c)
 {
        if (output_recursion)
@@ -316,6 +361,16 @@ static int nc_stdio_tstc(struct stdio_dev *dev)
        return input_size != 0;
 }
 
Quoted 11 lines

drivers/net/netconsole.c static int nc_stdio_tstc(struct stdio_dev *dev) · line 371

Quoted 8 lines
drivers/net/netconsole.c +8 -0
+static void usage(void)
+{
+       printf("USAGE:\n"
+               "NetConsole requires CONFIG_CONSOLE_MUX. At least one default console\n"
+               "must be specified in addition to nc console. For example, for boards\n"
+               "that the main console is serial, set the each of envs stdin/stdout/stderr\n"
+               "to serial,nc. Some kernel might fail to boot when nc is the only device in\n"
+               "stdout list\n");

How about creating a doc/ file with info about net console? This is a bit too much text to put in a user message.

Sure.

Quoted 18 lines
Quoted 18 lines
drivers/net/netconsole.c +7 -0
+}
+
 int drv_nc_init(void)
 {
        struct stdio_dev dev;
@@ -335,3 +390,8 @@ int drv_nc_init(void)
 
        return (rc == 0) ? 1 : rc;
 }
+
+void drv_nc_stop(void)
+{
+       nc_stdio_stop();
+}
include/stdio_dev.h +0 -1
index 3105928970..9d2375a67e 100644
--- a/include/stdio_dev.h
Quoted 8 lines

include/stdio_dev.h int drv_keyboard_init(void); · line 115

Quoted 6 lines

+++ b/include/stdio_dev.h

include/stdio_dev.h +1 -0
@@ -112,6 +112,7 @@ int drv_keyboard_init(void);
 int drv_usbtty_init(void);
 int drv_usbacm_init(void);
 int drv_nc_init(void);
+void drv_nc_stop(void);

Once this is a driver we won't need this.

Yes, but we still need the nc_stdio_stop() to do the cleanup, i.e. removing nc from stdin/stdout/stderr and deregistering the nc device. Except that it will be a uclass member like .pre_remove()?

It will be a bit of a learning curve for me to do the DM netconsole. But I will give it a shot.

Thanks,
Tony

Quoted 6 lines

include/stdio_dev.h int drv_keyboard_init(void); · line 117

Quoted 3 lines
include/stdio_dev.h +0 -0
 int drv_jtag_console_init(void);
 int cbmemc_init(void);

Regards,
Simon

author
#4 lore raw
Quoted 223 lines · Tony Dinh

HI Simon,

Quoted 28 lines · Simon Glass

Hi Tony,

Quoted 18 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

---

Changes in v2:
- Select CONFIG_CONSOLE_MUX if CONFIG_NETCONSOLE is enabled
- Add new functions in netconsole driver to support CONSOLE_MUX
- Add new function to encapsulate the process of stopping netconsole from bootm
- Remove unecessary net_timeout initial value = 1
- Resend to correct missing <stdio_dev.h> include in bootm.c

Quoted 5 lines
 boot/bootm.c             | 14 +++++++---
 drivers/net/Kconfig      | 10 +++++++
 drivers/net/netconsole.c | 60 ++++++++++++++++++++++++++++++++++++++++
 include/stdio_dev.h      |  1 +
 4 files changed, 81 insertions(+), 4 deletions(-)
Quoted 7 lines

This seems OK to me but for a few thoughts below.

But can we use this opportunity to move this to driver model? The netconsole driver could be bound in eth_post_bind() and the code in netconsole.c converted to be a driver.

I think that would be better than building on an out-of-date driver.

I'd agree that converting to a driver model is the logical next step. My motivation is to fix the booting problem for the Linux kernel first (I'm having problems booting some kernels without this patch). And then in the next go round, I'll convert netconsole to a driver. Most of the code in this small patch will be needed whether it is an old driver or DM anyway.

Quoted 135 lines
Quoted 135 lines
boot/bootm.c +10 -4
index 2eec60ec7b..1b2542b570 100644
@@ -18,6 +18,7 @@
 #include <malloc.h>
 #include <mapmem.h>
 #include <net.h>
+#include <stdio_dev.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -472,11 +473,16 @@ ulong bootm_disable_interrupts(void)
         * recover from any failures any more...
         */
        iflag = disable_interrupts();
-#ifdef CONFIG_NETCONSOLE
-       /* Stop the ethernet stack if NetConsole could have left it up */
-       eth_halt();
-#endif
 
+       if (IS_ENABLED(CONFIG_NETCONSOLE)) {
+               /*
+                * Make sure that the starting kernel message printed out,
+                * stop netconsole and the ethernet stack
+                */
+               printf("\n\nStarting kernel ...\n\n");
+               drv_nc_stop();
+               eth_halt();
+       }
 #if defined(CONFIG_CMD_USB)
        /*
         * turn off USB to prevent the host controller from writing to the
drivers/net/Kconfig +10 -0
index ceadee98a1..0661059dfa 100644
@@ -945,4 +945,14 @@ config MDIO_MUX_MESON_G12A
          This driver is used for the MDIO mux found on the Amlogic G12A & compatible
          SoCs.
 
+config NETCONSOLE
+       bool "Enable netconsole"
+       select CONSOLE_MUX
+       help
+         NetConsole requires CONSOLE_MUX, i.e. at least one default console such
+         must be specified in addition to nc console. For example, for boards that
+         the main console is serial, set each of the envs stdin/stdout/stderr to serial,nc.
+         See CONFIG_CONSOLE_MUX and CONFIG_SYS_CONSOLE_IS_IN_ENV help for detailed
+         description of usage.
+
 endif # NETDEVICES
drivers/net/netconsole.c +45 -0
index 151bc55e07..bb92d2e130 100644
@@ -7,6 +7,7 @@
 #include <common.h>
 #include <command.h>
 #include <env.h>
+#include <iomux.h>
 #include <log.h>
 #include <stdio_dev.h>
 #include <net.h>
@@ -33,6 +34,12 @@ static int output_packet_len;
  */
 enum proto_t net_loop_last_protocol = BOOTP;
 
+/*
+ * Net console helpers
+ */
+static void usage(void);
+static void remove_nc_from(const int console);
+
 static void nc_wait_arp_handler(uchar *pkt, unsigned dest,
                                 struct in_addr sip, unsigned src,
                                 unsigned len)
@@ -111,6 +118,21 @@ static int refresh_settings_from_env(void)
        return 0;
 }
 
+static void remove_nc_from(const int console)
+{
+       int ret;
+
+       ret = iomux_replace_device(console, "nc", "nulldev");
+       if (ret) {
+               printf("\n*** Warning: Cannot remove nc from %s Error=%d\n",
+                       stdio_names[console], ret);
+               printf("%s=", stdio_names[console]);
+               iomux_printdevs(console);
+               usage();
+               flush();
+       }
+}
+
 /**
  * Called from net_loop in net/net.c before each packet
  */
@@ -241,6 +263,29 @@ static int nc_stdio_start(struct stdio_dev *dev)
        return 0;
 }
 
+void nc_stdio_stop(void)
+{
+       if (IS_ENABLED(CONFIG_CONSOLE_MUX)) {
+               int ret;
+               struct stdio_dev *sdev;
+
+               /* Remove nc from each stdio file  */
+               remove_nc_from(stdin);
+               remove_nc_from(stderr);
+               remove_nc_from(stdout);
+
+               /* Deregister nc device */
+               sdev = stdio_get_by_name("nc");
+               ret = stdio_deregister_dev(sdev, true);
+               if (ret)
+                       printf("\nWarning: Cannot deregister nc console Error=%d\n", ret);
+       } else {
+               printf("\n*** Warning: CONFIG_CONSOLE_MUX must be enabled for netconsole\n"
+                       "to work properly. The nc console will be removed when\n"
+                       "netconsole driver stops\n");
+       }
+}
+
 static void nc_stdio_putc(struct stdio_dev *dev, char c)
 {
        if (output_recursion)
@@ -316,6 +361,16 @@ static int nc_stdio_tstc(struct stdio_dev *dev)
        return input_size != 0;
 }
 
Quoted 11 lines

drivers/net/netconsole.c static int nc_stdio_tstc(struct stdio_dev *dev) · line 371

Quoted 8 lines
drivers/net/netconsole.c +8 -0
+static void usage(void)
+{
+       printf("USAGE:\n"
+               "NetConsole requires CONFIG_CONSOLE_MUX. At least one default console\n"
+               "must be specified in addition to nc console. For example, for boards\n"
+               "that the main console is serial, set the each of envs stdin/stdout/stderr\n"
+               "to serial,nc. Some kernel might fail to boot when nc is the only device in\n"
+               "stdout list\n");

How about creating a doc/ file with info about net console? This is a bit too much text to put in a user message.

Sure.

Quoted 18 lines
Quoted 18 lines
drivers/net/netconsole.c +7 -0
+}
+
 int drv_nc_init(void)
 {
        struct stdio_dev dev;
@@ -335,3 +390,8 @@ int drv_nc_init(void)
 
        return (rc == 0) ? 1 : rc;
 }
+
+void drv_nc_stop(void)
+{
+       nc_stdio_stop();
+}
include/stdio_dev.h +0 -1
index 3105928970..9d2375a67e 100644
--- a/include/stdio_dev.h
Quoted 8 lines

include/stdio_dev.h int drv_keyboard_init(void); · line 115

Quoted 6 lines

+++ b/include/stdio_dev.h

include/stdio_dev.h +1 -0
@@ -112,6 +112,7 @@ int drv_keyboard_init(void);
 int drv_usbtty_init(void);
 int drv_usbacm_init(void);
 int drv_nc_init(void);
+void drv_nc_stop(void);

Once this is a driver we won't need this.

Quoted 6 lines

Yes, but we still need the nc_stdio_stop() to do the cleanup, i.e. removing nc from stdin/stdout/stderr and deregistering the nc device. Except that it will be a uclass member like .pre_remove()?

It will be a bit of a learning curve for me to do the DM netconsole. But I will give it a shot.

In the meantime, can this patch get merged on its own merit as a bug fix?

All the best,
Tony

Quoted 10 lines

Thanks,
Tony

Quoted 6 lines

include/stdio_dev.h int drv_keyboard_init(void); · line 117

Quoted 3 lines
include/stdio_dev.h +0 -0
 int drv_jtag_console_init(void);
 int cbmemc_init(void);

Regards,
Simon

#5 lore raw

Hi Tony,

Quoted 40 lines · Tony Dinh
Quoted 38 lines · Tony Dinh

HI Simon,

Quoted 34 lines · Simon Glass

Hi Tony,

Quoted 18 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

---

Changes in v2:
- Select CONFIG_CONSOLE_MUX if CONFIG_NETCONSOLE is enabled
- Add new functions in netconsole driver to support CONSOLE_MUX
- Add new function to encapsulate the process of stopping netconsole from bootm
- Remove unecessary net_timeout initial value = 1
- Resend to correct missing <stdio_dev.h> include in bootm.c

Quoted 5 lines
 boot/bootm.c             | 14 +++++++---
 drivers/net/Kconfig      | 10 +++++++
 drivers/net/netconsole.c | 60 ++++++++++++++++++++++++++++++++++++++++
 include/stdio_dev.h      |  1 +
 4 files changed, 81 insertions(+), 4 deletions(-)

This seems OK to me but for a few thoughts below.

But can we use this opportunity to move this to driver model? The netconsole driver could be bound in eth_post_bind() and the code in netconsole.c converted to be a driver.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

I think that would be better than building on an out-of-date driver.

I'd agree that converting to a driver model is the logical next step. My motivation is to fix the booting problem for the Linux kernel first (I'm having problems booting some kernels without this patch). And then in the next go round, I'll convert netconsole to a driver. Most of the code in this small patch will be needed whether it is an old driver or DM anyway.

This crosses the line to a feature, IMO...

[..]

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

include/stdio_dev.h int drv_keyboard_init(void); · line 115

Quoted 9 lines
include/stdio_dev.h +1 -0
index 3105928970..9d2375a67e 100644
@@ -112,6 +112,7 @@ int drv_keyboard_init(void);
 int drv_usbtty_init(void);
 int drv_usbacm_init(void);
 int drv_nc_init(void);
+void drv_nc_stop(void);

Once this is a driver we won't need this.

Quoted 3 lines
Quoted 3 lines

Yes, but we still need the nc_stdio_stop() to do the cleanup, i.e. removing nc from stdin/stdout/stderr and deregistering the nc device. Except that it will be a uclass member like .pre_remove()?

Yes, or perhaps the driver's remove() method.

Quoted 5 lines
Quoted 3 lines

It will be a bit of a learning curve for me to do the DM netconsole. But I will give it a shot.

In the meantime, can this patch get merged on its own merit as a bug fix?

I suppose so, so long as you can figure out the conversion. Let me know if you have any questions.

Regards,
Simon

author
#6 lore raw

Hi Simon,

Quoted 46 lines · Simon Glass

Hi Tony,

Quoted 42 lines · Tony Dinh
Quoted 40 lines · Tony Dinh

HI Simon,

Quoted 35 lines · Simon Glass

Hi Tony,

Quoted 18 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

---

Changes in v2:
- Select CONFIG_CONSOLE_MUX if CONFIG_NETCONSOLE is enabled
- Add new functions in netconsole driver to support CONSOLE_MUX
- Add new function to encapsulate the process of stopping netconsole from bootm
- Remove unecessary net_timeout initial value = 1
- Resend to correct missing <stdio_dev.h> include in bootm.c

Quoted 5 lines
 boot/bootm.c             | 14 +++++++---
 drivers/net/Kconfig      | 10 +++++++
 drivers/net/netconsole.c | 60 ++++++++++++++++++++++++++++++++++++++++
 include/stdio_dev.h      |  1 +
 4 files changed, 81 insertions(+), 4 deletions(-)

This seems OK to me but for a few thoughts below.

But can we use this opportunity to move this to driver model? The netconsole driver could be bound in eth_post_bind() and the code in netconsole.c converted to be a driver.

I think that would be better than building on an out-of-date driver.

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

I'd agree that converting to a driver model is the logical next step. My motivation is to fix the booting problem for the Linux kernel first (I'm having problems booting some kernels without this patch). And then in the next go round, I'll convert netconsole to a driver. Most of the code in this small patch will be needed whether it is an old driver or DM anyway.

This crosses the line to a feature, IMO...

My initial patch would be a pure bug fix. But it also breaks other boards like Nokia, as Pali has pointed out. So in the v2 patch, Console Mux is introduced to cover all boards. I don't think that we are adding any features here.

It's just that I'm using netconsole often so I noticed the booting problem with recent Linux kernels. It's kind of a catch-22, without a serial console I cannot debug Linux early booting problems, and with serial console active there is no booting problem.

All the best,
Tony

Quoted 32 lines

[..]

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

include/stdio_dev.h int drv_keyboard_init(void); · line 115

Quoted 9 lines
include/stdio_dev.h +1 -0
index 3105928970..9d2375a67e 100644
@@ -112,6 +112,7 @@ int drv_keyboard_init(void);
 int drv_usbtty_init(void);
 int drv_usbacm_init(void);
 int drv_nc_init(void);
+void drv_nc_stop(void);

Once this is a driver we won't need this.

Quoted 3 lines
Quoted 3 lines

Yes, but we still need the nc_stdio_stop() to do the cleanup, i.e. removing nc from stdin/stdout/stderr and deregistering the nc device. Except that it will be a uclass member like .pre_remove()?

Yes, or perhaps the driver's remove() method.

Quoted 5 lines
Quoted 3 lines

It will be a bit of a learning curve for me to do the DM netconsole. But I will give it a shot.

In the meantime, can this patch get merged on its own merit as a bug fix?

I suppose so, so long as you can figure out the conversion. Let me know if you have any questions.

Regards,
Simon

#7 lore raw
Quoted 63 lines · Tony Dinh

Hi Simon,

Quoted 46 lines · Simon Glass

Hi Tony,

Quoted 42 lines · Tony Dinh
Quoted 40 lines · Tony Dinh

HI Simon,

Quoted 35 lines · Simon Glass

Hi Tony,

Quoted 18 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

---

Changes in v2:
- Select CONFIG_CONSOLE_MUX if CONFIG_NETCONSOLE is enabled
- Add new functions in netconsole driver to support CONSOLE_MUX
- Add new function to encapsulate the process of stopping netconsole from bootm
- Remove unecessary net_timeout initial value = 1
- Resend to correct missing <stdio_dev.h> include in bootm.c

Quoted 5 lines
 boot/bootm.c             | 14 +++++++---
 drivers/net/Kconfig      | 10 +++++++
 drivers/net/netconsole.c | 60 ++++++++++++++++++++++++++++++++++++++++
 include/stdio_dev.h      |  1 +
 4 files changed, 81 insertions(+), 4 deletions(-)

This seems OK to me but for a few thoughts below.

But can we use this opportunity to move this to driver model? The netconsole driver could be bound in eth_post_bind() and the code in netconsole.c converted to be a driver.

I think that would be better than building on an out-of-date driver.

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

I'd agree that converting to a driver model is the logical next step. My motivation is to fix the booting problem for the Linux kernel first (I'm having problems booting some kernels without this patch). And then in the next go round, I'll convert netconsole to a driver. Most of the code in this small patch will be needed whether it is an old driver or DM anyway.

This crosses the line to a feature, IMO...

My initial patch would be a pure bug fix. But it also breaks other boards like Nokia, as Pali has pointed out. So in the v2 patch, Console Mux is introduced to cover all boards. I don't think that we are adding any features here.

Quoted 4 lines

It's just that I'm using netconsole often so I noticed the booting problem with recent Linux kernels. It's kind of a catch-22, without a serial console I cannot debug Linux early booting problems, and with serial console active there is no booting problem.

Yes, we should fix functionality then work on clean-ups.

Signature · 1 line
Tom
#8 lore raw
In reply to Tony Dinh
Quoted 7 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

This breaks the ut_bootstd_bootflow_cmd_boot test on sandbox. I'm not sure if it's a test issue or something else.

Signature · 1 line
Tom
author
#9 lore raw

Hi Tom,

Quoted 9 lines · Tom Rini
Quoted 6 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

Quoted 4 lines
Quoted 1 line

This breaks the ut_bootstd_bootflow_cmd_boot test on sandbox. I'm not sure if it's a test issue or something else.

Thanks for trying, I'm having some difficulty building a sandbox u-boot, so I can't get to the point where I can see what's the problem yet.

All the best,
Tony

Quoted 3 lines

--
Tom

#10 lore raw

Hi Tony,

Quoted 13 lines · Tony Dinh

Hi Tom,

Quoted 9 lines · Tom Rini
Quoted 6 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

This breaks the ut_bootstd_bootflow_cmd_boot test on sandbox. I'm not sure if it's a test issue or something else.

Thanks for trying, I'm having some difficulty building a sandbox u-boot, so I can't get to the point where I can see what's the problem yet.

What is going wrong? Does this help?

https://u-boot.readthedocs.io/en/latest/build/gcc.html

Regards,
Simon

author
#11 lore raw

Hi Simon,

Quoted 22 lines · Simon Glass

Hi Tony,

Quoted 18 lines · Tony Dinh

Hi Tom,

Quoted 13 lines · Tom Rini
Quoted 7 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

This breaks the ut_bootstd_bootflow_cmd_boot test on sandbox. I'm not sure if it's a test issue or something else.

Quoted 7 lines
Quoted 3 lines

Thanks for trying, I'm having some difficulty building a sandbox u-boot, so I can't get to the point where I can see what's the problem yet.

What is going wrong? Does this help?

https://u-boot.readthedocs.io/en/latest/build/gcc.html

Yes, I've done that when I realized my ARM development box setup missed several Debian packages building sandbox (I only build Linux kernels and U-Boot boards natively on ARM). However, after installing all those packages it is still not possible to build a sandbox on ARM. So currently I am switching to cross compiling on my Intel laptop. Later, I'll come back to the ARM box to see whether we need some documentation update for doc/build/gcc.rst.

Thanks,
Tony

Quoted 3 lines

Regards,
Simon

author
#12 lore raw
Quoted 34 lines · Tony Dinh

Hi Simon,

Quoted 22 lines · Simon Glass

Hi Tony,

Quoted 18 lines · Tony Dinh

Hi Tom,

Quoted 13 lines · Tom Rini
Quoted 7 lines · Tony Dinh

Use CONFIG_CONSOLE_MUX for netconsole. When netconsole is running, stdin/stdout/stder must be set to some primary console, in addtion to nc. For example, stdin=serial,nc. Some recent Linux kernels will not boot with only nc on the stdout list, ie. stdout=nc. When netconsole exits, remove nc from the list of devices in stdin/stdout/stderr.

This breaks the ut_bootstd_bootflow_cmd_boot test on sandbox. I'm not sure if it's a test issue or something else.

Quoted 7 lines
Quoted 3 lines

Thanks for trying, I'm having some difficulty building a sandbox u-boot, so I can't get to the point where I can see what's the problem yet.

What is going wrong? Does this help?

https://u-boot.readthedocs.io/en/latest/build/gcc.html

Quoted 7 lines

Yes, I've done that when I realized my ARM development box setup missed several Debian packages building sandbox (I only build Linux kernels and U-Boot boards natively on ARM). However, after installing all those packages it is still not possible to build a sandbox on ARM. So currently I am switching to cross compiling on my Intel laptop. Later, I'll come back to the ARM box to see whether we need some documentation update for doc/build/gcc.rst.

FYI, what's missing in the doc/build/gcc.rst is the SDL option. I could not build without NO_SDL=1.

make sandbox_defconfig all NO_SDL=1

All the best,
Tony