From patchwork Wed Feb 4 00:09:56 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1806 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=1770163872; bh=X2h1VWokiaEtHOZOWSMjRQR5wOVC3P/z4tQ6Mig5w0E=; 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=UE+SXvg1369VwcwvqC94KNQdKfaq7xKDgHHki4iZs4/0uPhy6dLKlH7NW1PeX+7pO yWOuzk4Es4cC/vk+t0mNM37u5R9960wjyD4H6nPrTcr+EyxqaTadSQMGDOxBqprPsl d2s6g9bDooYyZUYjnS7E/Q7XxJtypZECfWTfrKZdUf5tP1C4h8TSMPc2xT+5bgkO4j VGprrXjWOfjYSb/gPJH/RmNCr607Jx2eCHY5SGeARTfV1nURkgAAxiIQuvZ26gEaT6 Wu/hmH/s0VrVM1pTfsIMuVp7sstERI+Zl9t2t5HunqMiiYPtXzqnc247yvMwUD/AVm FXefxDC2E7O+w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D28C869914 for ; Tue, 3 Feb 2026 17:11:12 -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 VkqIilvS5aTC for ; Tue, 3 Feb 2026 17:11:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770163872; bh=X2h1VWokiaEtHOZOWSMjRQR5wOVC3P/z4tQ6Mig5w0E=; 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=UE+SXvg1369VwcwvqC94KNQdKfaq7xKDgHHki4iZs4/0uPhy6dLKlH7NW1PeX+7pO yWOuzk4Es4cC/vk+t0mNM37u5R9960wjyD4H6nPrTcr+EyxqaTadSQMGDOxBqprPsl d2s6g9bDooYyZUYjnS7E/Q7XxJtypZECfWTfrKZdUf5tP1C4h8TSMPc2xT+5bgkO4j VGprrXjWOfjYSb/gPJH/RmNCr607Jx2eCHY5SGeARTfV1nURkgAAxiIQuvZ26gEaT6 Wu/hmH/s0VrVM1pTfsIMuVp7sstERI+Zl9t2t5HunqMiiYPtXzqnc247yvMwUD/AVm FXefxDC2E7O+w== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C1B41698FD for ; Tue, 3 Feb 2026 17:11:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770163871; bh=/EKkGfhQ2KGHXiuJgi9ipcRpQbg4KDe1hILveoGM6YA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CWXZlEte0Y7TclWsAHYgrA4+ji9p1SEHivqItQIJWMcJlPiMGVHYa3LzHaXogtYoo 8trY00Ni1okGBpHYbTUWn9AKAoZmA278UHs1ibNAhsLY7/RbJEV83FObZx0PraRNXj B14JO6wLGolWJuU0r5T0A3nZ0C8nlJII7p2RrX0joM1y53Fg/ws4ZnpBdMQVahOPm9 gZneyDUjuwojrVyxXzXyblqEAfFy6IS2wMGwYmoI04an4b4w4akMqQy87XE0Bu7j5k 55ppbbof2JRODYRncmiwt2+vTSr5dD2JiVK7eZRuVujOvIhLj7pE7Tek7joryWy8Wt HiRpDm/hy0RrQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 10959698FD; Tue, 3 Feb 2026 17:11:11 -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 xTLEG3k-ZvSx; Tue, 3 Feb 2026 17:11:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770163867; bh=kxh8r6n3KjTBh8FqgM14FdXh1Ch959Vx7FBOKPJ/8PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hJ6i3VTLsDQB76NUmZnUnp0CSmFvfVjOxCFzwBes9dRApPXSv4qPEkETY84kbjkR3 jmcZkkxhCxcxjy74HIYnZ0h+5uDTm9FnjTRFwhyl92hAyemaU4rRZzTRTZ8F113Iku mjtgIEaOm6cCtfo1y7sNY9g6XjyyhCx7dXwiJA1nAHUr/98C0vfdoj3BM5HdnSV6WX DMbU4BoRHy7dWYhdZnVzl35+HnkpaCwReeXnK3YIZZga+tXkUMzDttsy0IWxjZoisr IKPBXv3xqB+AiDhpktsIGXfrSZzMfqhC1Wa4xjabuY7TqWP7xk8/c1k7swFAqJM1+K 01k8mBcKYZtpg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B432F69909; Tue, 3 Feb 2026 17:11:06 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 3 Feb 2026 17:09:56 -0700 Message-ID: <20260204001002.2638622-13-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: RXQGHM4ZLQZEN2LOOR645TL7CBYYBQKD X-Message-ID-Hash: RXQGHM4ZLQZEN2LOOR645TL7CBYYBQKD 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 12/13] console: Add putsn() to ulib 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 the ulib_putsn() function to the U-Boot library interface for standalone applications. This provides length-based string output without requiring nul-termination. The implementation outputs characters one at a time using the exported putc() function, making it available to standalone applications without requiring changes to the jump table. Co-developed-by: Claude Sonnet 4.5 Signed-off-by: Simon Glass --- include/u-boot-lib.h | 15 +++++++++++++++ lib/ulib/ulib.c | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/u-boot-lib.h b/include/u-boot-lib.h index 934cc33eff5..034ff12a344 100644 --- a/include/u-boot-lib.h +++ b/include/u-boot-lib.h @@ -38,4 +38,19 @@ void ulib_uninit(void); */ const char *ulib_get_version(void); +/** + * ulib_putsn() - Write a string with specified length + * + * This outputs exactly @len characters from @s, regardless of any nul + * characters that may be present. This is useful for printing substrings + * or binary data with embedded nuls. + * + * If CONFIG_CONSOLE_PUTSN is enabled, this calls putsn() directly. + * Otherwise, it outputs characters one at a time using putc(). + * + * @s: String to output (need not be nul-terminated) + * @len: Number of characters to output + */ +void ulib_putsn(const char *s, int len); + #endif diff --git a/lib/ulib/ulib.c b/lib/ulib/ulib.c index c957ae6ba67..bb2cbc7cbac 100644 --- a/lib/ulib/ulib.c +++ b/lib/ulib/ulib.c @@ -6,6 +6,7 @@ * Written by Simon Glass */ +#include #include #include #include @@ -36,3 +37,12 @@ const char *ulib_get_version(void) { return version_string; } + +void ulib_putsn(const char *s, int len) +{ + if (CONFIG_IS_ENABLED(CONSOLE_PUTSN)) + putsn(s, len); + else + while (len--) + putc(*s++); +}