From patchwork Wed Feb 4 00:09:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1800 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=1770163844; bh=zRUwA0X1RjOYJgbwmctfRMSSRzyFEEtiVrvWbG+EQkQ=; 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=NS09OD0tGsMWPLIimEHFM+OjzflpvfsKoUwjGQgFMnTXnGYQqi+wAxFJ+oe+J0X4v 1BipQLOtkKqu+LoFJJya04Q1wWQCx6toYPbtP2By9RRtjiJ4/0J9sHYRDSi6vMod9k NLCgO2jIhsHVW/Px/IqTEhvOwW9KtCPgF6ELLGfsS1KKnzdpK5j9yTnKVM2g1oNr2w mU1Smb17DuVFuX1r6TGdsGAgarsI5hZlL0xbpDpU7x+rZXb37rOCuWqfafyR0KHttB kn9v/N6vxIeHRVcZbE+EZ/Vvh1I5/0oglwXor5EJALvnoKQHf1VJOX3XX23H+ALdnf OOXuLRU3j5qlA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5C0A669868 for ; Tue, 3 Feb 2026 17:10:44 -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 tbP_v_9BG8Rj for ; Tue, 3 Feb 2026 17:10:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770163844; bh=zRUwA0X1RjOYJgbwmctfRMSSRzyFEEtiVrvWbG+EQkQ=; 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=NS09OD0tGsMWPLIimEHFM+OjzflpvfsKoUwjGQgFMnTXnGYQqi+wAxFJ+oe+J0X4v 1BipQLOtkKqu+LoFJJya04Q1wWQCx6toYPbtP2By9RRtjiJ4/0J9sHYRDSi6vMod9k NLCgO2jIhsHVW/Px/IqTEhvOwW9KtCPgF6ELLGfsS1KKnzdpK5j9yTnKVM2g1oNr2w mU1Smb17DuVFuX1r6TGdsGAgarsI5hZlL0xbpDpU7x+rZXb37rOCuWqfafyR0KHttB kn9v/N6vxIeHRVcZbE+EZ/Vvh1I5/0oglwXor5EJALvnoKQHf1VJOX3XX23H+ALdnf OOXuLRU3j5qlA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 41CD369911 for ; Tue, 3 Feb 2026 17:10:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770163843; bh=0raAGp77Q+tVSk6xc7VaekH9BlDcHAVAKQON78AVCw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mKS1aFdvv3Ci9PfsaudB1BFzNiVoOBmhp/Hk0FD7P5Zkyo1vPgB+02fxf4SXLRwj/ uv84VeiEjutAhfR5/WBPr6Tlt/V4rRI78Pr0x0zW5oGdQmp2v1SzCLgRuewDrr9HpF iBKEMiD78Pyxl5MxQnRM/dyHsqI8zqPB6zEG8AjSk/1qpEpg0CDs5vvqcQV5AalUFP G9lkngeZruQfGdvbGKQXl/6jgzd0NShzA0UxQG3e2srAJDohRDr4MAvFk8qUDIsijU y4GQGyakx7m8TRcop4Miii1a6EE+AEKlhKLHY014thmwD9aFEiCcOwlQtlzf8AT7GV 2V1sdwHOHIBtg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 56AC369868; Tue, 3 Feb 2026 17:10:43 -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 jAL_y06-66dI; Tue, 3 Feb 2026 17:10:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1770163839; bh=t3KIvymdqfLBHVbuST7NVcebbnLrb7euSpfo8ew33FI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SKmico2eOOdR8C8SvFYZRPym9gmfH5U2bA3Wg9M5EOZegy5Fl58TOfvjIEkD5Q1/j ZisSfl5ToYAay9AGw2c9bU+6tboWwxvndkbvrb+gKG36b8p4sleUjS7UODhTuah/Wa F3Ibo41DKO1Z+ga+r5oycC38cfjLCQkLIw54uHk2U4UCeCR73pY2ZPCEafhjEFtVFL PQm4Y/sNkEJfyXbBCijOvRXFvmB2NyvAOHu6jGFaFMvoLif+SfBwqhCYj89XhE2z+2 pw/GMvA6dDJbDjQJTE6A1sSo7UJ7UtlMGX99ZRshDYPmAiKw8qTchLYQb7T5eR7GUS 3XED4O1ruAdWA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 05E5769909; Tue, 3 Feb 2026 17:10:38 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 3 Feb 2026 17:09:50 -0700 Message-ID: <20260204001002.2638622-7-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: XGT6LVNLQTR5P2WUA35ORTUR7QYB7N3Z X-Message-ID-Hash: XGT6LVNLQTR5P2WUA35ORTUR7QYB7N3Z 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 06/13] sandbox: Add support for length-based console output 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 os_putsn() to support length-based output in sandbox environments. This allows putsn() to work correctly before the serial console is initialised. The implementation uses os_write() directly for efficiency, and os_puts() is refactored to use os_putsn() to reduce code duplication. Note this changes sandbox to write all characters in one call. Co-developed-by: Claude Sonnet 4.5 Signed-off-by: Simon Glass --- arch/sandbox/cpu/os.c | 8 ++++++-- include/os.h | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 5278ce55766..142b685e031 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -827,10 +827,14 @@ void os_putc(int ch) os_write(1, &ch, 1); } +void os_putsn(const char *str, int len) +{ + os_write(1, str, len); +} + void os_puts(const char *str) { - while (*str) - os_putc(*str++); + os_putsn(str, strlen(str)); } void os_flush(void) diff --git a/include/os.h b/include/os.h index 3ea88230af3..bc556f2195f 100644 --- a/include/os.h +++ b/include/os.h @@ -385,6 +385,19 @@ void os_putc(int ch); */ void os_puts(const char *str); +/** + * os_putsn() - write a string with length to controlling OS terminal + * + * This bypasses the U-Boot console support and writes directly to the OS + * stdout file descriptor. + * + * Outputs exactly @len characters from @str, regardless of any nul characters. + * + * @str: String to write (need not be nul-terminated) + * @len: Number of characters to write + */ +void os_putsn(const char *str, int len); + /** * os_flush() - flush controlling OS terminal *