blob: 2d1921898abc9dd26c2d607d637449f7074f47af [file] [log] [blame]
Peter Stuge483b7bb2009-04-14 07:40:01 +00001/*
2 * This file is part of the coreboot project.
3 *
Aaron Durbin899d13d2015-05-15 23:39:23 -05004 * Copyright 2015 Google Inc.
Peter Stuge483b7bb2009-04-14 07:40:01 +00005 *
Peter Stuge483b7bb2009-04-14 07:40:01 +00006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Peter Stuge483b7bb2009-04-14 07:40:01 +000014 */
15
16#ifndef _CBFS_H_
17#define _CBFS_H_
18
Aaron Durbin295d58b2015-12-15 13:33:51 -060019#include <commonlib/cbfs.h>
Aaron Durbin899d13d2015-05-15 23:39:23 -050020#include <program_loading.h>
Daisuke Nojirie1298df2014-12-01 15:30:01 -080021
Aaron Durbin899d13d2015-05-15 23:39:23 -050022/***********************************************
23 * Perform CBFS operations on the boot device. *
24 ***********************************************/
25
26/* Return mapping of option rom found in boot device. NULL on error. */
27void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device);
28/* Load stage by name into memory. Returns entry address on success. NULL on
29 * failure. */
30void *cbfs_boot_load_stage_by_name(const char *name);
31/* Locate file by name and optional type. Return 0 on success. < 0 on error. */
Aaron Durbin37a5d152015-09-17 16:09:30 -050032int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type);
Aaron Durbin899d13d2015-05-15 23:39:23 -050033/* Map file into memory leaking the mapping. Only should be used when
34 * leaking mappings are a no-op. Returns NULL on error, else returns
35 * the mapping and sets the size of the file. */
36void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size);
37
Julius Werner09f29212015-09-29 13:51:35 -070038/* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes
39 * large |buffer|, decompressing it according to |compression| in the process.
40 * Returns the decompressed file size, or 0 on error.
41 * LZMA files will be mapped for decompression. LZ4 files will be decompressed
42 * in-place with the buffer size requirements outlined in compression.h. */
43size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
44 size_t in_size, void *buffer, size_t buffer_size, uint32_t compression);
45
Aaron Durbin899d13d2015-05-15 23:39:23 -050046/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
47int cbfs_prog_stage_load(struct prog *prog);
48
Aaron Durbin899d13d2015-05-15 23:39:23 -050049/*****************************************************************
50 * Support structures and functions. Direct field access should *
51 * only be done by implementers of cbfs regions -- Not the above *
52 * API. *
53 *****************************************************************/
54
Aaron Durbin899d13d2015-05-15 23:39:23 -050055/* The cbfs_props struct describes the properties associated with a CBFS. */
56struct cbfs_props {
Aaron Durbin899d13d2015-05-15 23:39:23 -050057 /* CBFS starts at the following offset within the boot region. */
58 size_t offset;
59 /* CBFS size. */
60 size_t size;
61};
62
63/* Return < 0 on error otherwise props are filled out accordingly. */
64int cbfs_boot_region_properties(struct cbfs_props *props);
65
Aaron Durbin6d720f32015-12-08 17:00:23 -060066/* Allow external logic to take action prior to locating a program
67 * (stage or payload). */
68void cbfs_prepare_program_locate(void);
69
70/* Object used to identify location of current cbfs to use for cbfs_boot_*
71 * operations. It's used by cbfs_boot_region_properties() and
72 * cbfs_prepare_program_locate(). */
73struct cbfs_locator {
74 const char *name;
75 void (*prepare)(void);
76 /* Returns 0 on successful fill of cbfs properties. */
77 int (*locate)(struct cbfs_props *props);
78};
79
Peter Stuge483b7bb2009-04-14 07:40:01 +000080#endif