blob: 1350671af21a84b69bea462c203f744fdffeb1cd [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
Elyes HAOUAS918535a2016-07-28 21:25:21 +020026/* Return mapping of option ROM found in boot device. NULL on error. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050027void *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);
Pratik Prajapati2a7708a2016-11-30 17:29:10 -080037/* Locate file in a specific region of fmap. Return 0 on success. < 0 on error*/
38int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name,
39 const char *name, uint32_t *type);
Julius Wernerf975e552016-08-19 15:43:06 -070040/* Load a struct file from CBFS into a buffer. Returns amount of loaded
41 * bytes on success or 0 on error. File will get decompressed as necessary.
42 * Same decompression requirements as cbfs_load_and_decompress(). */
43size_t cbfs_boot_load_struct(const char *name, void *buf, size_t buf_size);
Aaron Durbin899d13d2015-05-15 23:39:23 -050044
Julius Werner09f29212015-09-29 13:51:35 -070045/* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes
46 * large |buffer|, decompressing it according to |compression| in the process.
47 * Returns the decompressed file size, or 0 on error.
48 * LZMA files will be mapped for decompression. LZ4 files will be decompressed
49 * in-place with the buffer size requirements outlined in compression.h. */
50size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
51 size_t in_size, void *buffer, size_t buffer_size, uint32_t compression);
52
Kyösti Mälkki9d6f3652016-06-28 07:38:46 +030053/* Return the size and fill base of the memory pstage will occupy after loaded. */
54size_t cbfs_prog_stage_section(struct prog *pstage, uintptr_t *base);
55
Aaron Durbin899d13d2015-05-15 23:39:23 -050056/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
57int cbfs_prog_stage_load(struct prog *prog);
58
Aaron Durbin899d13d2015-05-15 23:39:23 -050059/*****************************************************************
60 * Support structures and functions. Direct field access should *
61 * only be done by implementers of cbfs regions -- Not the above *
62 * API. *
63 *****************************************************************/
64
Aaron Durbin899d13d2015-05-15 23:39:23 -050065/* The cbfs_props struct describes the properties associated with a CBFS. */
66struct cbfs_props {
Aaron Durbin899d13d2015-05-15 23:39:23 -050067 /* CBFS starts at the following offset within the boot region. */
68 size_t offset;
69 /* CBFS size. */
70 size_t size;
71};
72
73/* Return < 0 on error otherwise props are filled out accordingly. */
74int cbfs_boot_region_properties(struct cbfs_props *props);
75
Aaron Durbin6d720f32015-12-08 17:00:23 -060076/* Allow external logic to take action prior to locating a program
77 * (stage or payload). */
78void cbfs_prepare_program_locate(void);
79
80/* Object used to identify location of current cbfs to use for cbfs_boot_*
81 * operations. It's used by cbfs_boot_region_properties() and
82 * cbfs_prepare_program_locate(). */
83struct cbfs_locator {
84 const char *name;
85 void (*prepare)(void);
86 /* Returns 0 on successful fill of cbfs properties. */
87 int (*locate)(struct cbfs_props *props);
88};
89
Peter Stuge483b7bb2009-04-14 07:40:01 +000090#endif