summaryrefslogtreecommitdiff
path: root/boot/bootmeth-uclass.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-06-01 10:22:38 -0600
committerTom Rini <trini@konsulko.com>2023-07-14 12:54:51 -0400
commitde7b5a8a1ac0b711db683711b3ccd800e00c4c46 (patch)
treef5f12491c203eb5d1156936434293e3ecc9f9ef0 /boot/bootmeth-uclass.c
parent5904d953a1183e191e9ec4ab15c31c6522f625ad (diff)
fs: Create functions to load and allocate a file
This functionality current sits in bootstd, but it is more generally useful. Add a function to load a file into memory, allocating it as needed. Adjust bootstd to use this version. Note: Tests are added in the subsequent patch which converts the 'cat' command to use this function. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'boot/bootmeth-uclass.c')
-rw-r--r--boot/bootmeth-uclass.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c
index 3b3e0614daf..701ee8ad1c8 100644
--- a/boot/bootmeth-uclass.c
+++ b/boot/bootmeth-uclass.c
@@ -301,32 +301,6 @@ int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc,
return 0;
}
-static int alloc_file(const char *fname, uint size, void **bufp)
-{
- loff_t bytes_read;
- ulong addr;
- char *buf;
- int ret;
-
- buf = malloc(size + 1);
- if (!buf)
- return log_msg_ret("buf", -ENOMEM);
- addr = map_to_sysmem(buf);
-
- ret = fs_read(fname, addr, 0, size, &bytes_read);
- if (ret) {
- free(buf);
- return log_msg_ret("read", ret);
- }
- if (size != bytes_read)
- return log_msg_ret("bread", -EIO);
- buf[size] = '\0';
-
- *bufp = buf;
-
- return 0;
-}
-
int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
{
void *buf;
@@ -338,7 +312,7 @@ int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
if (size > size_limit)
return log_msg_ret("chk", -E2BIG);
- ret = alloc_file(bflow->fname, bflow->size, &buf);
+ ret = fs_read_alloc(bflow->fname, bflow->size, align, &buf);
if (ret)
return log_msg_ret("all", ret);
@@ -374,7 +348,7 @@ int bootmeth_alloc_other(struct bootflow *bflow, const char *fname,
if (ret)
return log_msg_ret("fs", ret);
- ret = alloc_file(path, size, &buf);
+ ret = fs_read_alloc(path, size, 0, &buf);
if (ret)
return log_msg_ret("all", ret);