From patchwork Fri Aug 22 14:21:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 110 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=1755872551; bh=3tW3zR5U5VmoeuPie/wUjk8fYxIy6ZVGo81Oq5d/k3g=; 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=lpSiYIkv1h3YArmMBUS0nZBfMGgoA0UqkfDQkDyvHyeIGvwHz3G3decaNj3l5gXp7 bNN8WDwEPjZsZ3LHYsl33UuRlQ/lW97TjTKeauH0XisaYKZ7hpk3tCdtCwlUj+fVx5 dyGd3I9GO1uv/VmvcBlx+HGWVlQ1iJKcV5tNbc0igMIG78S27xb+1RYL5pgIlS+2xu EO+bw2+cCzQlZh4CeC09ySo+LKsbrOUhLY9DBhIf81SKtc6CPhXRhmzmwjuCrjZnk1 OsYXLyVxmDNpHveWbX+OxQ649+Pd96f2LG6dqT5gJ3RRf4B5hBqVoJR2dB7jpHjngR nhEHw3wMjEPew== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5B98767719 for ; Fri, 22 Aug 2025 08:22:31 -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 D1FMMGM5SVml 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=1755872547; bh=3tW3zR5U5VmoeuPie/wUjk8fYxIy6ZVGo81Oq5d/k3g=; 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=HvJKsrCBFfkZLgc9N31deva1lY6WNRYZBppBYVxXap1J6Bkw51gZ3JN3nvUv2ZIeP Cer5XblZMP6PVo4GLr+cRWfJDPyvjc6Qg1+w9Q0XmuP+9QkwepqGfyVrTq5bLatOaK nMAu/8s1Qav6F891YjEefddzKJz16gthKsyOuaGgnZhBk8ue+QeP9F8Tp41IpJ0vzf ZFdMbfZLgw4Y6hUew2x9V6hGJrm3irgnJ/PVmQ793CjaeuLxg5bq9wo2+WSML/4gi2 gMsNa1TcOR2sqAJgLlSuBnhYatb9VXkKPjA35GolxXHpbASJ+qgmt9KZK4OMNdSTAj Do14daAniFycA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9B436675E3 for ; Fri, 22 Aug 2025 08:22:27 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872546; bh=synMS3mw34wmdw9ES0aEeTlzV2cCCFYQ+8yS811lX/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fZZyR5nnXHf+usGpSoKq1+E1cskLR2ZuXzVg2g6TX+p5vHf+HKZxbY2W4rMU/b4mF ii/G41WrfpxgCQQbVL8uVQ9fWdjntm1fWzvpfHbxI8fkHzpQ8LhtpoUk+2Hx6gDtun 87ILLOgt0MeHTTcFxk28JHiJUuVxzKisspxlDhBwm3niBED3MPqoDM6pIhPOhy0x6h Lazgg5X5mR2E2yj12oH9sFjKEnRK1cfNRgkkzFQmtG44GNYCeu9oeS/ed5jkIn9mx/ MDIPQe2fUp6DcAA7NfrBf8jjbooay1oxCR3lXR8tqjAwrq3EExzvjZl2jfHKV47Ezj j6SvfSfxbwfIw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6FC8267714; Fri, 22 Aug 2025 08:22:26 -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 AA79HGNxz_4j; Fri, 22 Aug 2025 08:22:26 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872544; bh=JbQS4NOGAI2cEVhTRI6H0g+0W3MGD/8QZJ+Pvw64CSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BWxQTQNHNXwRH76x+dkrwdLG65Huualco7e+hmztZrO3CyN72+woGCq9syCdghmFx AJhY3fPiUuZMl8B44z4/EIN/LDp7bufrlY8Utbelh+QNehQXRQfscLHuaQQtL9/sWs YRBrZmJjn6GTuh6aHJg7ExsPYsfxm4/h//uIdPu50mDI4FNvZfnCoqHkPJYxvvAOYv Yu6fkXP82+BoGGFG9ulag9uMCHpGrTn74Z6cUwKraZPVPvGXrEHEXXP+QDKfY0hQoo yFRCa9QwHbQIkXDSdovm1Bvcy42jMGOJQh9htZ4KbURrlHwnkkaIVvVl1e2hlJkXXH gpRuakatxYhkg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 730F5676DB; Fri, 22 Aug 2025 08:22:24 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 22 Aug 2025 08:21:36 -0600 Message-ID: <20250822142153.3404275-6-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: 425QMZDGZNRLUATVOAUWCSOD5BAP6XHB X-Message-ID-Hash: 425QMZDGZNRLUATVOAUWCSOD5BAP6XHB 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 , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/16] console: Plumb in the pager 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 Send all console output via the pager. If it is disabled, it will do nothing. The pager is only supported if CONSOLE_MUX and SYS_CONSOLE_IS_IN_ENV are enabled. This is the common case for more richly featured boards, i.e. those that can cope with the extra code size of this feature. Co-developed-by: Claude Signed-off-by: Simon Glass --- common/Kconfig | 9 ++++++ common/console.c | 52 +++++++++++++++++++++++++------ include/asm-generic/global_data.h | 11 +++++++ 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/common/Kconfig b/common/Kconfig index 048530adff3..6c54f90109c 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -343,6 +343,15 @@ config CONSOLE_PAGER controlled by the 'pager' environment variable. If the variable is not set or is empty, paging is disabled. +config CONSOLE_PAGER_LINES + int "Number of lines per page" + depends on CONSOLE_PAGER + default 25 + help + Sets the default number of lines that the pager assumes is visible on + the display. This is used as a default if the "pager" environment + variable is unset. + endmenu menu "Logging" diff --git a/common/console.c b/common/console.c index fdccf156b5a..9bc506f0464 100644 --- a/common/console.c +++ b/common/console.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -377,17 +378,32 @@ int console_printf_select_stderr(bool serial_only, const char *fmt, ...) return ret; } -static void console_puts_pager(int file, const char *s) +static void console_puts(int file, bool use_pager, const char *s) { - int i; - struct stdio_dev *dev; + int key = 0; - for_each_console_dev(i, file, dev) { - if (dev->puts != NULL) - dev->puts(dev, s); + for (s = pager_post(gd_pager(), use_pager, s); s; + s = pager_next(gd_pager(), use_pager, key)) { + struct stdio_dev *dev; + int i; + + key = 0; + if (s == PAGER_WAITING) { + key = getchar(); + } else if (*s) { + for_each_console_dev(i, file, dev) { + if (dev->puts != NULL) + dev->puts(dev, s); + } + } } } +static void console_puts_pager(int file, const char *s) +{ + console_puts(file, true, s); +} + #ifdef CONFIG_CONSOLE_FLUSH_SUPPORT static void console_flush(int file) { @@ -407,7 +423,8 @@ static inline void console_doenv(int file, struct stdio_dev *dev) iomux_doenv(file, dev->name); } #endif -#else + +#else /* !CONSOLE_MUX */ static void console_devices_set(int file, struct stdio_dev *dev) { @@ -780,8 +797,8 @@ void puts(const char *s) return pre_console_puts(s); if (gd->flags & GD_FLG_DEVINIT) { - /* Send to the standard output */ - fputs(stdout, s); + /* Send to the standard output through pager system */ + console_puts_pager(stdout, s); } else { /* Send directly to the handler */ pre_console_puts(s); @@ -1101,6 +1118,21 @@ static void stdio_print_current_devices(void) printf("%s\n", stderrname); } +static void setup_pager(void) +{ + /* Init pager now that console is ready */ + if (IS_ENABLED(CONFIG_CONSOLE_PAGER)) { + int lines = IF_ENABLED_INT(CONFIG_CONSOLE_PAGER, + CONFIG_CONSOLE_PAGER_LINES); + int ret; + + ret = pager_init(gd_pagerp(), env_get_hex("pager", lines), + PAGER_BUF_SIZE); + if (ret) + printf("Failed to init pager\n"); + } +} + #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) /* Called after the relocation - use desired console functions */ int console_init_r(void) @@ -1185,6 +1217,7 @@ done: } gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ + setup_pager(); print_pre_console_buffer(flushpoint); return 0; @@ -1252,6 +1285,7 @@ int console_init_r(void) } gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ + setup_pager(); print_pre_console_buffer(flushpoint); return 0; diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 464b9c3eee1..0157fead337 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -477,6 +477,9 @@ struct global_data { */ struct upl *upl; #endif +#if CONFIG_IS_ENABLED(CONSOLE_PAGER) + struct pager *pager; +#endif }; #ifndef DO_DEPS_ONLY static_assert(sizeof(struct global_data) == GD_SIZE); @@ -618,6 +621,14 @@ static_assert(sizeof(struct global_data) == GD_SIZE); #define gd_passage_dtb() 0 #endif +#if CONFIG_IS_ENABLED(CONSOLE_PAGER) +#define gd_pager() gd->pager +#define gd_pagerp() &gd->pager +#else +#define gd_pager() NULL +#define gd_pagerp() NULL +#endif + /** * enum gd_flags - global data flags *