From patchwork Wed Feb 4 00:09:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1801 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=1770163849; bh=nl1EVOwRNOainkezL8nCQo3gxj8wagoWVXPf0LzKDnM=; 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=txvMLlDkGvvkC9hKKDmaIz8yM6S3VOFUgmQ9KCKi2G4indUJZ3TPreWPnxIhW69HA YLorvXNL3f9SNwQk7g7YPA9YPfW0YhLC509lSENDeHvCeisgY4fV/+09K55Alq4a4a LwGeqB5du1136cKeqcq1q7B7TPg54sGnNpoztTcRl2R6OYnOi91TDJ6yTTzE9r1VAO EpsxwUfX0dGeITx2HV/c8STqmgVPwwsgtXiKFeYGDLoPGM7BNS6UtHUDDUey/ZEcUu 5WNXKaxVZUEbo4zAj5aaa1sxxo6YYYQ0wHmh7rdjIo/q7tQFCIUPvsTokWESQbD73b FiA+GA12TXOtQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4CD4669917 for ; Tue, 3 Feb 2026 17:10:49 -0700 (MST) 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 C1SaPqV4W1na for ; Tue, 3 Feb 2026 17:10:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770163849; bh=nl1EVOwRNOainkezL8nCQo3gxj8wagoWVXPf0LzKDnM=; 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=txvMLlDkGvvkC9hKKDmaIz8yM6S3VOFUgmQ9KCKi2G4indUJZ3TPreWPnxIhW69HA YLorvXNL3f9SNwQk7g7YPA9YPfW0YhLC509lSENDeHvCeisgY4fV/+09K55Alq4a4a LwGeqB5du1136cKeqcq1q7B7TPg54sGnNpoztTcRl2R6OYnOi91TDJ6yTTzE9r1VAO EpsxwUfX0dGeITx2HV/c8STqmgVPwwsgtXiKFeYGDLoPGM7BNS6UtHUDDUey/ZEcUu 5WNXKaxVZUEbo4zAj5aaa1sxxo6YYYQ0wHmh7rdjIo/q7tQFCIUPvsTokWESQbD73b FiA+GA12TXOtQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3C80F69911 for ; Tue, 3 Feb 2026 17:10:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770163847; bh=1YIr9NOKjk/SNQyVy344bcXA2m3rRPxdaox0rkF+azM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dcEsvv4I9Mo58DZHj1SjNNE4WcoPyFk87fnbeRO+4TtTJUGA0JZBjQToraAIfKp4a L3fVgCWsHt24yqMGqmq+GrFQSqrwSTze541WEUkw/QGRGai5DGWm3Jlv6Xrcm+C874 5Fx8VuPxUrJHN4MQGlY6kldUCTgiVplXLs4LRhVcYh1U+IMCaWWh/MejK+nXYjl2ja KZ5IiroUT+Q+q2Nno38XzyVJl6RTR7w4FInkqqH7pKKwiDCZOwJ/SSCKlCtgNQKrDL gBGiCmL48Ev8VVDYcYYgYFzmvz6qzg2dDe+yjT0kzz98xJj2znm/gHDOQmTr/NLk1a 23Mb9suri4JTQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F1ADA69868; Tue, 3 Feb 2026 17:10:47 -0700 (MST) 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 XsZq9bbZZYnn; Tue, 3 Feb 2026 17:10:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770163843; bh=SNmoxeeO0L8g8irBpxz7gGV0ldjNlhPUflESnhfaPKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Le0sGfXdOTKF0S8N350WLi5gUqiTjpJi4ju8RFAw/+kvXKuTZWF1XWKsIBCEOBTVe lJNBhIaF8KSaz3V8X2UwUGPTPlOTd7ojsPBUPS0G2M632CmisNLyLtYLNddn9PRJ7S NsLgfi0DDivbIoyXdeWz/hRhTLkIMjUjPVi3CUdOBqULhbTPGZGZ/qllnNlT6oTtXt kNBeL8oBBHBG4/O6q9QAnqOlZ0MlFA/9eBjfcfQppXTbUn3q7fbPv+gKw5RLX+LvKk AYeLp4+uznorFtg+Hti70puOplMHf5OwPs1QKIVdpZq5A2Iv1YbZAEmsHUtQpfoHtf BMy3pybwOuCIg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 956C469909; Tue, 3 Feb 2026 17:10:43 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 3 Feb 2026 17:09:51 -0700 Message-ID: <20260204001002.2638622-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260204001002.2638622-1-sjg@u-boot.org> References: <20260204001002.2638622-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: IPWR6TRYFSJIXHYIIOENMN4AQIZUGSFP X-Message-ID-Hash: IPWR6TRYFSJIXHYIIOENMN4AQIZUGSFP 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 Sonnet 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/13] console: Add putsn() support to struct stdio_dev 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 Add an optional putsn() method to struct stdio_dev to allow devices to provide optimised length-based output. The field is added unconditionally but only used when CONFIG_CONSOLE_PUTSN is enabled. Add console_putsn_pager() and fputsn() to route length-based output through console devices. If a device provides a putsn method, it is used; otherwise, the output falls back to calling putc in a loop. Co-developed-by: Claude Sonnet 4.5 Signed-off-by: Simon Glass --- common/console.c | 31 ++++++++++++++++++++++++------- include/stdio_dev.h | 12 ++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/common/console.c b/common/console.c index c058d3d30a2..67d87c6edfa 100644 --- a/common/console.c +++ b/common/console.c @@ -271,6 +271,7 @@ static int console_tstc(int file) } static void console_puts_pager(int file, const char *s); +static void console_putsn_pager(int file, const char *s, int len); static void console_putc_pager(int file, const char c) { @@ -355,18 +356,28 @@ static void console_puts(int file, bool use_pager, const char *s) } } +static void console_putsn_pager(int file, const char *s, int len) +{ + struct stdio_dev *dev; + int i; + + for_each_console_dev(i, file, dev) { + if (dev->putsn) + dev->putsn(dev, s, len); + else if (dev->puts) + dev->puts(dev, s); + else + while (len--) + dev->putc(dev, *s++); + } +} + static void console_puts_pager(int file, const char *s) { if (IS_ENABLED(CONFIG_CONSOLE_PAGER) && gd_pager()) { console_puts(file, true, s); } else { - struct stdio_dev *dev; - int i; - - for_each_console_dev(i, file, dev) { - if (dev->puts != NULL) - dev->puts(dev, s); - } + console_putsn_pager(file, s, strlen(s)); } } @@ -629,6 +640,12 @@ void fputs(int file, const char *s) console_puts_pager(file, s); } +void fputsn(int file, const char *s, int len) +{ + if ((unsigned int)file < MAX_FILES) + console_putsn_pager(file, s, len); +} + #ifdef CONFIG_CONSOLE_FLUSH_SUPPORT void fflush(int file) { diff --git a/include/stdio_dev.h b/include/stdio_dev.h index 4e3c4708f80..2b2334c9918 100644 --- a/include/stdio_dev.h +++ b/include/stdio_dev.h @@ -38,6 +38,18 @@ struct stdio_dev { void (*putc)(struct stdio_dev *dev, const char c); /* To put a string (accelerator) */ void (*puts)(struct stdio_dev *dev, const char *s); + /** + * putsn() - Output a string with specified length + * + * This outputs exactly @len characters from @s, regardless of any nul + * characters that may be present. This is an optional accelerator - if + * NULL, the console will fall back to calling putc() in a loop. + * + * @dev: Device to output to + * @s: String to output (need not be nul-terminated) + * @len: Number of characters to output + */ + void (*putsn)(struct stdio_dev *dev, const char *s, int len); #ifdef CONFIG_CONSOLE_FLUSH_SUPPORT /* To flush output queue */ void (*flush)(struct stdio_dev *dev);