···66 * Written by Simon Glass <sjg@chromium.org>
77 */
8899-#include <part.h>
1010-#include <vsprintf.h>
99+#include <blk.h>
1010+#include <memalign.h>
1111+#include <spl.h>
1112#include "vbe_common.h"
12131314int vbe_get_blk(const char *storage, struct udevice **blkp)
···34353536 return 0;
3637}
3838+3939+int vbe_read_version(struct udevice *blk, ulong offset, char *version,
4040+ int max_size)
4141+{
4242+ ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN);
4343+4444+ /* we can use an assert() here since we already read only one block */
4545+ assert(max_size <= MMC_MAX_BLOCK_LEN);
4646+4747+ /*
4848+ * we can use an assert() here since reading the wrong block will just
4949+ * cause an invalid version-string to be (safely) read
5050+ */
5151+ assert(!(offset & (MMC_MAX_BLOCK_LEN - 1)));
5252+5353+ offset /= MMC_MAX_BLOCK_LEN;
5454+5555+ if (blk_read(blk, offset, 1, buf) != 1)
5656+ return log_msg_ret("read", -EIO);
5757+ strlcpy(version, buf, max_size);
5858+ log_debug("version=%s\n", version);
5959+6060+ return 0;
6161+}
+17
boot/vbe_common.h
···6161 */
6262int vbe_get_blk(const char *storage, struct udevice **blkp);
63636464+/**
6565+ * vbe_read_version() - Read version-string from a block device
6666+ *
6767+ * Reads the VBE version-string from a device. This function reads a single
6868+ * block from the device, so the string cannot be larger than that. It uses a
6969+ * temporary buffer for the read, then copies in up to @size bytes
7070+ *
7171+ * @blk: Device to read from
7272+ * @offset: Offset to read, in bytes
7373+ * @version: Place to put the string
7474+ * @max_size: Maximum size of @version
7575+ * Return: 0 if OK, -E2BIG if @max_size > block size, -EBADF if the offset is
7676+ * not block-aligned, -EIO if an I/O error occurred
7777+ */
7878+int vbe_read_version(struct udevice *blk, ulong offset, char *version,
7979+ int max_size);
8080+6481#endif /* __VBE_ABREC_H */
+2-28
boot/vbe_simple.c
···2121#include <u-boot/crc.h>
2222#include "vbe_simple.h"
23232424-static int simple_read_version(const struct simple_priv *priv,
2525- struct udevice *blk, u8 *buf,
2626- struct simple_state *state)
2727-{
2828- int start;
2929-3030- /* we can use an assert() here since we already read only one block */
3131- assert(priv->version_size <= MMC_MAX_BLOCK_LEN);
3232-3333- start = priv->area_start + priv->version_offset;
3434-3535- /*
3636- * we can use an assert() here since reading the wrong block will just
3737- * cause an invalid version-string to be (safely) read
3838- */
3939- assert(!(start & (MMC_MAX_BLOCK_LEN - 1)));
4040-4141- start /= MMC_MAX_BLOCK_LEN;
4242-4343- if (blk_read(blk, start, 1, buf) != 1)
4444- return log_msg_ret("read", -EIO);
4545- strlcpy(state->fw_version, buf, MAX_VERSION_LEN);
4646- log_debug("version=%s\n", state->fw_version);
4747-4848- return 0;
4949-}
5050-5124static int simple_read_nvdata(const struct simple_priv *priv,
5225 struct udevice *blk, u8 *buf,
5326 struct simple_state *state)
···10578 if (ret)
10679 return log_msg_ret("blk", ret);
10780108108- ret = simple_read_version(priv, blk, buf, state);
8181+ ret = vbe_read_version(blk, priv->area_start + priv->version_offset,
8282+ state->fw_version, MAX_VERSION_LEN);
10983 if (ret)
11084 return log_msg_ret("ver", ret);
11185