From patchwork Sat Jan 3 01:18: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: 1195 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=1767403168; bh=IynqD5f/SepzYFOPsVKe984qMZHyQTH7cQSx8KEdFUM=; 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=ajuCQywI4WOWtFjhV21O3sfrqn9Pz80Z9K2G+73FGrKu39j2gVAjqG3/kSfZGEyR0 SV15kt3ir3df1htJTP/gVF3qYf5d2ptQWWUkFKxIfaObsHPAv8YdHDEfDRKeWzX7TS GFkhA2NjefQ7KbqsCdKZIz/9HLLRH2malCAP2qbr4tp6sGSADie+0L76X1jC9pGUN1 40mdRJWrgRJhyFOQF/IHEX/xm0eQ4NJxGPoYcezlaN8kS0NCXpZlDiT7M3dTsuN5mK qcIUBb+e1AStvzlIauTJbxTU2rtmd0+dSYbS0CVW+LS2cixbBYi3135z9GavFSITlG f36PYab8gw0Sg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3360D69034 for ; Fri, 2 Jan 2026 18:19:28 -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 WvPBuuN1prTl for ; Fri, 2 Jan 2026 18:19:28 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403168; bh=IynqD5f/SepzYFOPsVKe984qMZHyQTH7cQSx8KEdFUM=; 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=ajuCQywI4WOWtFjhV21O3sfrqn9Pz80Z9K2G+73FGrKu39j2gVAjqG3/kSfZGEyR0 SV15kt3ir3df1htJTP/gVF3qYf5d2ptQWWUkFKxIfaObsHPAv8YdHDEfDRKeWzX7TS GFkhA2NjefQ7KbqsCdKZIz/9HLLRH2malCAP2qbr4tp6sGSADie+0L76X1jC9pGUN1 40mdRJWrgRJhyFOQF/IHEX/xm0eQ4NJxGPoYcezlaN8kS0NCXpZlDiT7M3dTsuN5mK qcIUBb+e1AStvzlIauTJbxTU2rtmd0+dSYbS0CVW+LS2cixbBYi3135z9GavFSITlG f36PYab8gw0Sg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 235996904D for ; Fri, 2 Jan 2026 18:19:28 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403166; bh=/EO18Qh//skRRcAvs1y/bq3CAsIYNMCmcLHYoACTFXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=awL+fGvVQhdHEZNgm+HXnxs8sfGpAzVEKljnFe1QsM6kmJpriLQyPueH2eXlbEr1N HmA8JG5Fp5mJ5jlhwGPtY6DobXnlDPZMo5mc0M4JhbCS8yLu/samB33ZrgRJl3GKiC lx5JiQbKvKy2g34Qgf1OHKSKtlB/5EGEA3k63HlnHjvy6BiY3f5+TCOwD3HRA/j2Yy f++0qV/EUGd+A5nZk9ZDf05oEZnrIDD5MvDbWZi00Mojhn1vSlD3xweXJefFkp0/6q LTRGmXxYEgxax/EzZb0osoZo5r3x1g0qItQ2dumLXFcF0hbdS+DlbxCWL9uWnP2Pxg nj/Q22huhu1Kw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 669F968FAF; Fri, 2 Jan 2026 18:19: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 dNnxPYvDaYf0; Fri, 2 Jan 2026 18:19:26 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403162; bh=N6z6cypwDRijyqRDHb1/AjI2swMxMl+xWPAcuH39Tuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uLwW3q2aU0TuS7aysBrw/Pjgewz4wPrSW5EcE7KlbZTF8PUXvLG2NcDr6g9XxMUlC 4+YNJUOVnVx/mm6mnNDYZjpnmK7giGNCGY0qXqTGsc0C/wgPNdbEtSiYYzPdVrNwjK YzwszCekjvBSUgquPDGr26hkCKvZylcNRFkdyBO8ZUMOaXNSjZRlov2S5Jry+aQvzM BdmLEld5pwPrvXmcXJUUybZetBi791Ur+iP7qBmkzjOUsXzoEBnrgvkgBOdAKJq2d/ TPRlCnhS+u5alqRMrX3Z4v8ILzsqbkkQ0LH3EtoqHZbWuSNuzlZzyoNGInDxI7BAnj AlkXsPdDyTiKQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2E54968F5F; Fri, 2 Jan 2026 18:19:22 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:37 -0700 Message-ID: <20260103011908.149445-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 2B6JEV2IRB3H2WAL6SILMOTSYIO3MOLO X-Message-ID-Hash: 2B6JEV2IRB3H2WAL6SILMOTSYIO3MOLO 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 01/24] 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 --- 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 01:18: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: 1196 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=1767403172; bh=RNKnamaOLVob8f19PiSsCsWWj9aS/dptgHtM7Tu5zjg=; 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=F0dN+LypwZx8doDEYY+I2xmTcQj4cXitiP4lCRrAK3tPtz/yRkO4TO+63Q66GhoXZ +2TnhxpUGPrzzYgOJPd267MAbS2Xy6gsebtBm/LSjHRgP0Fr0U+AkDw5OiNGNcbfiy FBjacb5KmV+Y+fnwOYbPo3ma4EImFmc/8n/P+WZxPt1jFmracZ6bVjSpgQ/ghEt51O TQQ9/QUMoBzTwhpOU0DWhxGBQRVzdkEeNDCmMrohsTckOcOMKExRhOR38bXs1P4WWD +ejv8sLEsoevLKH3fVs/gVaSUtOrsLHDIyi9WG6F7lBlx4dpYFYc68Wjpy8Ba3Lx6k 5nvN7ckdv3Nzg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EFC306904E for ; Fri, 2 Jan 2026 18:19: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 10024) with ESMTP id eDzzTwLvyKkv for ; Fri, 2 Jan 2026 18:19:32 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403172; bh=RNKnamaOLVob8f19PiSsCsWWj9aS/dptgHtM7Tu5zjg=; 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=F0dN+LypwZx8doDEYY+I2xmTcQj4cXitiP4lCRrAK3tPtz/yRkO4TO+63Q66GhoXZ +2TnhxpUGPrzzYgOJPd267MAbS2Xy6gsebtBm/LSjHRgP0Fr0U+AkDw5OiNGNcbfiy FBjacb5KmV+Y+fnwOYbPo3ma4EImFmc/8n/P+WZxPt1jFmracZ6bVjSpgQ/ghEt51O TQQ9/QUMoBzTwhpOU0DWhxGBQRVzdkEeNDCmMrohsTckOcOMKExRhOR38bXs1P4WWD +ejv8sLEsoevLKH3fVs/gVaSUtOrsLHDIyi9WG6F7lBlx4dpYFYc68Wjpy8Ba3Lx6k 5nvN7ckdv3Nzg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DEA1668FAF for ; Fri, 2 Jan 2026 18:19:32 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403170; bh=BEcC/7BuJTrH7BlRB74VVh0eHKTPbI1oD7aZHdOylI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LxKZ9FfhxSu07XWen3hKbK1zzS4vht43CBXVqiwEGSvX875b9gGXo0/aPo/M0LoVz GEBzS50bKpyDcHWZX0UVP1H+P5LlyVpAUw7oMgl/KpVCVBqZmbCkpgrn8OkJxLug15 I9SZZ5d3vOrQRgBENDEF1HrYZwvBWiThVa8hWcezp7/BrVXMD0kdnuMJxhDnZVbDgT rvMh77/OnvoGrBVVqTAV8d+yligBmyL9mnV97GOkrFQmLs8HBrd3W0ojfbYt6Geh1P qLMHEIjCRDKLm+LFppH84pR+2oyeD4x0m+YXx+cGuNuMWbPMeogTrFbBdU1tRePnBT wr9PUX4JbsXDA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D8B1168FAF; Fri, 2 Jan 2026 18:19:30 -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 CS1bFuExGxnB; Fri, 2 Jan 2026 18:19:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403166; bh=/WelOTMq2+fi9WvFIcmtbZIOE7TJo0NxCfLbaFA/qMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LFtaR7W9hzBRMf9SAhvyidWsKVLwr7MaSsdC5X0rV/R52ILJewSiSmmte70Pzoo2Z kCZmw+/SNgXMNtOBuuFkrfTzdCU7KxUXzwNUS0vp8SQLYZYDfRmQY631t7Hl+zYdug PBuKkUPTaKaBYuW9hxQWRQK92ji1sv1Fgt66sjVKL/yFGnXBkLbs+HhPcifF/oAkR2 QmBqGPw1NZAxLfXfkyvy+pzZWKiwYzy742ZAQPX8Ku8If30G4rOU91najcanyz5MDB YbvNS8pzRzySm+Tneecr6EgSTM9s2RPZ1plG3jh4lOK1VLxAscoYcAiqqM4gknAbdk vGG8FXjaWaiBA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id AB29568F5F; Fri, 2 Jan 2026 18:19:26 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:38 -0700 Message-ID: <20260103011908.149445-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WX3WGZIHEBAAGB6ROZ2MYHMGDUSWMQYP X-Message-ID-Hash: WX3WGZIHEBAAGB6ROZ2MYHMGDUSWMQYP 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 02/24] 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 --- 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 01:18: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: 1197 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=1767403177; bh=SX6z3+fCoLPBn06Xn7Q0TTUr7CZfpUX4wXFr6WzS0Qc=; 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=OX/8e9f63hg1hAwZCIipePeTliFV4TEUZzfrBfSleonJnHkELZe1X4rTWRI0/fcD9 hniLE5wuCtLjDF3V/uftUCYmegI12/zV5wBlNB1dtKqGurWD95fZAkzmov+/MmLvVs AfZjA3Grxovr3ja8NiKZQzmDsgbgichC+J/iFODjRE+pJ63Y/g2VjFzo/INifpmawI V0/AT8mwQSNAgDXoV+6J8csrGbCxsJ7VBRh1tltAITBktXkDBczxRTTAlXnM3eIiO5 N2RwGtgAdjM9YNMgyOf5WE1SLaTBPUKMMVLFB2OzvgoA753o+t4ZORzPg47jQslb4s Oy+h+g9Sw3vfQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 751686904E for ; Fri, 2 Jan 2026 18:19: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 10024) with ESMTP id IDd1SxL4kmk8 for ; Fri, 2 Jan 2026 18:19:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403177; bh=SX6z3+fCoLPBn06Xn7Q0TTUr7CZfpUX4wXFr6WzS0Qc=; 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=OX/8e9f63hg1hAwZCIipePeTliFV4TEUZzfrBfSleonJnHkELZe1X4rTWRI0/fcD9 hniLE5wuCtLjDF3V/uftUCYmegI12/zV5wBlNB1dtKqGurWD95fZAkzmov+/MmLvVs AfZjA3Grxovr3ja8NiKZQzmDsgbgichC+J/iFODjRE+pJ63Y/g2VjFzo/INifpmawI V0/AT8mwQSNAgDXoV+6J8csrGbCxsJ7VBRh1tltAITBktXkDBczxRTTAlXnM3eIiO5 N2RwGtgAdjM9YNMgyOf5WE1SLaTBPUKMMVLFB2OzvgoA753o+t4ZORzPg47jQslb4s Oy+h+g9Sw3vfQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 62FD468FAF for ; Fri, 2 Jan 2026 18:19:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403175; bh=8Qmf5y8pD51G4Y3MkDNjlsESCkItKZPPFUuYpYUA1ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=adGVS2+D4hMwpHTmpXbMIaTOh05VfV71SmAIF6i6zJpGcF1reDwKyo5AZE2MZTygq TZqSUHNQ4pnSxbUgzJywH/g+T4UA+Lalc4YA0kKohPrKZZs7o55APXK8PNC7768ewK 1rrqt0D2eQAvcSvE5b5FmPfbf1++U621WjovO6p8seVJb/AGnip4j3+ueoRgaRcVFj IXoKuRi1GozEv8hBa7OoyhYO4Bj2nUAIawNr0Y3c+3BQA5z9K/TC5DTFvOr+9BHSw+ OVItOW067Hk5DxctXtv0gGmn/1fsmesaUGJ0O5Ehi9xvsgA2OYPSYDPeK/YqGr04H1 bvA8t1JhEN3kg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7C25568FAF; Fri, 2 Jan 2026 18:19: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 EgehyaNutcsg; Fri, 2 Jan 2026 18:19:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403171; bh=4ptYSo4aRpCMLsi4lXlguRPH4cS4D7zfvSE2+PtYZ9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h6Uw/5PG3Nlc3JykkV1z3CPjhaRINc0UppXWMPeN/z2ITqCXQU98WHx2W4G7TI9qr soYPn9WA3j/k0dFviK1Zzb+DZDGo7surIkqOd5UcVLtLhfUFTNSl5gadH72a4wJIw6 C7QnDUAnw8EA/hW6y50heLxzoDuD8dm53iIy1nB58HaV8Qd3Ta5ykrYU6yhwiB/E8t u1N2bR/P6GWRyCOWLLEWmnCBTWq5JExJ/1E5zB9wNptEgeIL4+4j5OzBFBEb2sLYFY uvhFP1ssF4Oa+QRJjJDKU+if7BavrYxm/mLCYbZn40ChgDZ5raek0cHep6TtUW5h2F 7It0U0cI2YhRA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2A62068F5F; Fri, 2 Jan 2026 18:19:31 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:39 -0700 Message-ID: <20260103011908.149445-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 33YBQ5DEEYAHNGO43OBABDT5EA3FRPLX X-Message-ID-Hash: 33YBQ5DEEYAHNGO43OBABDT5EA3FRPLX 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 03/24] 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 --- 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 01:18: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: 1198 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=1767403181; bh=jfxGUckvidoW7ZYvOqRVvGr8LcRfYTFLaw7bQM8G2q4=; 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=nLimSiL7rmS3okg0LeDq61VtNEwnybJlru4PNcoZ7UzcaoHwNX1baU00dSNv6GZ8v nHukrsGG/KP52VeSESEpOLjcMme7z1InDc7Lsu7zblSJQ1vRqZt2QIuuXHyo4T3A6L qU5oGnKzuGTP3Y+Z3LzJ4C4/OpoDVj7hwwalWbhL8M1KYfOkRYCXKX9nkNDGnfBEr7 VAYiffLSRcZKzHFRQ1PyoyrgqqVwN9QkGWfCjVKWZASHmzQ1NxJs09Y5O0Zu9n4OE+ WrnOEfWRuaH34AU4yWc3iFpnhuf+MoXn/S+1/gAuKDY5FLtwkZ8uNBeLD+bS2ThIpJ oCLYPiVSnznPQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D59A669052 for ; Fri, 2 Jan 2026 18:19:41 -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 bD2cTEnTSQ65 for ; Fri, 2 Jan 2026 18:19:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403181; bh=jfxGUckvidoW7ZYvOqRVvGr8LcRfYTFLaw7bQM8G2q4=; 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=nLimSiL7rmS3okg0LeDq61VtNEwnybJlru4PNcoZ7UzcaoHwNX1baU00dSNv6GZ8v nHukrsGG/KP52VeSESEpOLjcMme7z1InDc7Lsu7zblSJQ1vRqZt2QIuuXHyo4T3A6L qU5oGnKzuGTP3Y+Z3LzJ4C4/OpoDVj7hwwalWbhL8M1KYfOkRYCXKX9nkNDGnfBEr7 VAYiffLSRcZKzHFRQ1PyoyrgqqVwN9QkGWfCjVKWZASHmzQ1NxJs09Y5O0Zu9n4OE+ WrnOEfWRuaH34AU4yWc3iFpnhuf+MoXn/S+1/gAuKDY5FLtwkZ8uNBeLD+bS2ThIpJ oCLYPiVSnznPQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C5A226904D for ; Fri, 2 Jan 2026 18:19:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403180; bh=rcP1SoOPa3cYtkY1s12V7bRYEiviC4b2P19Y7XuS6r8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eMdvffiIDUabPbL6hxiiUv9xA/bVV8yvsXa/ukfVpe4J3Gq5ireXNg7tDiBobvEVq bIRZ7DtFmxFF5vLnTp6tRC40QYo5/b2aCaX2nQb64eESlm13sVVeR6zMABP8mAAXfv B0j0eXHsDdhGi4Olw6CU/zWPK+DrydZbyd5J6CBkv2cfYbD0lD/jk6mPHTBeWd1ZB+ pV5EBfWWNiaMvW/bvnd/BcxKhdfiNUs90CI/xs+ejUUoQts+xPkFZntCJrCf8GlCMh pamsq5KqDFKXgpi2CYcNTd5XL/XxRQkG5kHQp8FIN4LkFBgsl9MQ/iEHC1E2fw6Hhm YVu07H2jFeQew== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2DB4768FAF; Fri, 2 Jan 2026 18:19: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 ZdWy-jUKIXgo; Fri, 2 Jan 2026 18:19:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403176; bh=4YBya9nUz6QY2ebBBauuYBb1WFuPSo/5MSv6l/itlLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hc4amwkKK2+z3s6U4jBDyH+Nx2U2EOZlaR5+vAe1oW+DuXbJ0xFXAe9A0ZmugD+b5 ycziMlbQAjH2t4I5PvdLyOfy5HezXIQypJL+nxOnUkpt3IPdPxhzM4MjuSTkaqd/P4 udvZIvkLqTHIEa5UOV0n1zjMCXgE9ruGsBBX+rIRvv0bNfPU+iySwjaGBYWXCjDrfv prPnia6QisTa54nHIRQq2F4wnK7G7QTiw3+ddJPSj/daGCPgAO0spCIDLRFX1nZcAj 5WxPEAgeirdlkhke4jDccrJAY9h18791mOnk1X2fu/7dedY3sQoRV9pBqsTjmqFGUb 1ED+Xl0jf/0Yw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BE70C68F5F; Fri, 2 Jan 2026 18:19:35 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:40 -0700 Message-ID: <20260103011908.149445-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 2BJ4TCI6AUALU6KHAQCDXZJTEDCSODMZ X-Message-ID-Hash: 2BJ4TCI6AUALU6KHAQCDXZJTEDCSODMZ 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 04/24] 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 --- 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 01:18: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: 1199 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=1767403187; bh=iTdpUg0sY4XEuSFkcfykBbYVSCpMWk8Aqxeou/X7lso=; 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=ihBw3gdUowpTrUO8oloXKpuzVPFLwrq7EsM0Tohb0NksN6luQsabUkjM432hRN8Nu +Kq3skZp5R5JM3JSkNE2MyLtdb/OsP94pi7f6oj39wpuKVwE3wv6+uKKc+cR6G07gY 91+2BdE88gR8gKSBAElp0Z7jluScgy6tLFmeUD1nAmtdr2OX0Xi07eD6VyWMix+v70 FFGiOg28eyaD5AKid5olETMfH5osk/63lQTrAmyHXUTRYg4OWnJJWpXs+LrViOze1Z zP+sfzP1tIbmBlgchcMQsaArghVgleOBA3FdBJpmtkUmKEXduc+l/fD4Ugc3k2wtdN Yqkt8fIfQSfng== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4CF3C6904E for ; Fri, 2 Jan 2026 18:19:47 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id YcOZQIrUkUKo for ; Fri, 2 Jan 2026 18:19:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403187; bh=iTdpUg0sY4XEuSFkcfykBbYVSCpMWk8Aqxeou/X7lso=; 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=ihBw3gdUowpTrUO8oloXKpuzVPFLwrq7EsM0Tohb0NksN6luQsabUkjM432hRN8Nu +Kq3skZp5R5JM3JSkNE2MyLtdb/OsP94pi7f6oj39wpuKVwE3wv6+uKKc+cR6G07gY 91+2BdE88gR8gKSBAElp0Z7jluScgy6tLFmeUD1nAmtdr2OX0Xi07eD6VyWMix+v70 FFGiOg28eyaD5AKid5olETMfH5osk/63lQTrAmyHXUTRYg4OWnJJWpXs+LrViOze1Z zP+sfzP1tIbmBlgchcMQsaArghVgleOBA3FdBJpmtkUmKEXduc+l/fD4Ugc3k2wtdN Yqkt8fIfQSfng== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3B5F869034 for ; Fri, 2 Jan 2026 18:19:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403184; bh=8TUGoqNk4cMa3akLRu1GphJNYxd+ek6iSutIJpX4LFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YMAOJBlp1HSx5BkhGxpR3eDGL4Kzu1alOhV2chg3cot3eSPyG0AEGWpG7nUWRJbN9 sHFBhyBq1TTuvZ4j1icNkVZjRmCIppH8DwSitQpnFEG6089RvcNhLEkGkR8oF9GKRT ugmZK4xC7Kj+5K7EFrkx0sE+5lJoKYROT1ug6OySb+DV46Qm4iypePCava7L812wej d9q1uj4gdSKXveqAJ+ohXzA2SHuR/Vvedwk4R2nXuAn69TxNboaih9ogXaIlJNDxvf gYCMCKXpT8JWC5iFGSif0jgL6jqux6b6ZXzxNiugs4moGsMKLKx/2TigBYOKm3ie9e AIuujLYNldVJQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5C11E68FAF; Fri, 2 Jan 2026 18:19: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 gKRc6KnZUXjs; Fri, 2 Jan 2026 18:19:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403180; bh=91WuaKjg2GIFCHPz87ddCXtqIiJv+tUw5MbucPku7vM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KWRbwawvOrFaMNO7M3lGv6vkDbmKtWJqYe0JAF67CkzlXXWIT6ST6j1+PEyz+zXT5 x7ErY2XUJLl+o9Viw7lABk+/5bSKIPS5uhAKrB7pwzNiiBjX/tQNhT0Xb7iwpJEeC8 wvPrIDUT5KIChC1+eVvPAI5hcEyCuFT2szErvytSI+gED8TV9xjJzH1Ecg0R2nAuus BMZ5CvrGcP7GP4/UVJPEso/yV76J11Dj8UrrHTp3FPp5fn/72a+5we/NT+pBD96oOR CQf2sJJhJ5xi6DCxhIcq9ALx4sMpvmrUzJ7ZdF3eRq48wbp7akRJsSB3NgaX3WCaLs mv+ApV7vpBEOw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6E9F468F5F; Fri, 2 Jan 2026 18:19:40 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:41 -0700 Message-ID: <20260103011908.149445-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: N5NUFQDB7AQTHXMFK563ITGQWZF5TK6T X-Message-ID-Hash: N5NUFQDB7AQTHXMFK563ITGQWZF5TK6T 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 05/24] 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 --- 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 01:18: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: 1200 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=1767403191; bh=47Vxzn5nGF2iaLL7Efj179QQdBDhqinirAF6NMv01Ok=; 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=eC8uG4tWyGgKnfSF3YwLgWZAPlfAhutcqDMoMYqvAqj1nvCobbmH9Fey9SUNaiLl2 wjc3qV4/HEE6wxqcqPGG+I5381ixVvorgAg8XXO8rgJcr13FNGYsqw7vT4Rfk3Xrin Q1ynpoY6+PZVTefgGBb5+NSA7pf9qPd3TACRbTpBJAr6I77wtjWh9k3Cip+Avnw7Ju 19+tasBWVIN/gWHAd+yS6pAY0H8whZQBWRNZ23FDXWjMMmAiv31utjFewGSeqbs4fD i1Ox++P78HGB3AyWkUV3cRULTNOOBapzYj+n7WOSzrFkcaZqOy2T9AHpJvMEQlAGjY 1EYfWSktr0zYA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AC9906904E for ; Fri, 2 Jan 2026 18:19: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 5YwdhceZNKnE for ; Fri, 2 Jan 2026 18:19:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403191; bh=47Vxzn5nGF2iaLL7Efj179QQdBDhqinirAF6NMv01Ok=; 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=eC8uG4tWyGgKnfSF3YwLgWZAPlfAhutcqDMoMYqvAqj1nvCobbmH9Fey9SUNaiLl2 wjc3qV4/HEE6wxqcqPGG+I5381ixVvorgAg8XXO8rgJcr13FNGYsqw7vT4Rfk3Xrin Q1ynpoY6+PZVTefgGBb5+NSA7pf9qPd3TACRbTpBJAr6I77wtjWh9k3Cip+Avnw7Ju 19+tasBWVIN/gWHAd+yS6pAY0H8whZQBWRNZ23FDXWjMMmAiv31utjFewGSeqbs4fD i1Ox++P78HGB3AyWkUV3cRULTNOOBapzYj+n7WOSzrFkcaZqOy2T9AHpJvMEQlAGjY 1EYfWSktr0zYA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9C93469034 for ; Fri, 2 Jan 2026 18:19:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403189; bh=g4JCYmYE35oX1JCOCwpQbngi+wOGdvlz/Fz8jxeXNwk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=muAVyac7Lx8cwNa830uQbGjUunRpwj9EYK5Y7pOo2fMNMBkaPwPcgPbg5y8tYhOW6 LKgs9mBErNecfPBrq41emsHVSYzXBQ7EMa8c3c9gLnhfDsF5taVPxthw7M6rL7vc6j P8YsiJSAbZuF4hdz8dCsdA1F+4Vx8JQDF7R2c7oLtbeYhZA+/BV50Q+7VVvNMEGnWr 6K4j/k7LZ0b53EmnbTJPtC1lvZTwjIxRfsJ89dGL+p4qHrJU1A/MtdNBq/iz1qn/dV nAYR5A3sYC8QIsbh/Gxq8pMLrtONouafer7COBOFrUuBJW9khjG1TWJbYHPEzujZC9 o163mE2nIruHQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A2F6269034; Fri, 2 Jan 2026 18:19: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 FoTCltm8o0jN; Fri, 2 Jan 2026 18:19:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403184; bh=HDnzoQKiICQcAxY52zrH2faf4HiP4Cm+ImWp+D3ue7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j9XMWWcnjpQ1kmdRSLYTlsqhxbZ+evWVFrcWu4O7B9l+jFyuklikOTgWztbABYmpQ HsMhUDOkyPKXyVZwveeA0N0A/Ska7bEzSTRgxiKt1oDwZBajZLhQB+9U/doTSxpRwn T22cF3b9eB+j5AMevs3qtpGtuDpT8mWjDnfCTyJ2QCtdB/hhQ0s/FUufbYKxyYO0kO 3I9dBetWq+3XOiH7NvwbFkjS472B/Hipm9NJaieXuaPVvTVrbFe5KazxdFQEstgd4x +k2CnsjMdxZFwXrwEl5vgZLlNuLJFGdipKk3t2qsM3S+wTTG6hBU2Fi+hzdvtPkXI0 miihF9s3kBKBw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9EE9E68F5F; Fri, 2 Jan 2026 18:19:44 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:42 -0700 Message-ID: <20260103011908.149445-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: IQHZ6BGQE5VKK2ZQVIUTY2V22SEM2HN3 X-Message-ID-Hash: IQHZ6BGQE5VKK2ZQVIUTY2V22SEM2HN3 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 06/24] 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 --- 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 01:18: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: 1201 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=1767403196; bh=atSJZhsMuRf8uZxShIQirfkZZ7Hn6hI3o8QoRMDUWE8=; 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=pfL0ZPHIYne4LfQG32PRDeax5AwueXebABTwxJ2M0FcsNjdrpVwyRLz0uD2y8zs/J aoGZF8w50iJ8LAEqicDQACI+9dCChUPl6qPCBOveVUimyWzrrUtS5XBv9tczylvZX1 4aEbaQPGQhER6WlRFvmkJ6uce0ylwsxqnk/GUqZXVzK9WqY4JWklw0y/wOxNkD+YoE 4lnfaEcc47XltbFFEl/sNoefcad+Pq6D9fwXTLqL6+5WDs4TN1mOEyBgBnktzLqqc8 8vc2nYPqJALd+dhyQ0W12CxUJ4hdQT0HF3HCfnZclMU8cPsteWkw9RcMyzX0jFrE84 IEwIE1rzRT4eg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 71D0A6904E for ; Fri, 2 Jan 2026 18:19: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 KHnKwHbdbGQj for ; Fri, 2 Jan 2026 18:19:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403196; bh=atSJZhsMuRf8uZxShIQirfkZZ7Hn6hI3o8QoRMDUWE8=; 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=pfL0ZPHIYne4LfQG32PRDeax5AwueXebABTwxJ2M0FcsNjdrpVwyRLz0uD2y8zs/J aoGZF8w50iJ8LAEqicDQACI+9dCChUPl6qPCBOveVUimyWzrrUtS5XBv9tczylvZX1 4aEbaQPGQhER6WlRFvmkJ6uce0ylwsxqnk/GUqZXVzK9WqY4JWklw0y/wOxNkD+YoE 4lnfaEcc47XltbFFEl/sNoefcad+Pq6D9fwXTLqL6+5WDs4TN1mOEyBgBnktzLqqc8 8vc2nYPqJALd+dhyQ0W12CxUJ4hdQT0HF3HCfnZclMU8cPsteWkw9RcMyzX0jFrE84 IEwIE1rzRT4eg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5C3A268F5F for ; Fri, 2 Jan 2026 18:19:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403193; bh=rKBwCUQShB1E7KjB7cQtzZbHS4kOlashNj0Q2uD0NV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OPXTL5InDSd/ZjcFHeOcZKroeKDYKvb82/+eolWG+glGVxIvM1ZnJBpxZ/B9yDLlg 1JKiDcKZts9LvECbJblsGA+YpRAt8U85DWafUBopLlruibflQNGMd0hyZiIgOb8SM+ YOHc7Gq7YyQVGZ8414HpAxf7oB7PW+z9aOYMoQ/0YT4PMD5AcZpf8cVDO71oDadLQU tdY7oPyJ7znP+SPHaY+gBeFNhors094BBcuoFVJ4F16mYZPfz6PxpCHf6THKJtYOfO J3Ung4iU57IwMhYGeyyBnfZsMzeVGcNBMiXF08wJcESeJeaMfPwkEiOk+Wm0Gb/JX/ 2JY51cTygWIKA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A84AB68F5F; Fri, 2 Jan 2026 18:19: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 9bV82YXSR0lo; Fri, 2 Jan 2026 18:19:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403189; bh=1cIiGiZQ/qbokLIpJ3qZ+5kBn+9BCekgjVYkvZV+Chg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NrODzZJqZHZuRSo0QthxDgm6avYckC9jDRE/uAj96XVZYNt/ggPs3Ba5GeZtjUpsp W19SbrIRt6W4Tms5sax8jzt0SMWBhqGDWIXYDShwBNJVIsmwQRDxf/I9pHTMJac752 ItUn/1u2FBmVnsjqmnlK3A+zm0oFYQXWhNCBEVCPSf8bzAVxAyrHN7Z4Gqhd4M428G 2fR+a0STRQQYmq+jQGHLo2snckDrDjOiED3N+Yd68UiY5hDkK2PKVRvr9PqP2HdyXZ KvyzS94/j7agLC7EVxUk4RhC8JPx65uK4WozGIlyf8vYmMMehfh9BNb/ZA46bbsX8a yfj40wf3uxlhg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 411A368FAF; Fri, 2 Jan 2026 18:19:49 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:43 -0700 Message-ID: <20260103011908.149445-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OZCKOZ56RTV5H6HUCTNPVOSBKFCUAIMF X-Message-ID-Hash: OZCKOZ56RTV5H6HUCTNPVOSBKFCUAIMF 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 07/24] 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 --- 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 6e65f55d598..c0574b75fbe 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 01:18: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: 1202 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=1767403200; bh=3oxFxAhJa1vz2huChI3xNGHZMlcIyJvrsb3xQKR3kCQ=; 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=DboCO3444fpEkVGVUETMScDaz0b5N1aVjvdJOxoqO1gNjv4HmLuK7QWw1g88MLcfZ txEa5DSQm7DEuR7OpLXHrm7jQINBlzRABOfsnCq/D+6N06FFWOixkk10RvJEclC9V2 szEejWE1HYo5vlQIwgyDcAfjuMZHN+C/YwYZe/8M9D04zt+u2gGg9YYem+dAt/oof/ 3NtR8L6qhpsuQAsk96koA8eLwJnWHfAsi1m859GBzIhGuPMMqZm2fGZoW1o+SrXM+G 7gkcFBrlFjg24JVmb9v681BO/Aq/praRwmSISUmDJWGjiRAol3Bu09sRr14NbQ5wnP Kc5hCat9gp9rA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DB9F46904E for ; Fri, 2 Jan 2026 18:20:00 -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 eSd0d72BmYzO for ; Fri, 2 Jan 2026 18:20:00 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403200; bh=3oxFxAhJa1vz2huChI3xNGHZMlcIyJvrsb3xQKR3kCQ=; 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=DboCO3444fpEkVGVUETMScDaz0b5N1aVjvdJOxoqO1gNjv4HmLuK7QWw1g88MLcfZ txEa5DSQm7DEuR7OpLXHrm7jQINBlzRABOfsnCq/D+6N06FFWOixkk10RvJEclC9V2 szEejWE1HYo5vlQIwgyDcAfjuMZHN+C/YwYZe/8M9D04zt+u2gGg9YYem+dAt/oof/ 3NtR8L6qhpsuQAsk96koA8eLwJnWHfAsi1m859GBzIhGuPMMqZm2fGZoW1o+SrXM+G 7gkcFBrlFjg24JVmb9v681BO/Aq/praRwmSISUmDJWGjiRAol3Bu09sRr14NbQ5wnP Kc5hCat9gp9rA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CA2BF68FAF for ; Fri, 2 Jan 2026 18:20:00 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403198; bh=26Qvl0orD0W+/13QhRdrfP2DfFZdIMmQk5Y0i5ePPMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eCquTY/srx4VZDTkzux/V/BzJgtaSMj4hhIRFTbjHg8cOCIIEn7fL25nkrjOyeb9u 5/MqRnKoM6+uKqdZV4T9VxEJEUUZwUyeeOlcEezUBmlqoHE4zMIIUkufX26m2tEcnY FlISaz5Av05OoiskKuA/1R7KIaxjxiSCp6RC3keUG7VcypihkLHASAgN2D5YsiIiQZ ytvgQA4MRMNDtAl26dgirXBQ+qMEn0siUtJYD0/7PjMla1b2xq1PGxDvNVgvaxq33b Nh4Rktu9dDIhm8qAaPHgJPcCM+yN4G0jvrwiY9A2Qd2vS7kOjZtv413Kh+2QLudqR+ xhqZ5sl02LO4g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C943E68F5F; Fri, 2 Jan 2026 18:19: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 VhmjV5Fm1EmH; Fri, 2 Jan 2026 18:19:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403194; bh=eiDSr9isc/174j06kfWMFPK4XAO9P11wq/DFiNf+AsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DBbmbumsb+r17d1Yn8lMAZ5xP4iBMU7xqXvbz5i9CKLCEO2br1DMQqezXJQWcFTgu NWyDRxi7Ag1tft19ljVBqP9mtlk+A4MMkFe3/Er5iSKcKQ9JfMH8wy55NQ4eYDsiY2 oWLaZV+5RlUCVX1wevMpXwe0TX2kXDWbyXAwJpLE5KaGX1gXfx8EEL7GNgu35A0CYb 1UnrjCrGeihSlN+6IEPgXAXQCXLDBKz5C20ntFx4yQ4OslSMre60vTDy9bn4si7N11 U/iIrxRUh0XpjkeemUqqp0NeW8odhhbbcwJOWvfn49ueXy+3N7ouMWCW8jj5uqCiGP 1um2vXvKRsF0A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E8B1F68FAF; Fri, 2 Jan 2026 18:19:53 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:44 -0700 Message-ID: <20260103011908.149445-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JLOFB5DBOJWFCWIWNIXB5XFWXE2XYWPM X-Message-ID-Hash: JLOFB5DBOJWFCWIWNIXB5XFWXE2XYWPM 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 08/24] 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 --- 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 3e02c48d399..698fe0e4caf 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 01:18: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: 1203 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=1767403205; bh=pKDBLO6d6D1pW+g5tPSOsw0BWcSnlkDZRGDWpdWZk28=; 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=W3sYEJxIKFgHpXE9ffAHpPZIQB4e9qYckxcC291tqndh2hcAkZreBm5UauSddHuFY gJoXvZUeD9lhIiGorzMXDrim61EERPMN6oUi41QRpkCpf4UN8I4ITqbe799u3yzQ0U r2hdpHvhUzwIUZ9iOT3ldWBz9gJp5Ip0ULTVSXWgYgQptf+xPnP8zjcUnsXFwSh0Nd vLv7fKCPZ6jlCbWL4XcXe107mZZm0B36i0TzFitbalkLoHOT6EmhXXH/DyKPGLcMU0 RzD+bHCvmmmUG+VE8H70WMWgTQleDfnSyvDFWMx/Akfk9By5+8j0j+BdoMNhNdMqNJ y3H/jQ/j5hi2A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 695346904E for ; Fri, 2 Jan 2026 18:20: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 C96vVAtIndDN for ; Fri, 2 Jan 2026 18:20:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403205; bh=pKDBLO6d6D1pW+g5tPSOsw0BWcSnlkDZRGDWpdWZk28=; 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=W3sYEJxIKFgHpXE9ffAHpPZIQB4e9qYckxcC291tqndh2hcAkZreBm5UauSddHuFY gJoXvZUeD9lhIiGorzMXDrim61EERPMN6oUi41QRpkCpf4UN8I4ITqbe799u3yzQ0U r2hdpHvhUzwIUZ9iOT3ldWBz9gJp5Ip0ULTVSXWgYgQptf+xPnP8zjcUnsXFwSh0Nd vLv7fKCPZ6jlCbWL4XcXe107mZZm0B36i0TzFitbalkLoHOT6EmhXXH/DyKPGLcMU0 RzD+bHCvmmmUG+VE8H70WMWgTQleDfnSyvDFWMx/Akfk9By5+8j0j+BdoMNhNdMqNJ y3H/jQ/j5hi2A== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 575E26904D for ; Fri, 2 Jan 2026 18:20:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403203; bh=BYifcV5kneS6uaXjSuAn8a2p1VJq2PzPnhqbOmu85dw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s61QLLx85Ae+EEY8433yZG8j37/srfJyHLOBpPVZXe+Y2itrD5ULRRd4HxukfE6qF 91cOdDL3WXrLwvxZn95HK+Ep+/T34BaH+pRprnz8XZh+QbvtNaBXOcgnaiKOuOoiso d8U2HKdKCJJ4uw2YxETh7blIEU6WdPotyAOuWos2qzb9OPOV+74IJv7Rmqt/oxiGvY zvLcgscpaw6bjmkdNTann1L+zGjoCI2QTK0SwYeoP8eUv34ab2ZZ/JX9lR2CAgaVaC grkVEQm5x+wEKOPxesrq97scZswwOHz+2zhu/khwWO4eBVKlNYjtL/1zf1x9bDRQMv TLLRiQM5DiLBg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 423016905F; Fri, 2 Jan 2026 18:20: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 BluL_mFrrhBc; Fri, 2 Jan 2026 18:20:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403198; bh=7hBL7g8i3CnyrVWRdISzsZHemVYftj13opWk5BrvNYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OkdNWPW9qLeCYb0Fl+pdyvlbs/fKtrtvSyIneUEFRI/sRjHtZS+5E7Xg0TacJCmur OqzBx1w4I6iSzrNKkCwQ+SV1B1kCLT6K70320tWUUdipWdIRG6FJ4D9Zo4MOqSKnIu /yPTqY5hkhDhkXIemx3BxmkyajE396a2hu34zRKVwdNWpsGLk+qWPeXUbumt25YCdR 0ivgMoaFLi1Wz4/SKiXZu7QU2BddiQL1Xj7hpNkBj7aDtUXzxEMXllehHuaF+s05KR NkPlHsOk3c/gESGXIpS0PG1q2X/lvt4+x+II5Lb8mXnO4sJIr7M53R0T0uWXoFuaxw 703ua7nWj7JAA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8EEF568BF2; Fri, 2 Jan 2026 18:19:58 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:45 -0700 Message-ID: <20260103011908.149445-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WM7JQWNGCNH4PVBKIOLNSVQL3IW3B6OG X-Message-ID-Hash: WM7JQWNGCNH4PVBKIOLNSVQL3IW3B6OG 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 09/24] 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 --- 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 01:18: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: 1204 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=1767403207; bh=iKXmQANeHRPwbSDUfjYMce1BWtzq3G5tgIr/sWwGFmY=; 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=shkTaLZ16CUrllLIcN47e3u2MJidyqzkQVBmsNB1+gIN5Bbu2sk3MWkUnk4eJL6H1 oJpKWRzFUU8c5qn3GRa7jwG7FPCn6XaP3OgWs0rSHmKKWf5z4lLrPFCWRC9DbCBdf6 YqN0rbYGrRxZaf1LIqAr/3CL71YH0/+c9miQu7v2Q5TNXvR59oLd+bjal37JNObrP3 YkVZArDCH6JitkhO4kUH3F0EswiksPUM+M0rDsng9WH1S8qQEMplVaK3lu+rxUleIq 9NnZjoBwzwegrQ9h0jf0HojTiTKEhXSQuMnHLj5Ki0+xJu5FNwqUV01mliLetuTVwV aI+Eu53xsgzxg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DBA996904D for ; Fri, 2 Jan 2026 18:20:07 -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 y-wwrKivomNB for ; Fri, 2 Jan 2026 18:20:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403206; bh=iKXmQANeHRPwbSDUfjYMce1BWtzq3G5tgIr/sWwGFmY=; 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=wTYFF3og48h7Q+nKiFsh4OiDQGRFF9tLHWh9kld6zfxHkfVeP1Qk1CFQVtPyh4/uW U7x3WwtEawbXTSfwd5fNyls3IcPY/nHWMaNnwJNI5V8tjYeW4JcRL2Lyu83waNDPSD oRsBc4ztDEmXUXQHi4+h5KtJ2mIsIjDzthjDN7b3tqtEc/tV63sZDgZJC4yy53CIrk MqZyiMaaUBy/t8012edWgF5tCeopZUpnyT5evTe3JL3b1eLNz0NHi5clPhiJ/gZFkl lk5Q8O6fU/Pt8bUCOnbXRVpOmTor7+TOalBRr/bktdM0zAaPkPWzQt1B4N5AjKdHJM jNqAOyVIIFOww== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1D3CE6905F for ; Fri, 2 Jan 2026 18:20:06 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403203; bh=AH4TZ6c1H3r8wV0mfZyAz8f2nQSOtNnw8T3CPAU93rI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bo9VDtOV3+utq7IjtcTadYu0D4PjVe/YsxvB7y6dTIXt5cSPZuUHmjqEUY9CKe6na DfOJokkR6w9/0WtT+lqhTZ5/2BWY9MFYLEK7+6Hf5ZcKChPinge1Atm46zrlEkZaoL zSwPRqzeLNNtL8beC5EfgE/klXPEMRschYF2qlzKsdPtcxdOCsjUlqg69cEMSmwuG0 AJb2BUqX6Hl0fGgmgX9ZIWDKrtl01p3nQwQdhR+dobsT1fRhnE3BIeC4AziC+8HYLl YVjB4i8oJE6ZTD/7qSB/YvfTEhwn97feeWeHMppZ3cF/NM6Eeb/D0Z8av1PTxDmMMJ OdpvU94VWXlXg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8873068FAF; Fri, 2 Jan 2026 18:20: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 pKdEK7dojp02; Fri, 2 Jan 2026 18:20:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403203; bh=Wj6J0bXupqRbdl1lIk7JxQc+h2aEzeFcbEFHepBAub4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nZOx6dg4NP2ae0bG9hIAVUKvJXt/ZA1dIegD8krJpzfQdkk6lcEBKUyJgIeSWBxNx 4TFM0TIknQWJ5qpzBlN0L1mfOWbxfD0d4tBuy+NlZL/A8I1/6HgucqOiFGfCRwreoE 409yYHbSpwhjw/9eal4musyhFcTuy+OoUqd61YowodI5a2yGX7e9FnIXvlLhw5wspk O9/1Yhlcxo/ULZDMvi2+6RVKZTSPSVMFhUZpluNJz3GNKQn9mMwbmkwAyvYo/l6y9P 6q072OXgO5V++HCiY6xL4u6BUdqZZsM4QxTi0hFEchBTbJS0bZLfX+wYZTjA5eCMXp uBTpzi3tN2Xfw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0143768F5F; Fri, 2 Jan 2026 18:20:02 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:46 -0700 Message-ID: <20260103011908.149445-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GNMUPEUQ5FWJJJA4PLDB37XLKLZKU3XB X-Message-ID-Hash: GNMUPEUQ5FWJJJA4PLDB37XLKLZKU3XB 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 10/24] sandbox: Increase CONFIG_MCHECK_CALLER_LEN to 80 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 80 to handle this. Signed-off-by: Simon Glass --- 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 01:18: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: 1205 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=1767403212; bh=We7uXnITjy38nZUN4W91aVJwCXPs9r15sAZWwXeOPUQ=; 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=wb/+gzfzjMTw0uht0VG3TLNkOZ82avITkCR4nc/0PVSuuPtpNSUlIptj/jNx39ysm cDQ8uJ1t+ZfqXLtQ5iOjYvr0smxS9yR42HiQWozCpiVprPwjZEtne+NlJiTekmkieh h/zCPGnRlew/koNpKJ1bSvtMewrvlcF/KW0ygAL3sjWEJqf9BWUO2jBt6aevy+AKjC Ozl2JiiFqY2Mk2rDq2GbVp4PnBfcKgg6rfCwwYmsMmHBHwUc1Juav2Y8DGA3IOwLbM KS2tmxX/JyTdcXDKuI4eBLTWt1zbxYmdW2ytAI9gS4F8641+sEr+2KWgXbt8yILbYG 0JopU9worgZjQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 15EFF6904E for ; Fri, 2 Jan 2026 18:20:12 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id D6sbwtM5FmDw for ; Fri, 2 Jan 2026 18:20:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403212; bh=We7uXnITjy38nZUN4W91aVJwCXPs9r15sAZWwXeOPUQ=; 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=wb/+gzfzjMTw0uht0VG3TLNkOZ82avITkCR4nc/0PVSuuPtpNSUlIptj/jNx39ysm cDQ8uJ1t+ZfqXLtQ5iOjYvr0smxS9yR42HiQWozCpiVprPwjZEtne+NlJiTekmkieh h/zCPGnRlew/koNpKJ1bSvtMewrvlcF/KW0ygAL3sjWEJqf9BWUO2jBt6aevy+AKjC Ozl2JiiFqY2Mk2rDq2GbVp4PnBfcKgg6rfCwwYmsMmHBHwUc1Juav2Y8DGA3IOwLbM KS2tmxX/JyTdcXDKuI4eBLTWt1zbxYmdW2ytAI9gS4F8641+sEr+2KWgXbt8yILbYG 0JopU9worgZjQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 042FB6904D for ; Fri, 2 Jan 2026 18:20:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403210; bh=//HNZAvV12GZMTqnLU5++m4bipEn6OC5J0Bc/0dvQAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dm42qvj4xeZaCYxTRs+MXkR4rwS5Igv6/k8cJ5aotb4+WBEUxJ+Nb1eLlLxRb1afL sscCu8WshrgZZn+7wSDgUxIkgjSDLctPNSeTmYcDtT3qNst1G4c6ng/XF1ShKHMqBu 9KKDvWye5bVjfMDL4HcUJ+tCo3BLZ/RBIlFl7u6bFc7NcNoDPBGYJ8/QfmD21jRfoR E6IrRIBN3XnGFqqxNAxwLEMdYutDwnc0jbw8QLxCEKk2gYFW1exh+Hx7nC77y32lvZ GfpCaY60U16xJcfw8uZ+CkUreBQe998pGRy0Ux1rOBfKqusntv3ccJeFICx8lK57jI YcPc4wvgZEaJg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2AADB6904E; Fri, 2 Jan 2026 18:20:10 -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 PuhWCVvWk-BU; Fri, 2 Jan 2026 18:20:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403204; bh=TwTGG0+cfGMpqQzDLEIE8kJ0Pe+f1e6Se8GmIn/sFls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MsKCYiCwG+/na9BaKSMos4TtPTRSszip76J86CKesh1VabpKBpjcB8uzazlt2y7Wx 9pCbdBpFOOIuDejmdAVXM702lBpPfXHQD4HKIQwN6+8+vO4XFipOLbSEFHqfe1sb27 MD62/oQCcbRfcOqX5YSXLmcQ0MwmOcrv13QkB5a7nO2apLNSVc620FtZ4cD+nVP5S6 QENvbHHw77NjfRh09kecDZHrIO1NXjdTicgVNl9rAvNy1T7wroGBH4kL39lMZQmxsm K6bWFa61YCRrmk/Aeb94V9H0cvHodgku4BKZh3fhOmEN8b5wotqrg3K7KpvPogzpax 9G6GAMwJ4YQHQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id C82FE68BF2; Fri, 2 Jan 2026 18:20:03 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:47 -0700 Message-ID: <20260103011908.149445-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: CJWU2ALKBGXVTFTHCYAYX3XJ6QZ6TFDR X-Message-ID-Hash: CJWU2ALKBGXVTFTHCYAYX3XJ6QZ6TFDR 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 11/24] 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 --- 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 01:18: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: 1206 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=1767403214; bh=e40qGDU32VOmSCPOxM08N/gYNwycYkXN1lFU4GROPpQ=; 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=NApe4R9pjK+UJ0thdBQHhxCcHpLYe4pjumo3S2RSwN52Mt1pOPdJ0jarAlBXJ6NjO A+9o8TYwKvYd9B8ylGbgp+tbh5Q+M4pSc2G4URZqehbJff07eA0JySMVYby0afEM/N XzxjY1MY5H2raDoibnyaWgH0QxRuerWlIl0SVXOqf4D5o4rqjgJ/g8U4NKS4FweG9F J6vKmQJOjb2oyU4xjDnqu8Vdf9i3MyFrp/r8es+ngtdw5iz4JEdrwEW0xv/qPk1E1u Wvg2QbjdshMeEaAS1fecqldVROy7SxcoQGW2zNOjdBIAV4o9YTZbW65qdsiD+eI4fe JhVCP/NNaRr+A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9800069068 for ; Fri, 2 Jan 2026 18:20: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 H_fvjI6I1Ga2 for ; Fri, 2 Jan 2026 18:20:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403212; bh=e40qGDU32VOmSCPOxM08N/gYNwycYkXN1lFU4GROPpQ=; 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=irh9co4NXKq+uInHsm/guLsaaSJ8VLwxUhDcG1DNJAM73RKnrS2+qEidGuFaUSFsW SHPogbVbdj2cI+bfsW23TAnG4SSgXJ6A0uyFl04dNAfIeJcPlEyjQuCoOJd3pSlZNS /U5ZTtN/JSpDW1HQ8lopHeZgwcjEyGgUqIP2uML11uVst4z18v2rODUZn+gQSV1Jny ZlOPNl4c6YPqcZyLYmuCTkpFf4ZJT1RDco8aeTDaQI/Ujphu8CqYFTcj4B1gTg6pNF iIuSVXQvBL102mcAGwgvKeNKraexzw2KBRmS3vE9xokQsx8ldKxDsm/WILPyuYYcIg 9yshHfS8lSlAg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 93DE168F87 for ; Fri, 2 Jan 2026 18:20:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403210; bh=gwCbcsVw9G7esfHYN/MqIGimB1/Hi7OFUtQK1XEFyJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B5hubAKSlEfZqQ6miQHy+n231opQefluINzysgVY+QEx8q+gqvuWL99wcw13yzCJc 5CPrYqIX77W1DCA1AXggVUOhVu7b5+TiYxh+1H5hzNo6NIdvq95J9X/penl2sucv06 qsDwq4xNSaoTOYZ5WlFwydmEVpb8f2aY8C101MRBaS9+gUvLqNlWUV1d7Rj0tMacXO BQDfeGDnIYMCTAc5NsCVc7fnutq3pWcC1BCVoYV2p62Oejd0dqLh3/kF59XshicesY nDs1P0twwf64JBu9mMrB44YWtILyy8BUUqV6EYVpY2vcCdiycJAREEaRlEFCIY8bn6 rv2YBILDmGybg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3360068BF2; Fri, 2 Jan 2026 18:20:10 -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 7BJGmkjjIqX7; Fri, 2 Jan 2026 18:20:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403208; bh=edaM7C2i2qY7W/LJ6/ny/n+zNVmtpU5X0U3aW1mCxiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h9HuV4pA6BhvBTqpZXG5yc41QHqoVtdPyqv0BcEeKE0190+YP2QBXEVvLygg3djIU GJwM6/DTw6JmEkAuuTVtvuaxaVYfJqqY+ucOOQz0j833MKRufSmF9weAtcKGD6ea3V MqLZWaA4UtZoTUV+2IgSfO9lcSUm0HptEa/RjObrDZSDeNkiMAhchsX2189tCYx5Sk 0KcINHtc3sJD+qqiYeIvtlL/X/vxct9XGaP8TztnPEEQaNB1L6Qe8BjjUahQH4LqDV hmvamMx6B2RR/xq0rn1ASXdIjm/lnIWrH21SKSOMJOVelmBwgqMZmc2eIn2ESLuWIG nBcX8p+zHYldA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 7A1B368FAF; Fri, 2 Jan 2026 18:20:08 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:48 -0700 Message-ID: <20260103011908.149445-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: YUELRGBBKNCTT3WP65ZVI2H7RQ4EW6NR X-Message-ID-Hash: YUELRGBBKNCTT3WP65ZVI2H7RQ4EW6NR 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 12/24] 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 --- 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 01:18: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: 1207 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=1767403214; bh=BaApWjLu307s29Uuu2tgRNhD9JwqdCa/rAPqMz3+GCw=; 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=G/aqk7LQExdr4sZJR8r+bR3vZ203F/nf6C3eCTRJZ+0gEWGVDFDJQAW7To3dHuaxR s1gBjIqBqxGUQLuQmTuCo+WyWP5QSgyU0tHwZdaUx0CY6t14HacRAPxgEI8wir31G6 PFWn8Mc1jjPFHrufuw2lnvrS8E6eCaRbFbPGWGcyRpLQU1Btz8mgp9HWxm+nfTbrI9 ndBeo99sidOxYIffYyUtqmOF4vMOJ/cLJIMVzsyfkgQSvghO+juSrArAqhp7jNorR9 qYCCgFiSJPbWYQxLbiKEtRPRTvZLnLuuf2E9RFj5O1Eoc/vujJ3N7wb7uCgbQ8s88+ ZcTrYrNtA2SyA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DB6F26904E for ; Fri, 2 Jan 2026 18:20: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 6gNk1LdOMuj7 for ; Fri, 2 Jan 2026 18:20:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403213; bh=BaApWjLu307s29Uuu2tgRNhD9JwqdCa/rAPqMz3+GCw=; 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=u4dtuqlKqlBlJ9/dv8vyJZew/Hj8eU+2yzfr94m4CxxOOF74RQjUgWfaXcGPmcKAO pTzlMJJmZgfMtU2GtWQLVMsyjhgt8meq9FbBMa4vQpCE5P5KMl8u1zFPV8KtqZpyoN SSe0ztOBtUxugaD94KKJR8403Lzsf++F+wWCWotO3csPFF6U+9LPmYIK0IzKayXrb3 M+Kc6VW6n/CSPjhQnbdTCtSC68Gh4aumqESb1eb/2m8n+iinGS4b+r/xBtQIU3ji/X La12IytYi9HYc33+wr70HX1LDzOj+Hzjrq2psXuHllt44VIAqbYuvF7td1Kej4gc20 X2NH8RbDYAzgQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0D9A369071 for ; Fri, 2 Jan 2026 18:20:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403210; bh=P4Y0tTrXgPITjloJZZloNOam382g/KZpTIFsbHAYlTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e9/26b2jaGWkVZPADgrwLhZoMz+0PmKmys4W9iJxB2knvGmMeACYMiyvIIacpjrIR YNslLSw8HLNd83AA28iVsIde3Jqea7VBCR5iYv/Rb5y3L3J3P+7j6B1xKsprcvCpQY l3gV3FSHClCHIthlft/bPfXkSvRsBe3EQ3DomEch8kbwjNriWxuG1epqmCxnIGwyd7 8Ji0WLloJEAv0LQTxAB3S5dSykxZ1cyiwVtmfTahimwhvREdvg3ipPbF9c2JCm/0dz 8JBknZjhfW9F5bbW+HPtqJVdzE1DAulLcBmv/m4UBDa9iDCD4V9Ir/dY6Q1+iL73Xn TdApXt6DbKRDg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 54F8C68F87; Fri, 2 Jan 2026 18:20:10 -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 mlN9v8KMyj9t; Fri, 2 Jan 2026 18:20:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403209; bh=JgpTyvuEqkeFxIIO4tscvqA/0gAZdgsmta/u2aOiOEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MVu41J24rQc9kNOa+wbOvfMNGePbSycnl8Nv+UdB3mdbJTXDj6qoQcz9QzBpPhGQv 9zUauDXoKftRQqJk5rgqfhG3bozOzp2BRZonWplIQHZqa9g1U2iHq1QKLYnq9hAYV/ znwpGslik2jOODQ2DJrNmiI5RUwEbgNR5TCfyOCO9DscW5HRPTQHsWGfn25XnsJ4SS LbPTcxBi0p6usIqSOuX7ozwbydU4A0coH6ZlP8EOp/b/dIY+0K8n13O8CasMuLdiiG tZUyLMG4IBN9//qJC49XEH2WEGQSCh2wqE5bLk7N43wrmffXrcw8n2cego3+cdFhGG G5zgzcgCMuRfQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 926BE6904D; Fri, 2 Jan 2026 18:20:09 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:49 -0700 Message-ID: <20260103011908.149445-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: SMFT5P5TGVT2RQWOLZDVG6YQSYRUERVO X-Message-ID-Hash: SMFT5P5TGVT2RQWOLZDVG6YQSYRUERVO 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 13/24] 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 --- common/dlmalloc.c | 69 ++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 71f81aeaec7..63792104ee3 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, ...) + __attribute__((format(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 01:18: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: 1208 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=1767403218; bh=u08fOxthOiIwxVaswWgojBN7ArUHmPWmJY2oKsGAw74=; 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=dB3utvvkNlFkOXlsoTBi5LY+4930hGjincEfmlur6bNVZookzBw0LGbM85pdvLVH1 18HmcpNyIy3ycIx9lI9Cqn6hhTE+MljCATyLDoMrD08+M6QomNJNuyzBq49F8jpm0o wulSES7sWFHA4XHlZYNYkcyDvqHEEiSj0gjskZRIaAPBNe8Agy8oONvhRovdpkK10b sDKoWFUhrZcfJ8DRQphcWhEZZ+7QezVUXh5l47cYyy6NYvMfyDa1OI2AmmQCLdLyMK cWrRTkTM0TFTAOtpugaStxU9CJV5WwDZuAbVQcWJ75MUamHDFMohTGzADMRo0zmgpl qoAENzcH45PTA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8E6126905F for ; Fri, 2 Jan 2026 18:20: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 10024) with ESMTP id RwMNtsjyfTlY for ; Fri, 2 Jan 2026 18:20:18 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403218; bh=u08fOxthOiIwxVaswWgojBN7ArUHmPWmJY2oKsGAw74=; 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=dB3utvvkNlFkOXlsoTBi5LY+4930hGjincEfmlur6bNVZookzBw0LGbM85pdvLVH1 18HmcpNyIy3ycIx9lI9Cqn6hhTE+MljCATyLDoMrD08+M6QomNJNuyzBq49F8jpm0o wulSES7sWFHA4XHlZYNYkcyDvqHEEiSj0gjskZRIaAPBNe8Agy8oONvhRovdpkK10b sDKoWFUhrZcfJ8DRQphcWhEZZ+7QezVUXh5l47cYyy6NYvMfyDa1OI2AmmQCLdLyMK cWrRTkTM0TFTAOtpugaStxU9CJV5WwDZuAbVQcWJ75MUamHDFMohTGzADMRo0zmgpl qoAENzcH45PTA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7E7566904D for ; Fri, 2 Jan 2026 18:20:18 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403217; bh=OOVK/KdSfKAM4DT3J9IRUvGGtXqJQHdF/Nobt1ArJHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=caBUTQ5UZRLAJfPclWpRM5R4mDTYfLr9WbbPqpKOYLVn8RlYLjQ+RzPYt8l8Ocpk4 PgP8CoAVx+umccSzk07EmWt+PLZBmutBNEZQufcZpQWuJBE/YlqDzkQgbBU5jSUYRM 9OFFlabl7XgL8aMkvtAF7ttFaHfkJQj+6msR4U9Q5Espm6kv72rZbIZbLvxKJaJB5G SxtIzG46Xz/XoXjhQf4KgpcmpBrJwTJt/rnHxjMM1wfB8FxJ/xmLgYLNnxWDcO/VOa DRhs2JGBjU5ewl+UujeaLitb5WLP7Ixfg3fuGJi2sy+X/rimsiOKEIjqpkNA8xaDC7 YxgCJr4CzPJZw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2628968F87; Fri, 2 Jan 2026 18:20: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 TX473HXdOn9x; Fri, 2 Jan 2026 18:20:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403211; bh=RrS2eCcIvvl8L9IeCAcz9a0sLSTdCP/+33ICiEag5+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pMtSGKlU5RINBVgBR0evmsymprgA8irtdBAm1HrLcMmjYNxRs5QQqiivyKSc8t0n0 puawt3lMdRsBVAVVg+tk7yANio9+053U2nmh8fj912yBHDyCEAFJH28XyZW6mn7efw EVARzJQ/PAr2DyxuEYFPwQO9cSBpnvH3LoY33+JhhPUugu3WH3/55I/wOBhuXNCGf6 KlnfTTS3oLNJZDrLnB44sCdy8CU2FEeCBcUNyKb4WWXhEPERSXXEVa7Nv4te6bYvLa rASowQDC579S6z22zID8c8E/tmfPdN1lVDtea+tOG5biyyFLP64Xw1C5p2rKGc61KQ QhORoZFn2RNng== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9717468FAF; Fri, 2 Jan 2026 18:20:10 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:50 -0700 Message-ID: <20260103011908.149445-15-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: P7A44PSGJ5N2DMF42SNZSTU6ETEN3GTM X-Message-ID-Hash: P7A44PSGJ5N2DMF42SNZSTU6ETEN3GTM 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 14/24] 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 --- Kconfig | 22 +++++ common/dlmalloc.c | 198 ++++++++++++++++++++++++++++++++++++++--- doc/develop/malloc.rst | 14 +++ include/malloc.h | 72 +++++++++++++++ test/common/malloc.c | 56 ++++++++++++ 5 files changed, 350 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 63792104ee3..bf60e3004d4 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..4e5bd68c013 100644 --- a/test/common/malloc.c +++ b/test/common/malloc.c @@ -637,3 +637,59 @@ 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; + + /* Should fail before log is started */ + ut_asserteq(-ENOENT, malloc_log_info(&info)); + ut_asserteq(-ENOENT, malloc_log_entry(0, &entry)); + + 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 01:18: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: 1209 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=1767403223; bh=zLZjOjRN/yzZEVDba2aCj3ZP/tEhnPoIb3ggZAFpcNg=; 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=fyoZaPoLRTq4PH1Pe2goXar7ypMWSqiAm6qUkUXqczIaMpYbOKtcaqfGQuDtXyv0P MnCYFE64rFvZZdgXpruS5ZLsv8K2TxQXVDH/2Mo7uuB2GXBIPrHJcbspEKD1iNHtbT pK4n3pt6hkNvUjf7V+M63hMl9CuWdSlp8FD+hEfFA8gbcWl5LfjvLJugSsvKJwtiKU O9e/5NReHKntqg9UZicc6dS9a850J8u3rPqrMIVggCsNgkpji/7yyGUTRR2p24z3Eq Hzt7L3qI+vQbgeeRa62nas+0gdWO5ax0SlxPV0BdassDfcSidd2plnffO27HkrACRY 0VU6HGHXcVMdA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4BDA56904E for ; Fri, 2 Jan 2026 18:20: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 nWjZz_pu_7-R for ; Fri, 2 Jan 2026 18:20:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403223; bh=zLZjOjRN/yzZEVDba2aCj3ZP/tEhnPoIb3ggZAFpcNg=; 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=fyoZaPoLRTq4PH1Pe2goXar7ypMWSqiAm6qUkUXqczIaMpYbOKtcaqfGQuDtXyv0P MnCYFE64rFvZZdgXpruS5ZLsv8K2TxQXVDH/2Mo7uuB2GXBIPrHJcbspEKD1iNHtbT pK4n3pt6hkNvUjf7V+M63hMl9CuWdSlp8FD+hEfFA8gbcWl5LfjvLJugSsvKJwtiKU O9e/5NReHKntqg9UZicc6dS9a850J8u3rPqrMIVggCsNgkpji/7yyGUTRR2p24z3Eq Hzt7L3qI+vQbgeeRa62nas+0gdWO5ax0SlxPV0BdassDfcSidd2plnffO27HkrACRY 0VU6HGHXcVMdA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3749E68FAF for ; Fri, 2 Jan 2026 18:20:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403220; bh=6VtzEXBH8ifkaymgVQ+DmSz3ChsPT8iSMkuHH5ZdMmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oOZkTqnZAvp69OLdE+tYgIDkPHt7eN3wf67/neptra7+Rncgaql+aVEpgQJx0+8Ky ev9evAuYYokf/dweFZi/JfRDILw87rDsLLHakJYT2XPaMlWZ1stXfz3IFRsGuwzNUo yjPfz5PadYYcQQHzbcotEutgacj8PQU1xEPRpC2/WFGj4KVUlLvAdNy24hzkyl9nfO XycOW4+4naOiCFQR6BlP9kbjJrkLhpDth/uoX7snLY10unajEzfGBQUbPU0Em7JHBf cSz9gQe0GH+BdpmudjvOx6Gfl2WEYDu16q/PEEiI4lC6gpI4bM5K0lP5NgL6KbnJ4V 4UqThDlLke02g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EA52268FAF; Fri, 2 Jan 2026 18:20: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 10026) with ESMTP id 00wYNfqBvEEW; Fri, 2 Jan 2026 18:20:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403215; bh=yE/I1APmoZb3E+/Frl9Ot4Olog9PMwTMhbiEB8iiMaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BAAqq4v2tNfQWw9OP5u3CkCUBFI1NH6QbqzscaS8oHJcgH/FPMP930PG7DOZO1SSP kUFyPdINvbdeIOZYpRt4VzaR3iIP9pmwcqSS2wJonSlvb/a11cdHb6O+tiEzoJbYWo eMQ02hK/MH7jsZs+2WPyGTjd8PkGiJTqXIKuXBvBEyayh9DjWsYh/N2qTCFpIMhZWI MDC3sTDOlqVXs31OtSlVuju8RJ2deXJpkv1TJvF+VQ0tT6H15Of6ga5V1LNQ3I0pHq YfpylWPOb0JdUGyKj5vf1Yp612LPYfuI0pPXtSMyB+Lb+YCpI5cp+X/Kw5SZq0zOsT +0AP1nUqzaKOw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6003B68BF2; Fri, 2 Jan 2026 18:20:15 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:51 -0700 Message-ID: <20260103011908.149445-16-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GFILVHXKXBKSDDGXBZMMQSEWDEILI6MM X-Message-ID-Hash: GFILVHXKXBKSDDGXBZMMQSEWDEILI6MM 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 15/24] 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 --- 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 bf60e3004d4..6f10a980d6e 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, ...) + __attribute__((format(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 4e5bd68c013..d29e9364b01 100644 --- a/test/common/malloc.c +++ b/test/common/malloc.c @@ -692,4 +692,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 01:18: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: 1210 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=1767403225; bh=Nq1isjIJobKlOGekEtvdfbNh4ovJWyLsqmd9vTCWd6U=; 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=EWQX2RA5i6G60X3POq3PbZgG3bYHVMdobtvFdGxykXSI953i07qq/1io6WTdH4uQ6 Nb05pDwMB7sZBTxF9jU8uwCebMYNwhXCfc3estRTloii7/HxvMyXpI1UBEoUmlecDb y9NJesi0jTGT0zGXuj3hgtmiRFk0CFvE9rhep8+K8kC2HfgsB1hsRZbIa+F63nVOPz o6H9x398lh0nmjyW70MM+qVsRRsS6DY2yv47xLXUCL82AUuGBP+zVzAbs9YFV8HvHB kGL+bCBI3UmQU+8MdMv3nEdO2iAtjsdSV2C/eJKbmRx6CatFovNIf2sS21BJ+diy/R W3waaVUJJAFdw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C206669060 for ; Fri, 2 Jan 2026 18:20:25 -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 K-GZ5ogHWQ30 for ; Fri, 2 Jan 2026 18:20:25 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403223; bh=Nq1isjIJobKlOGekEtvdfbNh4ovJWyLsqmd9vTCWd6U=; 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=KBL3xg23tl+SZzMg0FseoPoR2X/NawhQtQTOsPqA4Ku0lSVeBLqIrTRXk0xRiXB9s xsDV6wb2/JNRODsLyXDII+36y/FAOKqtfpJwFkbukCTzhR45T4lEvFs4Hj/1tWUuIO /RggoRGSxLN+dRrJH+bkmDxXIPbBysNjt/OC5G5vxUH2eNGPsmSKOThM5QV5tC6Ibp 8mj0wi90/L4fm/uiOojmTTPk5/dABnGQ9up6QS/tqtETxCOQlqlKMISM0/QOCBwSj+ nHog6kJMipyv/7Tq/s/oAvzw0tTbw4VTbpzmMynm3WD+xyFUK/xF4y6vGtwHjyIMDe GFgqRXfVycYwg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B9C9368F8A for ; Fri, 2 Jan 2026 18:20:23 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403220; bh=efrJPHlOS3zUYoCR4UKeiJjefdN3ajNjkr4ABufB4fI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2lqfzH8UTpaVdghNnD4l0bqzRrqnloemMqU1MCi02/1OwuRbK9FVsnbQ4Vst5FZB VTEoabmau3gg0dz5Jq6GrYm0UsXj0giH51f2UeMNN/cU/nPCGshQrwdnxDtOd9GNjb twqV/efL1sNX1pBysDaXiYEFE78bgJTlLGhuTTYLTu0w9c9mR/cAPyI5iKddhpBcXi 8QGeTna1WmWfk5qRcU+Fgur0z8KPac824ytQzsi81JivkCDLZU784ctNHmCU+T9MgP ESyu+g1egA+v9yU+buSvGsdfW3VBpv151z3Fh8PUwO2W57m6Fzn3EODzFNXT80pxuO 3KWtMJBspc5iQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EA53D6904D; Fri, 2 Jan 2026 18:20: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 10026) with ESMTP id NaJkKlxMYDYu; Fri, 2 Jan 2026 18:20:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403220; bh=TpG1pb+SMgwtS/fo/mXplpwcbPed0UkD0nMumx1MK4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qjFQRltOfMZS/uaqeLEo01X1CFl/BxNQcsrrPUpyVHZoizrntnkihT5y91HDOMSlo BmvTwgAlX7kKoQMJoBDTwdx+rXlX30VUrVS4qGKwT8iJk5zKakbywSocewVnZJK3lH WxMpEhlc6iSGbfw7H5pOJjvMS1AVstRVEuD6Sx1QRWSwkUock8BI5zgu6N2x/Y/DuM JccrzDP3aHWkMdZJONARSuDkqTfdRTvNR5q135zNTtLFjf043HizZQ5NOzshaQZ7ee glRDxnVI0nf0VhX4GpMVv5ay9hrI9nXlY6eHcwirhfPG2Vp7f52RLlP1CIi6AMfXMe syyYtiVjBkDaQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 07A4868F87; Fri, 2 Jan 2026 18:20:19 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:52 -0700 Message-ID: <20260103011908.149445-17-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5M2VDKMDXVBD5MCP54DYCRHLD7RBJDS6 X-Message-ID-Hash: 5M2VDKMDXVBD5MCP54DYCRHLD7RBJDS6 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 16/24] 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 --- 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 01:18: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: 1211 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=1767403226; bh=bxMLNlKbRAcG3Tf23pRpe7O7bVtxtpUl40DPQ3HlxZI=; 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=JGTqVLFUNf7B93DGbp2NL/RsDWJevNBPW6zmqNEKy7HttDTTFbPE439q9ptn1aJ7w 79vnbOx2o4OJDyieyTgYYXfp5B7eqjKv2u+gb9mDqPg4PBYiTlEI3EYXHtCQY3Skpq rOPdACXBPycwy0DeHc2z2y1QTRFqrMVYyIW2qbwm3mcgDGWHrOZYJ0E4A60sugLvpd qMkkFs455LBT1K8ihXLmnXjepjBwWhnxCMJzY+ddKT62Kp1joAR0hJkDA3k3fQb7XZ bo/hCocJNUOTvot26WswkYwTwXtgSNHzjZrklFGjT1dtADz2obXHE9WE1UnOp/uIYw 01ylVjm+dy/BA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0D18E6904E for ; Fri, 2 Jan 2026 18:20: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 10024) with ESMTP id Q4QfNYH1c26b for ; Fri, 2 Jan 2026 18:20:25 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403224; bh=bxMLNlKbRAcG3Tf23pRpe7O7bVtxtpUl40DPQ3HlxZI=; 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=bn63zBNqJzLOxkYfK1MyUcsJIYB2iTXf6zFOEgDbvHUEKqMfyAxoHeL8sQpczKBJd h4upZ3glNjQCvpZ9xXNPWXnFf4D1y20WSW+qhI6R433wUqwprzS3qhy1kVagc4Mbz/ ip6ygIpCXoCuoZr67U5q4Nx9viir5hRcnIF+RlBcvtSUW/qI0eddKmd8Ntu3jyNwv6 ZtDibnRPt8o+bEcTIcJNzYIjTcgYfLkl6U/0FGe70UDauVapnrymIQL7R2v0tRfU+V O7MIMDouaLTGvpKoyDh4rdTHdqP2hKoa/QK7/h+5PLp6DfjtFcxxzdGnjGU7pA/zxq nZp4CIvkMkw5g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2716D6905F for ; Fri, 2 Jan 2026 18:20:24 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403221; bh=7i4sI/P1X2xIOtLJPNcZZP/96jIIckznubR1cDt9Pl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZGCTV7wuqFpoELnaW302xB5viYbdxenZOAQKIj1j8+84lMiZpOUyvqT9riTcaotgc yCN9zTo7u5T3IRs1ZudK3sNycEoSQ0R7j2u7XCqEQhwwwlypYAGDDkTtZ0TjkgrtqS 3RJRrVJl9Ut9uAQ7PauaOQMHDONQeOaJXv6JE+KKt+y1OEbZKNPe16K6RshiYarhtf OEgmbwPOKiH8uc2LyIn80HJQtnayKSH+btls1FjFXadQdyWWtojk2XDe4JdePTaJwK xbXI88sNW9Z9O3ykhgd+AYdEzviMlmMtwlRziZMxu/Tmr8I9trqm1FQflMJsBlBKLK wNtFEoQDc91vA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9D76B68F87; Fri, 2 Jan 2026 18:20:21 -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 xjRWY1VpitkQ; Fri, 2 Jan 2026 18:20:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403221; bh=VnzNjG7G+XP+LasvX3qNRVApn+29rC3Lpe4EafWuC5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aVcChwnl579G5AgvMq5I8aU3mAElw52NIobQFHnmtRl5FSu57xoLRaDQRjLBbXEVE 6qEC4Oa7fDY5unadhyadCdtihqb1PhRv32Z+tHr933B1Dl3nNbGXosixUJpUqCRIQ+ QHdve5BTgJyrfWObLM79y3eSiHPoQxFfTRepYKusYh3tiD9Hro5LH6wuNWxi15N6XB uns6Woo1VThtJgigrzXTrkbS9CKFzLrE29bktDbNpaphIr/C1ragfdd1RpIhrRI5Gi lBoS7YBxhBJ9Xs1HP7CDHOSRNEAd2dO8x4Q0uvGxAzFWwpEjQud3wMJagjtOF2EBqw 1IUdOA9mwtXwA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0781068BF2; Fri, 2 Jan 2026 18:20:20 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:53 -0700 Message-ID: <20260103011908.149445-18-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: EQQZZN4TNOFDYCWZK6AIOCQMWXYI66QJ X-Message-ID-Hash: EQQZZN4TNOFDYCWZK6AIOCQMWXYI66QJ 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 17/24] 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 --- 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 6f10a980d6e..7f00dea6eb1 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 01:18: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: 1212 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=1767403231; bh=00c+Oocz3FsopmY0dCsTBWfBFZGGQ4JyShK3j/18Xc4=; 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=J4LCBa1hxJLjEogXB9gPvlgd/Wim7qMqGaEetw39i8YdX52mVcWVzA+g5TRGDiWJ8 txB3/+vLaUa3VBjbbOO6jUS1M65wkiTIZXKd7WQ5x8zKV42AGIM5RhQokbDKHdXnle UTP14ItoLa9wXkf2K058JDX0AK+SyjDQe1B+m30k1dEHQyWM8kXbRWDj1tHYgB2WHc jRJZ11OtNYihUKU/FCABI5JMXfRpPMFH1slRC5+1a9bF9/KOxhopMzHBDamGPMrmYy HExdMetKXMc5876svyahUESSJNv5oSK/24V5AeT8eajgey/BasvgTXXA+/hs7+eTlO kCLYwZ/BiFhsg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 08D096904D for ; Fri, 2 Jan 2026 18:20: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 10024) with ESMTP id Eaij997xroKX for ; Fri, 2 Jan 2026 18:20:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403230; bh=00c+Oocz3FsopmY0dCsTBWfBFZGGQ4JyShK3j/18Xc4=; 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=XiWA9K7CmLpQQy/q0tnNyC5ogkHDHik7i+KGurEekbpvEJRjEn1dlCPo/iIGJFJak 9A2bBOtTRyycZgeVzIWrPigC7raxM5aQpGlla0+zaK86nEAkjRhzreDwcbE1r3lGeT vs5il2WkZqVN8p9niS9+qW1BuZiDKQ/zA5S7lT3d51DDfo3XMnWgpGiBxF7yNk/z89 ZX+Iup2iq0xipHnoYs3/S/uLMpM0rjjdSdMsQuL0WygOGv7A6EPAY00gsb7rgTKnc5 c7GfsaLkJsXZWHX6h4vbctTYar2c4cBGgpBN2hjbP7v96+Xk9zAsDTcqk4+sxpGdQP ZS4DYUE5BDBwg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E97BE68BF2 for ; Fri, 2 Jan 2026 18:20:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403228; bh=ylApJgAbi3NyBysty9FVRnTCf+ECaEDVYF7COfJkaeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sCVG6s2rr/MUb2HXjmCxQapPZVvDt5m7YgJ+mA4ON92Eo2VNMTbe2r7VVWrDuT/QJ 5zH3ziqubNMKQcequPoLgELZZxUIc5UGZEYI7/zJ5o0gdXSx6Ndwb88iQDWPtYkWlU S+xSC4f2oxox5voTqbeHXxK6288hCmHrl4iXw2b3nvgS1DlQdkkSuqZR6ZN5XZ3zQk vqn+HdE8W5rE2hsUaEMJGqUCHAePkkUwOzHh/FdFRVehQ9a32ttlzliHSDmBJVIag5 cc37dNaTGWhI4Z6l68vibyiTgLCpnbH8Mvu89D/uCtoS4YFeCff9oeLCiVKZTF+gK4 uXxW8gsxVGgZw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4EF3468FAF; Fri, 2 Jan 2026 18:20:28 -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 486LOFTQcEne; Fri, 2 Jan 2026 18:20:28 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403222; bh=/qqwyzwveVuNUFr33BqNEfepr703XLb2ibLpBwLSY4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vQ7IBFCPVgizcYsgj6Gqv+EqcwUO3mrGbJOmzP3gJcyqGJ+tfxrtIR14GOcDnn4wL HyWQft8yZQH0GfF8tckMscFdGcggEZmBVTEBWrT+WWCEjdCorePMmc8FXMWuNWpMBF CvJbfemAjBk7q076tXDeWXO4LUQ4ddEqIca2/8YK/JPWG+cABXxh/dLytNGxbNRWAR EEK4WDBTDdJ3kYu5e9OsVr7AW80Kdd+NqWEaB3cgXtkNzlxrJxrPcpYhbWWDaDUtxW GtxqL2Dt0/3+nF5JPeITTpzP5UaGvZq5309iRnffw8ns+i6rkQZAR3Y2EgK0tTcgHo v+yeIaGIWdI6w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id DE94468BF2; Fri, 2 Jan 2026 18:20:21 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:54 -0700 Message-ID: <20260103011908.149445-19-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GIXM63UNP25CAY5ZNK3YYKRB7QWEJZYW X-Message-ID-Hash: GIXM63UNP25CAY5ZNK3YYKRB7QWEJZYW 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 18/24] 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 --- common/dlmalloc.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ include/malloc.h | 22 +++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 7f00dea6eb1..e47f3c153a2 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 01:18: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: 1213 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=1767403231; bh=PDW/EwlNaTTPQYQ4454e8PO7J4C9I0rDy4EpsMytRNo=; 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=j2GpZ8HKLPIKRW+O37A1//SQqs6450TlyvOrtygwpMHEJcOx5wGU4Y/eBJD6rA9aR RYAZzx34texsELHYKkE3mRYJLQRxgMxiiU0TEplHna3BqRezplnvv+b2OxiE6TB1W/ 5GIPg4F/fv4J+g6DdfCW5YKM0laupimFroRJE3A2vv+KgQQaSc0ycG88GeH3Xuo5iv frrZwrdbJxhvxbeFQmSGi0Rgody2Eg5tn4Z4R8o9NiVBfUX7xbSThT0qmTpC0qrQjp /hcTK2jUfY5fqJJjli+nrJm7NoYJ8WLdaVH04xdTrHNMByyHE0dxtOg0WQfcdEok5q W/Rs5NTWHVTPA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AC5EB6906F for ; Fri, 2 Jan 2026 18:20: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 10024) with ESMTP id Ql3Q07lrPQeG for ; Fri, 2 Jan 2026 18:20:31 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403231; bh=PDW/EwlNaTTPQYQ4454e8PO7J4C9I0rDy4EpsMytRNo=; 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=j2GpZ8HKLPIKRW+O37A1//SQqs6450TlyvOrtygwpMHEJcOx5wGU4Y/eBJD6rA9aR RYAZzx34texsELHYKkE3mRYJLQRxgMxiiU0TEplHna3BqRezplnvv+b2OxiE6TB1W/ 5GIPg4F/fv4J+g6DdfCW5YKM0laupimFroRJE3A2vv+KgQQaSc0ycG88GeH3Xuo5iv frrZwrdbJxhvxbeFQmSGi0Rgody2Eg5tn4Z4R8o9NiVBfUX7xbSThT0qmTpC0qrQjp /hcTK2jUfY5fqJJjli+nrJm7NoYJ8WLdaVH04xdTrHNMByyHE0dxtOg0WQfcdEok5q W/Rs5NTWHVTPA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 92AD66905F for ; Fri, 2 Jan 2026 18:20:31 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403228; bh=gtmKmy2TE7JIqRD1fAiI/iA8ZfTqeznVwhhcmJx79Oc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f8Bm9pFJzI0GeLD4BLoS2SNlBqT3pF8FwWMak/RXwgpGr6Jim6e5Pv0L4f6O/eGj3 vF0tRkQ3z2eE+ExhHBWu80flfmrCtXuKaAAq893Ljewyp1HiGj0E9LAO65Pnac+hnh OiiFZ6iL23rVrDGIRXaoicUKGez8c9ZaPMzuvlFyaZ7kYWWlX53VQUM9mGGKfIsArk OUF8zcHIsz8N6L0iyvxYza0Gcm50un0EXVkQa0fMnuWR6WFD3E3Zipip4GL+8CW23Y +Uw2Qi3aeeu9ngqa/O93M8NxET7RXKclomX8Mkr0rhukdi4Fei8ddLYl29kQe20JgY 8dL8nPw3TSRUQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 58AD468BF2; Fri, 2 Jan 2026 18:20:28 -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 E8W0l0tki515; Fri, 2 Jan 2026 18:20:28 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403226; bh=+GPEuvvpF7lfwHq5jKq2xCSRBzboKwishNKbQKNWOP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d+EJam/GheyXVN71s5Lr3y120xvnZNm4mizGMS8RvWRii7k7a5C+r8YmXkFjTfkVa qlUwMsnmN541GhlHJBDBIjUmzdL1wnPhrC5uLCtvAW2x3xv2fzuieldlgxWObIroQK cmLAcykT4InMyNJWSbREb9PpnpnxuhfFO5IBKmgh5FlJvY46JVpkvLE2WJaXFDx/Su OZh1x7lj4aDy3w52doUFTbVjSPfyFVCQjj8EMbzoJBfJ8t17Ch47R6/N8Sb4ZzvDMN +eMR8nDKa85iA9vLCzB28zoSWC6adGqdWjslKSti7VapZFr/4NXSuqSG0S+OVC24wr ddwEkhX+jl6Ig== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8EA2B68F87; Fri, 2 Jan 2026 18:20:26 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:55 -0700 Message-ID: <20260103011908.149445-20-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: O4MVQUNV7VT73MTSEVU6HJX7ISRJ5DAT X-Message-ID-Hash: O4MVQUNV7VT73MTSEVU6HJX7ISRJ5DAT 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 19/24] 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 --- doc/develop/malloc.rst | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/doc/develop/malloc.rst b/doc/develop/malloc.rst index 776294809b8..9becd573e8c 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 01:18: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: 1214 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=1767403234; bh=n2DBkezFcw9n5HZKvklxkiE4JAk6SM0wokJpdsVRROs=; 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=qmeR5IrnK9dn6p9vv5bApl+PR7emSFZvtA+050ZLUF3CcNdSTx+Hjty54NR63LmLl e7YYRbF83Zh8cNWkVrO/re1FxguH1LU570Lw2DOQqwNu+kyOAOE6kTQ+lJpNzvxBzz 3dA2IXz8OjtyIpjZjD8hP3EfhrBSRCcM3dgaBtXr51tcJSlXdDM6qUdxCIbm45qhhW 4bfQ/ItQNSpKqsBE3NS3TPyfUDmd08da27MYHCRmjv7DYg1/0a/zRgmX7ZxgYZWlRi F2JCjHT+aJ0v2y4DtaBy6Q3XQVst5I6lq4zvpi/hhJlc5mrI7OyxKYOh3WLwLoqrgx TZCumT+DTSyQA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 41A4468F87 for ; Fri, 2 Jan 2026 18:20:34 -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 N7UX4iBg_m9v for ; Fri, 2 Jan 2026 18:20:34 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403233; bh=n2DBkezFcw9n5HZKvklxkiE4JAk6SM0wokJpdsVRROs=; 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=UBqpfXU7pTLtv2COr23rkCUhcr4I7IMnm5IgbixtzB++ppk3EI4s8/E4zSPeMQGL4 nz3QM1WOvMBu1+Pt8fQH6OiIaROlQIvia9KYKO/Ww4UtozNyv8siEONcQEAff+90Y/ 0h/Z41G+U7K62pK17LRpaE54rSLr1FB+qNPEEqv8HUCGOILmwQKx6nuRqy8E6xz/9e 8T2V937gJsO6lTVsClU4Qo/8xiyx6H55DuSyf8EYkDzdGFpE8C428DeOEKD0TCp5BU JAosWJsNl/lK51nh4XQ1pxj+y/ENug+fBYX8RafZqLnP/G1hsDgO7+DiMCHFSnnWSf OHnwdhLe+BgfQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 45B7468FAF for ; Fri, 2 Jan 2026 18:20:33 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403231; bh=ys4gXOn6jRaU1znZk+qQQtohyOtibGQXO26Sj1ThTCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ADVxy008ItVkl1xKDdlw4VeVw2Vd/KbI04vhUrxBeqhNTZCjNmKWAhqYwnaNRm2NM m8fonGrEEsN+HfWO5wo/c6aZ+jAql1TpWJch1ja2v3bMyCUzYeFeI1F1tK1KEzF9Wf HyO+0/V965vmbT2DXFKOaS/GWzboOVXzb8ePgRHUiaCmxCUtrV23FjJhtHW0QiIEzF IXY6Zlv+yQ47+kVa6m74/2aBs9co2GR7TCxPwXSRRphKBiK80zAu5STqB5mJ3P630O JaSJEQtRmJD3zuqg/J4SDf7YtzgCgg6I+I+bZRKEbDpHQwk76w2OTrNvGSzF/fKG9A OghCJZ+ok0HNQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F31B769060; Fri, 2 Jan 2026 18:20: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 Xst9pKcjV1l6; Fri, 2 Jan 2026 18:20:31 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403227; bh=5uP14ASi2ex0VZmZ/Dsotw18PX7jYpIZPIdvY0SRqUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rmc591YnEHxPSdGt1paTxLNaxxBB46sIf45oXCn2/b1YSEko/DiqkdtaMGcOFULtY rqq2Zy0vPCzVnh4k+tn+u6I1LuGCAV/MkD3mWSfMM3/AvRSDMFSlIglWIqgW+5bDXe FkeIHX34/T9gF+N4wgjQB/YOvzwCOGrBrvSRqyuoslPSsJhikIZWE1S+MGaofNoVFx 1+qtarDfbgoF2uBub1mlviFSslw4E9rhOUN75Cz3fK0NIFSxA0Zpavhasy+Q5qaoEp PtUyYHBm/xq7ypHLM2pQNyw9R7uSJRqBH8fqEeSAU9X8Rfn8VRHKC/E0ac3C6upgYH poo2aB7hOVGMQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8130868F8A; Fri, 2 Jan 2026 18:20:27 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:56 -0700 Message-ID: <20260103011908.149445-21-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: TQCZG3U5PQRTZPY2UMLSMWGTKRHKMMKM X-Message-ID-Hash: TQCZG3U5PQRTZPY2UMLSMWGTKRHKMMKM 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 20/24] 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 --- 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 01:18: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: 1215 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=1767403236; bh=4ALHTAbTMDCebzs12K5qB3JLQtHEm1w6ErHC/wJNuI0=; 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=mKMT2/NOwTFcTIiHeFfAW4xBuo6wMk1JfuChab95VshTDMwDaZGdoMiA5U5WR576i nfBCOcddZI7Wy/4rRn0ICVXaqrLsYJ1muBC0+NImsWM0+2wny5Gq2dqlIf6I9+VYLX NRYHC1jjwze22mxG9kur6iWUXskKRvVOc5Y/OVWuqWz3ciC5pbT5TXkzTFio8qh+LC sG3ku3oEwajwQqqfcQ/s9HbTASE1U7wpUukMvud9njYJIno8x+X+5tIfNyQb3JKPa1 /gViZokpKnJTzn7bLvBLXANaNl1dZ9/d1X13bQh97HuqrpnskjkgVPn6rY1mXS9/eD eWJmX2KZ7uX7A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D510368F87 for ; Fri, 2 Jan 2026 18:20:36 -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 pG9WvogTVyNu for ; Fri, 2 Jan 2026 18:20:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403236; bh=4ALHTAbTMDCebzs12K5qB3JLQtHEm1w6ErHC/wJNuI0=; 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=mKMT2/NOwTFcTIiHeFfAW4xBuo6wMk1JfuChab95VshTDMwDaZGdoMiA5U5WR576i nfBCOcddZI7Wy/4rRn0ICVXaqrLsYJ1muBC0+NImsWM0+2wny5Gq2dqlIf6I9+VYLX NRYHC1jjwze22mxG9kur6iWUXskKRvVOc5Y/OVWuqWz3ciC5pbT5TXkzTFio8qh+LC sG3ku3oEwajwQqqfcQ/s9HbTASE1U7wpUukMvud9njYJIno8x+X+5tIfNyQb3JKPa1 /gViZokpKnJTzn7bLvBLXANaNl1dZ9/d1X13bQh97HuqrpnskjkgVPn6rY1mXS9/eD eWJmX2KZ7uX7A== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C4E5168FAF for ; Fri, 2 Jan 2026 18:20:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403234; bh=ed8wmOV6yKM0UZKnBIzZbmJ0M5n8Lu48IH0b3MxA0eg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DCz+amCf9OQtxnjBnWHtIMdVIPpidWq2m88zAqvKggaNE47xIRv+Yi19Kxp0wIrHh Vv5Zixz/BQ9XkucItq1M1XnA0M/DV0JvNZk6vMAJD+UOS1C0kGw27HfSrm61yUZAxw I9X5FGWUkBIqAdYp/BhWyV8cuzA21cMHxqIbZpvnIdjwlwGhrbD9pLFsnRGXluS9kb 2pM8dIrVOFK8CUz5JqQrJDt0FTqu++j5aynU+vvWYSc+6x3L6VSGVfef5ejyl1nCou OxYlEc/W5YR89t7NBd7CpeX0HgB0EY3UBkoEJ0laWpTJ9CyUqWTh9jKr0J8e0uZOFO j72rONzDQAjBA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2D2B86904D; Fri, 2 Jan 2026 18:20:34 -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 Roz-Be8ADXIT; Fri, 2 Jan 2026 18:20:34 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403232; bh=UO4Omr2/1SwuEMVX9eAJk/+/2EJZcjhJpPyLV7zmS/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wLhqo2jiBnbk0zJR2mgI524wsjWVotykFRuO6D2850OKCwW+l7E5urc78PvUUHCnS EQmpR7z8iRSrGeV7A5LZrCEBWyAKKVqsL+LUxGqJmpkrnMJ3e3cSHi6Ln+Vi2dz8AP VgZ5XfzxyfKs2tPiMUoM3RZNX5E9PdaH4FGqxtPNN9VXYVQNHSM1WrmA6BjA6NHeK5 ZSalkenZUX9LKMjNUGZJyv+Pi9FUF5oliOR/md0ZKotJ1w4Nld0GZG0nZmluN0p2zC qcz4jDC1ly4WuX5/8M9fxoBW+W6COkIZqowxkK/kxcghw8r28D0qS/J1v4Y7eDZVTp kMO4wDySiVv1g== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3C68568F8A; Fri, 2 Jan 2026 18:20:32 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:57 -0700 Message-ID: <20260103011908.149445-22-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: INKRLEYCHLYKCTTOVOTFFQMHIBJOUS2Z X-Message-ID-Hash: INKRLEYCHLYKCTTOVOTFFQMHIBJOUS2Z 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 21/24] 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 --- 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 01:18: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: 1216 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=1767403241; bh=eXcgJL0olKVhUsEdZYaSPS45Fn3IkMrvT75j4x/S4kE=; 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=SJK6UyfRyxhJEgJd0bq2FzmhttCVUw2yy0AADN22TvdaoJdymAytG3rslv28iZ3bz 7EmkzKMdedQ2yaYo7iocio+1RWXho8Kx5Crko03Qi9nX8iGwVHnTyegeTSgGS75AqS XbzVxM48LpP3a7ryyRwHra1TuKSypEx958z7X3IyCpYcrIZbASwDSHGf/i5tDu2G4u AtJzi7AuXBMPO3gaiIvBTffr64UIDmHdtiLDE3bIRuhnj/QbFU8X1YojHmNiXMoy6m qEaKhQJUcsh534+2moz/E76zGuYZDhra+ChDp0ncLgH2uLDIkl0OUVOIRWV+eUWI74 5pIYsld070vQg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 49CC56904D for ; Fri, 2 Jan 2026 18:20:41 -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 GRC9nQWBEfPs for ; Fri, 2 Jan 2026 18:20:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403241; bh=eXcgJL0olKVhUsEdZYaSPS45Fn3IkMrvT75j4x/S4kE=; 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=SJK6UyfRyxhJEgJd0bq2FzmhttCVUw2yy0AADN22TvdaoJdymAytG3rslv28iZ3bz 7EmkzKMdedQ2yaYo7iocio+1RWXho8Kx5Crko03Qi9nX8iGwVHnTyegeTSgGS75AqS XbzVxM48LpP3a7ryyRwHra1TuKSypEx958z7X3IyCpYcrIZbASwDSHGf/i5tDu2G4u AtJzi7AuXBMPO3gaiIvBTffr64UIDmHdtiLDE3bIRuhnj/QbFU8X1YojHmNiXMoy6m qEaKhQJUcsh534+2moz/E76zGuYZDhra+ChDp0ncLgH2uLDIkl0OUVOIRWV+eUWI74 5pIYsld070vQg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 38F0B68F8A for ; Fri, 2 Jan 2026 18:20:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403239; bh=PevnMRacnPojIGVkxMRz1zkNZ/BhxAMoX2F0SSBdX58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KoBuUiU/3hlQvY3JtojeMeg4Mbp9NV++bOJlGbYRydu9URBotGEFabKOxQmtIkDw2 QrllWVUdnKtUE6ndfvAQpCIJognFXIuLFBVHIUkiOZwqdVO9X5y6DifykMabDyvOxm E4bDUMDkVy66AxWPjP3h1qs5ZHvMYiNkw971Poxovx34IYKfOY907IKZeZpH5y0Eeo 6myZ5aOF1fM5jzV7xvgZt4KocaSzCLFHvApgKRpO22DAwjHSmqo0EFbg+RsFLg/1IW QSeiaI3DwLLKnitR5G/MNihAf6dIAeb74KXUMqTGqKSPfioKnrENHo0lXFBMtLJfg2 wTvybkygYJXIQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3B21F68F8A; Fri, 2 Jan 2026 18:20: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 10026) with ESMTP id 7wZ2rOgZEfj4; Fri, 2 Jan 2026 18:20:39 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403233; bh=GHdSEpGcH9l+QUhd0bAFyh3Mcvs80BqZ5JD7DByk8qg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uCQjqxhw4U/bpYfnthm1VpnoK6tKOZeC6VtC2vhTc1q3KOPWkIAUmx3Y50t81DhOG HHGVy3EHA3o/F3QWn3voY/XOAG4G3oELRFgjOm539egOJdT85F0X2N+c+32HhHIgki MTTaW9KmVL4tpalKeJdLTcyPjuPxYy0ZMToRpVtkM+7TWSHOXvFkxs8kYdOoVQnq33 0AZcykws3x88ifcFw5hQPbIzE2j1CENCeyi5ckvBkV4YGVrVT8bANV8T3X7mwWOJ41 mr352IxacgUDeU3ztfefhovtxtwQrB3hBwW/puruhN3D3ZwKbhAffW6fZHDZRbYCaA 3QS0bUsxXujPw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1FF1768BF2; Fri, 2 Jan 2026 18:20:33 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:58 -0700 Message-ID: <20260103011908.149445-23-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: BKFJKLMLRZ4MYL7MDZ5BBWSZKU52H7RR X-Message-ID-Hash: BKFJKLMLRZ4MYL7MDZ5BBWSZKU52H7RR 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 22/24] 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 --- 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 01:18: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: 1217 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=1767403246; bh=AASwVJZy/XHAiSRZFUMIcNHl7EGkVLLULZ3ziwzczyw=; 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=LQp2IYwGHVaRDEGeiKbIsqjyZ31iZObLQAeZjlrtwxpAaOWH8YI+YV8O7uXLUfJL+ wgdedCxJ0wixYLlaQCwoUX0Yb4dS/3s28Z0Y5F16Q3e6SS+5UZ/4048L/MnKJTlUFQ pRrCNm+FGxRjNugyZ1pwRI3loYA0WHA7BzqgcNiyz6eC127jLC2/c41/RFQu0itpy0 a4eZY1UJoTnz37aO6bfBqeyMtmj2mdRviBiv92Za4DguNpa/MbJrMT/XPKpzwPKvrN dCeAOmazwPvN3DqFKrGMKuCKmOx7idI0v3/h8xKslmgkE4vY6WS7rKK5TxwI0yE6Ie 8m0ZzOVrsq6Ig== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 656DB68FAF for ; Fri, 2 Jan 2026 18:20: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 n4sJxRx2eSJN for ; Fri, 2 Jan 2026 18:20:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403246; bh=AASwVJZy/XHAiSRZFUMIcNHl7EGkVLLULZ3ziwzczyw=; 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=LQp2IYwGHVaRDEGeiKbIsqjyZ31iZObLQAeZjlrtwxpAaOWH8YI+YV8O7uXLUfJL+ wgdedCxJ0wixYLlaQCwoUX0Yb4dS/3s28Z0Y5F16Q3e6SS+5UZ/4048L/MnKJTlUFQ pRrCNm+FGxRjNugyZ1pwRI3loYA0WHA7BzqgcNiyz6eC127jLC2/c41/RFQu0itpy0 a4eZY1UJoTnz37aO6bfBqeyMtmj2mdRviBiv92Za4DguNpa/MbJrMT/XPKpzwPKvrN dCeAOmazwPvN3DqFKrGMKuCKmOx7idI0v3/h8xKslmgkE4vY6WS7rKK5TxwI0yE6Ie 8m0ZzOVrsq6Ig== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4F05868BF2 for ; Fri, 2 Jan 2026 18:20:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403243; bh=yd2gHa11sq5uhAtbbm9ksPm0dJ+AVq1WE1JtYRHMT3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MYndHzJ+elOUfSTZM5L9BwW+lgprb/ij3eB1KlGJOiTzDBABzvzN/F/0DEaz991kj gWpJ3ukxcpMOBJvUiJEcz+b6sCPT1nQ99cAqYaB1xQP1ig02MDf65PzVYlD3+EOOgL mX73j9QoYVhj2wXkvzeb3y7TwMfmIvo6uy+cYY6rk2UQKisVkgDi8q0gtb7GPAhaya Qql5CLImCiWVFy05V9zQEwU+0u4dVdoMrXTFxBrBo2kFi/yAbOXkoB3pJwNdrFtErb AZSeO3Hg2iQ4rUREcpriyLQt1fVn7Ld+R5oW0n+kW/58sq0YRKRG6Qen73riybf22V FPfGIAvxHx/LQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9B33468FAF; Fri, 2 Jan 2026 18:20: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 RYHC3WhvxtKi; Fri, 2 Jan 2026 18:20:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403237; bh=t0Aw610biZKL/3dKi8jymVCFaLwFHG+z5ZQw4um+JNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=chiF9EH6CKbjO6ZufuC7rs95TgkhvuwnpcjOAyAJkkjd5gd+6GKhdVMs+hf908rdq GiKdcXa4/ItR/lOEDRiwZr7/M4e2PPMojIFlkJUO5HkBM4IxznER+XkVuufhAQcvoq 5W6dq7UZdPkEGbmdOAeViBFN8fAQkQi2L+FEqcxuOGZMA/CiLQiY0WC3xla6rFfu7t HmzKSRgl/Z3hxV+drzR8YTjVgM0lCKZoHM2lm6qgNuN89OU9tbdmg4Uyj0uzVWslaG 4U33jd6b4Gcf5Qk4l5sCtfI4WEhodoGYwl2qIhL8qyECiqOW46bcKEDZYQQ2iJIhau waW9FsChEn8Ew== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A9FD468F87; Fri, 2 Jan 2026 18:20:37 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:59 -0700 Message-ID: <20260103011908.149445-24-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: IX7T2SCWEMQZ45P5KT5U2ATVLZ7ZAEVG X-Message-ID-Hash: IX7T2SCWEMQZ45P5KT5U2ATVLZ7ZAEVG 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 23/24] 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 --- 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 01:19: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: 1218 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=1767403246; bh=R7cH29x0VeuSvWdBPkVOQhhalr9e/k8qLvbm5g5S2Us=; 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=TieX5cW5S/wmDbMz2/YMud2CX8FSCstvAwHK+8uq9xylm9DSID2RG1KgKyY/bfYPR WaxPbdg2APa6UU5R2vkWl3ja9wQ8FpzbB02a2IdtmODI5wmaqCuqMen94NGxxHxjgm 5wQ2y2RPNv86IryxKaZ0HEfqFVw8+jFAxy24iL5XZgCzyP+b+q0mT0feanzqTy0EU5 mIuuRA2TM6rkeW+SYGvfEFPwnCiRRAvp6I5xehpKJQ8dgmGgRy2bOeu1Gk9a/5+XWQ wHzIDBBPD7AI12yvSVEeR72KSXtthmhAEu3IX0YlAHlH1/ni2TlVZ+DerRb1nlbm3w aodGAsBK3TdKA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E0D886905F for ; Fri, 2 Jan 2026 18:20: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 R8rXY2RfXmh3 for ; Fri, 2 Jan 2026 18:20:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403246; bh=R7cH29x0VeuSvWdBPkVOQhhalr9e/k8qLvbm5g5S2Us=; 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=TieX5cW5S/wmDbMz2/YMud2CX8FSCstvAwHK+8uq9xylm9DSID2RG1KgKyY/bfYPR WaxPbdg2APa6UU5R2vkWl3ja9wQ8FpzbB02a2IdtmODI5wmaqCuqMen94NGxxHxjgm 5wQ2y2RPNv86IryxKaZ0HEfqFVw8+jFAxy24iL5XZgCzyP+b+q0mT0feanzqTy0EU5 mIuuRA2TM6rkeW+SYGvfEFPwnCiRRAvp6I5xehpKJQ8dgmGgRy2bOeu1Gk9a/5+XWQ wHzIDBBPD7AI12yvSVEeR72KSXtthmhAEu3IX0YlAHlH1/ni2TlVZ+DerRb1nlbm3w aodGAsBK3TdKA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C7BE668BF2 for ; Fri, 2 Jan 2026 18:20:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403243; bh=Dm3rx2dnGUoGIgedll6uGHqM9zbyRRKBSkK0ZU2WDF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XSdVBpY7AuswHaDy2N5dp+R3c+WRY1mArE57pPpUkgOXW26FYYFBqzH38ZvgmUsAE W230Vc8rDaZTOt/HEn0RxX2PxRlVOe0l5DRZGJMeZSVbXLBm3PgbztpBkm/IJh2qY5 SoB2gL+G+URQb9GekpnDwx5Zr5U+nhp6T5bnKCEdYzZv9sqCmvDD/DLWqz10OFNaol wNtTMKudP70gQK+rJIJ7p/YYMHH/h2FRdVkZqQgIDXRe5kTEBAwayWK5xXY5RvTWz0 2U4XijuTYPdq9a2MWXXojMPULMN551riu75+qJTXFfGF2Ac3hhzk7hEPIz4N6JLd0o /AXLWfW6MWBVQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id ACD4368F87; Fri, 2 Jan 2026 18:20: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 tPzOBEBlxHpm; Fri, 2 Jan 2026 18:20:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403242; bh=dYNtS/7iEskQ06DNzviNLEFPYybV9F7eMvHdVEf4kck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=INYsyg4jsF8CsbUhKuLK1nzCTNwBheTdaGfe3GJrducfggGlfwjr7Ve3eB8UE1YF9 EUd82QrrOkhIHqKr2snUjtU8CsCfhUDvS5EXTht9l3E8Xej53135tVULIipsV6WJjX HG6w9HK0+y1FveBUZvFv0ER/GXk+zYb+024ot7z2kWPj9KmrhxRvDDdpZFa1SUDM/l va5v3p4XTbnrQ4EP75MnI+ba5uBdy6w58YjBRv5yAk60of9NdpFr579NuLFhOQy0Sn zG/oxaXgyQ8NJIMTYp5ACerfi9GO6OyKdF53viTgrRRD9l1E3ui6NaDU2m+oaGQDLW DFKhZ2p9Cm4VA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 65E1068BF2; Fri, 2 Jan 2026 18:20:42 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:19:00 -0700 Message-ID: <20260103011908.149445-25-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KEMTZBHV2YVPC3XNUR2CTCSIBSMR4EZP X-Message-ID-Hash: KEMTZBHV2YVPC3XNUR2CTCSIBSMR4EZP 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 24/24] 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 --- 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