"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Simon Glass and committed by
Tom Rini
47e56185 190b1282

+46 -30
+27 -2
boot/vbe_common.c
··· 6 6 * Written by Simon Glass <sjg@chromium.org> 7 7 */ 8 8 9 - #include <part.h> 10 - #include <vsprintf.h> 9 + #include <blk.h> 10 + #include <memalign.h> 11 + #include <spl.h> 11 12 #include "vbe_common.h" 12 13 13 14 int vbe_get_blk(const char *storage, struct udevice **blkp) ··· 34 35 35 36 return 0; 36 37 } 38 + 39 + int vbe_read_version(struct udevice *blk, ulong offset, char *version, 40 + int max_size) 41 + { 42 + ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN); 43 + 44 + /* we can use an assert() here since we already read only one block */ 45 + assert(max_size <= MMC_MAX_BLOCK_LEN); 46 + 47 + /* 48 + * we can use an assert() here since reading the wrong block will just 49 + * cause an invalid version-string to be (safely) read 50 + */ 51 + assert(!(offset & (MMC_MAX_BLOCK_LEN - 1))); 52 + 53 + offset /= MMC_MAX_BLOCK_LEN; 54 + 55 + if (blk_read(blk, offset, 1, buf) != 1) 56 + return log_msg_ret("read", -EIO); 57 + strlcpy(version, buf, max_size); 58 + log_debug("version=%s\n", version); 59 + 60 + return 0; 61 + }
+17
boot/vbe_common.h
··· 61 61 */ 62 62 int vbe_get_blk(const char *storage, struct udevice **blkp); 63 63 64 + /** 65 + * vbe_read_version() - Read version-string from a block device 66 + * 67 + * Reads the VBE version-string from a device. This function reads a single 68 + * block from the device, so the string cannot be larger than that. It uses a 69 + * temporary buffer for the read, then copies in up to @size bytes 70 + * 71 + * @blk: Device to read from 72 + * @offset: Offset to read, in bytes 73 + * @version: Place to put the string 74 + * @max_size: Maximum size of @version 75 + * Return: 0 if OK, -E2BIG if @max_size > block size, -EBADF if the offset is 76 + * not block-aligned, -EIO if an I/O error occurred 77 + */ 78 + int vbe_read_version(struct udevice *blk, ulong offset, char *version, 79 + int max_size); 80 + 64 81 #endif /* __VBE_ABREC_H */
+2 -28
boot/vbe_simple.c
··· 21 21 #include <u-boot/crc.h> 22 22 #include "vbe_simple.h" 23 23 24 - static int simple_read_version(const struct simple_priv *priv, 25 - struct udevice *blk, u8 *buf, 26 - struct simple_state *state) 27 - { 28 - int start; 29 - 30 - /* we can use an assert() here since we already read only one block */ 31 - assert(priv->version_size <= MMC_MAX_BLOCK_LEN); 32 - 33 - start = priv->area_start + priv->version_offset; 34 - 35 - /* 36 - * we can use an assert() here since reading the wrong block will just 37 - * cause an invalid version-string to be (safely) read 38 - */ 39 - assert(!(start & (MMC_MAX_BLOCK_LEN - 1))); 40 - 41 - start /= MMC_MAX_BLOCK_LEN; 42 - 43 - if (blk_read(blk, start, 1, buf) != 1) 44 - return log_msg_ret("read", -EIO); 45 - strlcpy(state->fw_version, buf, MAX_VERSION_LEN); 46 - log_debug("version=%s\n", state->fw_version); 47 - 48 - return 0; 49 - } 50 - 51 24 static int simple_read_nvdata(const struct simple_priv *priv, 52 25 struct udevice *blk, u8 *buf, 53 26 struct simple_state *state) ··· 105 78 if (ret) 106 79 return log_msg_ret("blk", ret); 107 80 108 - ret = simple_read_version(priv, blk, buf, state); 81 + ret = vbe_read_version(blk, priv->area_start + priv->version_offset, 82 + state->fw_version, MAX_VERSION_LEN); 109 83 if (ret) 110 84 return log_msg_ret("ver", ret); 111 85