From patchwork Thu Sep 25 17:47:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 425 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=1758822538; bh=HWkYBW11k/oMtCkOK68Hilbu0GkWFVTnbbXDoMmDo48=; 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=dMrFSYgD/F1YniB6mFEQGfRgEbUbkrWb0/BsozrTj84fl07ZylYdjb3/uzItptcbD 565u5H41f8O8wDdxRhGBC8rgyfLJ4E3k4eVssRtbRUONuDfXZYlm5oV2tdKSsCVdbY EkvP0FMiFY6kFgtBujy+T5iJY1LWeRR4bBk4049uWUSucj5470FmnDpaPlbF9coNW8 297qs/W3iMn7lJsJH7DUD4bGl4o+fl0q9wWnc1lPh02TXaV0RYZ5cfGcZDUzxaR1OK efLMZPcoRWHN2JNMPJBF6GQEPUMMLfhbvxtbp/8mEvHbP4Fx8LmC5CTHPJNk0ah5ot dk14g4xLRpUjg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BE79C67D9A for ; Thu, 25 Sep 2025 11:48:58 -0600 (MDT) 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 H5Jw0Z6Epvt7 for ; Thu, 25 Sep 2025 11:48:58 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758822538; bh=HWkYBW11k/oMtCkOK68Hilbu0GkWFVTnbbXDoMmDo48=; 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=dMrFSYgD/F1YniB6mFEQGfRgEbUbkrWb0/BsozrTj84fl07ZylYdjb3/uzItptcbD 565u5H41f8O8wDdxRhGBC8rgyfLJ4E3k4eVssRtbRUONuDfXZYlm5oV2tdKSsCVdbY EkvP0FMiFY6kFgtBujy+T5iJY1LWeRR4bBk4049uWUSucj5470FmnDpaPlbF9coNW8 297qs/W3iMn7lJsJH7DUD4bGl4o+fl0q9wWnc1lPh02TXaV0RYZ5cfGcZDUzxaR1OK efLMZPcoRWHN2JNMPJBF6GQEPUMMLfhbvxtbp/8mEvHbP4Fx8LmC5CTHPJNk0ah5ot dk14g4xLRpUjg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id ADF9B67CEF for ; Thu, 25 Sep 2025 11:48:58 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758822537; bh=7eZznSxcToZ0JBBdAGKpYn91FWc61+bw/G752rQek0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q2ESxmJYN4/MDb0cJx57fMDbNdp/7eZ17lB6Ovv+Hx+c7z0JPTwMwvEQR3XxqN2Cd jaiNvO3CDYfDhU6xHrgaOjMXM1oND+clRhmykSRKTM6Yu4RelwBGqEdVQxuFewDAVt U4L0IBV3TVF8vMWW+sEAKY2+6ndSikvU9ZP4tudTu/u3P1nULoiHp0IV7oAFW8MQ3u kPQzj1zGnYOuMJA2/IHK4UWyxXjhUfAm2waeFznFT9dL198LodflrtF9aMnDc5APlk 58/6EmEkQKhO7lYanJ1hBHX8aPQZ0Ar9uRkpiQ0n1tg1TgAehSf7qT1gomRJmHueuu I0OXn6m0x2s+w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 45BF367DA2; Thu, 25 Sep 2025 11:48:57 -0600 (MDT) 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 8mBUNiS5GnU9; Thu, 25 Sep 2025 11:48:57 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758822531; bh=i0U/Pwf79y8J8o4hoJ6R+9vFQrDGmNCJXNS0BBt4KKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ON7+P5BXKXj116joS2PQ9LTxrSJd3m8wPGLcEF5gWf2F4Ppyz9GxNWICrS1wsuVSJ h42Hi1Dy6iXBv5SDeuX4iKvwKchXmM8B77eoXVgofI9nOzMZjOJytW6qPFMZHtl0UU cHUhD5kFtA2IX49Tev13AcqdlaFEaeTKYFqz5es3O1d3bp8GhAq7apFrvGqrpDE799 QHYbJt0U7gKSAIT3CYaikUv9C4vvYPaBUbbok76q0Xs0NW6qdiaeZLr2I5tdTxt/Kn Og9eR9gQzsWfgmYyNkrKrRJrZbwFc9UaAM5xVUsRu2xqjTeSaMPHFcz9f0eI8OmDuo NewOAh3R3h6OA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0D23C67D29; Thu, 25 Sep 2025 11:48:50 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 25 Sep 2025 11:47:37 -0600 Message-ID: <20250925174753.3429102-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250925174753.3429102-1-sjg@u-boot.org> References: <20250925174753.3429102-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: DZ3HZ2KAJHL4BIAOX67P7CHGRSUWTMQ4 X-Message-ID-Hash: DZ3HZ2KAJHL4BIAOX67P7CHGRSUWTMQ4 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 13/22] cmd: Update addr_find to use a simple lmb allocation 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 There should be no need to parse the LMB tables manually. Use the allocation-function provided instead. Adjust the argument checks while we are here. Also enable this command for sandbox and the EFI app, so it is built in CI. Signed-off-by: Simon Glass --- cmd/Kconfig | 4 ++-- cmd/addr_find.c | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 44e1b60c592..05c130b511e 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -129,8 +129,8 @@ config CMD_ACPI want to make hardware changes without the OS needing to be adjusted. config CMD_ADDR_FIND - bool "addr_find" - default y if EFI_APP + bool "addr_find" + default y if SANDBOX || EFI_APP help This command searches for an unused region of address space sufficiently large to hold a file. If successful, it sets the diff --git a/cmd/addr_find.c b/cmd/addr_find.c index 876c58feabd..64ecc816be3 100644 --- a/cmd/addr_find.c +++ b/cmd/addr_find.c @@ -17,8 +17,8 @@ DECLARE_GLOBAL_DATA_PTR; int do_addr_find(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { const char *filename; + phys_addr_t start; loff_t size; - ulong addr; int ret; if (!gd->fdt_blob) { @@ -47,24 +47,21 @@ int do_addr_find(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_FAILURE; } - addr = lmb_alloc(size, SZ_1M); - if (!addr) { + start = lmb_alloc(size, SZ_2M); + if ((long)start < 0) { log_err("Failed to find enough RAM for 0x%llx bytes\n", size); - return CMD_RET_FAILURE; - } - if (env_set_hex("loadaddr", addr)) { - log_err("Could not set loadaddr\n"); return CMD_RET_FAILURE; } - log_debug("Set loadaddr to %lx\n", addr); + env_set_hex("loadaddr", start); + debug("Set loadaddr to %llx\n", (u64)start); - return CMD_RET_SUCCESS; + return 0; } U_BOOT_CMD( - addr_find, 7, 1, do_addr_find, + addr_find, 4, 1, do_addr_find, "find a load address suitable for a file", " [] \n" "- find a consecutive region of memory sufficiently large to hold\n"