From patchwork Thu Dec 3 09:20:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1410224 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=TjACAivk; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cmr1153qtz9s1l for ; Thu, 3 Dec 2020 20:20:53 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DAE7E825D5; Thu, 3 Dec 2020 10:20:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=st.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=st.com header.i=@st.com header.b="TjACAivk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8D7DB8270C; Thu, 3 Dec 2020 10:20:41 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8E9578263B for ; Thu, 3 Dec 2020 10:20:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0B393GY0025837; Thu, 3 Dec 2020 10:20:37 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=4JGAz/U3zbCyC9kXeYcfSVEG4qgPVoUOSihe0T2gVvA=; b=TjACAivkC7cwvlEUFfmiv3crX5moqn2Qlx/Y1HeDqcI4kssUA+dYMD+ncql4iaFLoXLt 5Uheba7z5uOVYq5YRYsDIykyXZg+j+nKAvBZgbbCvE7E3GDhkxlKvthge2enJKie9sWf VTuh7vePbVyF5TB4uJOGj5xouH34ayd6Xd+M1oN7VGCTnP8j+S+rTkD+9Lfrym5YuZXx VqhgPtRvaJ7t2Bq0oIHO7/kYrC+Gn/oxO+qV9A3bjjY1E4wXyqXFuBOReMO2BrBQeYCy lkscCD/uHv+yD7zOxOPtQn3w1DCUgzFUDhdIa6a7c6rYVDdFrsZ7uNU5V/XTMGGudwI8 FA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 355w3e7um3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Dec 2020 10:20:37 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B046710002A; Thu, 3 Dec 2020 10:20:36 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id A46D023F6D5; Thu, 3 Dec 2020 10:20:36 +0100 (CET) Received: from localhost (10.75.127.49) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 3 Dec 2020 10:20:36 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Anatolij Gustschin , Bin Meng , Heinrich Schuchardt , Simon Glass , U-Boot STM32 Subject: [PATCH 1/4] console: remove #ifdef CONFIG when it is possible Date: Thu, 3 Dec 2020 10:20:28 +0100 Message-ID: <20201203102027.1.Iaf4e6c8a8adfa754adbf7a27200c0bc9e9f9b363@changeid> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201203092032.8124-1-patrick.delaunay@st.com> References: <20201203092032.8124-1-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG2NODE1.st.com (10.75.127.4) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-12-03_03:2020-12-03, 2020-12-03 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Remove #ifdef or #ifndef for CONFIG when it is possible to simplify the console.c code and respect the U-Boot coding rules. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- common/console.c | 149 +++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 88 deletions(-) diff --git a/common/console.c b/common/console.c index c3d552bb3e..6fc3957024 100644 --- a/common/console.c +++ b/common/console.c @@ -44,14 +44,15 @@ static int on_console(const char *name, const char *value, enum env_op op, case env_op_create: case env_op_overwrite: -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - if (iomux_doenv(console, value)) - return 1; -#else - /* Try assigning specified device */ - if (console_assign(console, value) < 0) - return 1; -#endif + if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { + if (iomux_doenv(console, value)) + return 1; + } else { + /* Try assigning specified device */ + if (console_assign(console, value) < 0) + return 1; + } + return 0; case env_op_delete: @@ -69,14 +70,13 @@ U_BOOT_ENV_CALLBACK(console, on_console); static int on_silent(const char *name, const char *value, enum env_op op, int flags) { -#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET) - if (flags & H_INTERACTIVE) - return 0; -#endif -#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC) - if ((flags & H_INTERACTIVE) == 0) - return 0; -#endif + if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET)) + if (flags & H_INTERACTIVE) + return 0; + + if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC)) + if ((flags & H_INTERACTIVE) == 0) + return 0; if (value != NULL) gd->flags |= GD_FLG_SILENT; @@ -159,14 +159,13 @@ static bool console_dev_is_serial(struct stdio_dev *sdev) { bool is_serial; -#ifdef CONFIG_DM_SERIAL - if (sdev->flags & DEV_FLAGS_DM) { + if (IS_ENABLED(CONFIG_DM_SERIAL) && (sdev->flags & DEV_FLAGS_DM)) { struct udevice *dev = sdev->priv; is_serial = device_get_uclass_id(dev) == UCLASS_SERIAL; - } else -#endif - is_serial = !strcmp(sdev->name, "serial"); + } else { + is_serial = !strcmp(sdev->name, "serial"); + } return is_serial; } @@ -350,13 +349,12 @@ int fgetc(int file) if (console_tstc(file)) return console_getc(file); #endif -#ifdef CONFIG_WATCHDOG /* * If the watchdog must be rate-limited then it should * already be handled in board-specific code. */ - udelay(1); -#endif + if (IS_ENABLED(CONFIG_WATCHDOG)) + udelay(1); } } @@ -406,10 +404,8 @@ int fprintf(int file, const char *fmt, ...) int getchar(void) { -#ifdef CONFIG_DISABLE_CONSOLE - if (gd->flags & GD_FLG_DISABLE_CONSOLE) + if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE)) return 0; -#endif if (!gd->have_console) return 0; @@ -434,10 +430,8 @@ int getchar(void) int tstc(void) { -#ifdef CONFIG_DISABLE_CONSOLE - if (gd->flags & GD_FLG_DISABLE_CONSOLE) + if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE)) return 0; -#endif if (!gd->have_console) return 0; @@ -485,10 +479,8 @@ static void print_pre_console_buffer(int flushpoint) char buf_out[CONFIG_PRE_CON_BUF_SZ + 1]; char *buf_in; -#ifdef CONFIG_SILENT_CONSOLE - if (gd->flags & GD_FLG_SILENT) + if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) return; -#endif buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ) @@ -530,25 +522,20 @@ void putc(const char c) return; } #endif -#ifdef CONFIG_DEBUG_UART /* if we don't have a console yet, use the debug UART */ - if (!(gd->flags & GD_FLG_SERIAL_READY)) { + if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) { printch(c); return; } -#endif -#ifdef CONFIG_SILENT_CONSOLE - if (gd->flags & GD_FLG_SILENT) { + + if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) { if (!(gd->flags & GD_FLG_DEVINIT)) pre_console_putc(c); return; } -#endif -#ifdef CONFIG_DISABLE_CONSOLE - if (gd->flags & GD_FLG_DISABLE_CONSOLE) + if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE)) return; -#endif if (!gd->have_console) return pre_console_putc(c); @@ -578,8 +565,8 @@ void puts(const char *s) return; } #endif -#ifdef CONFIG_DEBUG_UART - if (!(gd->flags & GD_FLG_SERIAL_READY)) { + + if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) { while (*s) { int ch = *s++; @@ -587,19 +574,15 @@ void puts(const char *s) } return; } -#endif -#ifdef CONFIG_SILENT_CONSOLE - if (gd->flags & GD_FLG_SILENT) { + + if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) { if (!(gd->flags & GD_FLG_DEVINIT)) pre_console_puts(s); return; } -#endif -#ifdef CONFIG_DISABLE_CONSOLE - if (gd->flags & GD_FLG_DISABLE_CONSOLE) + if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE)) return; -#endif if (!gd->have_console) return pre_console_puts(s); @@ -772,19 +755,19 @@ int console_assign(int file, const char *devname) /* return true if the 'silent' flag is removed */ static bool console_update_silent(void) { -#ifdef CONFIG_SILENT_CONSOLE - if (env_get("silent")) { - gd->flags |= GD_FLG_SILENT; - } else { - unsigned long flags = gd->flags; + unsigned long flags = gd->flags; - gd->flags &= ~GD_FLG_SILENT; + if (!IS_ENABLED(CONFIG_SILENT_CONSOLE)) + return false; - return !!(flags & GD_FLG_SILENT); + if (env_get("silent")) { + gd->flags |= GD_FLG_SILENT; + return false; } -#endif - return false; + gd->flags &= ~GD_FLG_SILENT; + + return !!(flags & GD_FLG_SILENT); } int console_announce_r(void) @@ -843,12 +826,8 @@ int console_init_r(void) { char *stdinname, *stdoutname, *stderrname; struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL; -#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE int i; -#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ -#if CONFIG_IS_ENABLED(CONSOLE_MUX) int iomux_err = 0; -#endif int flushpoint; /* update silent for env loaded from flash (initr_env) */ @@ -874,14 +853,14 @@ int console_init_r(void) inputdev = search_device(DEV_FLAGS_INPUT, stdinname); outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname); errdev = search_device(DEV_FLAGS_OUTPUT, stderrname); -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - iomux_err = iomux_doenv(stdin, stdinname); - iomux_err += iomux_doenv(stdout, stdoutname); - iomux_err += iomux_doenv(stderr, stderrname); - if (!iomux_err) - /* Successful, so skip all the code below. */ - goto done; -#endif + if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { + iomux_err = iomux_doenv(stdin, stdinname); + iomux_err += iomux_doenv(stdout, stdoutname); + iomux_err += iomux_doenv(stderr, stderrname); + if (!iomux_err) + /* Successful, so skip all the code below. */ + goto done; + } } /* if the devices are overwritten or not found, use default device */ if (inputdev == NULL) { @@ -907,25 +886,22 @@ int console_init_r(void) console_doenv(stdin, inputdev); } -#if CONFIG_IS_ENABLED(CONSOLE_MUX) done: -#endif -#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET - stdio_print_current_devices(); -#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ + if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET)) + stdio_print_current_devices(); + #ifdef CONFIG_VIDCONSOLE_AS_LCD if (strstr(stdoutname, CONFIG_VIDCONSOLE_AS_NAME)) printf("Warning: Please change '%s' to 'vidconsole' in stdout/stderr environment vars\n", CONFIG_VIDCONSOLE_AS_NAME); #endif -#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE - /* set the environment variables (will overwrite previous env settings) */ - for (i = 0; i < MAX_FILES; i++) { - env_set(stdio_names[i], stdio_devices[i]->name); + if (IS_ENABLED(CONFIG_SYS_CONSOLE_ENV_OVERWRITE)) { + /* set the environment variables (will overwrite previous env settings) */ + for (i = 0; i < MAX_FILES; i++) + env_set(stdio_names[i], stdio_devices[i]->name); } -#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ @@ -956,18 +932,16 @@ int console_init_r(void) else flushpoint = PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL; -#ifdef CONFIG_SPLASH_SCREEN /* * suppress all output if splash screen is enabled and we have * a bmp to display. We redirect the output from frame buffer * console to serial console in this case or suppress it if * "silent" mode was requested. */ - if (env_get("splashimage") != NULL) { + if (IS_ENABLED(CONFIG_SPLASH_SCREEN) && env_get("splashimage")) { if (!(gd->flags & GD_FLG_SILENT)) outputdev = search_device (DEV_FLAGS_OUTPUT, "serial"); } -#endif /* Scan devices looking for input and output devices */ list_for_each(pos, list) { @@ -1001,9 +975,8 @@ int console_init_r(void) #endif } -#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET - stdio_print_current_devices(); -#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ + if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET)) + stdio_print_current_devices(); /* Setting environment variables */ for (i = 0; i < MAX_FILES; i++) { From patchwork Thu Dec 3 09:20:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1410227 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=ArQU05kE; 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cmr1j6T0rz9sVY for ; Thu, 3 Dec 2020 20:21:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 76C3282807; Thu, 3 Dec 2020 10:20:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=st.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=st.com header.i=@st.com header.b="ArQU05kE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E64FC8280F; Thu, 3 Dec 2020 10:20:47 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 64FD08270C for ; Thu, 3 Dec 2020 10:20:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0B397i7T005962; Thu, 3 Dec 2020 10:20:40 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=a4Ut/s6FhEF9rF88SZ6qS+yBt2AE/KMWZqfz34Qg7pY=; b=ArQU05kELg4j1Wje8X1U/9dfe0ronfBr7C4nTHiQ2aBhljgl/H1q3uC0rjscn5elg2bL FjuTNhQEe38OI+DaPBWgxIhT+6WCUEqcgNgZzQ/Pjw5s27+b9QtqyiRsrWpGaNrnsSmj l+xeCeO5nwadv/MtaKFDwNDTtyBlgVHkniwv+14CbaMkbsqpt/S7wO42ASS4jDfkVs/e Cps7wo8J+hgPcvUOcTmthMFxMNNSbeTrve518hfNCkhvl1cTOJTXfawiz/uGvpnFew2Q o2N1/ikwq6V1LELbQcLjgKug0HoZkVKvpB7Hz4Stac+yoFlsAM4Ey7xqQTLAZqMBIk1A 1A== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 355w3hfqdx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Dec 2020 10:20:40 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 872BA10002A; Thu, 3 Dec 2020 10:20:37 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 77B1823F6D5; Thu, 3 Dec 2020 10:20:37 +0100 (CET) Received: from localhost (10.75.127.51) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 3 Dec 2020 10:20:37 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Anatolij Gustschin , Bin Meng , Heinrich Schuchardt , Simon Glass , U-Boot STM32 Subject: [PATCH 2/4] console: add function console_devices_set Date: Thu, 3 Dec 2020 10:20:29 +0100 Message-ID: <20201203102027.2.Icd4f9239c00329a77c50bc0c42b3638c744ea955@changeid> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201203092032.8124-1-patrick.delaunay@st.com> References: <20201203092032.8124-1-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG3NODE2.st.com (10.75.127.8) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-12-03_06:2020-12-03, 2020-12-03 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Add a new function to access to console_devices only defined if CONFIG_IS_ENABLED(CONSOLE_MUX). This path allows to remove #if CONFIG_IS_ENABLED(CONSOLE_MUX) in console_getc function. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- common/console.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/common/console.c b/common/console.c index 6fc3957024..9a63eaa664 100644 --- a/common/console.c +++ b/common/console.c @@ -177,6 +177,11 @@ static struct stdio_dev *tstcdev; struct stdio_dev **console_devices[MAX_FILES]; int cd_count[MAX_FILES]; +static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev) +{ + console_devices[file][0] = dev; +} + /* * This depends on tstc() always being called before getchar(). * This is guaranteed to be true because this routine is called @@ -275,6 +280,11 @@ static inline void console_doenv(int file, struct stdio_dev *dev) } #endif #else + +static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev) +{ +} + static inline int console_getc(int file) { return stdio_devices[file]->getc(stdio_devices[file]); @@ -961,18 +971,14 @@ int console_init_r(void) if (outputdev != NULL) { console_setfile(stdout, outputdev); console_setfile(stderr, outputdev); -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - console_devices[stdout][0] = outputdev; - console_devices[stderr][0] = outputdev; -#endif + console_devices_set(stdout, outputdev); + console_devices_set(stderr, outputdev); } /* Initializes input console */ if (inputdev != NULL) { console_setfile(stdin, inputdev); -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - console_devices[stdin][0] = inputdev; -#endif + console_devices_set(stdin, inputdev); } if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET)) From patchwork Thu Dec 3 09:20:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1410226 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=qivCMU6h; 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cmr1V5hcXz9s1l for ; Thu, 3 Dec 2020 20:21:18 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A5E8882800; Thu, 3 Dec 2020 10:20:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=st.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=st.com header.i=@st.com header.b="qivCMU6h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 102DC827F4; Thu, 3 Dec 2020 10:20:46 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 036608263B for ; Thu, 3 Dec 2020 10:20:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0B397hHZ005954; Thu, 3 Dec 2020 10:20:40 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=5ghMZ0wXbyZiUa3IN/DNYcT34r3/lt/nDmdrqozuOmY=; b=qivCMU6h9BMhF279NhKNU6GkMJOyzAJJgcVasuxID1q8OiKBEJ8088eLqSX/D0vtYWcU T+aaLhBr9Iu1VzrnNRWRXp7sMhrjOkryBQjE+IPnCop4pvC9iyDIJElZucz4EcxFJjAp DyrGCrFr7N7F11p4d4gxy1IM1efp19GWSSXUSLAKeyG11sjQiFxKF4q2l0+VMopkHQ8U q1pdkYGr3EUTlaO4wfSxL5dpPq3/hjqeH0LHlcPCh2elXEDmg6U2XbnwJMGrBKpsIrPa 3DjRs5lVTVwpPelFsASaFwOEiz7vIr7W893nzjq1i/mscHTMRAH7hSF6tw9dMoTD1L/g lQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 355w3hfqe1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Dec 2020 10:20:40 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6AD00100038; Thu, 3 Dec 2020 10:20:38 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 5CFDE23F6D5; Thu, 3 Dec 2020 10:20:38 +0100 (CET) Received: from localhost (10.75.127.49) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 3 Dec 2020 10:20:38 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Anatolij Gustschin , Bin Meng , Heinrich Schuchardt , Simon Glass , U-Boot STM32 Subject: [PATCH 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD Date: Thu, 3 Dec 2020 10:20:30 +0100 Message-ID: <20201203102027.3.I3e15d39becc5c180a3be52571bb570e29c6b4cd0@changeid> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201203092032.8124-1-patrick.delaunay@st.com> References: <20201203092032.8124-1-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-12-03_06:2020-12-03, 2020-12-03 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Add helper functions to access to gd->console_out and gd->console_in with membuff API and replace the #ifdef CONFIG_CONSOLE_RECORD test by if (IS_ENABLED(CONFIG_CONSOLE_RECORD)) to respect the U-Boot coding rule. Signed-off-by: Patrick Delaunay # Conflicts: # common/console.c Reviewed-by: Simon Glass --- common/console.c | 86 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/common/console.c b/common/console.c index 9a63eaa664..0b864444bb 100644 --- a/common/console.c +++ b/common/console.c @@ -88,6 +88,56 @@ static int on_silent(const char *name, const char *value, enum env_op op, U_BOOT_ENV_CALLBACK(silent, on_silent); #endif +#ifdef CONFIG_CONSOLE_RECORD +/* helper function: access to gd->console_out and gd->console_in */ +static void console_record_putc(const char c) +{ + if (gd->console_out.start) + membuff_putbyte((struct membuff *)&gd->console_out, c); +} + +static void console_record_puts(const char *s) +{ + if (gd->console_out.start) + membuff_put((struct membuff *)&gd->console_out, s, strlen(s)); +} + +static int console_record_getc(void) +{ + if (!gd->console_in.start) + return -1; + + return membuff_getbyte((struct membuff *)&gd->console_in); +} + +static int console_record_tstc(void) +{ + if (gd->console_in.start) { + if (membuff_peekbyte((struct membuff *)&gd->console_in) != -1) + return 1; + } + return 0; +} +#else +static void console_record_putc(char c) +{ +} + +static void console_record_puts(const char *s) +{ +} + +static int console_record_getc(void) +{ + return -1; +} + +static int console_record_tstc(void) +{ + return 0; +} +#endif + #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) /* * if overwrite_console returns 1, the stdin, stderr and stdout @@ -420,15 +470,13 @@ int getchar(void) if (!gd->have_console) return 0; -#ifdef CONFIG_CONSOLE_RECORD - if (gd->console_in.start) { - int ch; + if (IS_ENABLED(CONFIG_CONSOLE_RECORD)) { + int ch = console_record_getc(); - ch = membuff_getbyte((struct membuff *)&gd->console_in); if (ch != -1) - return 1; + return ch; } -#endif + if (gd->flags & GD_FLG_DEVINIT) { /* Get from the standard input */ return fgetc(stdin); @@ -445,12 +493,10 @@ int tstc(void) if (!gd->have_console) return 0; -#ifdef CONFIG_CONSOLE_RECORD - if (gd->console_in.start) { - if (membuff_peekbyte((struct membuff *)&gd->console_in) != -1) - return 1; - } -#endif + + if (IS_ENABLED(CONFIG_CONSOLE_RECORD) && console_record_tstc()) + return 1; + if (gd->flags & GD_FLG_DEVINIT) { /* Test the standard input */ return ftstc(stdin); @@ -521,10 +567,10 @@ void putc(const char c) { if (!gd) return; -#ifdef CONFIG_CONSOLE_RECORD - if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start) - membuff_putbyte((struct membuff *)&gd->console_out, c); -#endif + + if (IS_ENABLED(CONFIG_CONSOLE_RECORD) && (gd->flags & GD_FLG_RECORD)) + console_record_putc(c); + #ifdef CONFIG_SANDBOX /* sandbox can send characters to stdout before it has a console */ if (!(gd->flags & GD_FLG_SERIAL_READY)) { @@ -564,10 +610,10 @@ void puts(const char *s) { if (!gd) return; -#ifdef CONFIG_CONSOLE_RECORD - if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start) - membuff_put((struct membuff *)&gd->console_out, s, strlen(s)); -#endif + + if (IS_ENABLED(CONFIG_CONSOLE_RECORD) && (gd->flags & GD_FLG_RECORD)) + console_record_puts(s); + #ifdef CONFIG_SANDBOX /* sandbox can send characters to stdout before it has a console */ if (!(gd->flags & GD_FLG_SERIAL_READY)) { From patchwork Thu Dec 3 09:20:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1410225 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=s3V79CY5; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cmr1F5R8jz9s1l for ; Thu, 3 Dec 2020 20:21:05 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 950B78280E; Thu, 3 Dec 2020 10:20:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=st.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=st.com header.i=@st.com header.b="s3V79CY5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D364982800; Thu, 3 Dec 2020 10:20:44 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C2AEC825D5 for ; Thu, 3 Dec 2020 10:20:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0B397sBU006045; Thu, 3 Dec 2020 10:20:40 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=WECbQwB9kRgmWcVxcT4NTTN6rrb6d+PRrxPj/UGBAWI=; b=s3V79CY5gjl3wB2ZeoZ+HOL/3gWwbokVKOg8uuNPx2QRUb0eF8kMCqeFffzuZpGK3Io2 HnjUuGUgfdm1rgkJHBlb4p18K+oUvG2jTGOs9a9i3GH2OKqIwApqdAAQkP2/fCGNWD/j XyQ34QI4TwLgz54pONKb2uqANvt+RVr0OT2JCKOfDwSlsQWpsZJZal54PPLGzIOKfxa4 ntkizXIWYg61p5QhvxgCxhqxo2LJNiYbVka+YWtH3NnDnIxsvPA3Oqln9PD4q8zFhjI4 ptAY221CJZgcem5GH+mpITJrKpy/bSq79YOfx/cz1oJjheKN6EcDyLMQBERWZF5jWGTB zQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 355w3hfqe4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 03 Dec 2020 10:20:40 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 41D65100034; Thu, 3 Dec 2020 10:20:39 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 344CF23F6D7; Thu, 3 Dec 2020 10:20:39 +0100 (CET) Received: from localhost (10.75.127.51) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 3 Dec 2020 10:20:38 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Anatolij Gustschin , Bin Meng , Heinrich Schuchardt , Simon Glass , U-Boot STM32 Subject: [PATCH 4/4] console: add console_tstc_check helper function for CONSOLE_MUX Date: Thu, 3 Dec 2020 10:20:31 +0100 Message-ID: <20201203102027.4.I810a6b37da2c8aa13ca2e20408a8d54b08e2ef32@changeid> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201203092032.8124-1-patrick.delaunay@st.com> References: <20201203092032.8124-1-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-12-03_06:2020-12-03, 2020-12-03 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Add the helper function console_tstc_check() and replace the test #if CONFIG_IS_ENABLED(CONSOLE_MUX) to a simple if to respect the U-Boot coding rule. No functional change. Signed-off-by: Patrick Delaunay --- common/console.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/common/console.c b/common/console.c index 0b864444bb..c570cd88cf 100644 --- a/common/console.c +++ b/common/console.c @@ -248,6 +248,12 @@ static int console_getc(int file) return ret; } +/* Upper layer may have already called tstc(): check the saved result */ +static bool console_tstc_check(void) +{ + return !!tstcdev; +} + static int console_tstc(int file) { int i, ret; @@ -340,6 +346,11 @@ static inline int console_getc(int file) return stdio_devices[file]->getc(stdio_devices[file]); } +static bool console_tstc_check(void) +{ + return false; +} + static inline int console_tstc(int file) { return stdio_devices[file]->tstc(stdio_devices[file]); @@ -397,18 +408,19 @@ int fgetc(int file) */ for (;;) { WATCHDOG_RESET(); -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - /* - * Upper layer may have already called tstc() so - * check for that first. - */ - if (tstcdev != NULL) - return console_getc(file); - console_tstc(file); -#else - if (console_tstc(file)) - return console_getc(file); -#endif + if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { + /* + * Upper layer may have already called tstc() so + * check for that first. + */ + if (console_tstc_check()) + return console_getc(file); + console_tstc(file); + } else { + if (console_tstc(file)) + return console_getc(file); + } + /* * If the watchdog must be rate-limited then it should * already be handled in board-specific code.