From patchwork Mon Aug 25 16:27:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 133 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756139275; bh=sAWGVg3kKvOWFXHPagaq7+WujeuvXOTy8ki5+avGagI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=phJVvJYNclNP9BOA7GVLe53mHX8dsQ+aoy0c3+YsnyUq9XuBsDVzIo70P0y0fb/CQ RNm/hn2kw3MF2IrxLybgSLULSmuy9c7ROTMcJr8l4iOHxGybNyPzprKxnVjfG6XNqz l+tM9MzvK68uOiH9lrB9Kh4YXTjTxNQCS0mZUtDonN/IoDEzPm4pnkj3zgr+2xeunp wTr7dNBjbDQuJRGcjroaMCETVVnBjokFbSyOCROz28jP4c1UYIwu+/VAWO51ZY9885 LMGPDyD+s9yxSMrctDVOiodm1InRraY0C4Cao0eEISeEm87uAbVmfc0lpmMA8gBGdc XFff6RCHkHCrw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 18DA4677B2 for ; Mon, 25 Aug 2025 10:27:55 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 3QJ7TMSLFSlZ for ; Mon, 25 Aug 2025 10:27:55 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756139274; bh=sAWGVg3kKvOWFXHPagaq7+WujeuvXOTy8ki5+avGagI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=EgCcU4iTsaJeChbSt7uVlYf3qBJbtejUivdIPb/piVftGhXDYHqFfG17uAXBbvcdV W/GGXW8+eqMZTp/oiEUOp+LFa3a4J1qLncyE2Hbh9yG3/6Apyi5iFTwkvTAZf05CDl efXiEr5KolC6Em6uatYp8WtF6yAIVSBsNZv7qkyEhgMNMp9+8tw5TcvuGlBXJ3D4hp HOjvFX1DaKGkccEpCTGpxOw9QSY/qBA5tNY/Txd6Uq4jDYmPMP7XxinwHoFgmbXJ4T +r0sRJpnavCxeYs3hWMsIEPS4V/bpeAXPGqiRTC5hAjBk4SybHR9MB4miUcXzu2UmK 5qVEeg7PchTvw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C4B1867787 for ; Mon, 25 Aug 2025 10:27:54 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756139269; bh=9IUGipPhl6pvWWBaQX7HQyq+YsdEBn9B7fekunO8xRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wWMJhlr/kNojebld6uBnHQ7azB2cJP2dRw+2ZHJ9dCtf6RNlM+/6K8t/++x+Q3t/j xi+ow8L6dLMWSEbfVXIG7EzQMFWbSru1mEGwwxzEzAeiqvBUfOxSNfwP1CBSyqvvZN py/awyFaybypCbXH9Sk60FEyEKZLIzgmv+r/4IltdcRtF3WrW5YQmMB0odOipEHZF+ 1y58LoCWRr5fMq1cHEPmyDg1uPMSV6Gdsd75ISfsgmZJ8+LzZk7mNipEYFTj0gJDGK pXHLsWDxRsXfuREwXoVwk/SaT0Vkn5a7UViuShDZeGfLSHvPMwVSW4Whngw5XE0SVg OzLqpPcf/YLlQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1F7856779F; Mon, 25 Aug 2025 10:27:49 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id OT2qqbpUBRRd; Mon, 25 Aug 2025 10:27:49 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756139268; bh=LbWs6oUprjjIdnwDRRdnuR3pDdJcUypTD8Y+3tQd1II=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qwFtZGv9W2WrZs7J9F/wxgTLqs670vcH/mvSCHomxa3IDxCYPn609BNBYL0Z7Dw+T TXDfEApK+6auFjGYNjupwzp9VcQsFo0z5+wvNxzQ+5DecZGCRFI4jD7wyuUxG1HlTT w61DfdJRnZRFDRI/A8/RXPOBorvdSFdR/+NtLOFja0RnPde4zKbqQ2UMBFWxUhpgmh mFdZOadJyxAYCUzJoExVBRimfCKrF/Bgu/GpsiGaPkKnGC56Nhzhk5S80ncQjBxGaM swrPPxxvd2OWkmRP+EnurM6Q2M7chMr9rcyIZjMtQlku0jc2HUaQE0PWz30yUeye+O NAJrBs3qMcK8w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id D9F7A6778C; Mon, 25 Aug 2025 10:27:47 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 25 Aug 2025 10:27:15 -0600 Message-ID: <20250825162727.3185381-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250825162727.3185381-1-sjg@u-boot.org> References: <20250825162727.3185381-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: F3FJYH2FPDPKDJOC7JL3YBADG2Y7COSX X-Message-ID-Hash: F3FJYH2FPDPKDJOC7JL3YBADG2Y7COSX X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 12/16] console: Move environment handling lower in the file List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Move the environment callbacks lower so that we can call functions elsewhere in common/console.c Signed-off-by: Simon Glass --- Changes in v2: - Add new patch to move environment handling lower in the file common/console.c | 130 +++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/common/console.c b/common/console.c index c6dfed6e201..51f646d9fd4 100644 --- a/common/console.c +++ b/common/console.c @@ -29,71 +29,6 @@ DECLARE_GLOBAL_DATA_PTR; #define CSI "\x1b[" -static int on_console(const char *name, const char *value, enum env_op op, - int flags) -{ - int console = -1; - - /* Check for console redirection */ - if (strcmp(name, "stdin") == 0) - console = stdin; - else if (strcmp(name, "stdout") == 0) - console = stdout; - else if (strcmp(name, "stderr") == 0) - console = stderr; - - /* if not actually setting a console variable, we don't care */ - if (console == -1 || (gd->flags & GD_FLG_DEVINIT) == 0) - return 0; - - switch (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; - } - - return 0; - - case env_op_delete: - if ((flags & H_FORCE) == 0) - printf("Can't delete \"%s\"\n", name); - return 1; - - default: - return 0; - } -} -U_BOOT_ENV_CALLBACK(console, on_console); - -#ifdef CONFIG_SILENT_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; - - if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC)) - if ((flags & H_INTERACTIVE) == 0) - return 0; - - if (value != NULL) - gd->flags |= GD_FLG_SILENT; - else - gd->flags &= ~GD_FLG_SILENT; - - return 0; -} -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) @@ -1101,6 +1036,71 @@ static void stdio_print_current_devices(void) printf("%s\n", stderrname); } +static int on_console(const char *name, const char *value, enum env_op op, + int flags) +{ + int console = -1; + + /* Check for console redirection */ + if (strcmp(name, "stdin") == 0) + console = stdin; + else if (strcmp(name, "stdout") == 0) + console = stdout; + else if (strcmp(name, "stderr") == 0) + console = stderr; + + /* if not actually setting a console variable, we don't care */ + if (console == -1 || (gd->flags & GD_FLG_DEVINIT) == 0) + return 0; + + switch (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; + } + + return 0; + + case env_op_delete: + if ((flags & H_FORCE) == 0) + printf("Can't delete \"%s\"\n", name); + return 1; + + default: + return 0; + } +} +U_BOOT_ENV_CALLBACK(console, on_console); + +#ifdef CONFIG_SILENT_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; + + if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC)) + if ((flags & H_INTERACTIVE) == 0) + return 0; + + if (value) + gd->flags |= GD_FLG_SILENT; + else + gd->flags &= ~GD_FLG_SILENT; + + return 0; +} +U_BOOT_ENV_CALLBACK(silent, on_silent); +#endif + #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) /* Called after the relocation - use desired console functions */ int console_init_r(void)