From patchwork Sat Jan 3 20:04:32 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1219 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=1767470738; bh=gWs+RWYPg9ean7MpbEjVBh2Q0w8n7WplQz7XQ7CCKW0=; 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=spIVkBu/CqEwLb1zupVallUu4RNeOCzVxwTSpUWkwC80lZrRL99IZZ8E82DOagfV8 TMUp7XPoVeW0N9+PLyOmon7bmM77tgAPh6wm8c6e+DdJQgcXC9S8G0GHYJ2m601uzG EtnBnPNLxGNUTlKrZVMGIX3j/QXNkkkSpo5DoKoVMB0433CYZ1yfcN9G/iGhg28UGS LqUeE6EZ3gdbWmTZjeyiEUnn+2tEXe7+C0IAvTpFdoWtXpZ+V7rBm0UgW2/6fHk7bt ED4KomOaXB+4Z0qhwLsDAtA5/Vsro3vT8LmeU1l/lZKDB31Du1Xec+2iwR436XW4Ly JjBBu9EayFO2w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AC47269090 for ; Sat, 3 Jan 2026 13:05:38 -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 8IFq7GNBezwU for ; Sat, 3 Jan 2026 13:05:38 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470738; bh=gWs+RWYPg9ean7MpbEjVBh2Q0w8n7WplQz7XQ7CCKW0=; 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=spIVkBu/CqEwLb1zupVallUu4RNeOCzVxwTSpUWkwC80lZrRL99IZZ8E82DOagfV8 TMUp7XPoVeW0N9+PLyOmon7bmM77tgAPh6wm8c6e+DdJQgcXC9S8G0GHYJ2m601uzG EtnBnPNLxGNUTlKrZVMGIX3j/QXNkkkSpo5DoKoVMB0433CYZ1yfcN9G/iGhg28UGS LqUeE6EZ3gdbWmTZjeyiEUnn+2tEXe7+C0IAvTpFdoWtXpZ+V7rBm0UgW2/6fHk7bt ED4KomOaXB+4Z0qhwLsDAtA5/Vsro3vT8LmeU1l/lZKDB31Du1Xec+2iwR436XW4Ly JjBBu9EayFO2w== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9C54E69060 for ; Sat, 3 Jan 2026 13:05:38 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470735; bh=4xkCyR1byYOOVbf23u9obPtWPeVasOc8S98rAK6XWAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OFx+iothSvb++DmDZ2czqegomgzVpF2jel2gYmMr1Y27jUXUd8VM8AiCSqdBZC1pd T1nvMFvHHhkJFG5+o+ndDGLdOXeMrTWAs7roJRxddQYQAbDOIl3PbpJdoWXXq8NCSh r4ZCeZ/8O0DzZlOn6EQfizUpDGL+Bb4fGiwilt5h9AHYa/VTACdwMrJL0C/Flgbxmg atZmol2Vs+jKP01V2D2ogA5sVmI9lFM8mMLCVftcKLJ7pAscfL7nxQ5AVEGP+JsTZP BNx5dzutN0WOiIUDKdXHtqtrb7Fnhex62ZLc38kB6ecj7ZrhGw/kwPzn2czrrR30kT S5D4zzWp48Ntw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 971ED6908D; Sat, 3 Jan 2026 13:05:35 -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 zsagZULhMaUq; Sat, 3 Jan 2026 13:05:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470730; bh=sxbMwWvZHl1Mde2SzeFb1Ay5xHk6wjouchkcrGorf2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WumQUGMUREOW77ffEoDkCnFJOEUb6alIUuiVZ0gkglV2/K+d7bpWQ0yVCs6bYvy8E xicvUq0ObxHG3rfT1oO3IIBPjYL7Mll74sEMKRJgMetHzsrn5U8WcZb8kEtXrPN9YA QWBey4zBLXkqKacseh9c53UOY5Hhp/qrwcy+icP/+CS8JWLDEwJDpP2YZ3ggJlSyi3 HKpKupkLcOWQeEbPf4BtY/git7Q8CUikzNf/b/myXsH6eA8x2PdvMGQpGkvW5N+8GA ILziGJ5KT0tYULFmWTpSlh7Ajn3tbMrj/cTQykH1s4OPRjdnrVKNnGc+sNAemX0PL9 YXWthnO6tFqBQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 89BA768FCC; Sat, 3 Jan 2026 13:05:30 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:32 -0700 Message-ID: <20260103200510.3605009-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WOGX4QVTI2TCCJB5BVPF2YCIQYHGOW4T X-Message-ID-Hash: WOGX4QVTI2TCCJB5BVPF2YCIQYHGOW4T 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 v2 01/29] u_boot_pylib: command: Convert output before raising exception 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 Call to_output() before raising CommandExc so that callers catching the exception get string output rather than bytes. This avoids the need for callers to handle bytes decoding themselves. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) tools/u_boot_pylib/command.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/u_boot_pylib/command.py b/tools/u_boot_pylib/command.py index cb7ebf49ce5..6b3f9fe59bf 100644 --- a/tools/u_boot_pylib/command.py +++ b/tools/u_boot_pylib/command.py @@ -136,9 +136,10 @@ def run_pipe(pipe_list, infile=None, outfile=None, capture=False, if result.stdout and oneline: result.output = result.stdout.rstrip(b'\r\n') result.return_code = last_pipe.wait() + result = result.to_output(binary) if raise_on_error and result.return_code: raise CommandExc(f"Error running '{user_pipestr}'", result) - return result.to_output(binary) + return result def output(*cmd, **kwargs): From patchwork Sat Jan 3 20:04:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1220 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=1767470742; bh=jGLybr+ZAfFbAWN1o8q5X/1zRLw66hTyauA9J/Yq/6A=; 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=Mj+POg4aiy72L2mdPALt1HigfodsirntKG08WMgMNEa3/V5THHJFyFEX0qcoGwBx3 b3QSIqIZCxq+OKNd8PoKwCx17RiH/rsGvo7gelgczn961PQtCcxz7o5MxUdoTPK7zm YJL+qIHMl8Y/qFCDDAW8TuwhhTbW2H2DalXCo08p4vRSmfjs+IKI2/fPKHphxFWsSF uskkGWTSoDBwuB5HdGYAndXm9gTzUh4ZKCm5nR0HKgi6VR1bmUmwxerG5E2tXi8uv/ tbh4wDg2BrNNBMlHo75oOiatvyWMO6M5o53d9x3PHAL+oDZ8XS5KEQYeSLdK6ThCGz XneT+mN8ufBZg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 204736907B for ; Sat, 3 Jan 2026 13:05:42 -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 vUEi-s1CPgBV for ; Sat, 3 Jan 2026 13:05:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470742; bh=jGLybr+ZAfFbAWN1o8q5X/1zRLw66hTyauA9J/Yq/6A=; 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=Mj+POg4aiy72L2mdPALt1HigfodsirntKG08WMgMNEa3/V5THHJFyFEX0qcoGwBx3 b3QSIqIZCxq+OKNd8PoKwCx17RiH/rsGvo7gelgczn961PQtCcxz7o5MxUdoTPK7zm YJL+qIHMl8Y/qFCDDAW8TuwhhTbW2H2DalXCo08p4vRSmfjs+IKI2/fPKHphxFWsSF uskkGWTSoDBwuB5HdGYAndXm9gTzUh4ZKCm5nR0HKgi6VR1bmUmwxerG5E2tXi8uv/ tbh4wDg2BrNNBMlHo75oOiatvyWMO6M5o53d9x3PHAL+oDZ8XS5KEQYeSLdK6ThCGz XneT+mN8ufBZg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0F0866908D for ; Sat, 3 Jan 2026 13:05:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470740; bh=UEtTo8HpEg5enkyZZZ8oyHTPKnzrMuLy3wkzPmgKvW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LveQRUk7kXuyczA/hYxPRT9lMNL+NBi9qSxyEPJAFVBHn/Ka2IvRfL22gV2sd9N4L 6NLZOi+8mnfiT4zHs+FfTcMfYVbnw9zlw1tv/6BN2ETOdGyXAvTh1BRM3EtAL472FD Epf2XvQcqiAfMkkdKG8AnIBl0+VsY6U/ExuZsHvtH0ehdakSFtx1f4k3EDQsXdsagL +POR+E+RUtMrcCYAQT0/+y5OpodA2A1vFIXZwe511cUgpcdxDjw1rR3Ag4MAhxub6y EfBOJCNqsdwOubbnYdpe5NeTFUEfD8J8pxJdUArra/dJJXZQWsVblYP5pSAIADTlzd C8sKb5Mv4DIiw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 18C1D69060; Sat, 3 Jan 2026 13:05:40 -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 puSkfZHupBFP; Sat, 3 Jan 2026 13:05:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470735; bh=EgsWMvH2B3E3Gv8jSKjFZ9tWqopneQVertiYzUsnloo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VeQghGiPq0mc1wg7k+6Bh/A/4wd9327yT61I2uBNXGqDQ9uE93W4brQlzu8J+uybs vLI1rsb8DH1Fi0XyEJKd8VDC8mvEyxoeH2Z+vhaHZa8Lv6v8jn8T6lsdyoHpP7R+o/ SbyHaYPmHmoywYZjTPAjP3TIwHgXShZ/l6cpupS81p0pVFmZB+82IeSC5xMQhgBIZw hDeu+qGtI571ni3qhyMTVaxKaj0y791hEGdMOeS/egVIvwqrgecCtTYpeXUBAufE2w 60qtVTgOMh2ml0NjMQk2FXDGtGuj0EgmHIPml/h4/cAEu3Up3dBM2r7I73huul8ObP JAwnzI/bxQJHQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5CB176907B; Sat, 3 Jan 2026 13:05:35 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:33 -0700 Message-ID: <20260103200510.3605009-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: R6NSBM6QZ2EJE2V34PVLKCN54GPLZCCR X-Message-ID-Hash: R6NSBM6QZ2EJE2V34PVLKCN54GPLZCCR 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 02/29] u_boot_pylib: tout: Add newline parameter to output functions 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 a newline parameter to all output functions (info, error, warning, notice, detail, debug, user_output, do_output) to allow suppressing the trailing newline. This is useful for progress output where multiple calls should appear on the same line. Example: tout.info('Processing...', newline=False) tout.info('done') Also fix typos in docstrings (msg; -> msg:). Signed-off-by: Simon Glass --- (no changes since v1) tools/u_boot_pylib/tout.py | 70 ++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/tools/u_boot_pylib/tout.py b/tools/u_boot_pylib/tout.py index 137b55edfd0..c608806476c 100644 --- a/tools/u_boot_pylib/tout.py +++ b/tools/u_boot_pylib/tout.py @@ -62,98 +62,108 @@ def progress(msg, warning=False, trailer='...'): else: terminal.tprint(_progress) -def _output(level, msg, color=None): +def _output(level, msg, color=None, newline=True): """Output a message to the terminal. Args: level: Verbosity level for this message. It will only be displayed if this as high as the currently selected level. - msg; Message to display. - error: True if this is an error message, else False. + msg: Message to display. + color: Colour to use for the text, None for default. + newline: True to add a newline at the end. """ if verbose >= level: clear_progress() if level <= WARNING: - terminal.tprint(msg, colour=color, col=_color, stderr=True) + terminal.tprint(msg, newline=newline, colour=color, col=_color, + stderr=True) else: - terminal.tprint(msg, colour=color, col=_color) + terminal.tprint(msg, newline=newline, colour=color, col=_color) if level == FATAL: sys.exit(1) -def do_output(level, msg): +def do_output(level, msg, newline=True): """Output a message to the terminal. Args: level: Verbosity level for this message. It will only be displayed if this as high as the currently selected level. - msg; Message to display. + msg: Message to display. + newline: True to add a newline at the end. """ - _output(level, msg) + _output(level, msg, newline=newline) def fatal(msg): """Display an error message and exit Args: - msg; Message to display. + msg: Message to display. """ _output(FATAL, msg, _color.RED) -def error(msg): +def error(msg, newline=True): """Display an error message Args: - msg; Message to display. + msg: Message to display. + newline: True to add a newline at the end. """ - _output(ERROR, msg, _color.RED) + _output(ERROR, msg, _color.RED, newline=newline) -def warning(msg): +def warning(msg, newline=True): """Display a warning message Args: - msg; Message to display. + msg: Message to display. + newline: True to add a newline at the end. """ - _output(WARNING, msg, _color.YELLOW) + _output(WARNING, msg, _color.YELLOW, newline=newline) -def notice(msg): +def notice(msg, newline=True): """Display an important infomation message Args: - msg; Message to display. + msg: Message to display. + newline: True to add a newline at the end. """ - _output(NOTICE, msg) + _output(NOTICE, msg, newline=newline) -def info(msg): +def info(msg, newline=True): """Display an infomation message Args: - msg; Message to display. + msg: Message to display. + newline: True to add a newline at the end. """ - _output(INFO, msg) + _output(INFO, msg, newline=newline) -def detail(msg): +def detail(msg, newline=True): """Display a detailed message Args: - msg; Message to display. + msg: Message to display. + newline: True to add a newline at the end. """ - _output(DETAIL, msg) + _output(DETAIL, msg, newline=newline) -def debug(msg): +def debug(msg, newline=True): """Display a debug message Args: - msg; Message to display. + msg: Message to display. + newline: True to add a newline at the end. """ - _output(DEBUG, msg) + _output(DEBUG, msg, newline=newline) -def user_output(msg): +def user_output(msg, newline=True): """Display a message regardless of the current output level. This is used when the output was specifically requested by the user. Args: - msg; Message to display. + msg: Message to display. + newline: True to add a newline at the end. """ - _output(ERROR, msg) + _output(ERROR, msg, newline=newline) def init(_verbose=WARNING, stdout=sys.stdout, allow_colour=True): """Initialize a new output object. From patchwork Sat Jan 3 20:04:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1221 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=1767470745; bh=fmPizxng3c29EHINuLAErkN3vFeabLBMotsINFAl5bY=; 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=ZfAPpDNCvvrRHR/b30plLhHI0+oQkvYdnHJy9X4IoziUVtK8XLO/ZbapoVX2X+6dq JIP6ANHfR9StI0SOAkL8tGbjZ3b2JgYXSxBGvJ+duNePgT4pWkzlCrT301P+weFss1 SMnWw6zO5S61tC+U3TE+0AuNdgadO55GVNYH/5mh1xiUkRn5qR5qy1dvBPMIleU1r9 cuFqg9nS+ZtasrISy9wLz86koRg9+o+ZIa9VpaYbSv5zmcLq03kregLKir8CKvbohG 6zfw9iIR/Mj1kEMFEnS1hcErkQboUamKSCTduC0AKh1KVjiooVqv6tJTko3JEwg/yd YaXNMJNVNSlOw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8C47169093 for ; Sat, 3 Jan 2026 13:05:45 -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 UnoQ6UxDNfc8 for ; Sat, 3 Jan 2026 13:05:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470745; bh=fmPizxng3c29EHINuLAErkN3vFeabLBMotsINFAl5bY=; 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=ZfAPpDNCvvrRHR/b30plLhHI0+oQkvYdnHJy9X4IoziUVtK8XLO/ZbapoVX2X+6dq JIP6ANHfR9StI0SOAkL8tGbjZ3b2JgYXSxBGvJ+duNePgT4pWkzlCrT301P+weFss1 SMnWw6zO5S61tC+U3TE+0AuNdgadO55GVNYH/5mh1xiUkRn5qR5qy1dvBPMIleU1r9 cuFqg9nS+ZtasrISy9wLz86koRg9+o+ZIa9VpaYbSv5zmcLq03kregLKir8CKvbohG 6zfw9iIR/Mj1kEMFEnS1hcErkQboUamKSCTduC0AKh1KVjiooVqv6tJTko3JEwg/yd YaXNMJNVNSlOw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7BDD269090 for ; Sat, 3 Jan 2026 13:05:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470744; bh=HerlAAT3qnrrVkbVLyxeTT/z9/YZN5ME9GoeUzKhxa4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GSIgpZ9J1fuacYUYyhnIc8lsVpiMzEh0cNFZDGOPm1hw0uJ3MPBJrEvMv9QZDaWmv vxy27vIpNOL0yO4Zafj/cqPDjssAPaSZLXV8Zh9qnoGnwdPUro1RiwdkCDITXb6kYk 9JuXMGmN4dVduUdi2zt/cLUysGo2nyHJJRSADIzT9fPnPkzLqgqSwiMv9fZENd9iAU kZQ8rtWQQauNRliyDZCG54y5/rR/IZ3dbzjXvSf3febnXlC/VnvDFW/QLOQsS7y2Qz KY2dy0XvuB2V8OZr9iSLXV07JpOaXaKTzmw1Do2N8dyDu2mfH1c0V4us8ZU0XdxDoJ sA6H6Oj1MNHjw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8081069060; Sat, 3 Jan 2026 13:05: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 10026) with ESMTP id WLme_UKeOB6C; Sat, 3 Jan 2026 13:05:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470740; bh=XXI3DgTi911LhqhdWifJnCYTID+vN75wbgh2NCH91Ok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sJn+KTKZD+5Ekn03pj09AupdlFEY86wAHshEcgsg5PGTjs8qmw+QQo298FifBxwOc PzYoikRXsGL0hj/m24o6gVkEp90l/HVIahKdgKYOFrtscH3XfC2lK0Cj6BYhnQZuxv Fz1UqBnofpbPQQmV/ITSG+qy/spcR/z69SgUJDaQmaO18RleEyBt3WOO/obwLceOvs WKC85DpettyVVgH7hSjKaqNKl9lHcpPBKlBqgVDE5OntzfPC3nMocUhlymoN9eWWcU JeqKgaEKIuvAlmuoAdnVYIk7NB/BxhLfQSSYgLHrRlRpFswf1QknkLWOSsKGgk3wz6 mFBxuvGr4sU2A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id C6AEE68FCC; Sat, 3 Jan 2026 13:05:39 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:34 -0700 Message-ID: <20260103200510.3605009-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: UIOTBYUHFM7UQTBVBHXCSYTOM7Q6WQR5 X-Message-ID-Hash: UIOTBYUHFM7UQTBVBHXCSYTOM7Q6WQR5 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 v2 03/29] buildman: Fix IDE mode to show warnings 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 When IDE mode is enabled (-I), warnings are not shown because: 1. The process_result() function only shows output in verbose mode, not IDE mode 2. When there are warnings (stderr output), the build is considered "failed" and retried. The retry finds the object files already up to date from the first build, so make does not recompile them and produces no warnings. The second result (with empty stderr) then overwrites the first, losing the warnings. Fix this by: - Adding IDE mode handling in process_result() to write stderr directly - Changing the retry logic to only retry on actual failures (return_code != 0), not on warnings Fixes: 6a30a2666008 ("buildman: Support running from an IDE") Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) tools/buildman/builder.py | 14 ++++++++++---- tools/buildman/builderthread.py | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py index c2f0b4e409e..e218aa4184a 100644 --- a/tools/buildman/builder.py +++ b/tools/buildman/builder.py @@ -575,7 +575,10 @@ class Builder: self.already_done += 1 if result.kconfig_reconfig: self.kconfig_reconfig += 1 - if self._verbose: + if self._ide: + if result.stderr: + sys.stderr.write(result.stderr) + elif self._verbose: terminal.print_clear() boards_selected = {target : result.brd} self.reset_result_summary(boards_selected) @@ -1440,9 +1443,12 @@ class Builder: # For the IDE mode, print out all the output if self._ide: - outcome = board_dict[target] - for line in outcome.err_lines: - sys.stderr.write(line) + for target in board_dict: + if target not in board_selected: + continue + outcome = board_dict[target] + for line in outcome.err_lines: + sys.stderr.write(line) # Display results by arch elif any((ok_boards, warn_boards, err_boards, unknown_boards, new_boards, diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py index 9449485a4cb..3d1b656531d 100644 --- a/tools/buildman/builderthread.py +++ b/tools/buildman/builderthread.py @@ -769,7 +769,7 @@ class BuilderThread(threading.Thread): force_build or self.builder.force_build, self.builder.force_build_failures, job.work_in_output, job.adjust_cfg, job.fragments) - failed = result.return_code or result.stderr + failed = result.return_code did_config = do_config if failed and not do_config and not self.mrproper: # If our incremental build failed, try building again @@ -826,7 +826,7 @@ class BuilderThread(threading.Thread): self.mrproper, self.builder.config_only, True, self.builder.force_build_failures, job.work_in_output, job.adjust_cfg, job.fragments) - failed = result.return_code or result.stderr + failed = result.return_code if failed and not self.mrproper: result, request_config = self.run_commit(None, brd, work_dir, True, self.builder.fallback_mrproper, From patchwork Sat Jan 3 20:04:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1222 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=1767470751; bh=BsuxLtsghR4vtuUvfXLZiAcVbsSUy9WBVDX/uCiDYiw=; 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=cI53pqpFlziW6E7tpvU/c9ro/L4SQK8xXzACHUH6MmoQ8X77rpcNT/GyN7D5ivhWy 8dlc4IIVeEFuSUUGQa1sgxkCizQxUYqEYUURavdRbiUEumjeUuboxSDwQwsZIG+8aT FsmJ6XUsDzVx72LPiMKpE5j11PiDYl7Ooj0rpPJeByesqMxCrHcNG4ctS32mVyhCm7 OUnbnQ7au96xCoyxNUWwUaBgOnldNzH4tBr8HVi3Di7P4YUA9n2D+j+BslQTiGXy2L y4z9uI1iBh+FjcewX9LR6tqWNfZhaknMYFMQpqSeQLTLEGKqRextA5KHll3k07o37K 7GiUpjkM8M+Pg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9579569090 for ; Sat, 3 Jan 2026 13:05:51 -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 XjUAJ31-inbK for ; Sat, 3 Jan 2026 13:05:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470751; bh=BsuxLtsghR4vtuUvfXLZiAcVbsSUy9WBVDX/uCiDYiw=; 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=cI53pqpFlziW6E7tpvU/c9ro/L4SQK8xXzACHUH6MmoQ8X77rpcNT/GyN7D5ivhWy 8dlc4IIVeEFuSUUGQa1sgxkCizQxUYqEYUURavdRbiUEumjeUuboxSDwQwsZIG+8aT FsmJ6XUsDzVx72LPiMKpE5j11PiDYl7Ooj0rpPJeByesqMxCrHcNG4ctS32mVyhCm7 OUnbnQ7au96xCoyxNUWwUaBgOnldNzH4tBr8HVi3Di7P4YUA9n2D+j+BslQTiGXy2L y4z9uI1iBh+FjcewX9LR6tqWNfZhaknMYFMQpqSeQLTLEGKqRextA5KHll3k07o37K 7GiUpjkM8M+Pg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 82F9069060 for ; Sat, 3 Jan 2026 13:05:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470748; bh=+eqgUBDh8FRaO2nl4R6hWxByuyyczQ6bGXF9W2d+Evc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lvq9aRNyW+93DWW4Xb9RPxKk3ziaBEr63bBruAYSXzMNm3CthvNW97qOKnf3VJhLU wvjvhXzTtUEKXM0qSPr+Pnc3vzVDdw3sIi1XvBah/XSzMiFBLfvj2fk0PuEvjz/Xkb XJFscH3hXvgQ/5hp+FvfnIDRfohpKAFIhE6utgYIGEbLGpNuumXDCMqZ46osaOKzh3 Xsj6+xaU1X3TdkZdxy8gYQKKAUT2l/rrTKWf5bB0IdbBxcWgU7h4ZJko4sgZeT5oDE H3hv4ZQnlrGgdcwyx0c3e0Qq4KqbC/kYgbhrfBoNTWfxxzCz/I2n151hXtGClGcC0F zChma8XqsCAMA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E843169060; Sat, 3 Jan 2026 13:05:48 -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 9CEBG3Plj3nK; Sat, 3 Jan 2026 13:05:48 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470744; bh=LaXuLqp5skaMVLEGiBDouJf91V1ENgifpioIspaZ1c4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DTp1NsWuEydgDAPKTFTUIcb2gy2RY3wo7X+VU4Y/5KJC3loK1EKsXI3AbP4hpKWBJ 8j+UnzTAzwbrJOND6ULivgPIWD5n2OtofzRJ/ulWCy9XCvUjw5nGhnb+RdPrSXw69r W60qnSYe3JSpShgo9SYLMHVuLfomcOGncxZ+R6H2KjPZRBk1e+DROytzukmbOuUmpy wq6f/xMH5uWc7M9GHLNq+8ZaKFpoG0izu6pjPjD7C5b/Ebm4UBe2AnD3sFs3d9ErZH ncv1DOBulLbkMSAxuxZOKdVJxlUloOyc5gFrSwLoquFYLWikkO92bOxdGIe2/AqJ3Q 8pMax8o886jbA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8D63768FCC; Sat, 3 Jan 2026 13:05:44 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:35 -0700 Message-ID: <20260103200510.3605009-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: SSRFJMIZO7SWC2EN4OEFQYFW7QA6R4FL X-Message-ID-Hash: SSRFJMIZO7SWC2EN4OEFQYFW7QA6R4FL 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 v2 04/29] video: Fix memory leak of vidconsole device name 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 The vidconsole device name is allocated with strdup() but never marked as allocated, so it is not freed when the device is removed. This causes a memory leak on every video device probe/remove cycle. Mark the name as allocated so driver model frees it on device removal, and free it on the error path. Fixes: 83510766c90a ("dm: video: Add a uclass for the text console") Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) drivers/video/video-uclass.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 3e02c48d399..2789c352113 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -795,8 +795,10 @@ static int video_post_probe(struct udevice *dev) ret = device_bind_driver(dev, drv_name, str, &cons); if (ret) { debug("%s: Cannot bind console driver\n", __func__); + free(str); return ret; } + device_set_name_alloced(cons); ret = device_probe(cons); if (ret) { From patchwork Sat Jan 3 20:04:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1223 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=1767470753; bh=YxmRAX3x2pdbckx1gT267R8WHNjhvBDIJCyld2dj8PI=; 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=YtHj5igW2edCgjZWEwOTuxs3B7+tvi/fLv5oTHlmxzkM6yZG1F9bD23YBdPTitv+w rFZ0SGG6cH6CKiiXe34UnI0d9vxTEXaVIN9YtxoWRtf7nnPfO0rHKBZArqUJAOwRE6 2tZDvO4NNrBPWqbjQ6zPqHjD/Czqh4H865TlyDFQX7v3tzR9sznDF3X4z19mJdJ4gt OQcHaHmy+oquFm+GDUKuRKvymQhwrEfWggp5dz85E4AU2+4d/etZ4wFK3ZiKMviHIr mdn/HmSA75iAbRii/Ks1hxZqlkDDrE7qIrSsANzMvC/yUVjKwXMxWfwdAHhnM2D0hu ZUHgdmCTL0ReQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2719369060 for ; Sat, 3 Jan 2026 13:05:53 -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 MFgTGJ6lPofp for ; Sat, 3 Jan 2026 13:05:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470752; bh=YxmRAX3x2pdbckx1gT267R8WHNjhvBDIJCyld2dj8PI=; 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=FyIA//jAyKzqvkXDOrFIh76tEmo5JAkTzpMediu1DoEnwP+CawQGpCSZVh/KaBzeW QV/NJPowpbjr99qqGGf0IenUHlF/KXog7XjZr5HAaOZEcZvzRubEbyO65fHlMMSJ5K QhNEyffy7kxZFO2H47Dg089tZYWdDI7omw8h4lRR44J7rQhG6bVv/xEEu2Om4jCZs/ 7R5PNbX1XpvIaHEiPWmv1o+TiJMKz5OhbK4/DMMmTfDBN/xTSZ0xQr5x2H6wXIoW/k oZFbzhP6OFy4oExxY43q4CnyvU7Ezx9my0xem/IevSRvwUDywPyWc+2lopKxQhFEFm 7324xP+mBA8TA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1C92A69096 for ; Sat, 3 Jan 2026 13:05:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470749; bh=OuX7s3A7M5cosrRURHBHFjx+wR9kgGcpF6jpdZcccbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tS3inybeYFXQsIlW2pef8Ad6hlSrVLdP4CCvLmNXp2OpY4l7mOIMloKc0YbwZVYkV aLugTMFgzQ1Hx0QjkiQhSHxt7RAQaIvyzzoHiyeKz94LdUN5SnZzGEOdg6QkAfbbmG W117cie3jbhan4+GBSzLGZatN2WkOTkhy5eFV8c085p+USgPUEkj3VO2rbx7j8ijdk Z7Fnv8+p+KszgdS3mj1hV0VMoCtEvmDLh/dAaChciBP+efhKBIRYf1iW2aJpQkDEvh TQuZ+TyfCeyEjEwjftIPGcP8vLEZ92KCR/tXfsUrtUl8Z1GBHHM/eMTyAQm/uEYnPB TCkA64IdXLIvw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BD9F86907B; Sat, 3 Jan 2026 13:05: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 10026) with ESMTP id J1ESPTp5lGDG; Sat, 3 Jan 2026 13:05:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470749; bh=PDUw7nCohlQtatNGO9itRGlMg0px/UsWgDg4VuoYca4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ezd3aWbsxy+AV9JGl0q9xF65O6lctY9aisCLlou/Q/KSN84hMEMejFmzzKq2pc1RD d6u5OAlAyz6YRFJJB74SLBgIBeSN5cTbnofkf9MJ9MUrTd6sFz3ryCnQY5rrz0YqDl eEnBq3u7EIoyjsns/AB4BtR4JD2+338c8trywGSrYBesptudfLkOQ1wr95WiHgtPvu L6otjcR4fjgq3ILQ3t2Vhnm/Ju+S8mKChZAoC243aJoUzJCuyZb7crCit/rcX03Wg8 hJ1Fk485tpfMw42jZZUb2XF2nvo7i4jDma/iywbSqn640v/U+Y01Uz2m2QD5B2goEj A6SUH90bvRuew== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 36C8768FCC; Sat, 3 Jan 2026 13:05:49 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:36 -0700 Message-ID: <20260103200510.3605009-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KQBCY2UITMI5HPEG7DGV6IN3FEHUX2AY X-Message-ID-Hash: KQBCY2UITMI5HPEG7DGV6IN3FEHUX2AY 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 v2 05/29] video: vidconsole: Free cursor save buffer on device removal 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 The cursor save_data buffer is allocated when the cursor is enabled but never freed. Add a pre_remove callback to free this buffer when the vidconsole device is removed. Fixes: aebedeac4478 ("video: Provide a buffer to hold pixels behind the cursor") Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) drivers/video/vidconsole-uclass.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 52a51b5e1c1..8efe458287a 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -865,11 +866,21 @@ static int vidconsole_post_probe(struct udevice *dev) return stdio_register(sdev); } +static int vidconsole_pre_remove(struct udevice *dev) +{ + struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + + free(vc_priv->curs.save_data); + + return 0; +} + UCLASS_DRIVER(vidconsole) = { .id = UCLASS_VIDEO_CONSOLE, .name = "vidconsole0", .pre_probe = vidconsole_pre_probe, .post_probe = vidconsole_post_probe, + .pre_remove = vidconsole_pre_remove, .per_device_auto = sizeof(struct vidconsole_priv), }; From patchwork Sat Jan 3 20:04:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1224 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=1767470756; bh=tsrRvl3yKzgEwKLEhZsJkhrczyOQqD9UqYfHYadk7SU=; 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=JupaJdH1z077Khz9B2t5FAfXT5pF/hWQHtZvGHcXeEvaxz13Hkzp7l6hZM4nDVN1O RN7FbPOsiRuNpNPzM4zb0nkTRv1O8u7CPEpvm91+6Og2WjrXCax50lRtT2VhTZv6Ni XHNzXThBdIgVovXh1xcqeIv2Q0w4AyskIXojM2UlKF0Sp013y6lj1tF8KILQq3TOdk EUnLxv7U1WJs/qgnYT/2cZTthNZTbyXg1u34zvHiEf5yVDNiTsz3dmYbRxGLtBlLru OBRsHs6hUGhfkrhDsll/SA0sCABtWnhO70bMOp/nMrgSXt3Vp0la5IP35pridN916Z uDd8xhZKFmYZQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DA7B569095 for ; Sat, 3 Jan 2026 13:05:56 -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 FdArCEr2HT7t for ; Sat, 3 Jan 2026 13:05:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470756; bh=tsrRvl3yKzgEwKLEhZsJkhrczyOQqD9UqYfHYadk7SU=; 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=JupaJdH1z077Khz9B2t5FAfXT5pF/hWQHtZvGHcXeEvaxz13Hkzp7l6hZM4nDVN1O RN7FbPOsiRuNpNPzM4zb0nkTRv1O8u7CPEpvm91+6Og2WjrXCax50lRtT2VhTZv6Ni XHNzXThBdIgVovXh1xcqeIv2Q0w4AyskIXojM2UlKF0Sp013y6lj1tF8KILQq3TOdk EUnLxv7U1WJs/qgnYT/2cZTthNZTbyXg1u34zvHiEf5yVDNiTsz3dmYbRxGLtBlLru OBRsHs6hUGhfkrhDsll/SA0sCABtWnhO70bMOp/nMrgSXt3Vp0la5IP35pridN916Z uDd8xhZKFmYZQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C41B668FCC for ; Sat, 3 Jan 2026 13:05:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470755; bh=kYRIaAcBZQZy8I/t9hLOIVXJPc2Bk4CxXMX4VDvhDbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gqDBRkSlZoaGyYlguqui1gmLSOmGxvpOJkG+awoIGySAAghH2GQqJ/Pw9Bx9XR0rq fi41f0yiAoP5A3ngeyF7X7ZQ/6oXeBHk8aT5xsgtjvXx1QnVh3HDy+RQ3n+enY0dND Ziizyk1WLqrZBLX+CWPhmfS1z190kVeO07z0nOdogvCg6hDVeKMXHKDdihT9PYHCK+ J1V5GYsq7dXe7MRzM+b2Iwn/q2XPY2CPzxbcEbBYDEecSLc1y6OKn0UHTA+JF5+IKn TTdqPfwqfcEJKmOcqF7pPHSpWVHRSOBii/2RtO0V2kMAbPxswQullik+7VcvtY3s0C +VqYV2qJ0itxA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 75CF36907B; Sat, 3 Jan 2026 13:05:55 -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_mCIwPvbjZf; Sat, 3 Jan 2026 13:05:55 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470750; bh=QEV7gmdZeRtEyY2MlXz2HRWQI+OAfyYKuOqq7q6TV1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AkaDMwO7Iw5CdYcpw4hs9XanAUIsq8qtSGFNtD8+HDQb79rZMrwvQJ6/06iXS5lWs OJEm3MiECgnqT9x1nk91r64eaDct8dwweRhsHiBpK9sWTS7zTom2Pnyid/xypfO2Ql pgxkN4yp9RmG22Xp70oTxAK0BLfr0OnD4Z9ebHG8xU0CZeVVLuJoAQc91hK3CbQ/1B Bi7dpnDsGStJvDcR72PPxgR+B8HaJL1gpSd0Woh0W7NCPDvi12EmuusS2xjx2FqDAE uRHo66nXvy7waV23RIt1gMg+iET7DpgNzazsrkKjYgMUMwCBBcDSt676DKB9fjwFI9 6uKjLYZXA34xQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0E46E68FCC; Sat, 3 Jan 2026 13:05:50 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:37 -0700 Message-ID: <20260103200510.3605009-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5R5VULP6MTGEJIJ36K7E72CZZBQQZMTR X-Message-ID-Hash: 5R5VULP6MTGEJIJ36K7E72CZZBQQZMTR 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 v2 06/29] video: truetype: Free allocated buffers on device removal 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 The scratch buffer and glyph buffer are allocated during probe but never freed. Add a remove callback to free these buffers when the truetype console device is removed. Fixes: 159af15074f2 ("video: truetype: Add a scratch buffer to use malloc() less") Fixes: 69d2f4ab58d2 ("video: truetype: Use pre-allocated buffer for glyph rendering") Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) drivers/video/console_truetype.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index 6e65f55d598..c33686aff9b 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -1243,6 +1243,16 @@ static int console_truetype_probe(struct udevice *dev) return 0; } +static int console_truetype_remove(struct udevice *dev) +{ + struct console_tt_priv *priv = dev_get_priv(dev); + + free(priv->scratch_buf); + free(priv->glyph_buf); + + return 0; +} + struct vidconsole_ops console_truetype_ops = { .putc_xy = console_truetype_putc_xy, .move_rows = console_truetype_move_rows, @@ -1265,5 +1275,6 @@ U_BOOT_DRIVER(vidconsole_truetype) = { .id = UCLASS_VIDEO_CONSOLE, .ops = &console_truetype_ops, .probe = console_truetype_probe, + .remove = console_truetype_remove, .priv_auto = sizeof(struct console_tt_priv), }; From patchwork Sat Jan 3 20:04:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1225 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=1767470761; bh=dlp14m1qfnbQROSooy2XolkJYIl20n0CTPgu/O1wef4=; 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=VzNZeCnjY51ssv8qgV8snXCCrWOYeqQEFZL7USfHFgCQtGN2bSlt7005GFevVJovt ocYe+Ttehe50WvrV055bJ5XpwUDQ89vNX2wdaRL1FxYXkr/KkLOjl5wWthaNpKHHcs lCfFzoTq8z1xIq+YhCtsxL+9zoNMMPBdmKos5ZPfxsJMuBENxPavf5EX5vbnZzX8/q 2t/Sk8y4vlbN4QRnkZ1a1TKnsROYZLPycqKxCQo41f9ixrPOMAv/q2XexIwgS5Y4GC TiqdjAInTi9dx7j+9sxZUIjfD7Nun6Vk7wXBRlrlpC8hwRzsNqtvBLneDO2iX/mHD/ bJZnzeqA9SBXg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8470269095 for ; Sat, 3 Jan 2026 13:06:01 -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 vy29AgpaSvbY for ; Sat, 3 Jan 2026 13:06:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470761; bh=dlp14m1qfnbQROSooy2XolkJYIl20n0CTPgu/O1wef4=; 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=VzNZeCnjY51ssv8qgV8snXCCrWOYeqQEFZL7USfHFgCQtGN2bSlt7005GFevVJovt ocYe+Ttehe50WvrV055bJ5XpwUDQ89vNX2wdaRL1FxYXkr/KkLOjl5wWthaNpKHHcs lCfFzoTq8z1xIq+YhCtsxL+9zoNMMPBdmKos5ZPfxsJMuBENxPavf5EX5vbnZzX8/q 2t/Sk8y4vlbN4QRnkZ1a1TKnsROYZLPycqKxCQo41f9ixrPOMAv/q2XexIwgS5Y4GC TiqdjAInTi9dx7j+9sxZUIjfD7Nun6Vk7wXBRlrlpC8hwRzsNqtvBLneDO2iX/mHD/ bJZnzeqA9SBXg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7375A6907B for ; Sat, 3 Jan 2026 13:06:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470759; bh=CT2mtfCltXevd2d9HXnPdmaZ8VjZNxe+yLIvCk62d0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b9ekpO13hTbhF8KWZSUaWyGzfOfvZq2+XTFyKafSpQq8bdXLk+2/ChkkNqMufcikw jBd8KRnaqIbMfa8sop/xak1mmSGjSVAjI4AeRtmaKaK4AS0o8CpTKgzRshl9PioVUc pz4vEbMXc9FBwjLLyF+FVeloQqLlxTm7SFMG4pkpbhKPIdzRHgbXWnlIidpfJrPBst PAlg7Dwn1y1mmou/+KeCCXMA3TIW01XJSZ4XMDVp3Pm/aFJWgopxDT9xiixl84ZTiI NPoOgXNZtejOcD81UgCqjUIYjQsy63KLqdkVIdqHzWBEzY3/JRf49G2fqFFRKxwzpA jTbb1EK1P6sxw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 73C8A6907B; Sat, 3 Jan 2026 13:05:59 -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 7r1_sFKPP2l7; Sat, 3 Jan 2026 13:05:59 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470755; bh=Npn4KroJVFO5IQOUpYE57QKrQqh+Fb2LdUTfiz4fQhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ehO6nx0VoM6aMT0MXborSm7lqPmK8EjU5PZJ+Hab99Updem4T6wtnyHmmxvMv92YS 8ec4tX0ckzILZqog/P3agLmjoC+fOcB34d77Cde2cgYerDZpOLwGiqS5ZHjoPOhhmP Tp8iBwWZoPqeC6SSBgqLLgqPJGhhEvKLUNkMbpE9IeCpe/A3YmR66WttbBw3Hkvyoz DJusSZypzs9WTvNy76oTEQD/NqajTTaPYslG7zJUfokZEKzSxvj3URWi+j5q1HOBBG iqyqnzsP0GetFmji34j1hsq+Y/2cr2h3NNmAfsd7NmUShpGbNCRLW3Z5mDK0kWpMK9 THW+gp+5HcEig== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A99BD69060; Sat, 3 Jan 2026 13:05:54 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:38 -0700 Message-ID: <20260103200510.3605009-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: DF6NXY5FRWNS6IUOBPHLHU4DVMD5ULED X-Message-ID-Hash: DF6NXY5FRWNS6IUOBPHLHU4DVMD5ULED 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 Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 07/29] test: nand: Free allocated buffers after test 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 The run_test_nand() function allocates buf and gold buffers but never frees them, leaking about 2MB per test run. Fixes: bc8e8a4bfa0f ("nand: Add sandbox driver") Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- (no changes since v1) test/dm/nand.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/dm/nand.c b/test/dm/nand.c index c7e09850503..ec58815ecdb 100644 --- a/test/dm/nand.c +++ b/test/dm/nand.c @@ -85,6 +85,9 @@ static int run_test_nand(struct unit_test_state *uts, int dev, bool end) ut_asserteq(size, length); ut_asserteq_mem(gold, buf, size); + free(buf); + free(gold); + return 0; } From patchwork Sat Jan 3 20:04:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1226 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=1767470765; bh=WgrJl0yBgGiImTfO39U2SmkJnH+yg0wZuHbBgMNXVWA=; 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=QlFWq+3v6ndpjfsEUGiNd4CsKpNMqM0stWBoG1anNfkQdi3+CgPR4CS9QU19hnoJU 1Eo+5h9SbqwyyBVru0lPZQ8ctB3MwxobhavkOqAXWExfFM5DlJ3YhXYJqr2unBrrQT sbs0cU4OIzNQsU4pDIFUiR47WRRontpW/6t0e6rcndV3mclNrJNZdzEgLPGHehms0I BpdfOYtCd7kwefyeFgdxZKTIPtYX3K9dZ224YTOh+P8dajRzhrcSRXxFBSr5ggr3rA 0V4titJDu0yu/NCEzLfzVoltQ+nNJGg8pykFCXZq81HuGTgYAjQFp2seTgYJ8uCp5p 3XQOFFaYEg0aA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1366368FCC for ; Sat, 3 Jan 2026 13:06:05 -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 9DbM10559wZQ for ; Sat, 3 Jan 2026 13:06:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470765; bh=WgrJl0yBgGiImTfO39U2SmkJnH+yg0wZuHbBgMNXVWA=; 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=QlFWq+3v6ndpjfsEUGiNd4CsKpNMqM0stWBoG1anNfkQdi3+CgPR4CS9QU19hnoJU 1Eo+5h9SbqwyyBVru0lPZQ8ctB3MwxobhavkOqAXWExfFM5DlJ3YhXYJqr2unBrrQT sbs0cU4OIzNQsU4pDIFUiR47WRRontpW/6t0e6rcndV3mclNrJNZdzEgLPGHehms0I BpdfOYtCd7kwefyeFgdxZKTIPtYX3K9dZ224YTOh+P8dajRzhrcSRXxFBSr5ggr3rA 0V4titJDu0yu/NCEzLfzVoltQ+nNJGg8pykFCXZq81HuGTgYAjQFp2seTgYJ8uCp5p 3XQOFFaYEg0aA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 005AB68FD2 for ; Sat, 3 Jan 2026 13:06:04 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470763; bh=7pC190S5Co4GL6FFyASwPRK3PbYiFUqkawCO1WQAOiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kNqv+/fTV8kwWXsickuNX4f49bRuNnBlZuaDEyMh+MbmT6pvtRYrU8aTsc8IFVZCY pyHonHs4v6Bq9zyowQN1SneaUoiY7dtHlmo9EB96PAKH4YYMHGr1fa6YuC+9QIht2L OfdHQ1UsLtFxGM+8EWkzeI0h39flNFgSgH3IrBsS3Ig1NofK67rhIgeVZD9OuUTOXd OU+eK1dnQ2twE7ZUAWrfCDGZtKzbHCWvVNjgqKKYQC003UvcRWLaWrkz+L3amURgzz tLl42/0jSHjMxqFriuaApGXnNxUR8KLCVuNGyNwRrqfcdcJOg/lVDsM8qjOcDhtQar AvizqSACN6tqw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E644A69095; Sat, 3 Jan 2026 13:06:03 -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 I4FXjgN2Fpat; Sat, 3 Jan 2026 13:06:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470759; bh=4PZxrPa7jCbPB9CttD4+55qRP08v3lnl5gsimchxxmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KaNcZEzfgBn814NFEo8IJ1HWjFHPNML51ps4UGCXt5ixvIbfAfT9JT+6koq6VSByr MxrGjBvatPWTE5caMD4/de5tPDJP8BG7iplhG+iPwUW1MD+BAwpvNn9YI33yF3Gqo3 L7gN0suQXKmic0MflKxEWqV7clbyYkvpNFpa8IRJC1XvhkuDMK/Qa8925gj3JSGFeI RTOMkyNUANoHpkwVyLSa7gytsfx0sbdmrBK4zD7nqqIBdfpb15x36kkHnuxCyxPdkq li7GtqO3qsvQZovXBXRxYni0ogEliadRfNjtlZrOfgWkaT2UaY3tjLY4PG8YHBQxhI QzV6bgl2M0/cw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 59B1B68FCC; Sat, 3 Jan 2026 13:05:59 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:39 -0700 Message-ID: <20260103200510.3605009-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 4NMWV5H4Y5BOPXXZ5PZ4FMQHV575TUWK X-Message-ID-Hash: 4NMWV5H4Y5BOPXXZ5PZ4FMQHV575TUWK 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 v2 08/29] sandbox: Add gprof profiling support 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 a GPROF=1 build option to enable gprof profiling for sandbox. This adds the -pg flag to both compiler and linker when GPROF=1 is set, following the same pattern as the existing FTRACE option. Usage: make GPROF=1 sandbox_defconfig all ./u-boot -T -c "ut dm" ... gprof u-boot gmon.out Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) arch/sandbox/config.mk | 4 ++++ config.mk | 4 ++++ doc/develop/trace.rst | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index b92c259d2e3..92bac07963e 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -10,6 +10,10 @@ PLATFORM_LIBS += -L$(GCC_LIB_DIR) -lbacktrace endif PLATFORM_LIBS += -lrt +ifdef GPROF +PLATFORM_LIBS += -pg +endif + SDL_CONFIG ?= sdl2-config # Define this to avoid linking with SDL, which requires SDL libraries diff --git a/config.mk b/config.mk index e294be2a4c4..82fdbf3b4f6 100644 --- a/config.mk +++ b/config.mk @@ -63,6 +63,10 @@ ifdef FTRACE PLATFORM_CPPFLAGS += -finstrument-functions -DFTRACE endif +ifdef GPROF +PLATFORM_CPPFLAGS += -pg +endif + ######################################################################### RELFLAGS := $(PLATFORM_RELFLAGS) diff --git a/doc/develop/trace.rst b/doc/develop/trace.rst index d3c8628d124..d3393244658 100644 --- a/doc/develop/trace.rst +++ b/doc/develop/trace.rst @@ -491,6 +491,46 @@ can dramatically increase the size of the trace output as well as the execution time. +Wall-clock Profiling with gprof (Sandbox) +----------------------------------------- + +For sandbox builds, an alternative to U-Boot's internal tracing is to use +the standard GNU gprof profiler. This provides wall-clock profiling with +less overhead than function instrumentation, and produces output that can +be analysed with standard tools. + +To build sandbox with gprof support:: + + make GPROF=1 O=/tmp/b/sandbox sandbox_defconfig + make GPROF=1 O=/tmp/b/sandbox + +Then run U-Boot. A `gmon.out` file is created in the current directory when +the program exits:: + + cd /tmp/b/sandbox + ./u-boot -T -c "ut dm dm_test_rtc_set_get" + +Analyse the results with gprof:: + + gprof u-boot gmon.out | less + +This shows a flat profile (functions sorted by time) and a call graph. The +flat profile shows which functions consume the most CPU time:: + + % cumulative self self total + time seconds seconds calls ms/call ms/call name + 29.41 0.05 0.05 36922 0.00 0.00 memset + 17.65 0.08 0.03 read_uleb128 + 11.76 0.10 0.02 328472 0.00 0.00 string + ... + +The call graph shows the call hierarchy and time spent in each call chain. + +Note that gprof measures CPU time, not wall-clock time, so I/O wait time is +not captured. For boot-time optimisation where I/O is significant, use +bootstage or the internal trace system instead. + + Future Work ----------- From patchwork Sat Jan 3 20:04:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1227 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=1767470769; bh=bcb95kTs1DU6cIpt4CH8uVTbr2skP2hEY3/JqVIcRJA=; 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=kUW28uQ/mwoJwY9+eHPU+G3dLS1m7SkeOScdgfhQGwN6YLPenYb75feiit0uUppWL YtEkXqXsiUSSE855duBBBKDy1Ckrc7AGx6GHagbbltA7trUrmboOj1KvOT7QpO8xnS 4jm0Cp+kVK4Nd+w9RbWYx4Qj3dJVazqYc5mK/mf3Q09TfSeX+wH6CY4LSsltIB1sro MQrCaID6mpyRhQkG7YzhhS1jEiHZwDjhyqJU246/te3tvjX6ip58PBUHjeA0zxbAci Q5xoeqlr/BaNdE1oV/hse3tsfBjc4TJoJ5GZlv6MgJlllUkmmICkfT+7rG0HCJrNxR PMiyKDLAyAHzw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D4DE4690A1 for ; Sat, 3 Jan 2026 13:06:09 -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 NldAH6jfqY8w for ; Sat, 3 Jan 2026 13:06:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470769; bh=bcb95kTs1DU6cIpt4CH8uVTbr2skP2hEY3/JqVIcRJA=; 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=kUW28uQ/mwoJwY9+eHPU+G3dLS1m7SkeOScdgfhQGwN6YLPenYb75feiit0uUppWL YtEkXqXsiUSSE855duBBBKDy1Ckrc7AGx6GHagbbltA7trUrmboOj1KvOT7QpO8xnS 4jm0Cp+kVK4Nd+w9RbWYx4Qj3dJVazqYc5mK/mf3Q09TfSeX+wH6CY4LSsltIB1sro MQrCaID6mpyRhQkG7YzhhS1jEiHZwDjhyqJU246/te3tvjX6ip58PBUHjeA0zxbAci Q5xoeqlr/BaNdE1oV/hse3tsfBjc4TJoJ5GZlv6MgJlllUkmmICkfT+7rG0HCJrNxR PMiyKDLAyAHzw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C48E56908D for ; Sat, 3 Jan 2026 13:06:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470768; bh=khX7MgNr8ooGgEI/Ixy7caBDTogIuf7TcHN+IBwgoqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=usYLZcodCJ3xvy9ojrQbJgvi816lAiUYGdHx9seh5yfrvdl6L6vCtiVBkkfV+fzgK lkCe49MjleIxxIMvcVGLsJK0sVEsNw1yuHvFCk0VCxlMKvM68cBrbhlEY2mV8n/JUy g1pmft5WbcnYjmktYxa6q6ir26KCXfz3ppPQuu6/bcYpLk+tBKnYWVLHuFmDwtQnzg xejDXvnj9aW0h6EpsQqogu5Zt8adTuYgATkry19+sQ4ZFksEpBy11TuslXB65OxYRV 5Wd4Ea5oW7NTtXJLxrhAZgdsDabEGYl9T2+/eshlJD76AT1XsjLTBkmBj84e/JcmmL xX1VYCE2LeNPA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 264B668FCC; Sat, 3 Jan 2026 13:06:08 -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 XwCwujNRPHUH; Sat, 3 Jan 2026 13:06:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470764; bh=K+bseODHmu4GRegnBG1qhsiYe7SXKyYK3jKkJqepRNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JDmnnCoXM41W2VZoPKBqHo8dYBRXUakNzMAFU/vFMjom9q1MPiC4/Jqo6SVsN1Mqo o9BpHWY5iz6ciiAu9NnKIgIacu15LJTthJFz/CGr5SlogaBJIzU4HVTYHlXbrrKT6x 5DZU/JqBxI46IvNeWL1Jt49XifaLgM2QnZkUZFk2usKpVYQlgMRteZ7kiJ/paZ8JrZ unVnKLwuKJEQi9d2msc8YSVNe3vOpr0poNAhWbB8NQIWk5+x2fX2z7sI89QwHVt5xV Q3UQaf7oObd0T99Qn0K53MGsEyjig5ueyXjKipAPioFT6/LWGYoqYyONCJXa1zK8fB xFdp080tegTOw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B29286908D; Sat, 3 Jan 2026 13:06:03 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:40 -0700 Message-ID: <20260103200510.3605009-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: IGTWWB7GZSD6D6GAVE4SPGDU7BZZ7QFZ X-Message-ID-Hash: IGTWWB7GZSD6D6GAVE4SPGDU7BZZ7QFZ 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 v2 09/29] sandbox: Add -M option to disable mcheck at runtime 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 a command-line option (-M or --no_mcheck) to disable mcheck heap protection at runtime. When mcheck is disabled, the wrapper functions pass through directly to the underlying allocator without adding headers or checking for corruption. This is useful for debugging when mcheck interferes with test results, such as when memory-leak detection reports false positives due to accumulated allocations from other tests. Changes: - Add disable_mcheck flag to sandbox_state - Add mcheck_set_disabled() function to mcheck API - Modify dlmalloc wrappers to bypass mcheck when disabled - Add stub for when MCHECK_HEAP_PROTECTION is not enabled - Document the new option in sandbox.rst Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) arch/sandbox/cpu/start.c | 13 +++++++++++++ arch/sandbox/include/asm/state.h | 1 + common/dlmalloc.c | 33 +++++++++++++++++++++++++++++++- doc/arch/sandbox/sandbox.rst | 7 +++++++ include/mcheck.h | 11 +++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 1a5ca97e15e..b9f48376d22 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -523,6 +524,15 @@ static int sandbox_cmdline_cb_noflat(struct sandbox_state *state, } SANDBOX_CMDLINE_OPT_SHORT(noflat, 'F', 0, "Don't run second set of DM tests"); +static int sandbox_cmdline_cb_no_mcheck(struct sandbox_state *state, + const char *arg) +{ + state->disable_mcheck = true; + + return 0; +} +SANDBOX_CMDLINE_OPT_SHORT(no_mcheck, 'M', 0, "Disable mcheck heap protection"); + static int sandbox_cmdline_cb_soft_fail(struct sandbox_state *state, const char *arg) { @@ -674,6 +684,9 @@ int sandbox_init(int argc, char *argv[], struct global_data *data) if (os_parse_args(state, argc, argv)) return 1; + if (state->disable_mcheck) + mcheck_set_disabled(true); + /* Remove old frame*.bmp files if video_frames_dir is set */ if (state->video_frames_dir) { char pattern[256]; diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index ff7493ec5d6..1b6eef4a9c3 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -178,6 +178,7 @@ struct sandbox_state { bool pager_bypass; /* Enable pager-bypass mode */ bool no_term_present; /* Assume no terminal present */ bool quiet_vidconsole; /* Don't use vidconsole for stdout */ + bool disable_mcheck; /* Disable mcheck heap protection */ int video_test; /* ms to wait before next assert */ const char *video_frames_dir; /* Directory to write video frames */ int video_frame_count; /* Number of frames written */ diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 5069a95d9b3..78efdf5fd9a 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -5965,6 +5965,14 @@ static bool in_backtrace __section(".data"); */ static bool mcheck_skip_backtrace __section(".data"); +/* Runtime flag to disable mcheck - allows bypassing heap protection */ +static bool mcheck_disabled __section(".data"); + +void mcheck_set_disabled(bool disabled) +{ + mcheck_disabled = disabled; +} + void malloc_backtrace_skip(bool skip) { mcheck_skip_backtrace = skip; @@ -5993,6 +6001,9 @@ void *dlmalloc(size_t bytes) !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) return malloc_simple(bytes); + if (mcheck_disabled) + return dlmalloc_impl(bytes CALLER_NULL); + mcheck_pedantic_prehook(); size_t fullsz = mcheck_alloc_prehook(bytes); void *p = dlmalloc_impl(fullsz CALLER_NULL); @@ -6009,12 +6020,15 @@ void dlfree(void *mem) dlfree_impl(mem); return; } + if (mcheck_disabled) { + dlfree_impl(mem); + return; + } dlfree_impl(mcheck_free_prehook(mem)); } void *dlrealloc(void *oldmem, size_t bytes) { - mcheck_pedantic_prehook(); #ifdef REALLOC_ZERO_BYTES_FREES if (bytes == 0) { if (oldmem) @@ -6026,6 +6040,10 @@ void *dlrealloc(void *oldmem, size_t bytes) if (oldmem == NULL) return dlmalloc(bytes); + if (mcheck_disabled) + return dlrealloc_impl(oldmem, bytes); + + mcheck_pedantic_prehook(); void *p = mcheck_reallocfree_prehook(oldmem); size_t newsz = mcheck_alloc_prehook(bytes); @@ -6041,6 +6059,9 @@ void *dlmemalign(size_t alignment, size_t bytes) !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) return memalign_simple(alignment, bytes); + if (mcheck_disabled) + return dlmemalign_impl(alignment, bytes); + mcheck_pedantic_prehook(); size_t fullsz = mcheck_memalign_prehook(alignment, bytes); void *p = dlmemalign_impl(alignment, fullsz); @@ -6064,6 +6085,9 @@ void *dlcalloc(size_t n, size_t elem_size) return p; } + if (mcheck_disabled) + return dlcalloc_impl(n, elem_size); + mcheck_pedantic_prehook(); /* NB: no overflow check here */ size_t fullsz = mcheck_alloc_prehook(n * elem_size); @@ -6121,6 +6145,13 @@ void *dlcalloc(size_t n, size_t elem_size) } #endif /* MCHECK_HEAP_PROTECTION */ +#if !CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) +/* Stub when mcheck is not enabled */ +void mcheck_set_disabled(bool disabled) +{ +} +#endif + #endif /* !ONLY_MSPACES */ /* ----------------------------- user mspaces ---------------------------- */ diff --git a/doc/arch/sandbox/sandbox.rst b/doc/arch/sandbox/sandbox.rst index 90c3dfa837e..0962aeeb1a0 100644 --- a/doc/arch/sandbox/sandbox.rst +++ b/doc/arch/sandbox/sandbox.rst @@ -181,6 +181,13 @@ available options. Some of these are described below: all log statements at LOGL_DEBUG and below. The higher the number, the more info is shown. +-M, --no_mcheck + Disable mcheck heap protection at runtime. When enabled, the mcheck wrapper + functions pass through directly to the underlying allocator without adding + headers or checking for corruption. This is useful for debugging when mcheck + interferes with test results, such as when memory-leak detection reports false + positives due to accumulated allocations from other tests. + -m, --memory Sets the location of the file which holds sandbox's emulated RAM. This can be read and written across phases, so that sandbox behaves like a normal board. diff --git a/include/mcheck.h b/include/mcheck.h index b170acf6281..cd72edb6ae8 100644 --- a/include/mcheck.h +++ b/include/mcheck.h @@ -51,4 +51,15 @@ enum mcheck_status mprobe(void *__ptr); /* Called during RAM relocation to reset the heap registry */ void mcheck_on_ramrelocation(size_t offset); +/** + * mcheck_set_disabled() - Disable mcheck at runtime + * + * When disabled, mcheck wrapper functions pass through directly to the + * underlying allocator without adding headers or checking for corruption. + * This is useful for debugging when mcheck interferes with test results. + * + * @disabled: true to disable mcheck, false to enable + */ +void mcheck_set_disabled(bool disabled); + #endif From patchwork Sat Jan 3 20:04:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1228 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=1767470774; bh=y+46dbwTY2xs6bQ8dY4l9h+AgfTDBNmSBy+Efw25wyo=; 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=ijiU8kQ+/tLVGBs3CgWsfU9TCoxuX9AT38W/Tju7AqKx0dYvxyLZsDptWAEbD6ihi WlsopoYqtl7tZd+m9LwOyeNcSpeqIZp3CxkaiLQ8FMI8jshZRtEDZXunvqqOtZxthI FJ7SmFQSGMhTDYGTxlMd++nJsFKEYNt33HXUNQkZwh6quKzQRMcSo6TUJBCPfmy1S8 QnX9GR4vBJsB3vXfECGx3DJMonemyWxLecU7DbAEFrvogMiCDNbh2xewECbXx3KLKp l+I3dHjqdwHEW0uku1WC765ijrhMlF6mISkQ6iCpRzQwr/yH+m0BQK29ItitS7WwOU KQEmTDiUStRwQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 534CC690A1 for ; Sat, 3 Jan 2026 13:06:14 -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 I8B-y9aQB_64 for ; Sat, 3 Jan 2026 13:06:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470774; bh=y+46dbwTY2xs6bQ8dY4l9h+AgfTDBNmSBy+Efw25wyo=; 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=ijiU8kQ+/tLVGBs3CgWsfU9TCoxuX9AT38W/Tju7AqKx0dYvxyLZsDptWAEbD6ihi WlsopoYqtl7tZd+m9LwOyeNcSpeqIZp3CxkaiLQ8FMI8jshZRtEDZXunvqqOtZxthI FJ7SmFQSGMhTDYGTxlMd++nJsFKEYNt33HXUNQkZwh6quKzQRMcSo6TUJBCPfmy1S8 QnX9GR4vBJsB3vXfECGx3DJMonemyWxLecU7DbAEFrvogMiCDNbh2xewECbXx3KLKp l+I3dHjqdwHEW0uku1WC765ijrhMlF6mISkQ6iCpRzQwr/yH+m0BQK29ItitS7WwOU KQEmTDiUStRwQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4103B6908D for ; Sat, 3 Jan 2026 13:06:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470772; bh=Lgi9h/Gr/CP+zLJVz8uDYgG5/MBLC6MBWPX/UMVSM+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vjwgZC+mPT39v71cFWoTDv0u/+FUXuyASVbAYQ+svux/JdELML4qrR841CCK2Uwby wbvfaWG/Hjs2VDOOFlUQhsZvbYUSdyvnirRY8RbCSaPbqmBaz8h+K9x8Y34kybyJdU tjr2JiVP0K18INtr49MA1Y6IGXq6bGomP9GLs0c3VVsGpYQv+65BDN5n0PNFSZXrid vzxsm4/KbIwDXgsYU60AYa99QNYCERdUNu+QXJEHGC4E6XZ72eJS8OiGzD/AsIvAzZ rRov9UdmJbwXedYRQquPrnowVMyDgrSPxIru1/7q8t/xJefJlUSFEjgCRmYRQIORvG Nmdiu6my6bCug== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CA0BC68FCC; Sat, 3 Jan 2026 13:06: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 10026) with ESMTP id Vwvdk6eAYQDV; Sat, 3 Jan 2026 13:06:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470768; bh=2ZfNa/g46pnpw/ppK6Wkmn4c7h39BJcAAzHXqTCdYZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FHc53RJMLit1j1tx1an3IlWSoln/akHiV7DS769WNmbfoxnLIP5NOKuGjmRWd28Vo ru6U+Do7NYKuOxeOvaGRO4sAji5x+3y30aaZvfkYgzJk+QOZi7A6Rh1WK9enLv7Idb AFIokJmCiHgIxibRJWbVdrHGXiRhQ1eTPHKUuCayy2I0xaDT6AZsAXTIX7dU43Hfs1 K5khkxp8vWkvVojqhy19WBBTBMwiosplpQWizneDeTlMTUmAmhATJ4KkXIZ99tOLmU cjl1/SaAMZuK2+Rvhgszr2SLL1JDYTRnSsi86/6PpwQ1s74//afC8usdE6WFHa7bXP Fe5U5/500g49Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6790968FD2; Sat, 3 Jan 2026 13:06:08 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:41 -0700 Message-ID: <20260103200510.3605009-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: S2CRQCKDTY6EWWK6EB5E7PS3WYTKENKK X-Message-ID-Hash: S2CRQCKDTY6EWWK6EB5E7PS3WYTKENKK 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 10/29] Update Claude instructions for uman 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 Suggest using the new uman tool. Signed-off-by: Simon Glass --- (no changes since v1) CLAUDE.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index d9e0245cdee..aaec9cc031d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,11 +6,11 @@ This file contains information about building U-Boot for use with Claude Code. ### Using uman (Recommended) -To build U-Boot for sandbox testing, use the `uman` command: +To build U-Boot for sandbox testing, use the `um` command: ```bash # Build for sandbox without LTO (um is a symlink to uman) -um -B sandbox build +um build sandbox [flags] # The -l flag can be used to enable LTO # The build is silent unless there are warnings or errors @@ -40,17 +40,17 @@ There are aliases in ~/bin/git-alias which you can use. To run a sandbox test: ```bash -rtv +um test # For example: rtv dm_test_video_box -# which translates to: /tmp/b/sandbox/u-boot -v -Tf -c "ut dm video_box" +# similar to: /tmp/b/sandbox/u-boot -v -Tf -c "ut dm video_box" # test output is silenced unless -v is given ``` To run using the Python suite: ```bash -pyt -# alias for: test/py/test.py -B sandbox --build-dir /tmp/b/sandbox -k +um py -B sandbox +# similar to: test/py/test.py -B sandbox --build-dir /tmp/b/sandbox -k ``` ## Notes From patchwork Sat Jan 3 20:04:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229 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=1767470779; bh=dwf45oPZKU68V2KLL7anriO0EwFFOtMxTwy+qKyqb4s=; 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=wNFsRoNi0D5jBKd1ivOxPpYHfJAJcSUezAFkdwpvGl2qNwZblFlQhTT0O7malHjH7 9kdjBtZFDq3nY7AU/PTwCZ0pknVM6L+DkoOfWtn5qBRwjVijk34GDIAPgFAbvcUt/7 IfgTJ7NGtDxFJ62KZm8FV0rDucjZneFnNIPSQZYqysE8wUN9k//Pp3uLBCjiTMPqQj 9YStaYpc2QrJluRlkvfEzAtA2Q9a5B5o2u+AZqwJwr0ipL0QzoUYtnDcZMjd7U/aRd TL94xE7OpSBvQwGEz+v4ziT0ANE233tQhslY0S834bKO0Z1vW9RLH2KUn98M3nFSpn aw1lMfhv9xraw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C82E569097 for ; Sat, 3 Jan 2026 13:06: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 DdUKeh3YHCJb for ; Sat, 3 Jan 2026 13:06:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470779; bh=dwf45oPZKU68V2KLL7anriO0EwFFOtMxTwy+qKyqb4s=; 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=wNFsRoNi0D5jBKd1ivOxPpYHfJAJcSUezAFkdwpvGl2qNwZblFlQhTT0O7malHjH7 9kdjBtZFDq3nY7AU/PTwCZ0pknVM6L+DkoOfWtn5qBRwjVijk34GDIAPgFAbvcUt/7 IfgTJ7NGtDxFJ62KZm8FV0rDucjZneFnNIPSQZYqysE8wUN9k//Pp3uLBCjiTMPqQj 9YStaYpc2QrJluRlkvfEzAtA2Q9a5B5o2u+AZqwJwr0ipL0QzoUYtnDcZMjd7U/aRd TL94xE7OpSBvQwGEz+v4ziT0ANE233tQhslY0S834bKO0Z1vW9RLH2KUn98M3nFSpn aw1lMfhv9xraw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B760B6907B for ; Sat, 3 Jan 2026 13:06:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470777; bh=U0zby2pq4s1fYrTiId2TEOB31JJuz5835RbMvu6xSyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N2pSeSmwQt2P6ydnHuMs4RTFwXFCSZBkOFe0ycCgU8Hq5FQcDQI5kIVb2fA5m/43P Z6QO8NETQbCe34GUChzJcv+ui+cLyU0mUQNrCYy86G1I2WQv8bWOdg//tmWTcvtnHK lFiSRdFoHUWvsaYodboCVL+I4SjGNELYHXx8dSKHczzazWIbzDQkCZXkFUiQBP6tMU EuA0YrJ3ANNJeGSfmadSvllzaBg9LoTAbg9oKQMhsHHsbIpFUR7r5UMrBWdRMPgOd+ u1cnIc50kVFnzkK88z4GYJxsWtCMCEuHC7Bbjknu0S/NfDgWcn0a8jVUiIJjYESlNt rvOIS2ZtEQGnQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6EB2C68FCC; Sat, 3 Jan 2026 13:06: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 RqJoCADAmcUr; Sat, 3 Jan 2026 13:06:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470773; bh=+TkRlzW9Tzcv5ffXbM7Njij1kUD9ai2Sxl8EZmpUWeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FzDNdaDpDTpMkHdcubombNOzS7bYe94AchLTfkyTUSliq1wppNGMTAT9X2UiUuLQT YCI4wK3oO4dZeWG4+e29bFNGsEn1rmLGAddVq6ftct7Gw9YxgXCfShbj4IYnSHi5RO QCG5cg3xl6xVxG8sAsu3KsfCKHxSU4de6OVKFV805flDrJlWcmDGG1l2g8hENJ1daK SEb2MjQWhyMX0bSF8hLMDxs+sQsKFOSG51TJRKpccpNPiDRX4kUN1QalElLnt9JeBd rRv2ZQRQybyUB7lMXG4H94NWdVB15Khk6fng7VS2eYxVKGX0g1t83iI4B5sUNpGLjs aO7ocgCWy3BJQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1C9C468FD2; Sat, 3 Jan 2026 13:06:13 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:42 -0700 Message-ID: <20260103200510.3605009-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: X64IALXXOEOTFH6SO6MXPP2EFCPDXUTG X-Message-ID-Hash: X64IALXXOEOTFH6SO6MXPP2EFCPDXUTG 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 11/29] video: Update stb_truetype 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 This was last updated in 2023. The updates are minimal but we may as well keep it up to date. Bring in the latest version: f1c79c0 ("Merge pull request #1851 from jeffrbig2/master"_ Signed-off-by: Simon Glass --- (no changes since v1) drivers/video/stb_truetype.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/video/stb_truetype.h b/drivers/video/stb_truetype.h index 32a7b6e1dc0..90a5c2e2b3f 100644 --- a/drivers/video/stb_truetype.h +++ b/drivers/video/stb_truetype.h @@ -54,7 +54,7 @@ // Hou Qiming Derek Vinyard // Rob Loach Cort Stratton // Kenney Phillis Jr. Brian Costabile -// Ken Voskuil (kaesve) +// Ken Voskuil (kaesve) Yakov Galka // // VERSION HISTORY // @@ -412,6 +412,7 @@ int main(int arg, char **argv) } #endif + ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// //// @@ -482,7 +483,7 @@ int main(int arg, char **argv) #endif #ifndef STBTT_memcpy - #include + #include #define STBTT_memcpy memcpy #define STBTT_memset memset #endif @@ -563,6 +564,7 @@ STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int p STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap); // Query the font vertical metrics without having to create a font first. + ////////////////////////////////////////////////////////////////////////////// // // NEW TEXTURE BAKING API @@ -735,6 +737,7 @@ STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, in // need to do anything special to free it, because the contents are pure // value data with no additional data structures. Returns 0 on failure. + ////////////////////////////////////////////////////////////////////////////// // // CHARACTER TO GLYPH-INDEX CONVERSIOn @@ -746,6 +749,7 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep // codepoint-based functions. // Returns 0 if the character codepoint is not defined in the font. + ////////////////////////////////////////////////////////////////////////////// // // CHARACTER PROPERTIES @@ -915,6 +919,7 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1); STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1); + // @TODO: don't expose this structure typedef struct { @@ -989,6 +994,8 @@ STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, floa // The algorithm has not been optimized at all, so expect it to be slow // if computing lots of characters or very large sizes. + + ////////////////////////////////////////////////////////////////////////////// // // Finding the right font... @@ -1010,6 +1017,7 @@ STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, floa // from the file yourself and do your own comparisons on them. // You have to have called stbtt_InitFont() first. + STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags); // returns the offset (not index) of the font that matches, or -1 if none // if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold". @@ -2801,6 +2809,7 @@ typedef struct stbtt__edge { int invert; } stbtt__edge; + typedef struct stbtt__active_edge { struct stbtt__active_edge *next; @@ -4595,6 +4604,8 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc scale_y = -scale_y; { + // distance from singular values (in the same units as the pixel grid) + const float eps = 1./1024, eps2 = eps*eps; int x,y,i,j; float *precompute; stbtt_vertex *verts; @@ -4607,15 +4618,15 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y; float x1 = verts[j].x*scale_x, y1 = verts[j].y*scale_y; float dist = (float) STBTT_sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0)); - precompute[i] = (dist == 0) ? 0.0f : 1.0f / dist; + precompute[i] = (dist < eps) ? 0.0f : 1.0f / dist; } else if (verts[i].type == STBTT_vcurve) { float x2 = verts[j].x *scale_x, y2 = verts[j].y *scale_y; float x1 = verts[i].cx*scale_x, y1 = verts[i].cy*scale_y; float x0 = verts[i].x *scale_x, y0 = verts[i].y *scale_y; float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2; float len2 = bx*bx + by*by; - if (len2 != 0.0f) - precompute[i] = 1.0f / (bx*bx + by*by); + if (len2 >= eps2) + precompute[i] = 1.0f / len2; else precompute[i] = 0.0f; } else @@ -4680,8 +4691,8 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc float a = 3*(ax*bx + ay*by); float b = 2*(ax*ax + ay*ay) + (mx*bx+my*by); float c = mx*ax+my*ay; - if (a == 0.0) { // if a is 0, it's linear - if (b != 0.0) { + if (STBTT_fabs(a) < eps2) { // if a is 0, it's linear + if (STBTT_fabs(b) >= eps2) { res[num++] = -c/b; } } else { @@ -4961,6 +4972,7 @@ STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const #endif // STB_TRUETYPE_IMPLEMENTATION + // FULL VERSION HISTORY // // 1.25 (2021-07-11) many fixes From patchwork Sat Jan 3 20:04:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1230 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=1767470783; bh=sRaDAno0kiNmO2q/YKc/JwBrWAe6crZUbjDMY8KnkQc=; 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=KgzChjT2YgOp1LYqwBhRU8W/jrt75Wm5if/D6FqZHYFZdewZsEOnYTTDX6M/ZPu42 mLBwUlUvAewbuLpHT7f2tg/F2s0qP8qeH7OttklkXp8Fusk5AXv1IAhPaGR1JKIJ0E 4ACJhexE+VkP1W2GbGcT63TieNrsXTZWwhfhePqVfVEreqOcnxf1zpRgQaxAifhp0Y wELKGk8EW6CTW5WLaGZdcjr5cn5uzBWSxXaqYRylfjugrrxK4DQRATazleQOHUUJdB vDY9U3A840qdyyIWPicER6hNqp3KDitXOSiL+NF2AhGXiyEcHh51EfNpTAVMYK/eMo GxHsQ98QDLY2A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4693A690A2 for ; Sat, 3 Jan 2026 13:06:23 -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 tto6o67M0pqC for ; Sat, 3 Jan 2026 13:06:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470783; bh=sRaDAno0kiNmO2q/YKc/JwBrWAe6crZUbjDMY8KnkQc=; 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=KgzChjT2YgOp1LYqwBhRU8W/jrt75Wm5if/D6FqZHYFZdewZsEOnYTTDX6M/ZPu42 mLBwUlUvAewbuLpHT7f2tg/F2s0qP8qeH7OttklkXp8Fusk5AXv1IAhPaGR1JKIJ0E 4ACJhexE+VkP1W2GbGcT63TieNrsXTZWwhfhePqVfVEreqOcnxf1zpRgQaxAifhp0Y wELKGk8EW6CTW5WLaGZdcjr5cn5uzBWSxXaqYRylfjugrrxK4DQRATazleQOHUUJdB vDY9U3A840qdyyIWPicER6hNqp3KDitXOSiL+NF2AhGXiyEcHh51EfNpTAVMYK/eMo GxHsQ98QDLY2A== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 359C969095 for ; Sat, 3 Jan 2026 13:06:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470782; bh=Izb3IObN6NQ4tCU7ah0lAYEhU5lAFmKKSye6eNr74VU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bp6WcsfN2xScKvANLJhs5tA6y/+cXfIzz0ANNspC2xhvPUbGwcnx9VrXGa6/EtI+U A0onax2dY0koY00rK8Ue13Z4Sbi9AZ2m95gcVDoLS9atpdx+ghoX1tDQckAmynDtxt 8L/Q+DcIc3zON977WLwVECGf/nsf8B8sfDTYGWn0SLgFmcYqyPDglzE6VEWqN4oZdT b4+1Lefkid4C/sqrkuVfArmFHr6Jq/CnnFYKkyMHpObUOCuSY9gVTckMaDr6VCr7Q1 2Bf0+nIhuQhIyRf3xgQmps0EiiOvOtsD83/1ih5fuxFbIMPIkolZDB0jdlLRKkGcSJ 4pQ6fYiWrTiwA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 34CE668FCC; Sat, 3 Jan 2026 13:06:22 -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 cdpSnh7qMNcP; Sat, 3 Jan 2026 13:06:22 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470778; bh=cjsqfECpw5G1hgNQGZA9RprM2tnP13fmO/spRQML9Uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b7OUydMEBeZzSIc6YSY7CI1HxrcvvKSzYNHWOtjE+xR2MUebdjOpT7A6s/Q1rpGwP GC9JwP6RTZ+1T8Dt6uo6eYUVUH8zzIZ9zLNsm8qRdfLKCab+7utoPnBF7UoxvnAiQM OmzbV48zcfRUtQ7AkHxQFV5QB5nwP7/+mJOCl4+JaE3C6mYh4ZYZhjazUeZX3Bu2OA Bq9NuV6WzNPrOAT/Yn3wrQ1NafXSl7c2ijwSTmQpDo+Q56iXkbIQd9PBIdwyyjLDJH rsY1n4np+PbsBFhV0kFrSj8/okHjUusJUt+M5voWcRn2Uli8OWvTuI0MNIFPZGwJMO uj1/LZKm+t0kg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id AE14F68FD2; Sat, 3 Jan 2026 13:06:17 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:43 -0700 Message-ID: <20260103200510.3605009-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 4LXGKJ4RGOJBJFDRM6VNWCZ53KC46KPX X-Message-ID-Hash: 4LXGKJ4RGOJBJFDRM6VNWCZ53KC46KPX 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 v2 12/29] video: truetype: Add a scratch buffer to use malloc() less 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 The stb_truetype library performs around 5 allocations per character rendered, totalling approximately 26KB of temporary memory. This creates significant malloc/free overhead and heap fragmentation. Add a scratch buffer mechanism that pre-allocates memory once during probe and reuses it for each character. The buffer is reset at the start of each putc_xy() call, and allocations come from this buffer using a simple bump allocator with 8-byte alignment. If the scratch buffer is exhausted (e.g. for very complex glyphs), the allocator falls back to malloc transparently. The scratch buffer is controlled by two new Kconfig options: - CONSOLE_TRUETYPE_SCRATCH: Enable/disable the feature (default y) - CONSOLE_TRUETYPE_SCRATCH_SIZE: Buffer size in bytes (default 32KB) Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) doc/usage/cmd/font.rst | 9 +++++ drivers/video/Kconfig | 23 ++++++++++++ drivers/video/console_truetype.c | 62 ++++++++++++++++++++++++++++++-- drivers/video/stb_truetype.h | 46 ++++++++++++++++++++++-- 4 files changed, 136 insertions(+), 4 deletions(-) diff --git a/doc/usage/cmd/font.rst b/doc/usage/cmd/font.rst index f7a4897667b..a4b9495b977 100644 --- a/doc/usage/cmd/font.rst +++ b/doc/usage/cmd/font.rst @@ -85,6 +85,15 @@ CONFIG_CONSOLE_TRUETYPE_GLYPH_BUF enables a pre-allocated buffer for glyph rendering, avoiding malloc/free per character. The buffer starts at 4KB and grows as needed via realloc(). +CONFIG_CONSOLE_TRUETYPE_SCRATCH enables a scratch buffer for internal stbtt +allocations. Without this, the TrueType library performs around 5 allocations +per character (totalling ~26KB), creating malloc/free overhead and heap +fragmentation. With the scratch buffer, memory is allocated once at probe time +and reused for each character. CONFIG_CONSOLE_TRUETYPE_SCRATCH_SIZE sets the +buffer size (default 32KB), which is sufficient for most Latin characters. +Complex glyphs (CJK, emoji) or very large font sizes may need 64KB or more. +Allocations exceeding the buffer size fall back to malloc transparently. + CONFIG_VIDEO_GLYPH_STATS enables tracking of glyph-rendering statistics. Return value diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 0f99ba1845b..4a8090e622d 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -259,6 +259,29 @@ config CONSOLE_TRUETYPE_GLYPH_BUF The buffer starts at 4KB and grows via realloc() as needed to accommodate larger glyphs. +config CONSOLE_TRUETYPE_SCRATCH + bool "TrueType scratch buffer to reduce malloc traffic" + depends on CONSOLE_TRUETYPE + default y + help + Enable a pre-allocated scratch buffer for internal TrueType + rendering allocations. This eliminates malloc/free calls during + character rendering, improving performance and reducing heap + fragmentation. + + With this disabled, stbtt allocates and frees around 26KB of + temporary memory for each character rendered. + +config CONSOLE_TRUETYPE_SCRATCH_SIZE + int "TrueType scratch buffer size" + depends on CONSOLE_TRUETYPE_SCRATCH + default 32768 + help + Size of the scratch buffer in bytes for TrueType rendering. + 32KB is sufficient for most Latin characters. Complex glyphs + (CJK, emoji) may need 64KB or more. Allocations exceeding this + size fall back to malloc. + config VIDEO_GLYPH_STATS bool "Track glyph rendering statistics" depends on CONSOLE_TRUETYPE diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index c33686aff9b..cbc4473207c 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -105,8 +105,47 @@ static double tt_acos(double val) #define STBTT_fmod tt_fmod #define STBTT_cos tt_cos #define STBTT_acos tt_acos -#define STBTT_malloc(size, u) ((void)(u), malloc(size)) -#define STBTT_free(size, u) ((void)(u), free(size)) + +/* Scratch buffer for zero-malloc rendering - must match stb_truetype.h */ +#define STBTT_SCRATCH_DEFINED +struct stbtt_scratch { + char *buf; + size_t size; + size_t used; +}; + +static inline void stbtt_scratch_reset(struct stbtt_scratch *s) +{ + if (s) + s->used = 0; +} + +static inline void *stbtt__scratch_alloc(size_t size, void *userdata) +{ + struct stbtt_scratch *s = userdata; + size_t aligned = (size + 7) & ~7; + + if (s && s->used + aligned <= s->size) { + void *p = s->buf + s->used; + + s->used += aligned; + + return p; + } + + return malloc(size); +} + +static inline void stbtt__scratch_free(void *ptr, void *userdata) +{ + struct stbtt_scratch *s = userdata; + + if (!s || ptr < (void *)s->buf || ptr >= (void *)(s->buf + s->size)) + free(ptr); +} + +#define STBTT_malloc(size, u) stbtt__scratch_alloc(size, u) +#define STBTT_free(ptr, u) stbtt__scratch_free(ptr, u) #define STBTT_assert(x) #define STBTT_strlen(x) strlen(x) #define STBTT_memcpy memcpy @@ -184,6 +223,8 @@ struct console_tt_metrics { * this avoids malloc/free per character. Allocated lazily after * relocation to avoid using early malloc space. * @glyph_buf_size: Current size of glyph_buf in bytes + * @scratch: Scratch buffer state for stbtt internal allocations + * @scratch_buf: Memory for scratch buffer */ struct console_tt_priv { struct console_tt_metrics *cur_met; @@ -196,6 +237,8 @@ struct console_tt_priv { int pos_count; u8 *glyph_buf; int glyph_buf_size; + struct stbtt_scratch scratch; + char *scratch_buf; }; /** @@ -377,6 +420,9 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y, if (priv->cur_fontdata) return console_fixed_putc_xy(dev, x, y, cp, priv->cur_fontdata); + /* Reset scratch buffer for this character */ + stbtt_scratch_reset(&priv->scratch); + /* First get some basic metrics about this character */ font = &met->font; stbtt_GetCodepointHMetrics(font, cp, &advance, &lsb); @@ -813,6 +859,7 @@ static int truetype_add_metrics(struct udevice *dev, const char *font_name, debug("%s: Font init failed\n", __func__); return -EPERM; } + font->userdata = &priv->scratch; /* Pre-calculate some things we will need regularly */ met->scale = stbtt_ScaleForPixelHeight(font, font_size); @@ -1217,6 +1264,17 @@ static int console_truetype_probe(struct udevice *dev) int ret; debug("%s: start\n", __func__); + + /* Allocate scratch buffer for stbtt internal allocations */ + if (CONFIG_IS_ENABLED(CONSOLE_TRUETYPE_SCRATCH)) { + priv->scratch_buf = malloc(CONFIG_CONSOLE_TRUETYPE_SCRATCH_SIZE); + if (priv->scratch_buf) { + priv->scratch.buf = priv->scratch_buf; + priv->scratch.size = CONFIG_CONSOLE_TRUETYPE_SCRATCH_SIZE; + priv->scratch.used = 0; + } + } + if (vid_priv->font_size) font_size = vid_priv->font_size; else diff --git a/drivers/video/stb_truetype.h b/drivers/video/stb_truetype.h index 90a5c2e2b3f..23a88898287 100644 --- a/drivers/video/stb_truetype.h +++ b/drivers/video/stb_truetype.h @@ -465,11 +465,53 @@ int main(int arg, char **argv) #define STBTT_fabs(x) fabs(x) #endif + /* Scratch buffer for zero-malloc rendering */ + #ifndef STBTT_SCRATCH_DEFINED + #define STBTT_SCRATCH_DEFINED + struct stbtt_scratch { + char *buf; + size_t size; + size_t used; + }; + + static inline void stbtt_scratch_reset(struct stbtt_scratch *s) + { + if (s) + s->used = 0; + } + #endif + // #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h #ifndef STBTT_malloc #include - #define STBTT_malloc(x,u) ((void)(u),malloc(x)) - #define STBTT_free(x,u) ((void)(u),free(x)) + + static inline void *stbtt__scratch_alloc(size_t size, void *userdata) + { + struct stbtt_scratch *s = userdata; + size_t aligned = (size + 7) & ~7; /* 8-byte alignment */ + + if (s && s->used + aligned <= s->size) { + void *p = s->buf + s->used; + + s->used += aligned; + + return p; + } + + return malloc(size); /* fallback */ + } + + static inline void stbtt__scratch_free(void *ptr, void *userdata) + { + struct stbtt_scratch *s = userdata; + + /* Only free if not from scratch buffer */ + if (!s || ptr < (void *)s->buf || ptr >= (void *)(s->buf + s->size)) + free(ptr); + } + + #define STBTT_malloc(x,u) stbtt__scratch_alloc(x, u) + #define STBTT_free(x,u) stbtt__scratch_free(x, u) #endif #ifndef STBTT_assert From patchwork Sat Jan 3 20:04:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1231 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=1767470789; bh=AkRPa07ncdV17Y6ntQSJvVEeA2ebRELuUCh/4SzgFeM=; 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=NkW1V4mhdJ5UN9GeILykUjr1Yy/N2HRlNYjEt38h/aTuyV7iO7wOo6KLmtVwP8RDW L0pFGCBiDkq5hodKTHQbGX1j0Fn5VWfZR0xN9Tr6w1wraFAHRGJUUFlVUY9abxx3yE jYBc9gtHSkqQ7qF4PkpFBejFGtXOvOlp6NFCAwLZluwNxicuuamrgCbcayvU5foHJX N5vtiL/Myf+GIEijYnPAzEfRMmuINN4PxBM18LxhKrde4q9nb7DterR5BVkQSQDJJG q/4Mk4lRzrzr+RtIh512xFA5zwD2C6wNRRs3ft7LxaehpGTQYwSXAi1J1p39zO8CeC Hv+o3gnU6KUnQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 271E169097 for ; Sat, 3 Jan 2026 13:06:29 -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 DB8CvE3JNRJs for ; Sat, 3 Jan 2026 13:06:29 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470789; bh=AkRPa07ncdV17Y6ntQSJvVEeA2ebRELuUCh/4SzgFeM=; 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=NkW1V4mhdJ5UN9GeILykUjr1Yy/N2HRlNYjEt38h/aTuyV7iO7wOo6KLmtVwP8RDW L0pFGCBiDkq5hodKTHQbGX1j0Fn5VWfZR0xN9Tr6w1wraFAHRGJUUFlVUY9abxx3yE jYBc9gtHSkqQ7qF4PkpFBejFGtXOvOlp6NFCAwLZluwNxicuuamrgCbcayvU5foHJX N5vtiL/Myf+GIEijYnPAzEfRMmuINN4PxBM18LxhKrde4q9nb7DterR5BVkQSQDJJG q/4Mk4lRzrzr+RtIh512xFA5zwD2C6wNRRs3ft7LxaehpGTQYwSXAi1J1p39zO8CeC Hv+o3gnU6KUnQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 173B869095 for ; Sat, 3 Jan 2026 13:06:29 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470786; bh=W9dUv0C9tsV9mQeOhzoopPoxxNHwOHbpgZkybKRCYAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZY9EMP/eCciy+qW9UdDFjDD6BCTk+WQchrJA8NrwsKUAENXibzChs6AWw5tbxAhF0 1O71H6ybYbFs4Rg9TkXAGU5phzhm3RTYVVhFRSLheI77Nh+ngc4I1s7cP9+jy4AMIj ZxCn+GBCBga8dQsV6Uy3cDK/agBGa/moLEPgyU1Acjo9T58a55USd6i5/0lYkAlL0l D6zkbVEt29CIal8Y55CDeHn8GMcLjQlvoWLHlfPxqIAmLdgE+ARzk9vJmqCYIBIhmK zfFnYts/q2Xxr+RqZ/cFggWeac4qTsEDjErg3BEd80a2pKy0ce8fqHd91QqiE6dznW P90ByKIK4xhtg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B4B7068FCC; Sat, 3 Jan 2026 13:06:26 -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 QeGQ9AJnfKnX; Sat, 3 Jan 2026 13:06:26 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470782; bh=BHuYviJ3t4hS+pU6vZVdVtbOapcD9y7b9qLlH2kS2dA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jbaQK7oamwfrpCz8T9pQvvKq/9u/WAvCHMiUs3eL/0Gbx9X5QxDQ9pWxMHbOkPMFU 2k+BsZnIqrs0UjrBHZmQFioH1QH36tvvYCj47xYYSt+zE6RHE9Vgb6ounXIJ/5UsN4 +0o1ir8sdXXQr2d7JfgT8ec9KOBNR6cvJF0NYa4V+47XphxeeiAjtkZN+JwvAZmy0f /j2K1UaeQXehfkoR4QLlo+Gx7ecf4rxaVx03qK22tBhaqOeIIx/mhwBRwHD4vWWW42 yhTioRf6e/SKN9qBYTf7LgGzll4LcTCyfXn7UEWvi4e1g8OOEtLJ6cFtfxeA8a6MA/ 4SYGPRe1YQB2w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5E06968FD2; Sat, 3 Jan 2026 13:06:22 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:44 -0700 Message-ID: <20260103200510.3605009-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JQAY6EBKVYL6L4YIBMQI7MR3FQEFOXM4 X-Message-ID-Hash: JQAY6EBKVYL6L4YIBMQI7MR3FQEFOXM4 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 v2 13/29] video: Optimise video_flush_copy() for full-line damage 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 When copying partial framebuffer regions line by line, there is overhead from multiple memcpy() calls. Optimise video_flush_copy() to detect when entire lines are being copied (damage spans full width) and perform a single memcpy() for the whole region instead of looping line by line. Also invert the early-exit check to reduce nesting. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) drivers/video/video-uclass.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 2789c352113..75b13481380 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -507,16 +507,25 @@ static void video_flush_copy(struct udevice *vid) if (!priv->copy_fb) return; - if (damage->x1 && damage->y1) { - int lstart = damage->x0 * VNBYTES(priv->bpix); - int lend = damage->x1 * VNBYTES(priv->bpix); + if (!damage->x1 || !damage->y1) + return; + + int lstart = damage->x0 * VNBYTES(priv->bpix); + int llen = damage->x1 * VNBYTES(priv->bpix) - lstart; + + /* Copy entire region at once if full lines are damaged */ + if (!lstart && llen == priv->line_length) { + ulong offset = damage->y0 * priv->line_length; + ulong len = (damage->y1 - damage->y0) * priv->line_length; + + memcpy(priv->copy_fb + offset, priv->fb + offset, len); + } else { int y; for (y = damage->y0; y < damage->y1; y++) { - ulong offset = (y * priv->line_length) + lstart; - ulong len = lend - lstart; + ulong offset = y * priv->line_length + lstart; - memcpy(priv->copy_fb + offset, priv->fb + offset, len); + memcpy(priv->copy_fb + offset, priv->fb + offset, llen); } } } From patchwork Sat Jan 3 20:04:45 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1232 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=1767470793; bh=Fhl+iJPVAS/JZt1GFL+U4KfIvkPBkuaGRx+AGbUU05U=; 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=ZcwXCT0djmMQUsBZ+P6baXYrl+AZE4uiTv4tPgwjZZxmW86/7OBQaJDetqNgUWcYv 20FJpDIDr5VM4xZ+fORdhdUwqVekPpCnZtSbAxejfijQz+HRPWrgzG0wYhOrYxM5zj agmeRWAIQDH3yr9FgcPPnTijoJPdFkfEbZCxsVYt1zKcPN7rMmyAYKMVICLXdMgeR3 lYWw9tQHX7WTUt2pXDVsX0F8NjHjBv3P6JrKLXoW5eCiCcRwcRJ4zpfP5g+Ur10ulC BOHWVGwnIaDqXIsz6R/mVrnPPR3BPCk4C6To8CSZyIYGIOEMuYRWjqyxyqkrqcm7q0 qZtxj8i3ZRVqg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9806F690A2 for ; Sat, 3 Jan 2026 13:06:33 -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 Sfb1yb802GGk for ; Sat, 3 Jan 2026 13:06:33 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470793; bh=Fhl+iJPVAS/JZt1GFL+U4KfIvkPBkuaGRx+AGbUU05U=; 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=ZcwXCT0djmMQUsBZ+P6baXYrl+AZE4uiTv4tPgwjZZxmW86/7OBQaJDetqNgUWcYv 20FJpDIDr5VM4xZ+fORdhdUwqVekPpCnZtSbAxejfijQz+HRPWrgzG0wYhOrYxM5zj agmeRWAIQDH3yr9FgcPPnTijoJPdFkfEbZCxsVYt1zKcPN7rMmyAYKMVICLXdMgeR3 lYWw9tQHX7WTUt2pXDVsX0F8NjHjBv3P6JrKLXoW5eCiCcRwcRJ4zpfP5g+Ur10ulC BOHWVGwnIaDqXIsz6R/mVrnPPR3BPCk4C6To8CSZyIYGIOEMuYRWjqyxyqkrqcm7q0 qZtxj8i3ZRVqg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 87FFC69097 for ; Sat, 3 Jan 2026 13:06:33 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470791; bh=M7YIhPxiwoisYpCwvODodQUzP5bZbnmhe7emcc5uFKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bi+UavWDKP/759Rgy4SMvVyLo/gtUzGFP4PXQEMLonzPJNbAgvCVZhP4OHNYzgaaq biii+R9tPgpc/+K8whL1+GF1BfYZRrfeXgkIyiYLaQfHh2q5aVlGY/75iHopWFysJj Vg2fzqElik8PZqbd+2eVLwDqhFLiNv85+qE/go8uZLsbK9kBS9L7XqcpEzbyfb0qIX GfVFuZd1TrAJvoPMF6uZ4zzX0lXRIltJu1H0/8CjPMiVZ0FC7SqgjPAWWoT3CCs+/F wtVDDHorcK4HOfmLO4QCv+YpEoxKaHp+A+PwxmksL26A58BDuI/5uPc2vgbeEo7uv8 +vVuend3y4nHg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8648F68FCC; Sat, 3 Jan 2026 13:06:31 -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 OQRkcGidGIze; Sat, 3 Jan 2026 13:06:31 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470787; bh=SW+aXquX7iRF1IkLGWbYB7Zsgy0FIEt3pJFDcRKzL1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=npXiyPhYl+IeqFhYJacv7ntdl5Pds0tO7vdQhGv2jU9Rblq53CHoCre9Wi1A/s2ZX khfDC4QXvS6dGfn/kSjOd5Ml7XxAZ+y2Cf3CZJp4bxcpreTCnwXs/bBa1Cxm0im57W /N8O+ZM7zkS789te+opuBRJhRaT8p/bIQY6WBJ6z1TmAKzWLKl55/AJi4wJgqmUfvx qHdnK2iGF4kbSBMA1jzNdF66T5p5WtyTLwHl4m7USSPsEBC8MhMSmARX9xsacPQj+i I5F/O960k6LeNXHmRwKs9TfO0HlDLuHS6vHsdSHDGBdRCR+WQoa7naJed18ZrwIFin o4wkeeu/5a2OA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 03FE768FD2; Sat, 3 Jan 2026 13:06:26 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:45 -0700 Message-ID: <20260103200510.3605009-15-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 4XIQHG6OP2NHESACMVWL6GNNX5JF6LL3 X-Message-ID-Hash: 4XIQHG6OP2NHESACMVWL6GNNX5JF6LL3 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 14/29] test: Rename dm_test_host() 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 a _base suffix to this test so that it is easier to run it by itself with test.py without also getting dm_test_host_dup() Signed-off-by: Simon Glass --- (no changes since v1) test/dm/host.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dm/host.c b/test/dm/host.c index a126cc9b3a5..3abf573a54e 100644 --- a/test/dm/host.c +++ b/test/dm/host.c @@ -16,7 +16,7 @@ #include /* Basic test of host interface */ -static int dm_test_host(struct unit_test_state *uts) +static int dm_test_host_base(struct unit_test_state *uts) { static char label[] = "test"; struct udevice *dev, *part, *chk, *blk; @@ -72,7 +72,7 @@ static int dm_test_host(struct unit_test_state *uts) return 0; } -DM_TEST(dm_test_host, UTF_SCAN_FDT); +DM_TEST(dm_test_host_base, UTF_SCAN_FDT); /* reusing the same label should work */ static int dm_test_host_dup(struct unit_test_state *uts) From patchwork Sat Jan 3 20:04:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1233 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=1767470795; bh=aysGFv7RT+muhdtxiBRrSemQYakCfDgC+68DxIpQni4=; 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=qyapRJ6vZrCm0ailf7Vo1JbVpIHfzzy7UKa5peUnCLv4H8PKITvPTBiHoJlzI2STW 1BilLlQxbg94iTICxo7ikKZ5dSWfRb1u5jdRprejL287vpEh/Efkq+iXm2pNGiR+ot uNh1L/qgWtOOoSOGoumF4pycp5w3bcVGx2bmEf8Ma8p7+1J7kuiQxrJfk/k9o0FAAK Hf+eUCMus6mpl3NO5fwKpDT3ZkdfH//D0WBKUvSTPdJ9OfpW1DXh18U5sW1zVjpaQu 9Y9qnevdqi9sy/dvjaIRagRDiVt7QKh+tW9g2Q1JKS0M9nPIcbJwjcQRbTTL5qaAe2 S7S62a0xIsOyg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 17073690AA for ; Sat, 3 Jan 2026 13:06:35 -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 XZ4GOq_rOu9O for ; Sat, 3 Jan 2026 13:06:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470794; bh=aysGFv7RT+muhdtxiBRrSemQYakCfDgC+68DxIpQni4=; 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=i5feJjHxt5VYnq8HuvJToFcauH5+90rC8vlGyzXQRXE6JcKWW1RQP9trUIX4D2ufS ewrxpPw2sCm7DY2ZKw0dqUgecTOqaWZqbERgUnG/dpHLuXQ2gPeJJdIayAWE6pH/7n CBDYXVnJEKKPUpGzO/T7T1LEbdJPkEBRSicPxHeMCcxP1ju8aHS8w+pRhhDbzrtCWP /qcIdfQITmJxX6fmKrpuM4WMpH3oy23/nRVWnn1smFoXYQBGIKa+msQILRTuMut27c fXNnUfVmFPp0pIBRFIWQ0Qdko0FxSlqJXPs65miM4jpCKIqUzsjraxka3TbSHVBX3f lklcKBYD+6n6Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3844C69097 for ; Sat, 3 Jan 2026 13:06:34 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470792; bh=aTRr31PpD4sHe0LKYhP6aiLKATPltPRyVS4s5UXzJGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=peEzMtesjlWcm8opFY4syE4MQ96KpgOUf3zg/O+CMxZTJMrdclHxGH2sHTUDwvGw3 SNjfBQFjTvoDZ0Hs/0wtExRzQC5IWLema4KtB1XGYouT/1AAOx/i2B/PjbB8Dl+QcS xJm9uqR5eWXMgwbrHpevLkLEAwcuuwTyhwyTkx72KpfGyIqxxR9O6/ndwvJGSy5NfV /q2GTjAHbdmW9Hqh8L+rgw1cn6sFhi6CblhcZL7HyR1jPArZQegt3OF66T1i+LdYKJ 09efElb4/xrdmKM5lsC//1O1IRx5MIL/lhHIcwAunvELdGWYU4DeoQh+5tdT9eJbXP FZ1qvC0+0uGcA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 31C4F6907B; Sat, 3 Jan 2026 13:06:32 -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 jkuTnIMH-uAU; Sat, 3 Jan 2026 13:06:32 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470792; bh=t6VoGa3GMu9DhehyRDZ1PFyNASyxtXmiWgp6FW8Mv6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fN3CUQUGMD9CJgF+/a26sZ9ndZ1JoGO5s05pkbsGFYVOj3pVCtriKc7x9OPHT7k9Q htgqHe/1fiUbagtlSgDPQEWPaffq3zmAF4etsayeNrPt83xhS3ND6XKQ+350+ansEV MUfT58gu1F+htDUMpdxX8lo2ZsN0sebekCJ6pLK7tXFEuVMe1sVZI4fTetqF+w5lxS bTK4tyxrJftIBYIOXTLsau+R9DGF3Uus9xi3x8B0fJoRS9zy5TdS7hdXowgJF0G8+Y jOGuoxRNoVraeA5KiCWqMtDjBCH0pB6BfMTHFjtqpK7pXxqlnFPR0Z+XUe8nrDk0bk 5W/vyBnyqaaPw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B11C768FD2; Sat, 3 Jan 2026 13:06:31 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:46 -0700 Message-ID: <20260103200510.3605009-16-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JTL65VYL7B74EBV6PEI3X62OWCFOBON4 X-Message-ID-Hash: JTL65VYL7B74EBV6PEI3X62OWCFOBON4 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 15/29] sandbox: Increase CONFIG_MCHECK_CALLER_LEN to 64 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 In some cases longer function names mean that 48 characters is not enough to determine the call path. Increase the default to 64 to handle this. Signed-off-by: Simon Glass --- (no changes since v1) configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index e55aef8e7f9..eae9c5f5bd3 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -13,6 +13,7 @@ CONFIG_SYS_MEMTEST_START=0x00100000 CONFIG_SYS_MEMTEST_END=0x00101000 CONFIG_ULIB=y CONFIG_MCHECK_HEAP_PROTECTION=y +CONFIG_MCHECK_CALLER_LEN=80 CONFIG_EXAMPLES=y CONFIG_EFI_SECURE_BOOT=y CONFIG_EFI_RT_VOLATILE_STORE=y From patchwork Sat Jan 3 20:04:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1234 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=1767470795; bh=5VZ+N5ADsK3TeeD+7m4mpPx5BqOXI8nS7zDqSsnyiSE=; 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=VVvg7FInca4t25G2XUz6+L3EOK0OVy6ck/5s/QCAgSQLko+1vfDIes70QnzxKVvKZ xk86R61M99zMPa/JRChMUd010IpMDVSwSrp80lCvFW/xC15UfeuaLpICq/YgTD816T deYDz5M/JVd43jxx9c04xp/WNDrSUNNzlJFFVZFGfHeR1CkcU9mi71lNz7aqdqq6DV O6KBFgh7ib/rb7wVPjBVgzGoyY706rcVlf9HKDLCAvoBrAqv2YFe96/8iWXyibFkHj 47SZn0q7kgZLfZyIyOSquSJaxPHAFne3VheOedBDpi0MEPtjOtlQTM52qNNw7Cq22/ VIFRL5T61KzXg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5F806690A8 for ; Sat, 3 Jan 2026 13:06:35 -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 ZLIzRKLAt7RL for ; Sat, 3 Jan 2026 13:06:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470795; bh=5VZ+N5ADsK3TeeD+7m4mpPx5BqOXI8nS7zDqSsnyiSE=; 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=VVvg7FInca4t25G2XUz6+L3EOK0OVy6ck/5s/QCAgSQLko+1vfDIes70QnzxKVvKZ xk86R61M99zMPa/JRChMUd010IpMDVSwSrp80lCvFW/xC15UfeuaLpICq/YgTD816T deYDz5M/JVd43jxx9c04xp/WNDrSUNNzlJFFVZFGfHeR1CkcU9mi71lNz7aqdqq6DV O6KBFgh7ib/rb7wVPjBVgzGoyY706rcVlf9HKDLCAvoBrAqv2YFe96/8iWXyibFkHj 47SZn0q7kgZLfZyIyOSquSJaxPHAFne3VheOedBDpi0MEPtjOtlQTM52qNNw7Cq22/ VIFRL5T61KzXg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1988A690AD for ; Sat, 3 Jan 2026 13:06:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470793; bh=5u79aadjw5yhkUyYrJy6byEWJ8O3+EQAah2FCgNEjSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ppFxynIzisx1tIMocWP9TL5QPJJhYr1v/2UgnwMTNE2BcShyapgNcDx5PB6rXf28C Q+Ne00wBR6v5RrznOtcTby6JflRWyYFpzpRo4BSgxId/6PvM+ayi5MU174gmB8qdBA BULpgCOcZLLxc7X81rT/XpBLMWT1fcbfTfmOyuwHrRR07uEFMUzJiJRENJHu782FLv wpAwYSPbsch3ass2l+k8i1rZpp2ps8MdQlAwT3Pd3Xu9xYO4LuqSFIp0+B5wnUQLJY 4l6zt9nMh6nZvnMeCJKW5G13Ry2K1ZYxcjuZ8897tEafQEWEPuQegB2Re+iHCbHIZW mBlGWg6RWAOWA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0E24369095; Sat, 3 Jan 2026 13:06:33 -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 uwNXAgmisLRe; Sat, 3 Jan 2026 13:06:32 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470792; bh=PXgpgSyomoBKZco+Au9UUfHXlL8ThuxTpBNVcX27TeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qvsRx0NGgdG9+b3lYcOYXg5uuE/6gn4hRPnxlT/SQDPnXjg2e+kA2MZkhjqbP/I8A rBzB7Qlp1ORMOsnjjPsGV13uDh4h8J2FGiK5ZgFtKCoMhwpFU0Uzesn8hbdG633qr9 SOEqnclb8Q1tTcNl4RzpkKubPFdFwCeSi3gizHE6clHqxRCffhBgPli35Q9Ej+Gmd1 +jm230o+wffIeAFJ2yHKaakWX8Yf2E9bTbdhTj0Ud/Iqbqk9ZTUOcW1yarx5Tx2Z1G ygVeexif0q6iZdEB7oiBdr1fgVMaIAVYlsxNsPMNsnhuGBbQEm77GphusSods3LCiD wEOBqbhqgZRuw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 730FB68FD2; Sat, 3 Jan 2026 13:06:32 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:47 -0700 Message-ID: <20260103200510.3605009-17-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: ZJJX234QIB22WKIKPM4ASECZSLKDV2AV X-Message-ID-Hash: ZJJX234QIB22WKIKPM4ASECZSLKDV2AV 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 v2 16/29] malloc: Fix malloc_usable_size() to handle mcheck headers 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 When mcheck is enabled, malloc_usable_size() returns incorrect results because mem2chunk() is called on the offset user pointer rather than the actual chunk. The pointer returned to the user is offset by the mcheck header, but malloc_usable_size() is unaware of this. Add a wrapper that returns the user-requested size stored in the mcheck header. This fixes test failures when CONFIG_MCHECK_CALLER_LEN is set to larger values. Also add a wrapper for the case where MALLOC_DEBUG is enabled without MCHECK_HEAP_PROTECTION, since MALLOC_DEBUG makes dlmalloc_usable_size_impl() static but no public dlmalloc_usable_size exists outside the mcheck block. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) common/dlmalloc.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 78efdf5fd9a..71f81aeaec7 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -648,6 +648,7 @@ static inline void MALLOC_COPY(void *dest, const void *src, size_t sz) { memcpy( #define dlrealloc_impl dlrealloc #define dlmemalign_impl dlmemalign #define dlcalloc_impl dlcalloc +#define dlmalloc_usable_size_impl dlmalloc_usable_size #endif static bool malloc_testing; /* enable test mode */ @@ -5943,13 +5944,15 @@ int dlmallopt(int param_number, int value) { return change_mparam(param_number, value); } -size_t dlmalloc_usable_size(const void* mem) { - if (mem != 0) { - mchunkptr p = mem2chunk((void*)mem); - if (is_inuse(p)) - return chunksize(p) - overhead_for(p); - } - return 0; +STATIC_IF_MCHECK size_t dlmalloc_usable_size_impl(const void *mem) +{ + if (mem != 0) { + mchunkptr p = mem2chunk((void *)mem); + + if (is_inuse(p)) + return chunksize(p) - overhead_for(p); + } + return 0; } #if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) @@ -6098,6 +6101,20 @@ void *dlcalloc(size_t n, size_t elem_size) return mcheck_alloc_noclean_posthook(p, n * elem_size, mcheck_caller()); } +size_t dlmalloc_usable_size(const void *mem) +{ + if (!mem) + return 0; + + if (mcheck_disabled) + return dlmalloc_usable_size_impl(mem); + + /* Return the user-requested size from mcheck header */ + const struct mcheck_hdr *hdr = &((const struct mcheck_hdr *)mem)[-1]; + + return hdr->size; +} + /* mcheck API */ int mcheck_pedantic(mcheck_abortfunc_t f) { @@ -6145,6 +6162,14 @@ void *dlcalloc(size_t n, size_t elem_size) } #endif /* MCHECK_HEAP_PROTECTION */ +#if CONFIG_IS_ENABLED(MALLOC_DEBUG) && !CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) +/* Wrapper needed when MALLOC_DEBUG makes dlmalloc_usable_size_impl static */ +size_t dlmalloc_usable_size(const void *mem) +{ + return dlmalloc_usable_size_impl(mem); +} +#endif + #if !CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) /* Stub when mcheck is not enabled */ void mcheck_set_disabled(bool disabled) From patchwork Sat Jan 3 20:04:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1235 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=1767470799; bh=3oC5El3ls9jbTgxC8Z0pDdtriv2TKiwel0nfyfUQvdM=; 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=fUi8qpad1tTr0HAiI0rPr1UySWWRmCrcMVjZRKPcwd+2aaePslpkmPnFpCQyl1pu6 J+HKBUbdT5lTEFop7PTfffeLFS5TvIB5DZVVyTAxAnp64wipIeNXMZSgxG8TM9z+Xa Wxakeg+2REEPywJilCMIstf6Wa9qkK1sTyKkefEpm4EjiO3NQWUZftCxUKGW0Lq2Vb ICoi6AvMDLG2dcFE3sjraQZgQq55GXXh+LWpNuvDp4elbwa3lrTcrlRDgwiBHoG4mq AAN6h/rjmK4JqjRWUUXSzhW2KzSOqCZi/W1x6jADqsRhY9cqgIkX4vbXcMcpmoeLRl jckAZGgNfXoeg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9566F69097 for ; Sat, 3 Jan 2026 13:06:39 -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 WLL9xnVwFim3 for ; Sat, 3 Jan 2026 13:06:39 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470799; bh=3oC5El3ls9jbTgxC8Z0pDdtriv2TKiwel0nfyfUQvdM=; 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=fUi8qpad1tTr0HAiI0rPr1UySWWRmCrcMVjZRKPcwd+2aaePslpkmPnFpCQyl1pu6 J+HKBUbdT5lTEFop7PTfffeLFS5TvIB5DZVVyTAxAnp64wipIeNXMZSgxG8TM9z+Xa Wxakeg+2REEPywJilCMIstf6Wa9qkK1sTyKkefEpm4EjiO3NQWUZftCxUKGW0Lq2Vb ICoi6AvMDLG2dcFE3sjraQZgQq55GXXh+LWpNuvDp4elbwa3lrTcrlRDgwiBHoG4mq AAN6h/rjmK4JqjRWUUXSzhW2KzSOqCZi/W1x6jADqsRhY9cqgIkX4vbXcMcpmoeLRl jckAZGgNfXoeg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 85A286907B for ; Sat, 3 Jan 2026 13:06:39 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470797; bh=xpjDevNEIhV9PV/ykmb/IdJ7QyJS6u4qXEPNKGSVwxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m46Y52RDaK5MvMfCVDPeYALXtft1TQQR78l89qDuFnYUg4V64C4oP3ayDRIGP2dU/ qtC/dX8FgduCTZFHoFhCHSwgfSB2923ODNY7UzWa6HE5gdIs2DjWNbQxHGtThU0tKw AI6AnTEQqAHUFxOFDs8J8V3QEhflqwIwcpKb3t0DK6SoXjCfzmK++96vuyInXVXvlS 8Vw2+czUM/Ddwp6lFVhC4iC+AR5AzgCCDTA8YKy3DDt+MK7qzKIdfFthS5bD6EAJUI QeHvWeAnwIzkuE2mcJJfXecOOk6gmtmCaOgFOMLQDDUqt9lbdDb3cuH2B3bfaDPJtc 3w5JhKHDuHR2Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AF18B6907B; Sat, 3 Jan 2026 13:06:37 -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 rsNNfZjD8oKW; Sat, 3 Jan 2026 13:06:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470793; bh=S1/RZn1tbMAeqPrKCkg1fdvxKpSrF05LnaFzNH/j5+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D6HhIDgz1SPZbdwDsZDCq5O1/ubTbv958BYUpt4isq16zoxCS5vers7WKKKfSQyDp 2AmuTb4La83fqbBOYw9Jr8GySBHEshN4Kdu7IIfTO7Z2qBOPwmrbICCyrvZ6B3qxUv +3VGa2e0VxPeiyIJj5ZvOlFljq41cLyBSiDGNBY3PS7WSB+H4GNk2EDTyepHigSjhC KXVr91E0Ax1cEmgQMAGw3WwlZkiuAXSguv3GfV1IOQJVHHveP0BstwOO5H908+8gfj 2I0IsubGabfCEgy20pFZPN+5N0fKLMZDh2oSOYa+7sBHQBiBlL0lAtZsYmHRRvj+fj +FEXej3WLFlOg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 55C6368FCC; Sat, 3 Jan 2026 13:06:33 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:48 -0700 Message-ID: <20260103200510.3605009-18-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JK6FDJ3F55GOWUAJTEE3NLDKZYEYJZCZ X-Message-ID-Hash: JK6FDJ3F55GOWUAJTEE3NLDKZYEYJZCZ 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 v2 17/29] test: malloc: Account for mcheck overhead in the large test 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 The malloc_very_large() test fails when mcheck is enabled with large CONFIG_MCHECK_CALLER_LEN because the 64K margin does not account for the per-allocation overhead (header + canaries). Use a larger margin (256K) when mcheck is enabled to ensure the test passes regardless of the mcheck caller length setting. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) test/common/malloc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/common/malloc.c b/test/common/malloc.c index 9fdc1789645..436aac503be 100644 --- a/test/common/malloc.c +++ b/test/common/malloc.c @@ -535,11 +535,21 @@ COMMON_TEST(common_test_mallinfo, 0); /* Test allocating a very large size */ static int common_test_malloc_very_large(struct unit_test_state *uts) { - size_t size, before; + size_t size, before, margin; void *ptr; before = get_alloced_size(); - size = TOTAL_MALLOC_LEN - before - SZ_64K; + + /* + * When mcheck is enabled, it adds overhead per allocation (header + + * canaries). With large CONFIG_MCHECK_CALLER_LEN, this can be + * significant. Use a larger margin to account for mcheck overhead. + */ + if (CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION)) + margin = SZ_256K; + else + margin = SZ_64K; + size = TOTAL_MALLOC_LEN - before - margin; ptr = malloc(size); ut_assertnonnull(ptr); From patchwork Sat Jan 3 20:04:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1236 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=1767470804; bh=Zl2i6UxWATcoCBQ3HPO0fTIcevOtreZmksfQOWDZD+g=; 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=MXWQHtpSjSPjXOF7iUdJC+hCNw6Y+g3OMNBqfMmfDUnv2ClfQdWC/LN+/AAxrtuVB kKmy6lXeqmwqw2vhtcDZcjLa3DvPz3z8NCV3YsGI1EmBTn2MMmdok+9MdG8Oy7dtVv Ls+6ovhvROCRk0aYEL5NTz68ZtqXq+/UFr4Ykm/n9miSd6HFw0BjaEkK7KFPXVHOHU w3Cv2l01/3b3Vk6g8PzbElGq+oiVhM95i3/dKTkc97gpw4Yihw3TkoJ3Lul/obwgCU s9dIKs8UqhzPR+XrZZi4fxjmCRA3IG75mvtblT9/wvYZDeM9CZeReqrzigc3aAkYMO e1V0tAJy+rACw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 02E17690A1 for ; Sat, 3 Jan 2026 13:06: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 uVuceDgtqcly for ; Sat, 3 Jan 2026 13:06:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470803; bh=Zl2i6UxWATcoCBQ3HPO0fTIcevOtreZmksfQOWDZD+g=; 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=PdvdXOkAF5jwtL0lYW2w0lvmuH1fOWQuk6F25fZin1B8WA3kzJQrhTpmzXCbOtd+/ uBMySgfaKk+z76C8q8VDgpZ24Z2CiFE8m9Z1wmeoLBVLhxUcFbOxUaEKyhQk0kzPe5 oq/bX3MgkChNTkV+Vbg8Q/t9SymMEB7Akigc3HniZnIN1aqiioj/brRVTCDcdrcYI/ W7EUl3w/YeeCQLpE0v/ls4qE+EfzvbzhxBgbc89xmSM9MZ+5cxFweERorHOqEr9MEv xvyFU6jB08XopkNdqPAqv3L64TL27IA5RHg00LhwB7CGKEkLSXOC1BPX3dlcMCX+qF 2wcN7XKqUCRQQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E768169095 for ; Sat, 3 Jan 2026 13:06:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470802; bh=/dpVJYSxTrZkpEARaxFgyqDK+L6IF2glfEc5qC1DZfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pdQ+ziu5bsKONQ6yN5JZfogzGpFnXKiQxbDWMD8X6oEH/MYxZ0CjpVH3TdGxAYt7e cxayWgBRG2BaUWkW5kWkEFqaJw1ozxeSWQOfpfJRGfZT3IYY8Qa1hKJbUyD4Vinhmu s10KQv9Dnk9Y9t2a44IHaSciL/tX5h+Oisu4L1doJyDDqVXWU21V0nI6fy15j404lr e5qchZ4ezswAUHSiT8i2hI+TaDfsYI9rihHadTjaiRSavYkYgCX3DWf4lkUDeQ0ykP jnGcxuyG1I613mQRTRO3gKq2RUju54eCa83kOfgXCWW+H3qrFZaBCRug6XDA1wJsS7 bCXMumB6mjJ5g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5A28E68FD2; Sat, 3 Jan 2026 13:06:42 -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 TIPR2526gho2; Sat, 3 Jan 2026 13:06:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470798; bh=HhJQsWRQiiMLy72ZmP1jZIzV6E876HzPQoB4QE6RRPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MtFGkBcj2yOVraPVGq4qxYgKtPDlZRBSgZAbii0HX1+NpaisvtNfZI0QoftcTatJr T11A+l2bUwfCOiOgYZb2KUVysWMqbpZJRqHdNRuuNSSust1yz04F1J70zk1pVoqQw8 rTnOe1yf2q6U9rfVzWXv1blLRVQWANHfXdi09v8OHhoyzGcFq4L1OKowtqX3ZQXm2Q OGRnW5acQLK4/5kAAI0yHeiWtdOR1L14qkUohuy2qE6MiVOR1qoMLhUJdzG/62yuZI DopxuYb6HhW887huUAfmeHYG+kAykza4LLDtlng/86Y5f81dFyXNY+5Ps4Gq7bOEeV xaZISbEQIBlvQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id F16D968FCC; Sat, 3 Jan 2026 13:06:37 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:49 -0700 Message-ID: <20260103200510.3605009-19-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: MYGBUOC7NRWALX4SLQQM5QB5G2PGU4VN X-Message-ID-Hash: MYGBUOC7NRWALX4SLQQM5QB5G2PGU4VN 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 v2 18/29] malloc: Refactor malloc_dump() to use output callback 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 Replace direct printf calls in malloc_dump() with an output callback function. This introduces dump_out_fn type and dump_to_console() helper, with malloc_dump_impl() taking the callback and context pointer. This allows the same implementation logic to be reused for different output destinations such as writing to a file. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) common/dlmalloc.c | 69 ++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 71f81aeaec7..fae1d28a599 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -7215,7 +7215,21 @@ static struct mcheck_hdr *find_freed_mcheck_hdr(void *mem, size_t sz) } #endif -void malloc_dump(void) +/* Output function type for malloc_dump_impl */ +typedef void (*dump_out_fn)(void *ctx, const char *fmt, ...) + __printf(2, 3); + +/* Console output function for heap dump */ +static void dump_to_console(void *ctx, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +static void malloc_dump_impl(dump_out_fn out, void *ctx) { mchunkptr q; msegmentptr s; @@ -7223,21 +7237,21 @@ void malloc_dump(void) int used_count = 0, free_count = 0; if (!is_initialized(gm)) { - printf("dlmalloc not initialized\n"); + out(ctx, "dlmalloc not initialized\n"); return; } - printf("Heap dump: %lx - %lx\n", mem_malloc_start, mem_malloc_end); - printf("%12s %10s %s\n", "Address", "Size", "Status"); - printf("----------------------------------\n"); + out(ctx, "Heap dump: %lx - %lx\n", mem_malloc_start, mem_malloc_end); + out(ctx, "%12s %10s %s\n", "Address", "Size", "Status"); + out(ctx, "----------------------------------\n"); s = &gm->seg; while (s != 0) { q = align_as_chunk(s->base); /* Show chunk header before first allocation */ - printf("%12lx %10zx (chunk header)\n", (ulong)s->base, - (size_t)((char *)chunk2mem(q) - (char *)s->base)); + out(ctx, "%12lx %10zx (chunk header)\n", (ulong)s->base, + (size_t)((char *)chunk2mem(q) - (char *)s->base)); while (segment_holds(s, q) && q != gm->top && q->head != FENCEPOST_HEAD) { @@ -7250,14 +7264,14 @@ void malloc_dump(void) hdr = find_mcheck_hdr_in_chunk(mem, sz); if (hdr && hdr->caller[0]) - printf("%12lx %10zx %s\n", - (ulong)mem, sz, hdr->caller); + out(ctx, "%12lx %10zx %s\n", + (ulong)mem, sz, hdr->caller); else - printf("%12lx %10zx\n", - (ulong)mem, sz); + out(ctx, "%12lx %10zx\n", + (ulong)mem, sz); #else - printf("%12lx %10zx\n", - (ulong)mem, sz); + out(ctx, "%12lx %10zx\n", + (ulong)mem, sz); #endif used += sz; used_count++; @@ -7267,14 +7281,14 @@ void malloc_dump(void) hdr = find_freed_mcheck_hdr(mem, sz); if (hdr && hdr->caller[0]) - printf("%12lx %10zx free %s\n", - (ulong)mem, sz, hdr->caller); + out(ctx, "%12lx %10zx free %s\n", + (ulong)mem, sz, hdr->caller); else - printf("%12lx %10zx free\n", - (ulong)mem, sz); + out(ctx, "%12lx %10zx free\n", + (ulong)mem, sz); #else - printf("%12lx %10zx free\n", - (ulong)mem, sz); + out(ctx, "%12lx %10zx free\n", + (ulong)mem, sz); #endif free_space += sz; free_count++; @@ -7286,15 +7300,20 @@ void malloc_dump(void) /* Print top chunk (wilderness) */ if (gm->top && gm->topsize > 0) { - printf("%12lx %10zx top\n", - (ulong)chunk2mem(gm->top), gm->topsize); + out(ctx, "%12lx %10zx top\n", + (ulong)chunk2mem(gm->top), gm->topsize); free_space += gm->topsize; } - printf("%12lx %10s end\n", mem_malloc_end, ""); - printf("----------------------------------\n"); - printf("Used: %zx bytes in %d chunks\n", used, used_count); - printf("Free: %zx bytes in %d chunks + top\n", free_space, free_count); + out(ctx, "%12lx %10s end\n", mem_malloc_end, ""); + out(ctx, "----------------------------------\n"); + out(ctx, "Used: %zx bytes in %d chunks\n", used, used_count); + out(ctx, "Free: %zx bytes in %d chunks + top\n", free_space, free_count); +} + +void malloc_dump(void) +{ + malloc_dump_impl(dump_to_console, NULL); } int initf_malloc(void) From patchwork Sat Jan 3 20:04: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: 1237 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=1767470806; bh=fcex0WhrEo1qMDLmsas2EYroYHBUxWgaft7526wIOp0=; 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=SqNMjzoCUNbeqlHoPZhrDKNIV9BUjsszj6Hqtnx7qz0Xa/rqz97zk5euOEqkS3I3k ZqZu9+cujbNPOpWPtIozu8wdfAVhTQfYuMGe4YwVlIz2QK2z+ySvtKJhRsoS2ZDfn1 YwfhQBpJ5JUhNZgmlxm0BT8fB+O+ZmDkGcF/xm8KR6T/NJ9dTSCYsPvp11ZBrguU0x 7d/M9wtVUC8xh1Oo9duk0vNU2sc2Yo9WVU9xqPlOkUFB2Zi53YGtzLmRRRWevykITp RCJOse4uC7dudp0xDHHIRTYnr07V4t5nRa4ZrDrudI4pmAGbliM5gKEQLR5UjIxGOx dRnKWdKfrs2TA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 620F7690A8 for ; Sat, 3 Jan 2026 13:06:46 -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 BvIM6a4hHpST for ; Sat, 3 Jan 2026 13:06:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470805; bh=fcex0WhrEo1qMDLmsas2EYroYHBUxWgaft7526wIOp0=; 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=ryK4jvhl17q0VEnT2Pa+UIthilDaynAs4nhq9p2UoFQufRP7I7G0SkN/V0v/7daPQ QHIvDEA0R4uN+UbR4mjaiuhnfdTtBc+ZIj9VCiDNzPEuidcoAmM3ccr4p2b72yjXob 5cdBljcOYJLgQ/+YC8gQD+KvFk5bUSTKgDS7v2fQbtXjLhUJHUWwoR1VEcIwsSgibM yecJ6Kufi+1zBOZLV+vewsR2N49x1XFX7er2r7gLBgwcsn/sCL1lviDV4ajrne3uMw w5sCQHkmuh44YHB8BD9qFawrbbuLk/usCrhbsncaKKes002BSniUnIhS42bl4myKL/ q6NfnCUBUxdJA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5C4B769097 for ; Sat, 3 Jan 2026 13:06:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470803; bh=yzGPK4dx4IVor0r8/uoR52D/qEjfQCkulEYEU7+WzaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I50jE35oqPEG3uA93TI64BKGYNbwBjLWZaTYeoYYBYhTSU/Y0+q66eUlbRZCwD1SR dkZVtEVhvPtV34X4yoer4gKqlz9jILDwUf8HkOhHKUYiMThhLaSXzTRKObeVL7VyUy sjyhxoGMLAnPOx6jZMrY0JzFhYNhH3Ag8cuQG2clGsgmjV2VLxsciEfw9RN+fMWDCG 3KGlAHtyuW8b9uzg5KTMd/x6mHZYvBX4SPjCCEyfXGMVWToCOjy/62VJd4dLSsmEd8 xuLa1ML/kX1Rq/n6QYFTJamZZ5Mf7YRXcfbhnTl0sXcWxIcvVzS2wrrvrYKyHTLvku dEAUAVqglyn1w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BA3E56907B; Sat, 3 Jan 2026 13:06: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 3bwRT2h8d7YH; Sat, 3 Jan 2026 13:06:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470802; bh=ZvJJsy3RSs7F6lybDmyzQe0v5vSsY+N2+w5K7Lkj6eE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nkCrijAuAMa5CmQkdh04oB6ma24YvdRYdW5gVqmChStgElEY0fKs2CdmsCQE4D/wj jpylt9lUKN7hVa4bSCxbEhETNobg2wS2xvlunWp1qFl1QNCCSyRnbaXz66b+gEgWJ0 ui2Xxgzw49WxUVs2fFxPp3N4BUFllLjCn7iDmWSAwlAaIKG/NYzLW3uvR/kNlao7Td gE20Vpp+QF5Y936r1baic+WIC3EPMPOc0pWI18sG9g3D+qdZa6ov/pYUKvoPqusQ91 RHEtC9hPaoB/cWjOxJ+AExsZ1Zm1FEY4itvCsfiAItlEmTckAIo/j3an9xmOzPvVMu YC6YdEsKttmKA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9D81A68FCC; Sat, 3 Jan 2026 13:06:42 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:50 -0700 Message-ID: <20260103200510.3605009-20-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: BTGOGC6GFPOE2U2QJ5YT2LO3L7DNX5XZ X-Message-ID-Hash: BTGOGC6GFPOE2U2QJ5YT2LO3L7DNX5XZ 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 v2 19/29] malloc: Add a log for malloc() traffic 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 a malloc()-traffic log that records all malloc()-related calls with their addresses, sizes, and caller information. This is useful for debugging allocation patterns and finding the source of allocations that lack caller info in heap dumps. Each entry stores: - Operation type (alloc/free/realloc/memalign) - Pointer address - Size (and old size for realloc) - Full caller backtrace string On sandbox, the log buffer is allocated from host memory using os_malloc(), so it does not affect U-Boot's heap. The size is controlled by CONFIG_MCHECK_LOG_SIZE (default 512K entries). If the log fills up, it wraps around (circular buffer) and a warning is shown when dumping to indicate how many entries were lost. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) Kconfig | 22 +++++ common/dlmalloc.c | 198 ++++++++++++++++++++++++++++++++++++++--- doc/develop/malloc.rst | 14 +++ include/malloc.h | 72 +++++++++++++++ test/common/malloc.c | 52 +++++++++++ 5 files changed, 346 insertions(+), 12 deletions(-) diff --git a/Kconfig b/Kconfig index 3b89f2c48dd..d47077d43bc 100644 --- a/Kconfig +++ b/Kconfig @@ -366,6 +366,28 @@ config MCHECK_CALLER_LEN Larger values provide more context but increase memory overhead per allocation. +config MCHECK_LOG + bool "Enable malloc traffic log" + depends on MCHECK_HEAP_PROTECTION && SANDBOX + default y + help + Enable a log of all malloc()/free()/realloc() calls. This records + each call with its address, size, and caller backtrace. Useful for + debugging allocation patterns and finding the source of memory + leaks. The log uses host memory so it does not affect U-Boot's + heap. + +config MCHECK_LOG_SIZE + int "Number of entries in malloc traffic log" + depends on MCHECK_LOG + default 65536 + help + Sets the number of entries in the malloc traffic log. Each entry + records a malloc()/free()/realloc() call with address, size, and + caller info. The log uses host memory (os_malloc()) so it does not + affect U-Boot's heap. Use 'malloc log start' to begin logging and + 'malloc log' to dump the log. + config SPL_SYS_MALLOC_F bool "Enable malloc() pool in SPL" depends on SPL_FRAMEWORK && SYS_MALLOC_F && SPL diff --git a/common/dlmalloc.c b/common/dlmalloc.c index fae1d28a599..ef482cd3309 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -5957,6 +5957,7 @@ STATIC_IF_MCHECK size_t dlmalloc_usable_size_impl(const void *mem) #if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) #include +#include #include "mcheck_core.inc.h" /* Guard against recursive backtrace calls during malloc */ @@ -5993,8 +5994,152 @@ static const char *mcheck_caller(void) return caller; } +#if CONFIG_IS_ENABLED(MCHECK_LOG) +/* Malloc traffic logging for debugging allocation patterns */ + +#if IS_ENABLED(CONFIG_SANDBOX) +#define MLOG_SIZE CONFIG_MCHECK_LOG_SIZE +#else +#define MLOG_SIZE 1024 +#endif + +/** + * struct mlog_hdr - Header for the malloc traffic log + * + * @buf: Array of log entries + * @size: Number of entries in @buf + * @head: Index of next entry to write + * @count: Total number of entries written (may exceed @size if wrapped) + * @enabled: true if logging is active + */ +struct mlog_hdr { + struct mlog_entry *buf; + uint size; + uint head; + uint count; + bool enabled; +}; + +static struct mlog_hdr mlog __section(".data"); + +static void mlog_record(enum mlog_type type, void *ptr, size_t size, + size_t old_size, const char *caller) +{ + struct mlog_entry *ent; + + if (!mlog.enabled || !mlog.buf) + return; + + ent = &mlog.buf[mlog.head]; + ent->type = type; + ent->ptr = ptr; + ent->size = size; + ent->old_size = old_size; + if (caller) + strlcpy(ent->caller, caller, MLOG_CALLER_LEN); + else + ent->caller[0] = '\0'; + mlog.head = (mlog.head + 1) % mlog.size; + mlog.count++; +} + +void malloc_log_start(void) +{ + if (!mlog.buf) { + if (IS_ENABLED(CONFIG_SANDBOX)) { + mlog.buf = os_malloc(MLOG_SIZE * + sizeof(struct mlog_entry)); + if (!mlog.buf) { + printf("Failed to allocate malloc log buffer\n"); + return; + } + mlog.size = MLOG_SIZE; + } else { + printf("Malloc log not available on this platform\n"); + return; + } + } + memset(mlog.buf, '\0', mlog.size * sizeof(struct mlog_entry)); + mlog.head = 0; + mlog.count = 0; + mlog.enabled = true; +} + +void malloc_log_stop(void) +{ + mlog.enabled = false; +} + +int malloc_log_info(struct mlog_info *info) +{ + if (!mlog.buf) + return -ENOENT; + + if (mlog.count > mlog.size) + info->entry_count = mlog.size; + else + info->entry_count = mlog.count; + info->max_entries = mlog.size; + info->total_count = mlog.count; + + return 0; +} + +int malloc_log_entry(uint idx, struct mlog_entry **entryp) +{ + uint start, count; + + if (!mlog.buf) + return -ENOENT; + + if (mlog.count > mlog.size) { + count = mlog.size; + start = mlog.head; + } else { + count = mlog.count; + start = 0; + } + + if (idx >= count) + return -ERANGE; + + *entryp = &mlog.buf[(start + idx) % mlog.size]; + + return 0; +} + +#else /* !MCHECK_LOG */ + +static inline void mlog_record(enum mlog_type type, void *ptr, size_t size, + size_t old_size, const char *caller) +{ +} + +void malloc_log_start(void) +{ +} + +void malloc_log_stop(void) +{ +} + +int malloc_log_info(struct mlog_info *info) +{ + return -ENOENT; +} + +int malloc_log_entry(uint idx, struct mlog_entry **entryp) +{ + return -ENOENT; +} + +#endif /* MCHECK_LOG */ + void *dlmalloc(size_t bytes) { + const char *caller; + void *p; + /* * Skip mcheck for simple malloc (pre-relocation). Simple malloc is a * bump allocator that can't free, so mcheck overhead is useless and @@ -6007,13 +6152,17 @@ void *dlmalloc(size_t bytes) if (mcheck_disabled) return dlmalloc_impl(bytes CALLER_NULL); + caller = mcheck_caller(); mcheck_pedantic_prehook(); size_t fullsz = mcheck_alloc_prehook(bytes); - void *p = dlmalloc_impl(fullsz CALLER_NULL); + p = dlmalloc_impl(fullsz CALLER_NULL); if (!p) return p; - return mcheck_alloc_posthook(p, bytes, mcheck_caller()); + p = mcheck_alloc_posthook(p, bytes, caller); + mlog_record(MLOG_ALLOC, p, bytes, 0, caller); + + return p; } void dlfree(void *mem) @@ -6027,11 +6176,16 @@ void dlfree(void *mem) dlfree_impl(mem); return; } + mlog_record(MLOG_FREE, mem, 0, 0, mcheck_caller()); dlfree_impl(mcheck_free_prehook(mem)); } void *dlrealloc(void *oldmem, size_t bytes) { + const char *caller; + size_t old_size; + void *p; + #ifdef REALLOC_ZERO_BYTES_FREES if (bytes == 0) { if (oldmem) @@ -6046,18 +6200,26 @@ void *dlrealloc(void *oldmem, size_t bytes) if (mcheck_disabled) return dlrealloc_impl(oldmem, bytes); + caller = mcheck_caller(); + old_size = dlmalloc_usable_size(oldmem); mcheck_pedantic_prehook(); - void *p = mcheck_reallocfree_prehook(oldmem); + p = mcheck_reallocfree_prehook(oldmem); size_t newsz = mcheck_alloc_prehook(bytes); p = dlrealloc_impl(p, newsz); if (!p) return p; - return mcheck_alloc_noclean_posthook(p, bytes, mcheck_caller()); + p = mcheck_alloc_noclean_posthook(p, bytes, caller); + mlog_record(MLOG_REALLOC, p, bytes, old_size, caller); + + return p; } void *dlmemalign(size_t alignment, size_t bytes) { + const char *caller; + void *p; + if (CONFIG_IS_ENABLED(SYS_MALLOC_F) && !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) return memalign_simple(alignment, bytes); @@ -6065,24 +6227,31 @@ void *dlmemalign(size_t alignment, size_t bytes) if (mcheck_disabled) return dlmemalign_impl(alignment, bytes); + caller = mcheck_caller(); mcheck_pedantic_prehook(); size_t fullsz = mcheck_memalign_prehook(alignment, bytes); - void *p = dlmemalign_impl(alignment, fullsz); + p = dlmemalign_impl(alignment, fullsz); if (!p) return p; - return mcheck_memalign_posthook(alignment, p, bytes, mcheck_caller()); + p = mcheck_memalign_posthook(alignment, p, bytes, caller); + mlog_record(MLOG_MEMALIGN, p, bytes, 0, caller); + + return p; } /* dlpvalloc, dlvalloc redirect to dlmemalign, so they need no wrapping */ void *dlcalloc(size_t n, size_t elem_size) { + const char *caller; + size_t sz; + void *p; + if (CONFIG_IS_ENABLED(SYS_MALLOC_F) && !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { - size_t sz = n * elem_size; - void *p = malloc_simple(sz); - + sz = n * elem_size; + p = malloc_simple(sz); if (p) memset(p, '\0', sz); return p; @@ -6091,14 +6260,19 @@ void *dlcalloc(size_t n, size_t elem_size) if (mcheck_disabled) return dlcalloc_impl(n, elem_size); + sz = n * elem_size; + caller = mcheck_caller(); mcheck_pedantic_prehook(); /* NB: no overflow check here */ - size_t fullsz = mcheck_alloc_prehook(n * elem_size); - void *p = dlcalloc_impl(1, fullsz); + size_t fullsz = mcheck_alloc_prehook(sz); + p = dlcalloc_impl(1, fullsz); if (!p) return p; - return mcheck_alloc_noclean_posthook(p, n * elem_size, mcheck_caller()); + p = mcheck_alloc_noclean_posthook(p, sz, caller); + mlog_record(MLOG_ALLOC, p, sz, 0, caller); + + return p; } size_t dlmalloc_usable_size(const void *mem) diff --git a/doc/develop/malloc.rst b/doc/develop/malloc.rst index 8dba2d98afe..92180af055a 100644 --- a/doc/develop/malloc.rst +++ b/doc/develop/malloc.rst @@ -385,6 +385,20 @@ allocation was made:: This caller information makes it easy to track down memory leaks by showing exactly where each allocation originated. +Malloc-Traffic Log +~~~~~~~~~~~~~~~~~~ + +On sandbox, when mcheck is enabled, a malloc-traffic log can record all +malloc/free/realloc calls. This is useful for debugging allocation patterns +and finding where allocations without caller info originate. + +The log buffer is allocated from host memory using ``os_malloc()``, so it +does not affect U-Boot's heap. The size is controlled by +``CONFIG_MCHECK_LOG_SIZE`` (default 512K entries, about 80MB). + +If the log fills up, it wraps around and overwrites the oldest entries. +A warning is shown when dumping if entries were lost. + Valgrind ~~~~~~~~ diff --git a/include/malloc.h b/include/malloc.h index 3327bdcb44f..f8bfe843738 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -712,6 +712,78 @@ void malloc_disable_testing(void); */ void malloc_dump(void); +/** + * malloc_log_start() - Start logging malloc traffic + * + * Enables recording of malloc/free/realloc calls to a circular buffer. + * Use malloc_log_dump() to print the recorded entries. + */ +void malloc_log_start(void); + +/** + * malloc_log_stop() - Stop logging malloc traffic + */ +void malloc_log_stop(void); + +/** + * enum mlog_type - Type of malloc log entry + */ +enum mlog_type { + MLOG_ALLOC, + MLOG_FREE, + MLOG_REALLOC, + MLOG_MEMALIGN, +}; + +#define MLOG_CALLER_LEN 128 + +/** + * struct mlog_entry - Entry in the malloc traffic log + * + * @type: Operation type (alloc, free, realloc, memalign) + * @ptr: Pointer returned by or passed to the operation + * @size: Size of allocation (0 for free) + * @old_size: Previous size for realloc, 0 otherwise + * @caller: Backtrace string showing where the call originated + */ +struct mlog_entry { + enum mlog_type type; + void *ptr; + size_t size; + size_t old_size; + char caller[MLOG_CALLER_LEN]; +}; + +/** + * struct mlog_info - Information about the malloc log + * + * @entry_count: Number of entries currently available in the log + * @max_entries: Maximum number of entries the log can hold + * @total_count: Total number of entries recorded (may exceed max if wrapped) + */ +struct mlog_info { + uint entry_count; + uint max_entries; + uint total_count; +}; + +/** + * malloc_log_info() - Get information about the malloc log + * + * @info: Returns log statistics + * Return: 0 on success, -ENOENT if log not started + */ +int malloc_log_info(struct mlog_info *info); + +/** + * malloc_log_entry() - Get a specific entry from the malloc log + * + * @idx: Index of entry to retrieve (0 = oldest available) + * @entryp: Returns pointer to the log entry + * Return: 0 on success, -ENOENT if log not started, -ERANGE if idx out of range + */ +int malloc_log_entry(uint idx, struct mlog_entry **entryp); + /** * malloc_backtrace_skip() - Control backtrace collection in malloc * diff --git a/test/common/malloc.c b/test/common/malloc.c index 436aac503be..292efd777b2 100644 --- a/test/common/malloc.c +++ b/test/common/malloc.c @@ -637,3 +637,55 @@ static int common_test_malloc_fill_pool(struct unit_test_state *uts) return 0; } COMMON_TEST(common_test_malloc_fill_pool, 0); + +#if CONFIG_IS_ENABLED(MCHECK_LOG) +/* Test malloc_log_info() and malloc_log_entry() */ +static int common_test_malloc_log_info(struct unit_test_state *uts) +{ + struct mlog_entry *entry; + struct mlog_info info; + void *ptr, *ptr2; + + malloc_log_start(); + + /* Do an allocation, realloc, and free */ + ptr = malloc(0x100); + ut_assertnonnull(ptr); + + ptr2 = realloc(ptr, 0x200); + ut_assertnonnull(ptr2); + + free(ptr2); + + malloc_log_stop(); + + ut_assertok(malloc_log_info(&info)); + ut_asserteq(3, info.entry_count); + ut_assert(info.max_entries > 0); + ut_asserteq(info.entry_count, info.total_count); /* no wrapping */ + + /* Check the alloc entry */ + ut_assertok(malloc_log_entry(0, &entry)); + ut_asserteq(MLOG_ALLOC, entry->type); + ut_asserteq_ptr(ptr, entry->ptr); + ut_asserteq(0x100, entry->size); + + /* Check the realloc entry */ + ut_assertok(malloc_log_entry(1, &entry)); + ut_asserteq(MLOG_REALLOC, entry->type); + ut_asserteq_ptr(ptr2, entry->ptr); + ut_asserteq(0x200, entry->size); + ut_asserteq(0x100, entry->old_size); + + /* Check the free entry */ + ut_assertok(malloc_log_entry(2, &entry)); + ut_asserteq(MLOG_FREE, entry->type); + ut_asserteq_ptr(ptr2, entry->ptr); + + /* Out of range should fail */ + ut_asserteq(-ERANGE, malloc_log_entry(3, &entry)); + + return 0; +} +COMMON_TEST(common_test_malloc_log_info, 0); +#endif /* MCHECK_LOG */ From patchwork Sat Jan 3 20:04: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: 1238 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=1767470811; bh=56hJjPZrg83wpSmHQt/AmxkC+glh+AHxLYv5UHBwKRM=; 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=lUTXp6qdp9YLkzi6EHtqvVAtySoIG/KxgIj1QN1JcQkQyMXLUB/xb3EhO++4mmRZu zIjxdjPedSNOvxvO4K7qD/Zy7nDqH0x9Bm2Y7LKwfVKYKPozxIx+tzpOovQhQ8eKIu 9XVkgFsQ0uSHrUF6oD7IGpoiStrb5XfbT+VZ+BlBbtDvqTBvNfE3tia4VWzrnbN4Ip Gu5lV7j5bzLEfFfxWpgyXKS58fc7L19U0uxqAUAXDRvNbTGgc3Q05BHTso7FK501+Z oF8XX8G66ju5PQ0ib9Ud26lb+QeAjtCWaoKfjFz7WXx1u4wjgh/LVXr9wl47GA5yMC YcxJK3SlTnVNg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1AE3269097 for ; Sat, 3 Jan 2026 13:06:51 -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 ze8kBrlq42Hl for ; Sat, 3 Jan 2026 13:06:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470811; bh=56hJjPZrg83wpSmHQt/AmxkC+glh+AHxLYv5UHBwKRM=; 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=lUTXp6qdp9YLkzi6EHtqvVAtySoIG/KxgIj1QN1JcQkQyMXLUB/xb3EhO++4mmRZu zIjxdjPedSNOvxvO4K7qD/Zy7nDqH0x9Bm2Y7LKwfVKYKPozxIx+tzpOovQhQ8eKIu 9XVkgFsQ0uSHrUF6oD7IGpoiStrb5XfbT+VZ+BlBbtDvqTBvNfE3tia4VWzrnbN4Ip Gu5lV7j5bzLEfFfxWpgyXKS58fc7L19U0uxqAUAXDRvNbTGgc3Q05BHTso7FK501+Z oF8XX8G66ju5PQ0ib9Ud26lb+QeAjtCWaoKfjFz7WXx1u4wjgh/LVXr9wl47GA5yMC YcxJK3SlTnVNg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 099D56907B for ; Sat, 3 Jan 2026 13:06:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470808; bh=8ZDc8gsTb2/wv3YVoIxOtQjeHKG1YImjewsedgUeSXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aZPeB9Wl0WNBjN2MDsEL1E9yFBcAp66uzsAw20M6ImJRtlTEuFjzy/NRt64jgVe/s EHs23SERv/pYzdLpBg+vpmOX6feDgo8YWydzTnsB1ov5AZokPG4S6bIWQmEsE5VuVk QHHHBuSJUsRoPnOdG6cfecIZ568nh87/yeWxJPqbg6zGoTmHll0MPX5RNrlqWnfXho zkL6V9WJ/4vRcQCgO/pAy9e9sb16LbBGhTF8p0k2pYfVt4vAAC+s3YsD9f8T5D0T5y 1fPICdZwk+PJ8BUhYL2XOKZ4og7xoYvzsNUgStadNHz6lxN+9AuVSq10rE5XeoLwYg 7zDJZu+D8XnLQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B14B168FD2; Sat, 3 Jan 2026 13:06:48 -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 hnr-KHTift4M; Sat, 3 Jan 2026 13:06:48 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470804; bh=GIYf+2pfI+LDb1w8P5/JqRva9GF03WJlL8JCqzvWulQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=prAUA/J3V/OyN0vwAjFW7EWAerxhZnkGyiecLr3soaD0qI5RCcupDa/LRPsoME0Xg bwym1DACqu0n69makerX5M1nXa+3S16c7hnB9pY5ulmkYe6Xdjm24SY/bugoO/ow1g YDoGJb47zf4SngjSkdQEOeEEZ1tKbB2lFzKq5n6DBVkFMI2Rdj+75UpT622B8CwqZG jxkVbbEMT0ZIHbV7Ppf92hlA3OviC23yA7BdC5qxtoAIRaosX4GQgMXDcKvZPvIbL1 k17/ym541f4kXBVwmmVD0wjfXlzZIm111JTZ5Tp3UydGKkpULkTFhSCWCc1Uy1O2sF Hll2EK/YuTtIA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 070AB69095; Sat, 3 Jan 2026 13:06:43 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:51 -0700 Message-ID: <20260103200510.3605009-21-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: RA7ZDJYJ4CEMRFQPSRHGTQYZCUBG7L3M X-Message-ID-Hash: RA7ZDJYJ4CEMRFQPSRHGTQYZCUBG7L3M 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 v2 20/29] malloc: Add function to dump the malloc()-traffic log 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 malloc_log_dump() to print all recorded malloc/free/realloc calls with their addresses, sizes, and caller information. This provides a way to inspect the log after recording. The dump shows a summary line with entry counts, followed by a table with sequence number, operation type, pointer, size, and caller for each recorded operation. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) common/dlmalloc.c | 70 ++++++++++++++++++++++++++++++++++++++++++++ include/malloc.h | 8 +++++ test/common/malloc.c | 41 ++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index ef482cd3309..0e363e78e26 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -6070,6 +6070,72 @@ void malloc_log_stop(void) mlog.enabled = false; } +/* Output function type for malloc_log_impl */ +typedef void (*log_out_fn)(void *ctx, const char *fmt, ...) + __printf(2, 3); + +/* Console output function for log */ +static void log_to_console(void *ctx, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +static void malloc_log_impl(log_out_fn out, void *ctx) +{ + static const char * const mlog_type_names[] = { + "alloc", "free", "realloc", "memalign" + }; + uint i, start, count; + + if (!mlog.buf) { + out(ctx, "Malloc log not started\n"); + return; + } + + if (mlog.enabled) { + out(ctx, "Warning: log still active, results may be incomplete\n"); + malloc_log_stop(); + } + + if (mlog.count > mlog.size) { + out(ctx, "Warning: log wrapped, %u entries lost\n", + mlog.count - mlog.size); + count = mlog.size; + start = mlog.head; /* oldest entry is at current head */ + } else { + count = mlog.count; + start = 0; + } + + out(ctx, "Malloc log: %u entries (max %u, total %u)\n", count, mlog.size, + mlog.count); + out(ctx, "%4s %-8s %10s %8s %s\n", "Seq", "Type", "Address", "Size", + "Caller"); + out(ctx, "---- -------- ---------- -------- ------\n"); + + for (i = 0; i < count; i++) { + uint idx = (start + i) % mlog.size; + struct mlog_entry *ent = &mlog.buf[idx]; + + out(ctx, "%4u %-8s %10lx %8lx", i, mlog_type_names[ent->type], + (ulong)map_to_sysmem(ent->ptr), (ulong)ent->size); + if (ent->type == MLOG_REALLOC) + out(ctx, " (was %lx)", (ulong)ent->old_size); + if (ent->caller[0]) + out(ctx, " %s", ent->caller); + out(ctx, "\n"); + } +} + +void malloc_log_dump(void) +{ + malloc_log_impl(log_to_console, NULL); +} + int malloc_log_info(struct mlog_info *info) { if (!mlog.buf) @@ -6123,6 +6189,10 @@ void malloc_log_stop(void) { } +void malloc_log_dump(void) +{ +} + int malloc_log_info(struct mlog_info *info) { return -ENOENT; diff --git a/include/malloc.h b/include/malloc.h index f8bfe843738..4bd6458b70d 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -725,6 +725,14 @@ void malloc_log_start(void); */ void malloc_log_stop(void); +/** + * malloc_log_dump() - Dump the malloc traffic log + * + * Prints all recorded malloc/free/realloc calls with their addresses, + * sizes, and caller information. + */ +void malloc_log_dump(void); + /** * enum mlog_type - Type of malloc log entry */ diff --git a/test/common/malloc.c b/test/common/malloc.c index 292efd777b2..2a292fd969c 100644 --- a/test/common/malloc.c +++ b/test/common/malloc.c @@ -688,4 +688,45 @@ static int common_test_malloc_log_info(struct unit_test_state *uts) return 0; } COMMON_TEST(common_test_malloc_log_info, 0); + +/* Test malloc_log_dump() */ +static int common_test_malloc_log_dump(struct unit_test_state *uts) +{ + struct mlog_info info; + void *ptr, *ptr2; + + malloc_log_start(); + + /* Do an allocation, realloc, and free */ + ptr = malloc(0x100); + ut_assertnonnull(ptr); + + ptr2 = realloc(ptr, 0x200); + ut_assertnonnull(ptr2); + + free(ptr2); + + malloc_log_stop(); + + ut_assertok(malloc_log_info(&info)); + + console_record_reset_enable(); + malloc_log_dump(); + + ut_assert_nextline("Malloc log: 3 entries (max %u, total 3)", + info.max_entries); + ut_assert_nextline("%4s %-8s %10s %8s %s", "Seq", "Type", "Address", + "Size", "Caller"); + ut_assert_nextline("---- -------- ---------- -------- ------"); + ut_assert_nextlinen(" 0 alloc %10lx 100", + (ulong)map_to_sysmem(ptr)); + ut_assert_nextlinen(" 1 realloc %10lx 200 (was 100)", + (ulong)map_to_sysmem(ptr2)); + ut_assert_nextlinen(" 2 free %10lx 0", + (ulong)map_to_sysmem(ptr2)); + ut_assert_console_end(); + + return 0; +} +COMMON_TEST(common_test_malloc_log_dump, 0); #endif /* MCHECK_LOG */ From patchwork Sat Jan 3 20:04:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1239 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=1767470814; bh=WwLrehkaXUI4iQlt17/hoV/gqYhfla61VUeS/LyJ/wQ=; 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=ZniwOJodS/oLD61hwqK2dRwLxpvxoo+8vFDFwWxhc5Ufn6/hFWlShbokjajvebHp6 ak2wnLho9vH8EoQNJYSz/hKVAkK0refJcNdS0Ka1bZtzIatCwXApgdoyOC7qRLrb39 kKU+nmRuYncWoBHjHB6ZT1f3bmHjh8jUCDDfNLyArg+AmxlOaWZqOounZ1y21GX/vu XVb6j4kiGEYTeOqSL0eOvsnOr7eo3h6bjiT/RvdxUB6VRUrNBwtQ7aOHSkJkKuqPtF +ODn3GzUIJq5CdUuby55JYo8zcvX9Vys1R1f9uIXCAIwTM3ZAPz6cGgObhT2sFdzD/ MnImD+024SphA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 85F13690A1 for ; Sat, 3 Jan 2026 13:06:54 -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 MOZQXvdraU2X for ; Sat, 3 Jan 2026 13:06:54 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470814; bh=WwLrehkaXUI4iQlt17/hoV/gqYhfla61VUeS/LyJ/wQ=; 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=ZniwOJodS/oLD61hwqK2dRwLxpvxoo+8vFDFwWxhc5Ufn6/hFWlShbokjajvebHp6 ak2wnLho9vH8EoQNJYSz/hKVAkK0refJcNdS0Ka1bZtzIatCwXApgdoyOC7qRLrb39 kKU+nmRuYncWoBHjHB6ZT1f3bmHjh8jUCDDfNLyArg+AmxlOaWZqOounZ1y21GX/vu XVb6j4kiGEYTeOqSL0eOvsnOr7eo3h6bjiT/RvdxUB6VRUrNBwtQ7aOHSkJkKuqPtF +ODn3GzUIJq5CdUuby55JYo8zcvX9Vys1R1f9uIXCAIwTM3ZAPz6cGgObhT2sFdzD/ MnImD+024SphA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 75D1969095 for ; Sat, 3 Jan 2026 13:06:54 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470813; bh=zBPjLSMQhu5GmAgHU7NZtfDQH/58y4OhZ6hKIvoKu+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GtHxZkC/zOoUseAaQw406/mZ1PPZRNkZDdBlX0deVMhH6wWhS0d8OHnjbe6OE3NG6 01MPuwMrwHS7ARd5EwfP5Op6V1cRwsWBELULP7vAz6uFBvSaBSVtKx4pPXPEp+hItA dw4zprruDlBOHHICtHUbO1ELUuQYYxtMnFL6pqi1aILpYPKd6NRa15yKbKCXaHMt9H J0EGg040zBlp+rIAKbYU7yhyZRo3UOIaalb1YOz8U/qBqdaAc8CvPClW49eCetlVs0 EqN74Pm9WvZMXf6zva5PH5iVnbGCJ9ICkmLeaQcCFZQR55iTaNExYoWgF5qceXg81i YpbmTrU9CN/Ww== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7D3416907B; Sat, 3 Jan 2026 13:06:53 -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 HzNzraAg_xW1; Sat, 3 Jan 2026 13:06:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470809; bh=dSoP+jiTKHim38V/k+Ems0GdrNr2IDtirPU4Me03AFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZqTxmhLOk0tCB5pia+Jl15EL2YQStqdVCMAxRA3WoVkVg1YH+V5BB98Gk14YGjNk8 iYKVwGAXE6WwqkO9byP7WffqIwll5VON5p5Exvjm+r9HJt8sgFVxeTvlZK6/EPqJkg cAnG6UEaH+Tx84aQ7Lclm07RMNxzEusu1mdNAWqhhws50UguloSBctQzlSEM/n8824 +owd5oVeL9HJwT/YmkhIdXZciygEmq4ArbOyXOTvzYQ92+E6Kt4qj6pyVVhcfJfQSd /FcrnS9pDZsS2vCG4u3ixGPS9Q1fkRJOpaKyxUw4FtYtgH/H7q+5xYFrbPratr2JLK 3SIo1oYRnWLpQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A244E68FCC; Sat, 3 Jan 2026 13:06:48 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:52 -0700 Message-ID: <20260103200510.3605009-22-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: V2F7V7GOMLE6KJSTG5EZZRZHMXDDWO2G X-Message-ID-Hash: V2F7V7GOMLE6KJSTG5EZZRZHMXDDWO2G 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 v2 21/29] cmd: malloc: Add a command to show the malloc log 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 a command interface for the malloc-traffic log: - malloc log start: Start recording allocations - malloc log stop: Stop recording - malloc log: Dump the recorded entries Example output: => malloc log Malloc log: 29 entries (max 524288, total 29) Seq Type Ptr Size Caller ---- -------- ---------------- -------- ------ 0 free 16a016e0 0 free_pipe_list:2001 <-parse_stream_outer:3208 <-parse_file_outer:3300 1 alloc 16a01b90 20 hush_file_init:3277 <-parse_file_outer:3295 <-run_pipe_real:1986 Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) cmd/Kconfig | 10 +++++++++ cmd/malloc.c | 41 ++++++++++++++++++++++++++++++++-- doc/develop/malloc.rst | 3 ++- doc/usage/cmd/malloc.rst | 30 ++++++++++++++++++++++++- test/cmd/malloc.c | 48 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 4 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index d602f430ab6..072ff879cd8 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -3049,6 +3049,16 @@ config CMD_MALLOC about memory allocation, such as total memory allocated and currently in use. +config CMD_MALLOC_LOG + bool "malloc log - Log malloc traffic" + depends on CMD_MALLOC && MCHECK_LOG + default y + help + This adds the 'malloc log' subcommand which records all + malloc/free/realloc calls with their addresses, sizes, and caller + information. Use 'malloc log start' to begin recording and + 'malloc log' to display the recorded entries. + config CMD_MOUSE bool "mouse - Show mouse input" default y if MOUSE diff --git a/cmd/malloc.c b/cmd/malloc.c index 9c7dfbfc0c3..361750c45dd 100644 --- a/cmd/malloc.c +++ b/cmd/malloc.c @@ -38,10 +38,47 @@ static int do_malloc_dump(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } +static int __maybe_unused do_malloc_log(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) +{ + if (argc < 2) { + malloc_log_dump(); + return 0; + } + + if (!strcmp(argv[1], "start")) { + malloc_log_start(); + printf("Malloc logging started\n"); + } else if (!strcmp(argv[1], "stop")) { + malloc_log_stop(); + printf("Malloc logging stopped\n"); + } else if (!strcmp(argv[1], "dump")) { + malloc_log_dump(); + } else { + return CMD_RET_USAGE; + } + + return 0; +} + +#if CONFIG_IS_ENABLED(CMD_MALLOC_LOG) +#define MALLOC_LOG_HELP \ + "malloc log [start|stop|dump] - log malloc traffic\n" \ + " start - start recording malloc/free calls\n" \ + " stop - stop recording\n" \ + " dump - print the log (or just 'malloc log')\n" +#define MALLOC_LOG_SUBCMD , U_BOOT_SUBCMD_MKENT(log, 3, 1, do_malloc_log) +#else +#define MALLOC_LOG_HELP +#define MALLOC_LOG_SUBCMD +#endif + U_BOOT_LONGHELP(malloc, "info - display malloc statistics\n" - "malloc dump - dump heap chunks (address, size, status)\n"); + "malloc dump - dump heap chunks (address, size, status)\n" + MALLOC_LOG_HELP); U_BOOT_CMD_WITH_SUBCMDS(malloc, "malloc information", malloc_help_text, U_BOOT_SUBCMD_MKENT(info, 1, 1, do_malloc_info), - U_BOOT_SUBCMD_MKENT(dump, 1, 1, do_malloc_dump)); + U_BOOT_SUBCMD_MKENT(dump, 1, 1, do_malloc_dump) + MALLOC_LOG_SUBCMD); diff --git a/doc/develop/malloc.rst b/doc/develop/malloc.rst index 92180af055a..b9ab884d419 100644 --- a/doc/develop/malloc.rst +++ b/doc/develop/malloc.rst @@ -390,7 +390,8 @@ Malloc-Traffic Log On sandbox, when mcheck is enabled, a malloc-traffic log can record all malloc/free/realloc calls. This is useful for debugging allocation patterns -and finding where allocations without caller info originate. +and finding where allocations without caller info originate. See +:doc:`../usage/cmd/malloc` for usage. The log buffer is allocated from host memory using ``os_malloc()``, so it does not affect U-Boot's heap. The size is controlled by diff --git a/doc/usage/cmd/malloc.rst b/doc/usage/cmd/malloc.rst index 3693034b41e..03f0669658b 100644 --- a/doc/usage/cmd/malloc.rst +++ b/doc/usage/cmd/malloc.rst @@ -13,6 +13,7 @@ Synopsis malloc info malloc dump + malloc log [start|stop] Description ----------- @@ -31,6 +32,13 @@ dump for debugging memory allocation issues. When CONFIG_MCHECK_HEAP_PROTECTION is enabled, the caller string is also shown if available. +log + Controls the malloc traffic log. With no argument, dumps the recorded log + entries. Use ``start`` to begin recording malloc/free/realloc calls, and + ``stop`` to stop recording. Each entry shows the operation type, pointer + address, size, and caller backtrace. This is useful for tracking down + memory leaks or understanding allocation patterns. + The total heap size is set by ``CONFIG_SYS_MALLOC_LEN``. Example @@ -71,11 +79,31 @@ With CONFIG_MCHECK_HEAP_PROTECTION enabled, the caller backtrace is shown:: 18a3b840 90 used of_alias_scan:911 <-board_init_ ... +With CONFIG_CMD_MALLOC_LOG enabled, the log subcommand is available:: + + => malloc log start + Malloc logging started + => ... do some operations ... + => malloc log stop + Malloc logging stopped + => malloc log + Malloc log: 5 entries (max 524288, total 5) + Seq Type Ptr Size Caller + ---- -------- ---------------- -------- ------ + 0 alloc 16a01b90 20 hush_file_init:3277 + <-parse_file_outer:3295 <-run_pipe_real:1986 + 1 alloc 16a01bc0 100 xmalloc:107 <-xzalloc:117 + <-new_pipe:1498 <-run_list_real:1702 + 2 free 16a01bc0 0 free_pipe_list:2001 + <-parse_stream_outer:3208 <-parse_file_outer:3300 + ... + Configuration ------------- The malloc command is enabled by CONFIG_CMD_MALLOC which depends on -CONFIG_MALLOC_DEBUG. +CONFIG_MALLOC_DEBUG. The log subcommand is enabled by CONFIG_CMD_MALLOC_LOG +which additionally requires CONFIG_MCHECK_LOG. Return value ------------ diff --git a/test/cmd/malloc.c b/test/cmd/malloc.c index 3c1a44bcacf..75e8afdec63 100644 --- a/test/cmd/malloc.c +++ b/test/cmd/malloc.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -52,3 +53,50 @@ static int cmd_test_malloc_dump(struct unit_test_state *uts) return 0; } CMD_TEST(cmd_test_malloc_dump, UTF_CONSOLE); + +#if CONFIG_IS_ENABLED(MCHECK_LOG) +/* Test 'malloc log' command */ +static int cmd_test_malloc_log(struct unit_test_state *uts) +{ + struct mlog_info info; + void *ptr, *ptr2; + int seq; + + ut_assertok(run_command("malloc log start", 0)); + ut_assert_nextline("Malloc logging started"); + ut_assert_console_end(); + + /* Get current log position so we know our sequence numbers */ + ut_assertok(malloc_log_info(&info)); + seq = info.total_count; + + /* Do allocations with distinctive sizes we can search for */ + ptr = malloc(12345); + ut_assertnonnull(ptr); + ptr2 = realloc(ptr, 23456); + ut_assertnonnull(ptr2); + free(ptr2); + + ut_assertok(run_command("malloc log stop", 0)); + ut_assert_nextline("Malloc logging stopped"); + ut_assert_console_end(); + + /* Dump the log and find our allocations by sequence number and size */ + ut_assertok(run_command("malloc log", 0)); + ut_assert_nextlinen("Malloc log: "); + ut_assert_nextline("%4s %-8s %10s %8s %s", + "Seq", "Type", "Address", "Size", "Caller"); + ut_assert_nextline("---- -------- ---------- -------- ------"); + /* 12345 = 0x3039, 23456 = 0x5ba0 */ + ut_assert_skip_to_linen("%4d alloc %10lx 3039", seq, + (ulong)map_to_sysmem(ptr)); + ut_assert_skip_to_linen("%4d realloc %10lx 5ba0", seq + 1, + (ulong)map_to_sysmem(ptr2)); + ut_assert_skip_to_linen("%4d free %10lx 0", seq + 2, + (ulong)map_to_sysmem(ptr2)); + console_record_reset_enable(); /* discard remaining output */ + + return 0; +} +CMD_TEST(cmd_test_malloc_log, UTF_CONSOLE); +#endif /* MCHECK_LOG */ From patchwork Sat Jan 3 20:04:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1240 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=1767470819; bh=skxCC+wdwTZEn02U/drCi/yfcrKJzseOk7maRjIevk4=; 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=v6Yb7D/SUTjL4rx6J3f5cp9wLWfJpkU4pa5eeBd3Xh5SVe28gNusNnMeMFovBEI4M uef6dkJ48zM2jUEZo2Bn15nKkXWFnFuczwAkyG0Te6uBxHgFYIcW6dLiBr8WilpToc fhhZO8ZME3q2wsOFrdcBD2d8GrbdRoj+znp0r2B0WziyCj7tw9NVadAyviZF59Z4PO vnSAMP7MtNqKAWxQU9jDvyV3kiD8HGM+SDvN/GQwEHSQ1KRfjRILtyRNQVfsDK8Isy dYXku+i0y7hJfKjaAtDb3WqOjmmExn18m3Uxn/Il9DcQAV1kEb4dDr6eGSiARABDh8 f0wIsgMCDnd+Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 01DD6690A1 for ; Sat, 3 Jan 2026 13:06:59 -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 BcCRgi_nRGY9 for ; Sat, 3 Jan 2026 13:06:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470818; bh=skxCC+wdwTZEn02U/drCi/yfcrKJzseOk7maRjIevk4=; 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=GoCytdKTooUUzHxHTroKu2hBvL4dhdqTEJCV0OxohG0+P+9UX9rWOGywDJwSirr2A dnXPFVJoZaakvw7MU9WsqHve0B+76RmN6EdqEVEugKm7oZKsdiNd/v4C+5mpaHHLwm 2L3xQ48Ico2zclvSoS2E/hG1JOmRC+YJOZ4mhRb3v60PMJ0qULoWaeJ9vxWJJHjxiZ uiPv59qkYFtxh9nz88/eX+U0FyqShQO5icswvHdcr0k+1K51lYATpupYcbYpob7eRY /1U/mUWi/ljpxyDw8Z0tt4MAbP6OjJN6nqOsmpeBXJueLQKN7h6gS9z28madQ1skCR nqujp76zMPLig== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E58EA69097 for ; Sat, 3 Jan 2026 13:06:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470817; bh=ifGlxxXIOUqPWuaD+Dwyl6XMaBN0ZOzw9hkYA9MTr60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ODjEVY81bRM8A67D414c8xL+dQWkO5z5CjFlOL4sEXqH9MbG9yRq7+ZhO7L3BdUxh z/oMGCNZLWnm7gZ17SQWpE1rRhpsZEbgbXwjeTvyzLh9VO5WlacA65aAym/Ew9lQlS vl/fwyLeSDmpkPfqsADBPg76pkNaEmcoeknI6Mrqm221EjvR++p0ffF1oq8HDRGETK 9hvePl5Ho0KTmOBl9h/TSQc4sDpCXA6qX2i5eWkELioSKVGF6OyNyhNxru77Hctz5G ynX8Atvm+Q03A8MAgDGzKG6hWzNwja8FK/OL8ianlXLq3/EI7hkd2jF4rXBGrDGyX5 twzQNdccDtO3Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AA3EC68FCC; Sat, 3 Jan 2026 13:06:57 -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 ARepfVZCLchf; Sat, 3 Jan 2026 13:06:57 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470813; bh=/v0OaphbWu+qsHZGjMqpOtWNJ2FW96aYgV1zhIMYTrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WtxBFH7Wpqf5ELE3b8BNhJX/Q3HdQEBx5scmxzEzzHPXoTIgdN2O0Ka76xcZgENpk K/nWkOCMEuD7zwEdHazTHzWDtwDU3BFGsSWMIv29HGlym/nY9cfi9f0SBszj01mmGv f34w3pkpyiKoXPMHo/Vuocatt/ab/bNsADLioYC3i+t54OeegpuWKp4S0Bh3FsKu/U l9N9deSmL752R5cJF19Z5UeoUXDmI9ZoHftgL5lrNUnc6WuFC9d4hAvlPeC9q6eBLQ n0KavGH1FPkTf7cvCuYMDBBDM7HTsm+j/S1p9qzanWGnxu+4BIOMdceXZ3Q9bzJDeE cLp+xTJYqzaDg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 4E18F68FD2; Sat, 3 Jan 2026 13:06:53 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:53 -0700 Message-ID: <20260103200510.3605009-23-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: FWPH4Y6LUJ33O37KBAAUXOTEDKEQ5WOV X-Message-ID-Hash: FWPH4Y6LUJ33O37KBAAUXOTEDKEQ5WOV 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 v2 22/29] malloc: Add an option to disable mcheck-backtrace collection 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 Backtrace collection is relatively expensive and can significantly slow down malloc()-heavy code when mcheck is enabled. Add a new CONFIG_MCHECK_BACKTRACE option (default y) to allow disabling backtrace collection while keeping the other mcheck features (canaries, double-free detection, etc.) enabled. This allows using mcheck with less overhead when caller information is not needed. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) Kconfig | 10 ++++++++++ common/dlmalloc.c | 8 ++++++++ doc/develop/malloc.rst | 7 +++++++ 3 files changed, 25 insertions(+) diff --git a/Kconfig b/Kconfig index d47077d43bc..a058bd1a2aa 100644 --- a/Kconfig +++ b/Kconfig @@ -355,6 +355,16 @@ config MCHECK_HEAP_PROTECTION significantly increases memory overhead and should only be used for debugging. +config MCHECK_BACKTRACE + bool "Enable backtrace for mcheck caller info" + depends on MCHECK_HEAP_PROTECTION + default y + help + Enable collection of stack backtrace for each allocation. This + records the function/file/line that allocated the memory, useful + for debugging memory leaks. Disable this to reduce the overhead + of mcheck, since backtrace collection is relatively expensive. + config MCHECK_CALLER_LEN int "Length of caller string in mcheck header" depends on MCHECK_HEAP_PROTECTION diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 0e363e78e26..ebcf8439ff7 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -5960,6 +5960,7 @@ STATIC_IF_MCHECK size_t dlmalloc_usable_size_impl(const void *mem) #include #include "mcheck_core.inc.h" +#if CONFIG_IS_ENABLED(MCHECK_BACKTRACE) /* Guard against recursive backtrace calls during malloc */ static bool in_backtrace __section(".data"); @@ -5968,6 +5969,7 @@ static bool in_backtrace __section(".data"); * Set via malloc_backtrace_skip() before calling panic(). */ static bool mcheck_skip_backtrace __section(".data"); +#endif /* Runtime flag to disable mcheck - allows bypassing heap protection */ static bool mcheck_disabled __section(".data"); @@ -5979,11 +5981,14 @@ void mcheck_set_disabled(bool disabled) void malloc_backtrace_skip(bool skip) { +#if CONFIG_IS_ENABLED(MCHECK_BACKTRACE) mcheck_skip_backtrace = skip; +#endif } static const char *mcheck_caller(void) { +#if CONFIG_IS_ENABLED(MCHECK_BACKTRACE) const char *caller = NULL; if (!in_backtrace && !mcheck_skip_backtrace) { @@ -5992,6 +5997,9 @@ static const char *mcheck_caller(void) in_backtrace = false; } return caller; +#else + return NULL; +#endif } #if CONFIG_IS_ENABLED(MCHECK_LOG) diff --git a/doc/develop/malloc.rst b/doc/develop/malloc.rst index b9ab884d419..776294809b8 100644 --- a/doc/develop/malloc.rst +++ b/doc/develop/malloc.rst @@ -130,6 +130,13 @@ Main U-Boot (post-relocation) ``malloc dump``. This significantly increases memory overhead and should only be used for debugging. Default: n +``CONFIG_MCHECK_BACKTRACE`` + Bool to enable backtrace collection for mcheck caller information. When + enabled (the default), each allocation records a stack backtrace showing + where it was made. This is useful for debugging memory leaks but adds + overhead to every malloc call. Disable this to reduce mcheck overhead + while keeping the canary checks and double-free detection. Default: y + xPL Boot Phases ~~~~~~~~~~~~~~~ From patchwork Sat Jan 3 20:04:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1241 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=1767470821; bh=ilZcAqdY6VU0hIk/gArqlIlpaIuNdgS/tp/SvbTc42g=; 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=iVystiZ2Q/BQFuBdbp35VSaAgedfN3z547AMYKLKC/ZZMEMUbyni2j082AF48Q2AS 16xMpI8/J1C7SytjvV639b+Rr+i58GG1aFuYB0Zj2eAYCaxyBKLsbTuWdbdzSLDcow H4ijkHSySe86DW3Y0k/XyhNa5I51njWO5S39p8eqMCWxQ+MLFCmkn+ETwGqOzZdJYs /w4I4XHjhLzfmOd1SQDftSMNXCz77r4lOva+GrHwC5B0QBKC47jsK5twl+H+cyYins yh2Or1EFtUokvHjCkSjvEd2RbLGE8EKvM9hqQACJXeHiA/R+ZshObqTfZ9LQ0+CeBJ LEEqrNl+0iOCQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7D20268FCC for ; Sat, 3 Jan 2026 13:07:01 -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 6nTncqbZVKhW for ; Sat, 3 Jan 2026 13:07:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470819; bh=ilZcAqdY6VU0hIk/gArqlIlpaIuNdgS/tp/SvbTc42g=; 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=jWzkfYfb332IIuaVqBHgDqsblEjf820Ax/eKYoYzdBim/Xs4Ph60qp4HML9Nf/xij nwDCkOWQ76Zd36LTBtYqRSZ2n4YbLtBfC7lR3IE2E+uAw4fWAguW+sPRsfOw0ZhQMW jygdVN5omdWJSgr5pzIsh5vluT8G96x34PYnZtiHZec37tngSjuVst6MPx8xmob9u9 HGpIgcI5TOnssR6WN4aCKII4qP5rmlXGbYPBxOWiTHTQvvUS60jqYsQH7Hy+AGVqqK FDoxrAc4Uf9vOHFi+Fgp+KCjmwW/4gZWcgYWFmPqhPInr3QXP9FYOPYKXW/ZqypcD3 zQLbNM9nsH5HQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DBC48690A1 for ; Sat, 3 Jan 2026 13:06:59 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470818; bh=eDu7ibpR58PfLWI7MJNSCPh0Plfb50DKXIS8nRS9kDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KdN5usowN1Jyvn8HfhIXV5wJm+BRgSQFw2KZ/qb7DpOSIJNTJESpA3oXG5xsL/d+t 2Gm1oYQWre6yq/YpnCEovOIaUKpyOpPSMxd4qWi+EzdD9ccdh6iHDOtG8rTGYlLdtc rNQLg+bKqEntt+XjJ8AmwVgCRKMR1kpgpQDgi8GwvCDwVmqvJFTaCij1GwyycQwd2t pG1Lz3cT940+bjE/QADlqDoq6WzUpMKLKJylaIelR+O5bDl5ejazuNak+ZS1H3dj05 RXgt01nvP9ng3eFuGqH5h4gg4DbHzhxkcSg7ThV9rrY1u95FV69wTw8Xxl3DtP4yYG c5iJQoJQV4izQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9D8086907B; Sat, 3 Jan 2026 13:06:58 -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 fsUD9-vD17fv; Sat, 3 Jan 2026 13:06:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470818; bh=k7gJh3hnWoJIkSFY/N+FdsTff5wfqRYgUvrAvLqw1NA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OLj/M8ORCLppeFpUHCCKG0XbTXosWtzR72C+vq9HVwyUVzcaRxwcfZ2ciq5iQb3Wd yteWxIfP++XpNLrNaVAneEO+qdZHA0DaEiBVORet2pEZHc5dwC9SDPrd6uVTCwq4jw wsIgoJ9a7/uOoRgm8kaXJPN0PnGICheBBt7/lamiQkOTOPe5dvfDKU6W77P6NVh1Lw 05CWwidVPG1HSW5ZtNhSmBduFDDq68sTnKyiJB7YW8ajNLM0BvLpBXNuM96WwlusLY SO8qTJn0b5DagakyWYPkKrbbHIY2P8sbv1h5Ss5Ooezsx5CpmH9S68n2OqQNHTZAgn 7Imq6R6bHEdFA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id EE74B68FD2; Sat, 3 Jan 2026 13:06:57 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:54 -0700 Message-ID: <20260103200510.3605009-24-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: NA3WN3OVXDYDAT7KG7KAWEQORUE6KQE7 X-Message-ID-Hash: NA3WN3OVXDYDAT7KG7KAWEQORUE6KQE7 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 v2 23/29] malloc: Add file output for heap dump and malloc log 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 malloc_dump_to_file() and malloc_log_to_file() functions to write heap dumps and malloc traffic logs to host files. This is useful for debugging memory leaks in sandbox by allowing comparison of before/after heap states with external tools like diff. These functions are only available in sandbox builds since they use host-filesystem access. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) common/dlmalloc.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ include/malloc.h | 22 +++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index ebcf8439ff7..2bc5f63c0a8 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -6144,6 +6144,38 @@ void malloc_log_dump(void) malloc_log_impl(log_to_console, NULL); } +#if IS_ENABLED(CONFIG_SANDBOX) +/* File output function for log */ +static void log_to_file(void *ctx, const char *fmt, ...) +{ + int fd = *(int *)ctx; + char buf[256]; + va_list args; + int len; + + va_start(args, fmt); + len = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + if (len > 0) + os_write(fd, buf, len); +} + +int malloc_log_to_file(const char *fname) +{ + int fd; + + fd = os_open(fname, OS_O_WRONLY | OS_O_CREAT | OS_O_TRUNC); + if (fd < 0) + return fd; + + malloc_log_impl(log_to_file, &fd); + os_close(fd); + + return 0; +} +#endif + int malloc_log_info(struct mlog_info *info) { if (!mlog.buf) @@ -7481,6 +7513,26 @@ static void dump_to_console(void *ctx, const char *fmt, ...) va_end(args); } +#if IS_ENABLED(CONFIG_SANDBOX) +#include + +/* File output function for heap dump */ +static void dump_to_file(void *ctx, const char *fmt, ...) +{ + int fd = *(int *)ctx; + char buf[256]; + va_list args; + int len; + + va_start(args, fmt); + len = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + if (len > 0) + os_write(fd, buf, len); +} +#endif + static void malloc_dump_impl(dump_out_fn out, void *ctx) { mchunkptr q; @@ -7568,6 +7620,22 @@ void malloc_dump(void) malloc_dump_impl(dump_to_console, NULL); } +#if IS_ENABLED(CONFIG_SANDBOX) +int malloc_dump_to_file(const char *fname) +{ + int fd; + + fd = os_open(fname, OS_O_WRONLY | OS_O_CREAT | OS_O_TRUNC); + if (fd < 0) + return fd; + + malloc_dump_impl(dump_to_file, &fd); + os_close(fd); + + return 0; +} +#endif + int initf_malloc(void) { #if CONFIG_IS_ENABLED(SYS_MALLOC_F) diff --git a/include/malloc.h b/include/malloc.h index 4bd6458b70d..3deb90b2a0b 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -712,6 +712,17 @@ void malloc_disable_testing(void); */ void malloc_dump(void); +/** + * malloc_dump_to_file() - Write heap dump to a host file + * + * @fname: Path to the output file on the host filesystem + * Return: 0 on success, negative error code on failure + * + * This is only available in sandbox builds. It writes the same information + * as malloc_dump() but to a file instead of the console. + */ +int malloc_dump_to_file(const char *fname); + /** * malloc_log_start() - Start logging malloc traffic * @@ -733,6 +744,17 @@ void malloc_log_stop(void); */ void malloc_log_dump(void); +/** + * malloc_log_to_file() - Write malloc()-traffic log to a host file + * + * @fname: Path to the output file on the host filesystem + * Return: 0 on success, negative error code on failure + * + * This is only available in sandbox builds. It writes the same information + * as malloc_log_dump() but to a file instead of the console. + */ +int malloc_log_to_file(const char *fname); + /** * enum mlog_type - Type of malloc log entry */ From patchwork Sat Jan 3 20:04:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1242 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=1767470823; bh=WhKTa2DMIzQ6Evrnw9BkfZKdN2duEO6102DyzV/79DQ=; 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=t3muE+N0ciCivj/AQHVYJ+mpkgVcAjPsk7Q9zDH+YjJGtOH9jj6JhULRvzXOiP7qe IyahhF1gVWOAQhw1Jeb5JIuuoLClcpDwbEYzwHUHzMARo0olB+3ZzJDSwSo1qgCuIY oldjat/KBXHESuyIdXIQ0BoN66Swvpu0II9TOflbTg2C6RTxGmgsAyGDAkFydCZ6KU HOj6CDClgBjjaM/o4CMabpQAyE6i50dbPxc0s/fcGgY/W9BsyJBwRN865UPIknWFGJ xnqgtMBPB7gpf+/LFTlmP9WgEKkV8tlEtuKajcpKnDlEEnno8bT4MqLPhouXmrV07l bzETzbU8WXzhQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EA4FB68FD2 for ; Sat, 3 Jan 2026 13:07:03 -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 M-0Wl4PJy8RE for ; Sat, 3 Jan 2026 13:07:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470823; bh=WhKTa2DMIzQ6Evrnw9BkfZKdN2duEO6102DyzV/79DQ=; 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=t3muE+N0ciCivj/AQHVYJ+mpkgVcAjPsk7Q9zDH+YjJGtOH9jj6JhULRvzXOiP7qe IyahhF1gVWOAQhw1Jeb5JIuuoLClcpDwbEYzwHUHzMARo0olB+3ZzJDSwSo1qgCuIY oldjat/KBXHESuyIdXIQ0BoN66Swvpu0II9TOflbTg2C6RTxGmgsAyGDAkFydCZ6KU HOj6CDClgBjjaM/o4CMabpQAyE6i50dbPxc0s/fcGgY/W9BsyJBwRN865UPIknWFGJ xnqgtMBPB7gpf+/LFTlmP9WgEKkV8tlEtuKajcpKnDlEEnno8bT4MqLPhouXmrV07l bzETzbU8WXzhQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8B4246907B for ; Sat, 3 Jan 2026 13:07:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470821; bh=7RhMejDA6PuSN5gAg6qlg4dEoNOthZUZRkyr5w34suY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N8NYgvJeZa5LHmu3oNe2fbMB9njz+nmmSlZQXwRyDWzs8Lm4smjhU1CWHJfsiByDD eol6QhRHwz2Dc25HOF0RBtkPJJo4xgeaADsJtVPlSBDewiunr+HKWNWxtB8f3mUPoE UrTD8dNmWXUvVYMb7YzHPi6+UzgRRkOuKLNXDX2JCFeryp0Tn8aMWqztLjpApaVfha Vn4gUm+e8Uk4Ao+KVikhSzgtoQ1gv+TBSnEdKNMjAqWjPaVnaYnICb6gN7pcq9CNGr e6dv+snlN4pTFg/KiVqw+8MiZWmdNSfbNidjltnYBlvnXI/dlxOEK6C/cpYMvf2UIi /oWSuljUirJag== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5FEB269097; Sat, 3 Jan 2026 13:07:01 -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 K3pCG3w_PckA; Sat, 3 Jan 2026 13:07:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470819; bh=nrdhZnIZ0Rqb5gOw1Y6vkZccxF4IFCkBP42YyVsqcHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NdZi4LoXb5OsVreBbzjo8qIbrPPe+yk69pLIzzx/Yvx+/g3qjcAJvuLAwPQjcTNF/ bI6kgcNe8WEac02BWoj2SM9lJq3gjhsh4v+MBNkg+2rB9RKjRXYIMjQdfNWjnsMCLk VZfgJfVEjwzwUps8U+ExtJGM0iyt01cthFiaaCiOk3pPFfi4FLnsbBUi/Ckhb1jCn3 GWY/ZrpsacRDLJ/+sWvPca1yaNUvZaJB8lrQn2tQv0vuSgcTGpEGDPNlZfklHww0g6 byJLI3AlV//W6r+UzxBMLyn5YDqe/V/WWELIKMFCioOleCIdIgqacf7zgZJZ+2gp6P zZr1+F/m66jog== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id DDF8869085; Sat, 3 Jan 2026 13:06:58 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:55 -0700 Message-ID: <20260103200510.3605009-25-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WAL42DV4CCZ2GNXFX2LV23A375L6HIZE X-Message-ID-Hash: WAL42DV4CCZ2GNXFX2LV23A375L6HIZE 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 v2 24/29] doc: malloc: Add a section on finding memory leaks 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 Document the practical workflow for detecting and diagnosing memory leaks in U-Boot, particularly in sandbox builds. This covers: - Using ut_check_delta() in unit tests for leak detection - Comparing heap dumps with malloc_dump_to_file() - Using malloc traffic logging to trace allocations - Verifying debug functions don't affect heap state - A step-by-step practical workflow Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) doc/develop/malloc.rst | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/doc/develop/malloc.rst b/doc/develop/malloc.rst index 776294809b8..b5c84c4c3bd 100644 --- a/doc/develop/malloc.rst +++ b/doc/develop/malloc.rst @@ -418,6 +418,99 @@ malloc testing Unit tests can use malloc_enable_testing() to simulate allocation failures. +Finding Memory Leaks +~~~~~~~~~~~~~~~~~~~~ + +U-Boot provides several tools for detecting and diagnosing memory leaks. +These techniques are primarily supported on sandbox, which has the full +debugging infrastructure enabled by default (``CONFIG_MALLOC_DEBUG``, +``CONFIG_MCHECK_HEAP_PROTECTION``) and access to host filesystem functions +for writing dump files. + +**Leak detection in unit tests** + +Unit tests can use ``ut_check_delta()`` to detect memory leaks:: + + ulong mem_start; + + mem_start = ut_check_delta(0); /* Record starting heap usage */ + + /* ... test code that allocates and frees memory ... */ + + ut_asserteq(0, ut_check_delta(mem_start)); /* Verify no leak */ + +This uses ``mallinfo().uordblks`` to compare heap usage before and after. + +**Heap dump comparison** + +When a leak is detected, use ``malloc_dump()`` to capture heap state before +and after the operation. In sandbox builds, ``malloc_dump_to_file()`` writes +the dump to a host file for easier comparison:: + + malloc_dump_to_file("/tmp/before.txt"); + + /* ... operation that may leak ... */ + + malloc_dump_to_file("/tmp/after.txt"); + +Then compare the dumps to find leaked allocations:: + + $ diff /tmp/before.txt /tmp/after.txt + +Or extract just the addresses and sizes for comparison:: + + $ awk '{print $1, $2}' /tmp/before.txt | sort > /tmp/b.txt + $ awk '{print $1, $2}' /tmp/after.txt | sort > /tmp/a.txt + $ comm -13 /tmp/b.txt /tmp/a.txt # Show allocations only in 'after' + +The dump includes caller information when ``CONFIG_MCHECK_HEAP_PROTECTION`` +is enabled, showing exactly where each leaked allocation originated. + +**Malloc-traffic logging** + +For more detailed analysis, use the malloc-traffic log to record all +allocations during an operation:: + + malloc_log_start(); + + /* ... operation to trace ... */ + + malloc_log_stop(); + malloc_log_to_file("/tmp/malloc_log.txt"); /* Sandbox only */ + +The log shows every malloc(), free(), and realloc() call with addresses, sizes, +and caller backtraces (if enabled). Search for allocations that were never +freed:: + + $ grep "alloc" /tmp/malloc_log.txt # Find all allocations + $ grep "16ad1290" /tmp/malloc_log.txt # Check if a specific address was freed + +**Verifying debug functions don't allocate** + +When using these debugging functions, verify they don't affect heap state +by checking ``malloc_get_info()`` before and after:: + + struct malloc_info before, after; + + malloc_get_info(&before); + malloc_dump_to_file("/tmp/dump.txt"); + malloc_get_info(&after); + + /* Verify no allocations occurred */ + assert(before.malloc_count == after.malloc_count); + assert(before.in_use_bytes == after.in_use_bytes); + +**Practical workflow** + +1. Add ``ut_check_delta()`` assertions to your test to detect leaks +2. When a leak is detected, add ``malloc_dump_to_file()`` calls before and + after the leaking operation +3. Run the test and compare the dump files to identify leaked allocations +4. Use the caller backtrace in the dump to find the allocation site +5. If more detail is needed, enable ``malloc_log_start()`` to trace all + allocations during the operation +6. Fix the leak and verify the test passes + API Reference ------------- From patchwork Sat Jan 3 20:04: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: 1243 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=1767470828; bh=2l875QD1OwZ+GXKgi7ChsHYs272oebr77iEIEf8ukoQ=; 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=UjrgR9SvvygdPKnW4xqQVY3hw7fA8UF18j8SZmuesliwa6dfirKEKi5mfmdNZAmH8 L9gS/fb4z8NkSXsiE6zGQNIf1NA9/Jfn1h3DWRYoMzydI/MUeYoA5+Cgz0+5AQ6n0S apevsMoDDxEZdAZFShfK5YQidkNuWP5bFetcFdfZgIcDeQmD1DLaU35m7OHNU/EdxJ sTp7/R0Op3rR0H0T4dsguGReYPg5d9yBHGcVYc6OIVD6zHyE1ZSuGTwMyn6Er+XDxw APR2e87k2TqVVVl6BeGl08e07fN3qc0jEGoBB25sguwLbyJ/NgaUHH2kiFQwaGTUP1 tzGHjWbsfhgtg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 18C8268FCC for ; Sat, 3 Jan 2026 13:07:08 -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 06dG1QQuPHxj for ; Sat, 3 Jan 2026 13:07:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470828; bh=2l875QD1OwZ+GXKgi7ChsHYs272oebr77iEIEf8ukoQ=; 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=UjrgR9SvvygdPKnW4xqQVY3hw7fA8UF18j8SZmuesliwa6dfirKEKi5mfmdNZAmH8 L9gS/fb4z8NkSXsiE6zGQNIf1NA9/Jfn1h3DWRYoMzydI/MUeYoA5+Cgz0+5AQ6n0S apevsMoDDxEZdAZFShfK5YQidkNuWP5bFetcFdfZgIcDeQmD1DLaU35m7OHNU/EdxJ sTp7/R0Op3rR0H0T4dsguGReYPg5d9yBHGcVYc6OIVD6zHyE1ZSuGTwMyn6Er+XDxw APR2e87k2TqVVVl6BeGl08e07fN3qc0jEGoBB25sguwLbyJ/NgaUHH2kiFQwaGTUP1 tzGHjWbsfhgtg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0693A68FD2 for ; Sat, 3 Jan 2026 13:07:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470826; bh=Qi70dORVIzw+LboyIa0qsj31G5+/VhOOkv8L9ptjzkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RNPS14ilNdhIqQDoBe9a9wuzNLiSPtdxOrp66ufnlR8uT83IZRaYFqyF7TIZ1seIr 7NdejPIx8XhlhhZqYqziS3RZXBx75+XsltDo/77fhmvpclWMfNE7ukWw22pvxuLrww lszSpvcwgwBEOl09uD0fVP58RHU1Cud1PpR6Xyczt/TihnEPxg3/i5vXmXxaFQAeBO n6brkz3B4lmoMul9/bQ/aq9Tv8cr1R4wBfSgt6hF90EHWNdMyIZ5Y36zRdnWRlqi8M +E3a3TVk5lzw+1du0fCU0xy5KnztM5RZVZXi38oTNhDDXLts+HCGvO2/kf6gNcBP+w GltZZ2mn0cOQQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3BB2C68FCC; Sat, 3 Jan 2026 13:07:06 -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 UG-FQoZOYreH; Sat, 3 Jan 2026 13:07:06 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470820; bh=9M0AKA6qf5o2Y7TcKidGHxzqFsEBMzMHF+khLAmjtUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oedY+Gg/bn15aCezVe8ezOYWTmdK2YlluihDh6LHWjc2YYJ63Q7Ez1m+e6X7yZ6XH EDbGYx4E2/KFOb9kZem1gLThhOCZjFsaNQlSH+N+ilghDf7cxas2ywE9QaDzhxWTUa I07ZKrgRvxKBWmwoc6eJ3nKaS5uOW0pymLa8m2BkCMRtieFbvDjYEEvVM/8f0CT85Q AUp7h1z7Yk9bur7xujn78Yt0vZMMUMqy9DIw8OyqZssmrpy1pbtbS7sfMuN1guvfxS L2xO7dpI3y9fR2Tbdt4AzcpJeYxTGz0am0KlKOII1V/SEluEcMC1uONqgHi6nq+jne Khqb9EuUOuOnA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E78E6690A2; Sat, 3 Jan 2026 13:06:59 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:56 -0700 Message-ID: <20260103200510.3605009-26-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OLEYK4CDYM5KBK25YYOH6IBBS27NHKGN X-Message-ID-Hash: OLEYK4CDYM5KBK25YYOH6IBBS27NHKGN 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 25/29] test/py: Handle a failure during configuration 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 If the build does not exist we can get an error when starting up: INTERNALERROR> Exception: .config does not exist; try passing --build option? Exception ignored in atexit callback: Traceback (most recent call last): File "test/py/conftest.py", line 697, in cleanup show_timings() File "test/py/conftest.py", line 644, in show_timings if ubconfig and ubconfig.timing: ^^^^^^^^^^^^^^^ Fix this by setting up the timing member at the start. Signed-off-by: Simon Glass --- (no changes since v1) test/py/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/py/conftest.py b/test/py/conftest.py index b79080af961..0060f3da986 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -301,6 +301,7 @@ def pytest_configure(config): ubconfig = ArbitraryAttributeContainer() ubconfig.brd = dict() ubconfig.env = dict() + ubconfig.timing = None not_found = [] with log.section('Loading lab modules', 'load_modules'): From patchwork Sat Jan 3 20:04:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1244 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=1767470831; bh=yysf9I36JlwMV6vigd/BBd9aBZ5RfLymmfeMshvVCsc=; 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=hlXGNkoMZzVU1qpg4h6dy37NDr96aP3pQcAWWRFmdtj9AMhjIv3HgRqaUOS/nNFbA +YiZc9F3XOudPTG8wL3kqtPUecfi7pG6p7FdHw4hFNhpuZDqCRrmCmCGx1zgKAnaBN sY4gCN65LDHxWdrqnaZNZhGpujLWP3ufDNK94JXbMnLINfXGP6tXV0AAQkrTh3aPs9 sMkJq1pY37TmKX+uQ7OucVUD1euup0QSFhNwLuN+E0/a84FP1xr68QMl6XcXPqX0XG Fij9fU5k4kfEiGOoE5utbsJ7uFoFdEdzFs8MEs/eNR9dXgA23dmbOBsXWssapi4ZIL rdSHNy0OUYnEQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2838269095 for ; Sat, 3 Jan 2026 13:07: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 10024) with ESMTP id f8aGZfN6dugT for ; Sat, 3 Jan 2026 13:07:11 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470831; bh=yysf9I36JlwMV6vigd/BBd9aBZ5RfLymmfeMshvVCsc=; 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=hlXGNkoMZzVU1qpg4h6dy37NDr96aP3pQcAWWRFmdtj9AMhjIv3HgRqaUOS/nNFbA +YiZc9F3XOudPTG8wL3kqtPUecfi7pG6p7FdHw4hFNhpuZDqCRrmCmCGx1zgKAnaBN sY4gCN65LDHxWdrqnaZNZhGpujLWP3ufDNK94JXbMnLINfXGP6tXV0AAQkrTh3aPs9 sMkJq1pY37TmKX+uQ7OucVUD1euup0QSFhNwLuN+E0/a84FP1xr68QMl6XcXPqX0XG Fij9fU5k4kfEiGOoE5utbsJ7uFoFdEdzFs8MEs/eNR9dXgA23dmbOBsXWssapi4ZIL rdSHNy0OUYnEQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1763E68FD2 for ; Sat, 3 Jan 2026 13:07:11 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470828; bh=W6HPVerUpqgQPLe5iG/UrJR3Rd1IJTQJ4+CcCNwhBSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WGKwidcwe8tt0wQhTTCyo4AxXemiJuVpJS07aOWsnjiy5pqIB+lgfL2S/738Hbefj K1jQdqJOgzMcpjG5SWfGjMLCvDiZVeXxd0fIJG/LKs3Ra9zq6zVP4Qi8oYqT8cPorN YDUOh6ATAonoY7lJAwpHfPj6us+BAdzq/uGahjKkYC3HhJrxJvNhj5Quv/eBcH/l2C 2j9H1jzVGkZKwf8zNPF9RER2vRHMhX4ANIOvEOdQXKOPZ7wLipayMKcUOzqPOHbFhB 2qiT69yrxsRyzEluEXpG4r7yUL5hqLcs5GJTxRT77u+0kyVAJWzD1FhrSEZr4uNjZo sQVcFSHUBvF5A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AE39768FD2; Sat, 3 Jan 2026 13:07:08 -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 dvovJGjpWoRL; Sat, 3 Jan 2026 13:07:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470824; bh=HD64RQJBO4lXmuRfZPJ9p3h6M2hLAuzSMFrpCFxDoWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NnFRQR0pFvHs1/6Ptxjrv1UAaO4XO1Sgz+JINit5DkRCYP8negMXVhskIbZMQL6Ke FBcwj86Ctib8MgwGdjRuSnZ4TqFIj5lfWB5ayErJM9pc1QT7OorzPZWpWUJRybFQhN da4VOp1PHiZRCnhmKK8O0mlyXyFkfL0bIPWZ+BhBdpLR7NAkpnmyC+5o2OG/PA8AOq T2ZAB0MBMHo2HKCol4gjX+/989sCI5WHYGNJFi1hWJ4PUcw36IsLUvcu/0yBS1eAQg DFIBBJxYMlF9STZ4O4hvuEYd4q58h9mFBekuIm9Who4yz2KQs4MgWdAERnk35vHioG oA4XB2BSeGdmQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 621E469085; Sat, 3 Jan 2026 13:07:04 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:57 -0700 Message-ID: <20260103200510.3605009-27-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OII56MIZEPL4TNYOSEVRT2O7ZRYU2KPH X-Message-ID-Hash: OII56MIZEPL4TNYOSEVRT2O7ZRYU2KPH 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 v2 26/29] test/py: Reduce CPU usage when waiting for 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 In some cases the target sends a lot of data. This is typically limited to 4K on Linux (PTY size), but when (say) 100K of console output is sent, pytest uses all available CPU, often only reading 50 bytes at a time. Add a 1ms delay before polling, to help with this. Increase the read-buffer size from 1KB to 4KB to reduce the number of system calls. To test this change, dm_test_host() was modified to do 10 malloc_dump() calls, thus producing a lot of output. The impact of this patch is: total time 17s -> 6s total CPU 40s -> 18s Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) test/py/console_base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/py/console_base.py b/test/py/console_base.py index 86b6da1f5b0..6d117413aa3 100644 --- a/test/py/console_base.py +++ b/test/py/console_base.py @@ -32,6 +32,10 @@ pattern_lab_mode = re.compile('{lab mode.*}') TIMEOUT_MS = 30000 # Standard timeout TIMEOUT_CMD_MS = 10000 # Command-echo timeout +# Maximum bytes to read at once from the console. 4KB matches the typical +# Linux PTY buffer size (N_TTY_BUF_SIZE), so there's no benefit to larger. +RECV_BUF_SIZE = 4096 + # Timeout for board preparation in lab mode. This needs to be enough to build # U-Boot, write it to the board and then boot the board. Since this process is # under the control of another program (e.g. Labgrid), it will failure sooner @@ -803,7 +807,10 @@ class ConsoleBase(): events = self.p.poll.poll(poll_maxwait) if not events: raise Timeout() - c = self.p.receive(1024) + # Small delay to let more data accumulate in PTY buffer, to + # reduce CPU usage for test.py from 100% + time.sleep(0.001) + c = self.p.receive(RECV_BUF_SIZE) if self.logfile_read: self.logfile_read.write(c) self.buf += c From patchwork Sat Jan 3 20:04:58 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1245 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=1767470835; bh=3pWhcG9T5kW1s64DKpTiaAkADuRCdxzxNf10hr7Mg5Q=; 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=DBQfI6dKr0GVfRp6Wq8Brx9Q3wDyMYKhaiWFDxW9shyDwMomku+KCWx2CPtsyDY/W 1j9FXd7OjEBY1IUBEnIJPF7U4oFsyPiKsgHJIkRnwbCPw89C2PE2RezFP9jj9buV4W Sh/1RfCTinTk7V0sVJAN4XNJMFcx659nkU1PK+95SE7v6FijwaKw1RTsEEYuMFPFEx 2+dCtKBPkEhwqiYm0TuYGaPJFfx8HWiIhmeMlzDaaiU+nOw7f84J890g0B7494RSqJ uFQpG8XvLP2HGLyCBje/MbyBwHNSJwV2oHq+dlgAwbSs2Epy/+DrH8DhWxkrrUUQ4Y RCC0EDg/Ds8zQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9ACBE69095 for ; Sat, 3 Jan 2026 13:07:15 -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 nv1T-bTTNf5I for ; Sat, 3 Jan 2026 13:07:15 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470835; bh=3pWhcG9T5kW1s64DKpTiaAkADuRCdxzxNf10hr7Mg5Q=; 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=DBQfI6dKr0GVfRp6Wq8Brx9Q3wDyMYKhaiWFDxW9shyDwMomku+KCWx2CPtsyDY/W 1j9FXd7OjEBY1IUBEnIJPF7U4oFsyPiKsgHJIkRnwbCPw89C2PE2RezFP9jj9buV4W Sh/1RfCTinTk7V0sVJAN4XNJMFcx659nkU1PK+95SE7v6FijwaKw1RTsEEYuMFPFEx 2+dCtKBPkEhwqiYm0TuYGaPJFfx8HWiIhmeMlzDaaiU+nOw7f84J890g0B7494RSqJ uFQpG8XvLP2HGLyCBje/MbyBwHNSJwV2oHq+dlgAwbSs2Epy/+DrH8DhWxkrrUUQ4Y RCC0EDg/Ds8zQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8A6B66907B for ; Sat, 3 Jan 2026 13:07:15 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470833; bh=H0xfTGA0eBn4Rs4ZOzyQjsqzQjlDAK6EZMg0em/gI68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q48q1A9T8p2l/A5/V+ScqzYklPC0Vq5NOLMIqauivBLrmt9IvOlHUkVi9oVPQjlt/ iv+AsbCq1mC56QUchaKhUlfVuuIAB0AHbX+kcnULOse9DpimnwbG7B8gF56hUQGPyu LPuS6qGdDARvSarmU1cfRTDnNeQB0An8wewaGSycAxQGCBhmdezzP2oPkIbzxtKw7A 9UM1hxzPlCU4f72DQWqgjup1eLY9FD73A8+STyrnLD42vo+OnfNlqXumOKql2XWPfN tL4G9TwWEKOx8LyeuGfnzxPFeYuf2GO1TaeS9r2ObGoxEx5yOntyxTBdrV1UeYlS0K n2I1JahX5QUjg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 906FB68FCC; Sat, 3 Jan 2026 13:07:13 -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 CaNBehkUc-vL; Sat, 3 Jan 2026 13:07:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470829; bh=miwgdPmilFRPYIs/3AaT72uzfJk/vF2C7zVq0jbYYak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kQLJXObaQVQkpBKC7612Xh30BOBWAnfuaVUVbg647Kq2CqJ3r8gcw8MdrwT+KfTnS h69oInQ0DB8ynIwl6maWAs1QtQguj6nfYTUuZOPDBzjoTGSfWbIMd39WqWjk9NXHrk cerrleB1tNVWNJtBL/G92KvdXaI0u2gIxzuKNo38OMv9oSLpzMcAXe3Xo1BzwpJWNC EXLa0J3OyNxQXi//joe0k7csv0oph6+Ue7/qdp4x0m/ggsIfCs8YvVBelQbpFgYSF8 65NlBNMmyRLraI4pblLblOiE05Vq4zrWBmqwEsCDYffRp967ir3hCqQvyeFTgi520I YZtJ6SraccijQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id EE77269085; Sat, 3 Jan 2026 13:07:08 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:58 -0700 Message-ID: <20260103200510.3605009-28-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: BHRIGXON36PQBS5YAQHQGKKSWYXPY3SN X-Message-ID-Hash: BHRIGXON36PQBS5YAQHQGKKSWYXPY3SN 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 27/29] test/py: Speed up VT100-filtering in expect() 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 The VT100 escape sequence filter is applied to the entire buffer on every read iteration, causing O(n^2) performance. With 1.6MB of output from verbose unit tests and 1KB reads, this results in ~1600 iterations, each processing an ever-growing buffer. Fix this by filtering only the newly received data before appending it to the buffer. To test this, dm_test_host() was modified to do 10 malloc_dump() calls, thus producing a lot of output. The impact of this patch is: total time 6s -> 4.5s total CPU 18s -> 13s Note: Various other approaches were tried, including removing the concatenation to self.buf and updating expect() to only consider recent text. None of these yielded useful results. Signed-off-by: Simon Glass --- (no changes since v1) test/py/console_base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/py/console_base.py b/test/py/console_base.py index 6d117413aa3..c4472420c31 100644 --- a/test/py/console_base.py +++ b/test/py/console_base.py @@ -813,11 +813,13 @@ class ConsoleBase(): c = self.p.receive(RECV_BUF_SIZE) if self.logfile_read: self.logfile_read.write(c) - self.buf += c + # Filter VT100 escapes from new data only, not entire buffer. + # This avoids O(n^2) behaviour when receiving large output. # count=0 is supposed to be the default, which indicates # unlimited substitutions, but in practice the version of # Python in Ubuntu 14.04 appears to default to count=2! - self.buf = self.re_vt100.sub('', self.buf, count=1000000) + c = self.re_vt100.sub('', c, count=1000000) + self.buf += c finally: if self.logfile_read: self.logfile_read.flush() From patchwork Sat Jan 3 20:04:59 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1246 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=1767470840; bh=bqTVIlZaOAbRkcEAh9JX+SWxzv4jtG0Mpc4mN6bLMxM=; 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=n8eS43rTwu0O1+FcCyMDshzcuJ0+FnCx7MK+P41Qif3xMTxJ0KxdjaC6YJ3tPdcdC B8Yvi/+eXj4sXnaPxAaNYKeAPZtmVYxgddqzBEED4IHY0jQGaEX+fldXR+1nuqZ7Gy Tw+w5SjfsQjjUlEv/KGyajs183UYINXeRTV7NVcxDHNTelg/GtJqjE28eUUomrtKtC v6/2ClmKqRXb/FyM7ptJY1U5novwVAdcF5/eXiG86fh+EiX8nTndsyDiJryTtFkVSB mjcITVWSTXjRKkDMvAw6f6t5t77DBgTdn5p915hgcyUl2qj507T0qFlLlD3YFdkUyt wara0xGDP4b4w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 10DCC69095 for ; Sat, 3 Jan 2026 13:07:20 -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 rhLMjrM3_VyK for ; Sat, 3 Jan 2026 13:07:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470840; bh=bqTVIlZaOAbRkcEAh9JX+SWxzv4jtG0Mpc4mN6bLMxM=; 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=n8eS43rTwu0O1+FcCyMDshzcuJ0+FnCx7MK+P41Qif3xMTxJ0KxdjaC6YJ3tPdcdC B8Yvi/+eXj4sXnaPxAaNYKeAPZtmVYxgddqzBEED4IHY0jQGaEX+fldXR+1nuqZ7Gy Tw+w5SjfsQjjUlEv/KGyajs183UYINXeRTV7NVcxDHNTelg/GtJqjE28eUUomrtKtC v6/2ClmKqRXb/FyM7ptJY1U5novwVAdcF5/eXiG86fh+EiX8nTndsyDiJryTtFkVSB mjcITVWSTXjRKkDMvAw6f6t5t77DBgTdn5p915hgcyUl2qj507T0qFlLlD3YFdkUyt wara0xGDP4b4w== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 00D5A6907B for ; Sat, 3 Jan 2026 13:07:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470838; bh=Rln2mHG4qY0L775vFlT2WMsxatHYm8LsAtSPM4hpnvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FZ7Hn117pQivknRwZl1gPqDuk5Lrom3P2G5ymX/8ZYHmSNhNR3sUzvvRlwyf86lpL wo20LHfiqJWgDSVdzBiPB3bhDqxt7lNTfQjnxs+jDysrklX3QGqDbKNK7IQ27ynnol 8CCies67R0qPCdPVo3mx9lMZpNC1xGFlwMkCP82lx5lsofvOAsVkhE/B2ziXNPkBT+ VWozJxs5mCU2D4Z91iLFlKyGEgeBAuMn1+bNyaPPSmNJiZPBB+XLcVtzQskOmZLJ2K GgE0Vsf3UeyFra94pkb2nSc8zPLXiU2qZofbjQ9gjEch98v/5xNbl4l3OMJfkSFQkq wg/fvKuZvOKfw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0127668FCC; Sat, 3 Jan 2026 13:07:18 -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 vwCwlioYKW2e; Sat, 3 Jan 2026 13:07:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470833; bh=krkc8TKRkoR0r/qbYFK8Z84GtVX0rS2+BJVyFWn5lFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jaCake91dBrkY59X0Gzdp+pHYc7aXM3U92qzGFrPS4wX8PxSobMgbeqLJOVLkEhzc LUpzLtzj2Taerv5M864XCoXX8twjelIothajHRrz1N8wOppgxX3Y5GCa7y4DNmChx8 7qAPQV3De5y+FecJcBm39SKraSUztBTt+SwJEugmOhOdJDl+w3F9gMadDs7AHML9YN 8ycI+bxaHp/8kVPMzZfZs2KOMZ6EPuKz6+sDs4Fe1B5m8eSHpcvwc11WeJuHhgKxLR VA/ZTCpUx1sQJy9WnRLOvkTIVpYztyg1LaOmaKtTg8YoLPkQe1Lgj/Ssw+qnEkC5wn A43vVeFKuYl+w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9396468FD2; Sat, 3 Jan 2026 13:07:13 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:59 -0700 Message-ID: <20260103200510.3605009-29-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KHSF5X3JMZ7RO7T7RLM4CARP2RGGIJ3U X-Message-ID-Hash: KHSF5X3JMZ7RO7T7RLM4CARP2RGGIJ3U 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 28/29] test/py: Add an add option to skip flat-tree tests 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 a --no-full option to pytest that passes -F to sandbox, skipping flat-tree tests. This allows running only live-tree tests for faster iteration during development. The default is to run full tests (both live and flat tree). Use --no-full to run only live-tree tests. Signed-off-by: Simon Glass --- (no changes since v1) test/py/conftest.py | 6 ++++++ test/py/console_sandbox.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/test/py/conftest.py b/test/py/conftest.py index 0060f3da986..bd0c226276a 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -102,6 +102,10 @@ def pytest_addoption(parser): help='Show info on test timing') parser.addoption('-P', '--persist', default=False, action='store_true', help='Persist test artifacts (do not clean up after tests)') + parser.addoption('--no-timeout', default=False, action='store_true', + help='Disable console timeout (useful for debugging)') + parser.addoption('--no-full', default=False, action='store_true', + help='Skip flat-tree tests (run live-tree only)') def run_build(config, source_dir, build_dir, board_type, log): @@ -352,6 +356,8 @@ def pytest_configure(config): ubconfig.persist = config.getoption('persist') ubconfig.role = config.getoption('role') ubconfig.allow_exceptions = config.getoption('allow_exceptions') + ubconfig.no_timeout = config.getoption('no_timeout') + ubconfig.no_full = config.getoption('no_full') env_vars = ( 'board_type', diff --git a/test/py/console_sandbox.py b/test/py/console_sandbox.py index 565dce27e56..3bd109acef5 100644 --- a/test/py/console_sandbox.py +++ b/test/py/console_sandbox.py @@ -53,6 +53,10 @@ class ConsoleSandbox(ConsoleBase): cmd += ['-d', self.config.dtb] cmd += self.sandbox_flags + # Skip flat-tree tests if --no-full was passed + if self.config.no_full: + cmd.append('-F') + # Always disable the pager cmd.append('-P') From patchwork Sat Jan 3 20:05:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1247 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=1767470844; bh=vQVrZ1UhmExaAvQuTUkaGGud4vmeq2gFc1Tvmw6zIWA=; 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=X3Dhoix/lDLaDpfXG/X5nu4y943bP0U6NoyoqXaJmhKsHHkh2stBB89tSNw84s/zh 9enGDfL3T1ILVjlhwxHeALxwaGnvDuqu7ZxGBaQyIlrwoVyosFgHBD1Cs3j03OkEEk zm9GD0uUiPoN22BpJebfSdorr6LYsyRsyQczD6cVcwpsll6nOdCiPhzEHmP8joK/Q7 IMhhdK0Y978kld/XkE/gTioLcN6Qdsaqksbu+YgjUZQ1MyS13mM5JUxegpNBLUxv2S JebTBhVsR1wxC87JVEeIUho8zzebRSrEFk89LndQyfTIt+f5Nvw2sFyq7JxdneuuBH a8kiSVbHCWTRA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9234669095 for ; Sat, 3 Jan 2026 13:07:24 -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 T9Hz_GhEjjxd for ; Sat, 3 Jan 2026 13:07:24 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470844; bh=vQVrZ1UhmExaAvQuTUkaGGud4vmeq2gFc1Tvmw6zIWA=; 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=X3Dhoix/lDLaDpfXG/X5nu4y943bP0U6NoyoqXaJmhKsHHkh2stBB89tSNw84s/zh 9enGDfL3T1ILVjlhwxHeALxwaGnvDuqu7ZxGBaQyIlrwoVyosFgHBD1Cs3j03OkEEk zm9GD0uUiPoN22BpJebfSdorr6LYsyRsyQczD6cVcwpsll6nOdCiPhzEHmP8joK/Q7 IMhhdK0Y978kld/XkE/gTioLcN6Qdsaqksbu+YgjUZQ1MyS13mM5JUxegpNBLUxv2S JebTBhVsR1wxC87JVEeIUho8zzebRSrEFk89LndQyfTIt+f5Nvw2sFyq7JxdneuuBH a8kiSVbHCWTRA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 81F8A68FD2 for ; Sat, 3 Jan 2026 13:07:24 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470842; bh=9sFY14ombdZEr55J2/PN/yaaY+RJQjtGht/SqDWcx4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMrQNwB4cUxfyPAa4U17HEIXEBrG9lLGEiycqQe3GScIjho99qMR4vp+8HThJSYgb 0/abS0Q8auKYC4WpVquAgOwKX8gMENpK5yQgIs2qz7e9qaETZQ7qdrammd5HxNpluu rVdGCKagjpSbS6ncf21ejn+2eC9sR9KRKr5ZU5QHy6CQTylX/eQuXpIF9xKbsGXvai hg4mH9vvbXwc8IYwKhc3p/CPIBL44+db9HIWcM5WYkjDZDq0x+7Stv4ZnMoPY4tJIo btUwIWbk86EvOzUul1aXaHaqvQAJmAjflfImnpAKna33/B8i8m0/fUv44ZkJsYum00 2mpwn4je2E6bQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6FC2168FCC; Sat, 3 Jan 2026 13:07:22 -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 cTCGxhPZuToL; Sat, 3 Jan 2026 13:07:22 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470838; bh=KpZaLYRMZlPNoiy/g+rMYI8rrcO83ebeSSFmFIdmnKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LtC8zu2FLF8wOO9heIksJnHEqsAnIIr+i8CnRnAEDE3y5bXPb+OB+EwCL1losUHvz ldy6CELGW9axHWH83WGcW8nJuJNoCmjvazWLLAjmU32Q0LiL8BizylyOlneP+pWzQl P/4z8LF4ULQLTOCWhh9jvweKKT1DpdSt2cmf5oBShoPPkRpaa7P9h8KO3Ot7WXSfjD XtHFu74LeVu+uvtdSflz4bA+4SD/XXjAAImMF7Q2grg49FdVYr/Il3ttBThPIxvsZy 2WCyfrnp3D1hj/uZ400TksQAL7Y4iDgBdyKAu7CKvGxpRSwT+ls1bpfAe8Hd9UtjQK FpikE1EBImgFw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0F85B68FD2; Sat, 3 Jan 2026 13:07:17 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:05:00 -0700 Message-ID: <20260103200510.3605009-30-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: QVVFZ74Q6RPGXNA6B6MOYS3VHDJGKQJS X-Message-ID-Hash: QVVFZ74Q6RPGXNA6B6MOYS3VHDJGKQJS 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 v2 29/29] test/py: Add an option to disable the console timeout 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 When debugging, particularly when stepping through code in a debugger or dealing with very slow operations, the console timeout can interfere. Add a --no-timeout command-line option that disables the console timeout. Adjust get_default_timeout() to checks for both --gdbserver and --no-timeout, returning None to disable timeouts in either case. This consolidates the timeout-disable logic that was previously spread across multiple locations. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) test/py/console_base.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/py/console_base.py b/test/py/console_base.py index c4472420c31..7f044b587b6 100644 --- a/test/py/console_base.py +++ b/test/py/console_base.py @@ -271,6 +271,19 @@ class ConsoleBase(): # call, where the function returns None (assignment-from-none) return spawn.Spawn([]) + def get_default_timeout(self): + """Get the default timeout for commands. + + Subclasses can override this to provide a different timeout. + For example, sandbox may need a longer timeout when mcheck is enabled. + + Returns: + int: Timeout in milliseconds, or None if timeout is disabled + """ + if self.config.gdbserver or self.config.no_timeout: + return None + return TIMEOUT_MS + def eval_patterns(self): """Set up lists of regexes for patterns we don't expect on console""" self.bad_patterns = [pat.pattern for pat in self.avail_patterns @@ -328,7 +341,7 @@ class ConsoleBase(): m = pattern_ready_prompt.search(self.after) self.u_boot_version_string = m.group(2) self.log.info('Lab: Board is ready') - self.timeout = TIMEOUT_MS + self.timeout = self.get_default_timeout() break if m == 2: self.log.info(f'Found autoboot prompt {m}') @@ -616,8 +629,7 @@ class ConsoleBase(): if self.p: # Reset the console timeout value as some tests may change # its default value during the execution - if not self.config.gdbserver: - self.timeout = TIMEOUT_MS + self.timeout = self.get_default_timeout() return try: self.log.start_section('Starting U-Boot') @@ -628,8 +640,7 @@ class ConsoleBase(): # text if LCD is enabled. This value may need tweaking in the # future, possibly per-test to be optimal. This works for 'help' # on board 'seaboard'. - if not self.config.gdbserver: - self.timeout = TIMEOUT_MS + self.timeout = self.get_default_timeout() self.logfile_read = self.logstream if self.config.use_running_system: # Send an empty command to set up the 'expect' logic. This has