blob: 5d60716ef4e1248c7aa3ed854521f101f53827d2 [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Peter Stuge483b7bb2009-04-14 07:40:01 +000018 */
19
20#ifndef _CBFS_H_
21#define _CBFS_H_
22
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050023#include <commonlib/cbfs_serialized.h>
24#include <commonlib/region.h>
Aaron Durbin899d13d2015-05-15 23:39:23 -050025#include <program_loading.h>
Daisuke Nojirie1298df2014-12-01 15:30:01 -080026
27/*
Aaron Durbin899d13d2015-05-15 23:39:23 -050028 * CBFS operations consist of the following concepts:
29 * - region_device for the boot media
30 * - cbfsd which is a descriptor for representing a cbfs instance
Daisuke Nojirie1298df2014-12-01 15:30:01 -080031 */
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +080032
Aaron Durbin37a5d152015-09-17 16:09:30 -050033/* Object representing cbfs files. */
34struct cbfsf;
Aaron Durbin899d13d2015-05-15 23:39:23 -050035
36/***********************************************
37 * Perform CBFS operations on the boot device. *
38 ***********************************************/
39
40/* Return mapping of option rom found in boot device. NULL on error. */
41void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device);
42/* Load stage by name into memory. Returns entry address on success. NULL on
43 * failure. */
44void *cbfs_boot_load_stage_by_name(const char *name);
45/* Locate file by name and optional type. Return 0 on success. < 0 on error. */
Aaron Durbin37a5d152015-09-17 16:09:30 -050046int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type);
Aaron Durbin899d13d2015-05-15 23:39:23 -050047/* Map file into memory leaking the mapping. Only should be used when
48 * leaking mappings are a no-op. Returns NULL on error, else returns
49 * the mapping and sets the size of the file. */
50void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size);
51
52/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
53int cbfs_prog_stage_load(struct prog *prog);
54
55/* Locate file by name and optional type. Returns 0 on succcess else < 0 on
56 * error.*/
Aaron Durbin37a5d152015-09-17 16:09:30 -050057int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs,
Aaron Durbin899d13d2015-05-15 23:39:23 -050058 const char *name, uint32_t *type);
59
60/*****************************************************************
61 * Support structures and functions. Direct field access should *
62 * only be done by implementers of cbfs regions -- Not the above *
63 * API. *
64 *****************************************************************/
65
Aaron Durbin37a5d152015-09-17 16:09:30 -050066struct cbfsf {
67 struct region_device metadata;
68 struct region_device data;
Aaron Durbin899d13d2015-05-15 23:39:23 -050069};
70
Aaron Durbin37a5d152015-09-17 16:09:30 -050071static inline void cbfs_file_data(struct region_device *data,
72 const struct cbfsf *file)
73{
74 rdev_chain(data, &file->data, 0, region_device_sz(&file->data));
75}
76
Aaron Durbin899d13d2015-05-15 23:39:23 -050077/* The cbfs_props struct describes the properties associated with a CBFS. */
78struct cbfs_props {
Aaron Durbin899d13d2015-05-15 23:39:23 -050079 /* CBFS starts at the following offset within the boot region. */
80 size_t offset;
81 /* CBFS size. */
82 size_t size;
83};
84
85/* Return < 0 on error otherwise props are filled out accordingly. */
86int cbfs_boot_region_properties(struct cbfs_props *props);
87
Peter Stuge483b7bb2009-04-14 07:40:01 +000088#endif