From patchwork Fri Aug 22 14:21:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 111 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=1755872555; bh=1jkjJ9jKpmN2Hc867FqlL9YMK3D5YpZfzV+2WQtq7Bs=; 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=auChWIVkzitJiEdJt/r2l0/DTV8EatemLUmKZZQlrkVQzxN/YlF1ij8OJfbT7T3Aw BV5Q2fAgjHf+JgwBPiGkB7M+p2ybaQRzK49QNAsfyjUmP44MqrIvHCyqweBSgKoewL LbI+Or0MfLY9clg0Ii54FE8MCUdrWmn6GPpKcUDAqOa5+I0bccehV1V/AnU28nOnuo aM6+kva3dkQoftB0GFgcrYRF/QQ9JfA6ko8OlpNZs9d6Iwfoagf4hR9UG8qp+9JLF3 o3cYmUtYVDVMcS+4Iq5ajCAw4W8O1B70JbxkxmK7X0gF6YrICmytbsdMYrm5GyCCoq JcNiP8jiw0f2Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DE7B16770E for ; Fri, 22 Aug 2025 08:22:35 -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 rFuzrGCZbNjc for ; Fri, 22 Aug 2025 08:22:35 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872551; bh=1jkjJ9jKpmN2Hc867FqlL9YMK3D5YpZfzV+2WQtq7Bs=; 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=liZW6+ms226glJCOfeAmD8nfe9MdbaIOt0innk906GuV+OQEaFbwwE7jdBEHiPsh5 lyGHXtm5yIsOV+dEPPf+whDHfOI3ngOSN6MNKAkvqr5RzCDZG3eyp23nImKjzV0YAO a+NqHXjIQnpH8R+z0+bMT/rM/ECA6k1galoqpT+EtAzWnBFxKmkj5BRugf8tdleAme FM11ZS/SC/gKMsbfeqqF5ldglo+khsnwoAOAE57fiA7Dkg9xHRYlF4NE4h7HzZRFIv pedpgaXXPI+WHGyRez1kjIICeKhiPQ8x9mcUL6EMHcuspc1U1naj3f0qnDIpoQ6lVw KNiYUB7Fi/Ldw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 043B767712 for ; Fri, 22 Aug 2025 08:22:31 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872549; bh=TbZZ5yrWmmltJIoskhJZ9wp5l0/1hQ74oQ9GvFWPfmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u3mPUPrZYyuw0KyQ4XxieLpadljTEfOXMjVAXyk0/lF4D5SUmZd6JGSld2HB6MTvJ k1L5FPazxIfZt/49NZE3nDoSV4oGP14BxMR0ENdIs+xfejnzc7lmpTjp0j/KruecCe HE8pGKbGn+BVWYUOwI83EiOlKAxTLTxCM/D+cj2qkBUJ/recOKHMm/qRyk2Jwc/vcd gUaoR0XW1qTUipCftvwgtQ+N2lvI/xLhvb450Avm4CMsRGY8TjwK5MwkRLCVaamqsC MHzeAsFS73mz/B/ImCZ4T7bxN4lT9laddWIbRcdU0VqctLBamn7fCvAJHbR7zSkyjU EYlA2QxDKOzOw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 44892676F0; Fri, 22 Aug 2025 08:22:29 -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 fdhNVzV8jSQg; Fri, 22 Aug 2025 08:22:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872546; bh=ARwW9h+XE+uOk3FW+bW4uJmhy6mjHlUKzLndrfrpBpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ds5Xyk6Sy3mWgZVex+w/CHXIhAu3IMJXB1wYDWhGP0QqGfKjSfj5bJPGxRKc1/231 RkYG0HjBG0nG+LwAD6GJurSfq9PnoKLTy1iSPXA/PS2TzufCK4xcPhQ46EtCwt7o9h MKTbHVVtGsMbQMLQzkR/0BxUvDWIcpQ9AR9flUGQGOQUJMobc+K8QpjmCfUrFfzGRp aLMzWc8JtwDHRDwtgQlRacT1JDlA2wtv2Ww3ZLMMcRt7x2/QUmZb1Foq4cJMRGsuRB b6Xxjqlv/B/xY02NhaNzhg7dP+kWuIhlhJCBb8rY7gK7dHNJN8QZdJbZSpg0VpsZBT C+X+qDx+2gqsQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 58AF567711; Fri, 22 Aug 2025 08:22:26 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 22 Aug 2025 08:21:38 -0600 Message-ID: <20250822142153.3404275-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822142153.3404275-1-sjg@u-boot.org> References: <20250822142153.3404275-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: FSTYQ73EJZKGZIDCOYXW3RFIRUUT4CW2 X-Message-ID-Hash: FSTYQ73EJZKGZIDCOYXW3RFIRUUT4CW2 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: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/16] console: Support paging with single characters 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 A single character may result in a stall waiting for user input, which means that it may request that a string be output. So when the pager is active we never actually use the devices' putc() methods. Add a special case so they don't go to wrack and ruin. As before, the pager is only supported with CONFIG_CONSOLE_MUX enabled. Signed-off-by: Simon Glass --- common/console.c | 22 +++++++++++++++------- test/common/pager.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/common/console.c b/common/console.c index 9bc506f0464..7bafe98375a 100644 --- a/common/console.c +++ b/common/console.c @@ -322,14 +322,22 @@ static int console_tstc(int file) return 0; } +static void console_puts_pager(int file, const char *s); + static void console_putc_pager(int file, const char c) { - int i; - struct stdio_dev *dev; + if (IS_ENABLED(CONFIG_CONSOLE_PAGER) && gd_pager()) { + char str[2] = {c, '\0'}; - for_each_console_dev(i, file, dev) { - if (dev->putc != NULL) - dev->putc(dev, c); + console_puts_pager(file, str); + } else { + int i; + struct stdio_dev *dev; + + for_each_console_dev(i, file, dev) { + if (dev->putc != NULL) + dev->putc(dev, c); + } } } @@ -757,8 +765,8 @@ void putc(const char c) return pre_console_putc(c); if (gd->flags & GD_FLG_DEVINIT) { - /* Send to the standard output */ - fputc(stdout, c); + /* Send to the standard output through pager system */ + console_putc_pager(stdout, c); } else { /* Send directly to the handler */ pre_console_putc(c); diff --git a/test/common/pager.c b/test/common/pager.c index 2512652ea01..c1c2d40f648 100644 --- a/test/common/pager.c +++ b/test/common/pager.c @@ -425,3 +425,43 @@ static int pager_test_bypass_mode(struct unit_test_state *uts) return 0; } COMMON_TEST(pager_test_bypass_mode, 0); + +/* Test that single character output via putc goes through pager */ +static int pager_test_putc(struct unit_test_state *uts) +{ + struct pager *pag; + const char *result; + + /* Init pager */ + ut_assertok(pager_init(&pag, 20, 1024)); + pager_set_bypass(pag, true); + + /* + * Test that individual characters can be posted via pager API + * This verifies that console_putc_pager() routes through the pager + * system + */ + result = pager_post(pag, true, "A"); + ut_asserteq_ptr("A", result); /* Bypass mode returns original pointer */ + + result = pager_post(pag, true, "\n"); + ut_asserteq_ptr("\n", result); + + result = pager_post(pag, true, "B"); + ut_asserteq_ptr("B", result); + + /* Disable bypass to test normal functionality with single chars */ + pager_set_bypass(pag, false); + + result = pager_post(pag, true, "X"); + ut_assertnonnull(result); + ut_asserteq_str("X", result); + + result = pager_next(pag, true, 0); + ut_assertnull(result); + + pager_uninit(pag); + + return 0; +} +COMMON_TEST(pager_test_putc, 0);