From patchwork Mon Apr 3 21:41:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Dinh X-Patchwork-Id: 1764624 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=TDtZ6/+o; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pr49t2J2gz1yYb for ; Tue, 4 Apr 2023 07:42:24 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 398AA85829; Mon, 3 Apr 2023 23:42:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TDtZ6/+o"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 18BD385982; Mon, 3 Apr 2023 23:42:10 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BE0C4857B1 for ; Mon, 3 Apr 2023 23:42:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mibodhi@gmail.com Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-54601d90118so422878337b3.12 for ; Mon, 03 Apr 2023 14:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680558125; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JtFUhGCFMExnbyD6PtwUWYEwoccgyQngvvIVQMPs4to=; b=TDtZ6/+oGon7k72oEgNW+MWiGPhNYZ6w0Kep3DZipCXgv/bwvU5MWbK9d5hTIFJKm3 FJLE4ZdIeKy+JH3fDRD7m6CqIiS8fM8SufKZiXB+nzPaBWy96EApFb/2pNWVoN1cKexW al/nINqdPVZy0135rdpnDvjPBATToxzhFEKNgubQNQbOgCvhjppf365YziyGD042HOsF ZwSyakzjml1y/F4hD/EqJErMEqgeSScLHmj31GSV8FQ7t/D7yYkzE0gZBv7DEn4YquwO +gmSuffALIHlWAMb2bLr9bVCXUiLFBjiL8oP3hLoeCTzCUEvkfgZwj8z5Vq+GzG2K+Zw oP8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680558125; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JtFUhGCFMExnbyD6PtwUWYEwoccgyQngvvIVQMPs4to=; b=uHXzd8s6j2eRrVRb9EYVs1bERgMtoVO8l06dKsVpRp2DcyNGUp1X6OXpptrskZO1S7 RKDd6EYKe3HIdkcQd5bkyov/dsZKCzWJ0a7CGvexnAjgyCQTFha+r4xhRrtO3EDcDDkr Xi5ZyUbkIzHaBvkHUEq4O1LMTtJ5ElAgHuOsKSWUAZfp+9DthswV30+GwrOurVll6V64 tCV2iPYbD+bX5nOVKAQmnEtYu6nHNWymFaiY9uQM1sX9qqGIc3L05zLPgVLEpRQfwBiq WE6E/jGDK10WkaRTZ8EHWkn2DVX6Pps+uk5pCU09yLQOiJxmrgX4pFbzfaHlqe/vzL1z HLMw== X-Gm-Message-State: AAQBX9ffs4J2NJ+0blvZHI3GU/4LLAnlaT4kAEJmu3FaZ9pSp8ZRjePK Fiq3iRWK18eSbEKmXdNXrXY= X-Google-Smtp-Source: AKy350ZCqPMB/Cen7zbVbABFEdhU7zDxLO1HKYvnMSKXUjMKMVp/y23jj2gwXaZF+6R5zwr98sjuyg== X-Received: by 2002:a81:920f:0:b0:545:7635:335e with SMTP id j15-20020a81920f000000b005457635335emr379587ywg.30.1680558125475; Mon, 03 Apr 2023 14:42:05 -0700 (PDT) Received: from localhost.localdomain (76-229-100-169.lightspeed.irvnca.sbcglobal.net. [76.229.100.169]) by smtp.gmail.com with ESMTPSA id 135-20020a81088d000000b00545a0818470sm2781298ywi.0.2023.04.03.14.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 14:42:05 -0700 (PDT) From: Tony Dinh To: =?unknown-8bit?q?Joe_Hershberger_=3Cjoe=2Ehershberger=40ni=2Ecom=3E=2C_R?= =?unknown-8bit?q?amon_Fried_=3Crfried=2Edev=40gmail=2Ecom=3E=2C_Pali_Roh=E1?= =?unknown-8bit?q?r__=3Cpali=40kernel=2Eorg=3E=2C_Simon_Glass_=3Csjg=40chrom?= =?unknown-8bit?q?ium=2Eorg=3E=2C_Stefan_Roese_=3Csr=40denx=2Ede=3E=2C_U-Boo?= =?unknown-8bit?q?t_Mailing_List_=3Cu-boot=40lists=2Edenx=2Ede=3E?= Cc: Tom Rini , Tony Dinh , Daniel Golle , Sean Anderson Subject: [RESEND PATCH v2] netconsole: various improvements Date: Mon, 3 Apr 2023 14:41:52 -0700 Message-Id: <20230403214152.20225-1-mibodhi@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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. Signed-off-by: Tony Dinh --- 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 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(-) diff --git a/boot/bootm.c b/boot/bootm.c index 2eec60ec7b..1b2542b570 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -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 diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index ceadee98a1..0661059dfa 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -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 diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 151bc55e07..bb92d2e130 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -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(); +} diff --git a/include/stdio_dev.h b/include/stdio_dev.h index 3105928970..9d2375a67e 100644 --- a/include/stdio_dev.h +++ b/include/stdio_dev.h @@ -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);