blob: d3c3722c4814985de6b9707f21864092e679f1da [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Gabe Black7f8574c2012-10-12 14:26:11 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Gabe Black7f8574c2012-10-12 14:26:11 +00004 */
5
Guillaume GARDET647ffed2016-06-17 11:45:37 +02006#include <common.h>
Gabe Black7f8574c2012-10-12 14:26:11 +00007#include <cbfs.h>
8#include <malloc.h>
9#include <asm/byteorder.h>
10
Simon Glasse78f9bb2020-05-24 17:38:17 -060011/* Offset of master header from the start of a coreboot ROM */
12#define MASTER_HDR_OFFSET 0x38
13
Simon Glass7b5ee962019-08-14 19:56:11 -060014static const u32 good_magic = 0x4f524243;
15static const u8 good_file_magic[] = "LARCHIVE";
Simon Glassbc94f0a2019-08-14 19:56:12 -060016
Simon Glassec36d7a2020-05-24 17:38:20 -060017/**
18 * struct cbfs_priv - Private data for this driver
19 *
20 * @initialised: true if this CBFS has been inited
21 * @start: Start position of CBFS in memory, typically memory-mapped SPI flash
22 * @header: Header read from the CBFS, byte-swapped so U-Boot can access it
23 * @file_cache: List of file headers read from CBFS
24 * @result: Success/error result
25 */
Simon Glassbc94f0a2019-08-14 19:56:12 -060026struct cbfs_priv {
Simon Glass2029a6d2020-05-24 17:38:14 -060027 bool initialized;
Simon Glassec36d7a2020-05-24 17:38:20 -060028 void *start;
Simon Glassbc94f0a2019-08-14 19:56:12 -060029 struct cbfs_header header;
30 struct cbfs_cachenode *file_cache;
Simon Glassf152bf02019-08-14 19:56:13 -060031 enum cbfs_result result;
Simon Glassbc94f0a2019-08-14 19:56:12 -060032};
33
34static struct cbfs_priv cbfs_s;
Gabe Black7f8574c2012-10-12 14:26:11 +000035
36const char *file_cbfs_error(void)
37{
Simon Glassf152bf02019-08-14 19:56:13 -060038 switch (cbfs_s.result) {
Gabe Black7f8574c2012-10-12 14:26:11 +000039 case CBFS_SUCCESS:
40 return "Success";
41 case CBFS_NOT_INITIALIZED:
42 return "CBFS not initialized";
43 case CBFS_BAD_HEADER:
44 return "Bad CBFS header";
45 case CBFS_BAD_FILE:
46 return "Bad CBFS file";
47 case CBFS_FILE_NOT_FOUND:
48 return "File not found";
49 default:
50 return "Unknown";
51 }
52}
53
Simon Glassf152bf02019-08-14 19:56:13 -060054enum cbfs_result cbfs_get_result(void)
55{
56 return cbfs_s.result;
57}
58
Gabe Black7f8574c2012-10-12 14:26:11 +000059/* Do endian conversion on the CBFS header structure. */
60static void swap_header(struct cbfs_header *dest, struct cbfs_header *src)
61{
62 dest->magic = be32_to_cpu(src->magic);
63 dest->version = be32_to_cpu(src->version);
64 dest->rom_size = be32_to_cpu(src->rom_size);
65 dest->boot_block_size = be32_to_cpu(src->boot_block_size);
66 dest->align = be32_to_cpu(src->align);
67 dest->offset = be32_to_cpu(src->offset);
68}
69
70/* Do endian conversion on a CBFS file header. */
71static void swap_file_header(struct cbfs_fileheader *dest,
72 const struct cbfs_fileheader *src)
73{
74 memcpy(&dest->magic, &src->magic, sizeof(dest->magic));
75 dest->len = be32_to_cpu(src->len);
76 dest->type = be32_to_cpu(src->type);
Simon Glass87d15042019-07-08 13:18:22 -060077 dest->attributes_offset = be32_to_cpu(src->attributes_offset);
Gabe Black7f8574c2012-10-12 14:26:11 +000078 dest->offset = be32_to_cpu(src->offset);
79}
80
81/*
82 * Given a starting position in memory, scan forward, bounded by a size, and
83 * find the next valid CBFS file. No memory is allocated by this function. The
84 * caller is responsible for allocating space for the new file structure.
85 *
86 * @param start The location in memory to start from.
87 * @param size The size of the memory region to search.
88 * @param align The alignment boundaries to check on.
Simon Glassefbd7b12019-08-14 19:56:15 -060089 * @param new_node A pointer to the file structure to load.
Gabe Black7f8574c2012-10-12 14:26:11 +000090 * @param used A pointer to the count of of bytes scanned through,
91 * including the file if one is found.
92 *
Simon Glassc72d4a82020-05-24 17:38:15 -060093 * @return 0 if a file is found, -ENOENT if one isn't, -EBADF if a bad header
94 * is found.
Gabe Black7f8574c2012-10-12 14:26:11 +000095 */
Simon Glass6ca4c382020-05-24 17:38:19 -060096static int file_cbfs_next_file(struct cbfs_priv *priv, void *start, int size,
Simon Glassc72d4a82020-05-24 17:38:15 -060097 int align, struct cbfs_cachenode *new_node,
98 int *used)
Gabe Black7f8574c2012-10-12 14:26:11 +000099{
100 struct cbfs_fileheader header;
101
102 *used = 0;
103
104 while (size >= align) {
Simon Glass6ca4c382020-05-24 17:38:19 -0600105 const struct cbfs_fileheader *file_header = start;
Gabe Black7f8574c2012-10-12 14:26:11 +0000106 u32 name_len;
107 u32 step;
108
109 /* Check if there's a file here. */
Simon Glassefbd7b12019-08-14 19:56:15 -0600110 if (memcmp(good_file_magic, &file_header->magic,
111 sizeof(file_header->magic))) {
Gabe Black7f8574c2012-10-12 14:26:11 +0000112 *used += align;
113 size -= align;
114 start += align;
115 continue;
116 }
117
Simon Glassefbd7b12019-08-14 19:56:15 -0600118 swap_file_header(&header, file_header);
Christian Gmeiner81ff3bb2018-12-22 01:55:48 -0800119 if (header.offset < sizeof(struct cbfs_fileheader)) {
Simon Glassf152bf02019-08-14 19:56:13 -0600120 priv->result = CBFS_BAD_FILE;
Simon Glassc72d4a82020-05-24 17:38:15 -0600121 return -EBADF;
Gabe Black7f8574c2012-10-12 14:26:11 +0000122 }
Simon Glassefbd7b12019-08-14 19:56:15 -0600123 new_node->next = NULL;
124 new_node->type = header.type;
125 new_node->data = start + header.offset;
126 new_node->data_length = header.len;
Yaroslav K9999bb82016-08-08 20:32:15 -0700127 name_len = header.offset - sizeof(struct cbfs_fileheader);
Simon Glassefbd7b12019-08-14 19:56:15 -0600128 new_node->name = (char *)file_header +
Yaroslav K9999bb82016-08-08 20:32:15 -0700129 sizeof(struct cbfs_fileheader);
Simon Glassefbd7b12019-08-14 19:56:15 -0600130 new_node->name_length = name_len;
131 new_node->attributes_offset = header.attributes_offset;
Gabe Black7f8574c2012-10-12 14:26:11 +0000132
133 step = header.len;
134 if (step % align)
135 step = step + align - step % align;
136
137 *used += step;
Simon Glassc72d4a82020-05-24 17:38:15 -0600138 return 0;
Gabe Black7f8574c2012-10-12 14:26:11 +0000139 }
Simon Glassc72d4a82020-05-24 17:38:15 -0600140
141 return -ENOENT;
Gabe Black7f8574c2012-10-12 14:26:11 +0000142}
143
144/* Look through a CBFS instance and copy file metadata into regular memory. */
Simon Glassec36d7a2020-05-24 17:38:20 -0600145static int file_cbfs_fill_cache(struct cbfs_priv *priv, int size, int align)
Gabe Black7f8574c2012-10-12 14:26:11 +0000146{
147 struct cbfs_cachenode *cache_node;
Simon Glassefbd7b12019-08-14 19:56:15 -0600148 struct cbfs_cachenode *new_node;
Simon Glassbc94f0a2019-08-14 19:56:12 -0600149 struct cbfs_cachenode **cache_tail = &priv->file_cache;
Simon Glassec36d7a2020-05-24 17:38:20 -0600150 void *start;
Gabe Black7f8574c2012-10-12 14:26:11 +0000151
152 /* Clear out old information. */
Simon Glassbc94f0a2019-08-14 19:56:12 -0600153 cache_node = priv->file_cache;
Gabe Black7f8574c2012-10-12 14:26:11 +0000154 while (cache_node) {
Simon Glassefbd7b12019-08-14 19:56:15 -0600155 struct cbfs_cachenode *old_node = cache_node;
Gabe Black7f8574c2012-10-12 14:26:11 +0000156 cache_node = cache_node->next;
Simon Glassefbd7b12019-08-14 19:56:15 -0600157 free(old_node);
Gabe Black7f8574c2012-10-12 14:26:11 +0000158 }
Simon Glassbc94f0a2019-08-14 19:56:12 -0600159 priv->file_cache = NULL;
Gabe Black7f8574c2012-10-12 14:26:11 +0000160
Simon Glassec36d7a2020-05-24 17:38:20 -0600161 start = priv->start;
Gabe Black7f8574c2012-10-12 14:26:11 +0000162 while (size >= align) {
Simon Glassc72d4a82020-05-24 17:38:15 -0600163 int used;
Simon Glass650b2412020-05-24 17:38:12 -0600164 int ret;
Gabe Black7f8574c2012-10-12 14:26:11 +0000165
Simon Glassefbd7b12019-08-14 19:56:15 -0600166 new_node = (struct cbfs_cachenode *)
Gabe Black7f8574c2012-10-12 14:26:11 +0000167 malloc(sizeof(struct cbfs_cachenode));
Simon Glassc72d4a82020-05-24 17:38:15 -0600168 if (!new_node)
169 return -ENOMEM;
Simon Glass650b2412020-05-24 17:38:12 -0600170 ret = file_cbfs_next_file(priv, start, size, align, new_node,
171 &used);
Gabe Black7f8574c2012-10-12 14:26:11 +0000172
Simon Glass650b2412020-05-24 17:38:12 -0600173 if (ret < 0) {
Simon Glassefbd7b12019-08-14 19:56:15 -0600174 free(new_node);
Simon Glassc72d4a82020-05-24 17:38:15 -0600175 if (ret == -ENOENT)
176 break;
177 return ret;
Gabe Black7f8574c2012-10-12 14:26:11 +0000178 }
Simon Glassefbd7b12019-08-14 19:56:15 -0600179 *cache_tail = new_node;
180 cache_tail = &new_node->next;
Gabe Black7f8574c2012-10-12 14:26:11 +0000181
182 size -= used;
183 start += used;
184 }
Simon Glassf152bf02019-08-14 19:56:13 -0600185 priv->result = CBFS_SUCCESS;
Simon Glassc72d4a82020-05-24 17:38:15 -0600186
187 return 0;
Gabe Black7f8574c2012-10-12 14:26:11 +0000188}
189
Simon Glass51541002020-05-24 17:38:18 -0600190/**
191 * load_header() - Load the CBFS header
192 *
193 * Get the CBFS header out of the ROM and do endian conversion.
194 *
195 * @priv: Private data, which is inited by this function
196 * @addr: Address of CBFS header in memory-mapped SPI flash
197 * @return 0 if OK, -ENXIO if the header is bad
198 */
199static int load_header(struct cbfs_priv *priv, ulong addr)
Gabe Black7f8574c2012-10-12 14:26:11 +0000200{
Simon Glass9ad16d62020-05-24 17:38:16 -0600201 struct cbfs_header *header = &priv->header;
Gabe Black7f8574c2012-10-12 14:26:11 +0000202 struct cbfs_header *header_in_rom;
203
Simon Glass51541002020-05-24 17:38:18 -0600204 memset(priv, '\0', sizeof(*priv));
205 header_in_rom = (struct cbfs_header *)addr;
Gabe Black7f8574c2012-10-12 14:26:11 +0000206 swap_header(header, header_in_rom);
207
208 if (header->magic != good_magic || header->offset >
209 header->rom_size - header->boot_block_size) {
Simon Glass9ad16d62020-05-24 17:38:16 -0600210 priv->result = CBFS_BAD_HEADER;
Simon Glass51541002020-05-24 17:38:18 -0600211 return -ENXIO;
Gabe Black7f8574c2012-10-12 14:26:11 +0000212 }
Simon Glass51541002020-05-24 17:38:18 -0600213
Gabe Black7f8574c2012-10-12 14:26:11 +0000214 return 0;
215}
216
Simon Glass51541002020-05-24 17:38:18 -0600217/**
218 * file_cbfs_load_header() - Get the CBFS header out of the ROM, given the end
219 *
220 * @priv: Private data, which is inited by this function
221 * @end_of_rom: Address of the last byte of the ROM (typically 0xffffffff)
222 * @return 0 if OK, -ENXIO if the header is bad
223 */
224static int file_cbfs_load_header(struct cbfs_priv *priv, ulong end_of_rom)
Simon Glassaa4274e2019-08-14 19:56:14 -0600225{
Simon Glass51541002020-05-24 17:38:18 -0600226 int offset = *(u32 *)(end_of_rom - 3);
Simon Glassec36d7a2020-05-24 17:38:20 -0600227 int ret;
228
229 ret = load_header(priv, end_of_rom + offset + 1);
230 if (ret)
231 return ret;
232 priv->start = (void *)(end_of_rom + 1 - priv->header.rom_size);
Simon Glassaa4274e2019-08-14 19:56:14 -0600233
Simon Glassec36d7a2020-05-24 17:38:20 -0600234 return 0;
Simon Glass51541002020-05-24 17:38:18 -0600235}
Simon Glassaa4274e2019-08-14 19:56:14 -0600236
Simon Glass51541002020-05-24 17:38:18 -0600237/**
238 * cbfs_load_header_ptr() - Get the CBFS header out of the ROM, given the base
239 *
240 * @priv: Private data, which is inited by this function
241 * @base: Address of the first byte of the ROM (e.g. 0xff000000)
242 * @return 0 if OK, -ENXIO if the header is bad
243 */
244static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base)
245{
Simon Glassec36d7a2020-05-24 17:38:20 -0600246 int ret;
247
248 ret = load_header(priv, base + MASTER_HDR_OFFSET);
249 if (ret)
250 return ret;
251 priv->start = (void *)base;
252
253 return 0;
Simon Glassaa4274e2019-08-14 19:56:14 -0600254}
255
Simon Glass04923172020-05-24 17:38:21 -0600256static int cbfs_init(struct cbfs_priv *priv, ulong end_of_rom)
Gabe Black7f8574c2012-10-12 14:26:11 +0000257{
Simon Glass04923172020-05-24 17:38:21 -0600258 int ret;
Gabe Black7f8574c2012-10-12 14:26:11 +0000259
Simon Glass04923172020-05-24 17:38:21 -0600260 ret = file_cbfs_load_header(priv, end_of_rom);
261 if (ret)
262 return ret;
263
264 ret = file_cbfs_fill_cache(priv, priv->header.rom_size,
265 priv->header.align);
266 if (ret)
267 return ret;
268 priv->initialized = true;
269
270 return 0;
Simon Glassbc94f0a2019-08-14 19:56:12 -0600271}
272
Simon Glass04923172020-05-24 17:38:21 -0600273int file_cbfs_init(ulong end_of_rom)
Simon Glassbc94f0a2019-08-14 19:56:12 -0600274{
Simon Glass04923172020-05-24 17:38:21 -0600275 return cbfs_init(&cbfs_s, end_of_rom);
Gabe Black7f8574c2012-10-12 14:26:11 +0000276}
277
Simon Glassaa4274e2019-08-14 19:56:14 -0600278int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp)
279{
280 struct cbfs_priv priv_s, *priv = &priv_s;
281 int ret;
282
283 /*
284 * Use a local variable to start with until we know that the CBFS is
Simon Glass51541002020-05-24 17:38:18 -0600285 * valid.
Simon Glassaa4274e2019-08-14 19:56:14 -0600286 */
Simon Glass51541002020-05-24 17:38:18 -0600287 ret = cbfs_load_header_ptr(priv, base);
Simon Glassaa4274e2019-08-14 19:56:14 -0600288 if (ret)
289 return ret;
290
Simon Glassec36d7a2020-05-24 17:38:20 -0600291 file_cbfs_fill_cache(priv, priv->header.rom_size, priv->header.align);
Simon Glassaa4274e2019-08-14 19:56:14 -0600292 if (priv->result != CBFS_SUCCESS)
293 return -EINVAL;
294
Simon Glass2029a6d2020-05-24 17:38:14 -0600295 priv->initialized = true;
Simon Glassaa4274e2019-08-14 19:56:14 -0600296 priv = malloc(sizeof(priv_s));
297 if (!priv)
298 return -ENOMEM;
299 memcpy(priv, &priv_s, sizeof(priv_s));
300 *privp = priv;
301
302 return 0;
303}
304
Gabe Black7f8574c2012-10-12 14:26:11 +0000305const struct cbfs_header *file_cbfs_get_header(void)
306{
Simon Glassbc94f0a2019-08-14 19:56:12 -0600307 struct cbfs_priv *priv = &cbfs_s;
308
309 if (priv->initialized) {
Simon Glassf152bf02019-08-14 19:56:13 -0600310 priv->result = CBFS_SUCCESS;
Simon Glassbc94f0a2019-08-14 19:56:12 -0600311 return &priv->header;
Gabe Black7f8574c2012-10-12 14:26:11 +0000312 } else {
Simon Glassf152bf02019-08-14 19:56:13 -0600313 priv->result = CBFS_NOT_INITIALIZED;
Gabe Black7f8574c2012-10-12 14:26:11 +0000314 return NULL;
315 }
316}
317
318const struct cbfs_cachenode *file_cbfs_get_first(void)
319{
Simon Glassbc94f0a2019-08-14 19:56:12 -0600320 struct cbfs_priv *priv = &cbfs_s;
321
322 if (!priv->initialized) {
Simon Glassf152bf02019-08-14 19:56:13 -0600323 priv->result = CBFS_NOT_INITIALIZED;
Gabe Black7f8574c2012-10-12 14:26:11 +0000324 return NULL;
325 } else {
Simon Glassf152bf02019-08-14 19:56:13 -0600326 priv->result = CBFS_SUCCESS;
Simon Glassbc94f0a2019-08-14 19:56:12 -0600327 return priv->file_cache;
Gabe Black7f8574c2012-10-12 14:26:11 +0000328 }
329}
330
331void file_cbfs_get_next(const struct cbfs_cachenode **file)
332{
Simon Glassbc94f0a2019-08-14 19:56:12 -0600333 struct cbfs_priv *priv = &cbfs_s;
334
335 if (!priv->initialized) {
Simon Glassf152bf02019-08-14 19:56:13 -0600336 priv->result = CBFS_NOT_INITIALIZED;
Simon Glassbc94f0a2019-08-14 19:56:12 -0600337 *file = NULL;
Gabe Black7f8574c2012-10-12 14:26:11 +0000338 return;
339 }
340
341 if (*file)
342 *file = (*file)->next;
Simon Glassf152bf02019-08-14 19:56:13 -0600343 priv->result = CBFS_SUCCESS;
Gabe Black7f8574c2012-10-12 14:26:11 +0000344}
345
Simon Glassbc94f0a2019-08-14 19:56:12 -0600346const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv,
347 const char *name)
Gabe Black7f8574c2012-10-12 14:26:11 +0000348{
Simon Glassbc94f0a2019-08-14 19:56:12 -0600349 struct cbfs_cachenode *cache_node = priv->file_cache;
Gabe Black7f8574c2012-10-12 14:26:11 +0000350
Simon Glassbc94f0a2019-08-14 19:56:12 -0600351 if (!priv->initialized) {
Simon Glassf152bf02019-08-14 19:56:13 -0600352 priv->result = CBFS_NOT_INITIALIZED;
Gabe Black7f8574c2012-10-12 14:26:11 +0000353 return NULL;
354 }
355
356 while (cache_node) {
357 if (!strcmp(name, cache_node->name))
358 break;
359 cache_node = cache_node->next;
360 }
361 if (!cache_node)
Simon Glassf152bf02019-08-14 19:56:13 -0600362 priv->result = CBFS_FILE_NOT_FOUND;
Gabe Black7f8574c2012-10-12 14:26:11 +0000363 else
Simon Glassf152bf02019-08-14 19:56:13 -0600364 priv->result = CBFS_SUCCESS;
Gabe Black7f8574c2012-10-12 14:26:11 +0000365
366 return cache_node;
367}
368
Simon Glassbc94f0a2019-08-14 19:56:12 -0600369const struct cbfs_cachenode *file_cbfs_find(const char *name)
370{
371 return cbfs_find_file(&cbfs_s, name);
372}
373
Simon Glass9c422152020-05-24 17:38:22 -0600374static int find_uncached(struct cbfs_priv *priv, const char *name, void *start,
375 struct cbfs_cachenode *node)
Gabe Black7f8574c2012-10-12 14:26:11 +0000376{
Simon Glass9c422152020-05-24 17:38:22 -0600377 int size = priv->header.rom_size;
378 int align = priv->header.align;
Gabe Black7f8574c2012-10-12 14:26:11 +0000379
380 while (size >= align) {
Simon Glassc72d4a82020-05-24 17:38:15 -0600381 int used;
Simon Glass9c422152020-05-24 17:38:22 -0600382 int ret;
Gabe Black7f8574c2012-10-12 14:26:11 +0000383
Simon Glass9c422152020-05-24 17:38:22 -0600384 ret = file_cbfs_next_file(priv, start, size, align, node,
Simon Glass650b2412020-05-24 17:38:12 -0600385 &used);
Simon Glassc72d4a82020-05-24 17:38:15 -0600386 if (ret == -ENOENT)
Gabe Black7f8574c2012-10-12 14:26:11 +0000387 break;
Simon Glassc72d4a82020-05-24 17:38:15 -0600388 else if (ret)
Simon Glass9c422152020-05-24 17:38:22 -0600389 return ret;
390 if (!strcmp(name, node->name))
391 return 0;
Gabe Black7f8574c2012-10-12 14:26:11 +0000392
393 size -= used;
394 start += used;
395 }
Simon Glass9c422152020-05-24 17:38:22 -0600396 priv->result = CBFS_FILE_NOT_FOUND;
397
398 return -ENOENT;
399}
400
401int file_cbfs_find_uncached(ulong end_of_rom, const char *name,
402 struct cbfs_cachenode *node)
403{
404 struct cbfs_priv priv;
405 void *start;
406 int ret;
407
408 ret = file_cbfs_load_header(&priv, end_of_rom);
409 if (ret)
410 return ret;
411 start = priv.start;
412
413 return find_uncached(&priv, name, start, node);
Gabe Black7f8574c2012-10-12 14:26:11 +0000414}
415
Simon Glass333a97d2020-05-24 17:38:23 -0600416int file_cbfs_find_uncached_base(ulong base, const char *name,
417 struct cbfs_cachenode *node)
418{
419 struct cbfs_priv priv;
420 int ret;
421
422 ret = cbfs_load_header_ptr(&priv, base);
423 if (ret)
424 return ret;
425
426 return find_uncached(&priv, name, (void *)base, node);
427}
428
Gabe Black7f8574c2012-10-12 14:26:11 +0000429const char *file_cbfs_name(const struct cbfs_cachenode *file)
430{
Simon Glassf152bf02019-08-14 19:56:13 -0600431 cbfs_s.result = CBFS_SUCCESS;
432
Gabe Black7f8574c2012-10-12 14:26:11 +0000433 return file->name;
434}
435
436u32 file_cbfs_size(const struct cbfs_cachenode *file)
437{
Simon Glassf152bf02019-08-14 19:56:13 -0600438 cbfs_s.result = CBFS_SUCCESS;
439
Gabe Black7f8574c2012-10-12 14:26:11 +0000440 return file->data_length;
441}
442
443u32 file_cbfs_type(const struct cbfs_cachenode *file)
444{
Simon Glassf152bf02019-08-14 19:56:13 -0600445 cbfs_s.result = CBFS_SUCCESS;
446
Gabe Black7f8574c2012-10-12 14:26:11 +0000447 return file->type;
448}
449
450long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer,
451 unsigned long maxsize)
452{
453 u32 size;
454
455 size = file->data_length;
456 if (maxsize && size > maxsize)
457 size = maxsize;
458
459 memcpy(buffer, file->data, size);
Simon Glassf152bf02019-08-14 19:56:13 -0600460 cbfs_s.result = CBFS_SUCCESS;
Gabe Black7f8574c2012-10-12 14:26:11 +0000461
Gabe Black7f8574c2012-10-12 14:26:11 +0000462 return size;
463}