diff options
author | Simon Glass <sjg@chromium.org> | 2025-01-15 18:27:08 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-01-22 09:47:49 -0600 |
commit | 47e56185084941f3bccc8b8352260ba2ee5e5e56 (patch) | |
tree | e9fe386597e64d7305c82beab6c8b737e32ec5de /boot/vbe_common.c | |
parent | 190b128252b3861865d63c73ac9f13731aeb950f (diff) |
vbe: Move reading the version into the common file
All VBE methods read a version string, so move this function into a
common file.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'boot/vbe_common.c')
-rw-r--r-- | boot/vbe_common.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/boot/vbe_common.c b/boot/vbe_common.c index ede452ba306..8bbcc37e67e 100644 --- a/boot/vbe_common.c +++ b/boot/vbe_common.c @@ -6,8 +6,9 @@ * Written by Simon Glass <sjg@chromium.org> */ -#include <part.h> -#include <vsprintf.h> +#include <blk.h> +#include <memalign.h> +#include <spl.h> #include "vbe_common.h" int vbe_get_blk(const char *storage, struct udevice **blkp) @@ -34,3 +35,27 @@ int vbe_get_blk(const char *storage, struct udevice **blkp) return 0; } + +int vbe_read_version(struct udevice *blk, ulong offset, char *version, + int max_size) +{ + ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN); + + /* we can use an assert() here since we already read only one block */ + assert(max_size <= MMC_MAX_BLOCK_LEN); + + /* + * we can use an assert() here since reading the wrong block will just + * cause an invalid version-string to be (safely) read + */ + assert(!(offset & (MMC_MAX_BLOCK_LEN - 1))); + + offset /= MMC_MAX_BLOCK_LEN; + + if (blk_read(blk, offset, 1, buf) != 1) + return log_msg_ret("read", -EIO); + strlcpy(version, buf, max_size); + log_debug("version=%s\n", version); + + return 0; +} |