diff options
author | Simon Glass <sjg@chromium.org> | 2023-01-06 08:52:34 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-01-16 18:26:50 -0500 |
commit | 24d8e1b37b90760a6c9867f37210aa4b1f2e8f63 (patch) | |
tree | c9193497e5ac61483354472520a01f872f0cb2f3 /boot | |
parent | 2175e76a51e53798ee4e19903b368a7e6c98356a (diff) | |
download | u-boot-24d8e1b37b90760a6c9867f37210aa4b1f2e8f63.tar.gz |
bootstd: Allow reading a logo for the OS
Some operating systems provide a logo in bmp format. Read this in if
present so it can be displayed in the menu.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'boot')
-rw-r--r-- | boot/bootmeth-uclass.c | 69 | ||||
-rw-r--r-- | boot/bootmeth_script.c | 4 |
2 files changed, 64 insertions, 9 deletions
diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c index 25552dd96f6..4c3529d1555 100644 --- a/boot/bootmeth-uclass.c +++ b/boot/bootmeth-uclass.c @@ -290,25 +290,19 @@ int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc, return 0; } -int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align) +static int alloc_file(const char *fname, uint size, void **bufp) { loff_t bytes_read; ulong addr; char *buf; - uint size; int ret; - size = bflow->size; - log_debug(" - script file size %x\n", size); - if (size > size_limit) - return log_msg_ret("chk", -E2BIG); - - buf = memalign(align, size + 1); + buf = malloc(size + 1); if (!buf) return log_msg_ret("buf", -ENOMEM); addr = map_to_sysmem(buf); - ret = fs_read(bflow->fname, addr, 0, 0, &bytes_read); + ret = fs_read(fname, addr, 0, size, &bytes_read); if (ret) { free(buf); return log_msg_ret("read", ret); @@ -316,12 +310,69 @@ int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align) if (size != bytes_read) return log_msg_ret("bread", -EINVAL); buf[size] = '\0'; + + *bufp = buf; + + return 0; +} + +int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align) +{ + void *buf; + uint size; + int ret; + + size = bflow->size; + log_debug(" - script file size %x\n", size); + if (size > size_limit) + return log_msg_ret("chk", -E2BIG); + + ret = alloc_file(bflow->fname, bflow->size, &buf); + if (ret) + return log_msg_ret("all", ret); + bflow->state = BOOTFLOWST_READY; bflow->buf = buf; return 0; } +int bootmeth_alloc_other(struct bootflow *bflow, const char *fname, + void **bufp, uint *sizep) +{ + struct blk_desc *desc = NULL; + char path[200]; + loff_t size; + void *buf; + int ret; + + snprintf(path, sizeof(path), "%s%s", bflow->subdir, fname); + log_debug("trying: %s\n", path); + + if (bflow->blk) + desc = dev_get_uclass_plat(bflow->blk); + + ret = setup_fs(bflow, desc); + if (ret) + return log_msg_ret("fs", ret); + + ret = fs_size(path, &size); + log_debug(" %s - err=%d\n", path, ret); + + ret = setup_fs(bflow, desc); + if (ret) + return log_msg_ret("fs", ret); + + ret = alloc_file(path, size, &buf); + if (ret) + return log_msg_ret("all", ret); + + *bufp = buf; + *sizep = size; + + return 0; +} + int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow, const char *file_path, ulong addr, ulong *sizep) { diff --git a/boot/bootmeth_script.c b/boot/bootmeth_script.c index ba8e5d0438a..c7061eb998f 100644 --- a/boot/bootmeth_script.c +++ b/boot/bootmeth_script.c @@ -109,6 +109,10 @@ static int script_read_bootflow(struct udevice *dev, struct bootflow *bflow) if (ret) return log_msg_ret("inf", ret); + ret = bootmeth_alloc_other(bflow, "boot.bmp", &bflow->logo, + &bflow->logo_size); + /* ignore error */ + return 0; } |