From patchwork Sun Dec 14 17:54:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 897 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=1765734919; bh=h8shfPXVX8F8o44+5UDfh14P60snpzf1T0IycwTkkYM=; 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=cOP6WLX9pRH7cHoxyKBSY6FjtJsM1KX2G8eVyzSfmtWnqsAg3CFUr9fU4mmOhJPlE a2p8eboATyoRJYla+6g+d6118icdyi09hAXHrOBIjITGBsJ5x44d4nLTxpW6bylNMf 79L6ptav2iVn8y099610LTwdFYlOfvEiO037BNsfapYKCj8bPXID6cCFO/orr4cXpA IYXAtIWNsmrskMMZvFou9UbVCQEO29A0QFizR5cFRHze2yAF9yOF1EpD5xjjXtevG1 7M9wEjzizu0VaQ2L/2uinPjwSH2bD9sTP+2KW7llTZ4WBNRKrfwXwG2KRNNgLM9m0b dDRIvPLodVXEw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6188B68AFE for ; Sun, 14 Dec 2025 10:55:19 -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 pxGjw1_ayJ5B for ; Sun, 14 Dec 2025 10:55:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734919; bh=h8shfPXVX8F8o44+5UDfh14P60snpzf1T0IycwTkkYM=; 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=cOP6WLX9pRH7cHoxyKBSY6FjtJsM1KX2G8eVyzSfmtWnqsAg3CFUr9fU4mmOhJPlE a2p8eboATyoRJYla+6g+d6118icdyi09hAXHrOBIjITGBsJ5x44d4nLTxpW6bylNMf 79L6ptav2iVn8y099610LTwdFYlOfvEiO037BNsfapYKCj8bPXID6cCFO/orr4cXpA IYXAtIWNsmrskMMZvFou9UbVCQEO29A0QFizR5cFRHze2yAF9yOF1EpD5xjjXtevG1 7M9wEjzizu0VaQ2L/2uinPjwSH2bD9sTP+2KW7llTZ4WBNRKrfwXwG2KRNNgLM9m0b dDRIvPLodVXEw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 51F3168ADC for ; Sun, 14 Dec 2025 10:55:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734917; bh=joffOa2OGMb70ktQo4WFLUv99hrzK8ig4+ZrIKMTV+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E8AgLF+ZaDD5vilRyVkETjeXEjlV+JJfZUJ4WEtuiIBkvpzFBEeqdgk1+aARCrp+R V/6H7EDO0guWkrW7CC9TXk/JncCiwYmiVbUReeNut5OO5TpB+VOPsl7Ra/ktFBEVRH e1ZiW1hHmWEqs4zug7zRizjodBUl0Z7cMwNJVjcKarocdUE3N8gS9CqoLJDay/EfE9 As8QomhX4cbFCpyq7O14cwsZZC8ZGSeeZJNBlSmyAUDvQAxAgm2bxiik1bq10zm/hH HLV8ydVwvvKWUCnszvOjDZL8V2ffUqw2uVmVkR9oG7Aq6qeUZicNuhXBQBKF1FMyAE 2q1iysdbsLCsw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CC48568A89; Sun, 14 Dec 2025 10:55:17 -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 A-CzS0oASiWW; Sun, 14 Dec 2025 10:55:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734917; bh=76DRXad1qdHoJAZdxIPtta/+eLA2frV4L9SyQUktAaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jOE+kwqDWOnusIw4hHNGG/TXMpoSuP6nQ//h+cgJ4Mz2M9R9HPb8e0cVE/DAo1GLx 8RphGTo04CUbdAEARmoFyTBSoDSRz7sxiqJwebw9CAMNU7+N12zkuWj5g0jN5QhNiM QQf0qS/+9EcCP6ruPqw343L6jZkn1jCW89Qz9/u29Wyxpww40q24Obv0arufe3FeVq LHl2CqEiqRNmRtbcFPoKummaxgOBXrIkURAAGkvTT6HzU9yshmzV6uxTwVw33jQFpp muXWBHiSJ7ms7lb1s+NZYhoOFpD/L7C3oZzw0eWD98mzh5/xO3flcDCmvuq03V2LCx DAyxHzJpcKBjA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 314C368A84; Sun, 14 Dec 2025 10:55:17 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 14 Dec 2025 10:54:27 -0700 Message-ID: <20251214175449.3799539-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251214175449.3799539-1-sjg@u-boot.org> References: <20251214175449.3799539-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: SG74WHXSFTCQIRRS43IGWKPJNO5LIKDY X-Message-ID-Hash: SG74WHXSFTCQIRRS43IGWKPJNO5LIKDY 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/21] doc: Document tiny printf for SPL 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 documentation for the tiny printf implementation used in SPL, TPL, and VPL when CONFIG_SPL_USE_TINY_PRINTF (or equivalent) is enabled. Document the supported format specifiers, limitations, and the warning about snprintf() not performing bounds checking in this implementation. Co-developed-by: Claude Signed-off-by: Simon Glass --- doc/develop/printf.rst | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/doc/develop/printf.rst b/doc/develop/printf.rst index 4a0f054aae1..edda8b24a8e 100644 --- a/doc/develop/printf.rst +++ b/doc/develop/printf.rst @@ -257,3 +257,78 @@ Pointers prints text description of a GUID or if such is not known little endian, lower case (requires CONFIG_LIB_UUID), e.g. 'system' for a GUID identifying an EFI system partition. + + +Tiny printf +----------- + +For space-constrained environments like SPL, U-Boot provides a minimal printf +implementation enabled by CONFIG_SPL_USE_TINY_PRINTF (and corresponding +CONFIG_TPL_USE_TINY_PRINTF, CONFIG_VPL_USE_TINY_PRINTF for TPL and VPL). This +reduces code size by approximately 2.5KiB on armv7. + +The tiny printf supports only a limited set of format specifiers: + +Basic specifiers +'''''''''''''''' + +%c + prints a single character + +%s + prints a string + +%d, %i + signed decimal integer + +%u + unsigned decimal integer + +%x + unsigned hexadecimal (lowercase) + +%% + a literal '%' character + +Length modifiers +'''''''''''''''' + +%l + long (e.g., %ld, %lu, %lx) + +Width and padding +''''''''''''''''' + +Field width and zero-padding are supported (e.g., %08x, %4d). + +Pointer specifiers (CONFIG_SPL_NET only) +'''''''''''''''''''''''''''''''''''''''' + +When CONFIG_SPL_NET is enabled, the following pointer formats are available: + +%pM + MAC address colon-separated, e.g. '00:11:22:33:44:55' + +%pm + MAC address without separators, e.g. '001122334455' + +%pI4 + IPv4 address, e.g. '192.168.1.1' + +Limitations +''''''''''' + +The tiny printf does NOT support: + +* Floating point (%f, %e, %g, etc.) +* Long long (%ll) +* Size/ptrdiff modifiers (%z, %t) +* Precision (%.Nf, %.Ns) +* Most pointer formats (%pU, %pD, %pV, etc.) +* The snprintf() size parameter is ignored - no bounds checking is performed + +.. warning:: + + Because snprintf() ignores the size parameter in tiny printf, buffer + overflows are possible. Ensure buffers are large enough for the expected + output.