From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Matthew Garrett <mgarrett@aurora.tech>,
Simon Glass <sjg@chromium.org>,
AKASHI Takahiro <akashi.tkhro@gmail.com>,
Dmitry Rokosov <ddrokosov@salutedevices.com>,
Francis Laniel <francis.laniel@amarulasolutions.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Jerome Forissier <jerome.forissier@linaro.org>,
Mattijs Korpershoek <mkorpershoek@baylibre.com>,
Tom Rini <trini@konsulko.com>
Subject: [PATCH 6/8] addr_find: Use a simple lmb allocation
Date: Mon, 9 Dec 2024 09:27:59 -0700 [thread overview]
Message-ID: <20241209162801.288363-7-sjg@chromium.org> (raw)
In-Reply-To: <20241209162801.288363-1-sjg@chromium.org>
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 <sjg@chromium.org>
---
cmd/Kconfig | 1 +
cmd/addr_find.c | 40 +++++++++++++---------------------------
2 files changed, 14 insertions(+), 27 deletions(-)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index c8ca55194c0..d4da504bea4 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -130,6 +130,7 @@ config CMD_ACPI
config CMD_ADDR_FIND
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 b187337d885..2c20b959031 100644
--- a/cmd/addr_find.c
+++ b/cmd/addr_find.c
@@ -16,12 +16,13 @@ DECLARE_GLOBAL_DATA_PTR;
int do_addr_find(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
- struct lmb_region *mem, *reserved;
const char *filename;
- struct lmb lmb;
+ phys_addr_t start;
loff_t size;
int ret;
- int i, j;
+
+ if (argc < 3)
+ return CMD_RET_USAGE;
if (!gd->fdt_blob) {
log_err("No FDT setup\n");
@@ -49,36 +50,21 @@ int do_addr_find(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
return CMD_RET_FAILURE;
}
- lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
- mem = &lmb.memory;
- reserved = &lmb.reserved;
-
- for (i = 0; i < mem->cnt; i++) {
- unsigned long long start, end;
+ start = lmb_alloc(size, SZ_2M);
+ if ((long)start < 0) {
+ log_err("Failed to find enough RAM for 0x%llx bytes\n", size);
- start = mem->region[i].base;
- end = mem->region[i].base + mem->region[i].size - 1;
- if ((start + size) > end)
- continue;
- for (j = 0; j < reserved->cnt; j++) {
- if ((reserved->region[j].base + reserved->region[j].size) < start)
- continue;
- if ((start + size) > reserved->region[j].base)
- start = reserved->region[j].base + reserved->region[j].size;
- }
- if ((start + size) <= end) {
- env_set_hex("loadaddr", start);
- debug("Set loadaddr to 0x%llx\n", start);
- return CMD_RET_SUCCESS;
- }
+ return CMD_RET_FAILURE;
}
- log_err("Failed to find enough RAM for 0x%llx bytes\n", size);
- return CMD_RET_FAILURE;
+ env_set_hex("loadaddr", start);
+ debug("Set loadaddr to %llx\n", (u64)start);
+
+ 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",
"<interface> [<dev[:part]>] <filename>\n"
"- find a consecutive region of memory sufficiently large to hold\n"
--
2.34.1
next prev parent reply other threads:[~2024-12-09 16:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 16:27 [PATCH 0/8] efi: Add docs and tests and a few tweaks Simon Glass
2024-12-09 16:27 ` [PATCH 1/8] fdtdec: Correct devicetree symbol for EFI app Simon Glass
2024-12-09 16:27 ` [PATCH 2/8] part_find: Enable for sandbox and correct radix and calls Simon Glass
2024-12-09 16:27 ` [PATCH 3/8] doc: test: Add docs and test for part_find Simon Glass
2024-12-10 8:15 ` Heinrich Schuchardt
2024-12-10 16:16 ` Simon Glass
2024-12-10 17:08 ` Tom Rini
2024-12-16 0:29 ` Simon Glass
2024-12-16 8:05 ` Heinrich Schuchardt
2024-12-09 16:27 ` [PATCH 4/8] efi: Drop config.h Simon Glass
2024-12-09 16:27 ` [PATCH 5/8] cmd: Refactor part_find() into separate functions Simon Glass
2024-12-09 16:27 ` Simon Glass [this message]
2024-12-09 16:28 ` [PATCH 7/8] doc: test: Add docs and test for addr_find Simon Glass
2024-12-09 16:28 ` [PATCH 8/8] efi: Avoid a memory leak in efi_bind_block() on error path Simon Glass
2024-12-10 8:10 ` Heinrich Schuchardt
2024-12-16 15:15 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241209162801.288363-7-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=akashi.tkhro@gmail.com \
--cc=ddrokosov@salutedevices.com \
--cc=francis.laniel@amarulasolutions.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jerome.forissier@linaro.org \
--cc=mgarrett@aurora.tech \
--cc=mkorpershoek@baylibre.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox