From patchwork Thu Sep 25 17:47:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 427 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=1758822545; bh=m2k8KZAcZIz56fYN6tMuRVHPDmwyKMYOyHSYUaSPPr4=; 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=XBXLnineGHXhILM6VGMW+CynPB3aR9sTyft7D2Zs+JDqg05CyjuW3DnJeVB378Qsb ijbd3v8g05bGIwlT0Sg4OqyZktcG/nwmkJj/gbMIAkF5aZuK0PzKtf0atmTR1BudAU IdifBsTbGwwRj3bF3HD389jd3U5GIs/8xyA7pi+JnTGacoxe0zb04sY41BHG6odlJB JTB3uy8pdfcPY/cJGk+bA4rflmrnNMWEs0FfkScxi6kJ9VgkcN1r+zxR9SJNOJGhft j/CHEC4Z1QzYleNcxZ8Ccf5l1RvhMpJ9i0LkfwKWdWFYATc8UH55uJO4L1hipIfk6m MeemWk8fjLApw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9B79E67CEF for ; Thu, 25 Sep 2025 11:49:05 -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 aeS3gfjH4gGr for ; Thu, 25 Sep 2025 11:49:05 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758822543; bh=m2k8KZAcZIz56fYN6tMuRVHPDmwyKMYOyHSYUaSPPr4=; 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=mbkmD5nOK/Rrcll6LY3Y2ZxonA1AKHqFhQmUX1SYeylbdpWFXccSSvCx5a0CY+8SJ I6aUeLLh43v7MSWGYOVMECs0d0WH/jiy4E1dCG0iSe+UMKrM+xr8XgrsVd/mvc/+wx 2x+h2TjQXvl1EEHVnhaRyWL3AnwCRCT0Yb29JJjnSlZZ4Ch2E+Et8Q/rP1MC8bUy9M Tkf8+iXXpcxZLW3m+AqgM3Hue/dKiugur0F2scrI21FCxEDYqAnMlm/2tyw6Lzv+o9 VU0ib4DlOt5saAJtUm9QtQXF0heazieyshS2HluSwRjEgE/FKh8Sk0RLDqlfJNgmZf iccu0V6cKm8Yw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AD35867D29 for ; Thu, 25 Sep 2025 11:49:03 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758822542; bh=7lZhOSKyRi0PEe+3mdx2Uq1fNIoHU9qIT2lQcKqpW1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DSIlf1JTXGNjWNrd3WqMs0+0wlKkl9UTPDfwPGglMoO5ukJjZ5yuE6ZMbEHd3EpXk Nkm1X/OAHCAIHQ3ODWDJ/Y59fHfdwIxoNZTcppL+tfZy8Ol0NChDonFLs3bNM2EAyR b5uDHtKyZtMVdnl0lSoMF8Pbc6hyMvk+E+BcIR9NRR8Zw540mLLX29013a39fk3Dn8 pS3q6DfPnSxuCkYeJU4LA1YjS6DMG7oue4skcoaHe0fvuWl8C1s+h2ABvpcQoTNkRw Ddqw0G6Dk8h9Bua3FP46o1v4m1iJi6j+t85MXIwJ2Jv72qs8PTg16Qy9yFmlprEsNa tY5/iige4fdBg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 07A2167D29; Thu, 25 Sep 2025 11:49:02 -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 SvXac6EyRT8b; Thu, 25 Sep 2025 11:49:01 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758822540; bh=C/CLoB5Y6p6bzOmToUsLfl/evgpPeqT9OL5/oA5DIc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NVrNXTOgR5dFArcFROcQROX11kFt5Q6I1ohSfpRVzSNeFZ9Joo7+5LkbxSPD5O7uQ XcTGqpgeCLM9IMdwwKx1kYvU+/cViu8UpeEdwhA951Lwzopmr8tgcROf/YW2rhczhw sleA6nKIhnxogZYndNJqJ9LwFHPdJBAU8kmSs1PNfNoR/mAkvxmMFiNvicdBalbKmZ nrLCsKlfbEnOqriUumiXAwyARKx79ZLyx1XQDQcQgUNoXGOoyyy1BF80gnTSDexFrP 1XjvLlTMo4TUfdl+jm9VXh5N+PMaLxJkwhEdtHiUBWP7SJ/7PQ4KyIxTTqPi4KulU9 rlE3kvIZ0+Vqg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3435867C2B; Thu, 25 Sep 2025 11:49:00 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 25 Sep 2025 11:47:39 -0600 Message-ID: <20250925174753.3429102-16-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: W4FQZ3V4YTR4KDEVB7VHBEWT24DTYIBD X-Message-ID-Hash: W4FQZ3V4YTR4KDEVB7VHBEWT24DTYIBD 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 15/22] doc: test: Add docs and test for addr_find List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add documentation and a test for this command. Drop the use of config.h while we are here. Signed-off-by: Simon Glass --- cmd/addr_find.c | 1 - doc/usage/cmd/addr_find.rst | 63 +++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + test/cmd/Makefile | 1 + test/cmd/addr_find.c | 27 ++++++++++++++++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 doc/usage/cmd/addr_find.rst create mode 100644 test/cmd/addr_find.c diff --git a/cmd/addr_find.c b/cmd/addr_find.c index 9d88091f541..55f50830771 100644 --- a/cmd/addr_find.c +++ b/cmd/addr_find.c @@ -5,7 +5,6 @@ */ #include -#include #include #include #include diff --git a/doc/usage/cmd/addr_find.rst b/doc/usage/cmd/addr_find.rst new file mode 100644 index 00000000000..0d16ffd236b --- /dev/null +++ b/doc/usage/cmd/addr_find.rst @@ -0,0 +1,63 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +.. index:: + single: addr_find (command) + +addr_find command +================= + +Synopsis +-------- + +:: + + addr_find [ []] + +Description +----------- + +The addr_find command is used to find a consecutive region of memory +sufficiently large to hold a file, ensuring that the memory is not currently in +use for another file, etc. + +If successful, 'loadaddr' is set to the located address. + +The number of transferred bytes is saved in the environment variable filesize. +The load address is saved in the environment variable fileaddr. + +interface + interface for accessing the block device (mmc, sata, scsi, usb, ....) + +dev + device number + +part + partition number, defaults to 0 (whole device) + +filename + path to file, defaults to environment variable 'bootfile' + +Example +------- + +This shows obtaining an address suitable for a file on an mmc disk:: + + => ls mmc 1 + extlinux/ + 97135227 initramfs-5.3.7-301.fc31.armv7hl.img + dtb-5.3.7-301.fc31.armv7hl/ + 12531628 vmlinuz-5.3.7-301.fc31.armv7hl + + 2 file(s), 2 dir(s) + + => addr_find mmc 1 vmlinuz-5.3.7-301.fc31.armv7hl + => print loadaddr + loadaddr=7c00000 + => + + +Return value +------------ + +The return value $? is set to 0 (true) if the command succeeds. If no suitable +address could be found, the return value $? is set to 1 (false). diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 4d6b2f5227a..21d6d120e7c 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -26,6 +26,7 @@ Shell commands :maxdepth: 1 cmd/acpi + cmd/addr_find cmd/addrmap cmd/armffa cmd/askenv diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 773b3d7569b..ffb78f69041 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_CMD_PAUSE) += test_pause.o endif obj-y += exit.o obj-$(CONFIG_X86) += cpuid.o msr.o +obj-$(CONFIG_CMD_ADDR_FIND) += addr_find.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o obj-$(CONFIG_CMD_BDI) += bdinfo.o obj-$(CONFIG_CMD_CHID) += chid.o diff --git a/test/cmd/addr_find.c b/test/cmd/addr_find.c new file mode 100644 index 00000000000..ce087759d9e --- /dev/null +++ b/test/cmd/addr_find.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for 'part_find' command + * + * Copyright 2024 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include + +/* Test 'addr_find' command */ +static int cmd_test_addr_find(struct unit_test_state *uts) +{ + ut_assertok(env_set("loadaddr", NULL)); + ut_assertok(run_command("addr_find mmc 1:1 vmlinuz-5.3.7-301.fc31.armv7hl", 0)); + ut_assert_console_end(); + + ut_assertnonnull(env_get("loadaddr")); + + return 0; +} +CMD_TEST(cmd_test_addr_find, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);