1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/* SPDX-License-Identifier: BSD-3-Clause */
#ifndef _CBFS_H_
#define _CBFS_H_
#include <commonlib/bsd/cb_err.h>
#include <commonlib/bsd/cbfs_mdata.h>
#include <endian.h>
#include <stdbool.h>
/**********************************************************************************************
* CBFS FILE ACCESS APIs *
**********************************************************************************************/
/* For documentation look in src/include/cbfs.h file in the main coreboot source tree. */
static inline size_t cbfs_load(const char *name, void *buf, size_t size);
static inline size_t cbfs_ro_load(const char *name, void *buf, size_t size);
static inline void *cbfs_map(const char *name, size_t *size_out);
static inline void *cbfs_ro_map(const char *name, size_t *size_out);
void cbfs_unmap(void *mapping);
static inline size_t cbfs_get_size(const char *name);
static inline size_t cbfs_ro_get_size(const char *name);
static inline enum cbfs_type cbfs_get_type(const char *name);
static inline enum cbfs_type cbfs_ro_get_type(const char *name);
static inline bool cbfs_file_exists(const char *name);
static inline bool cbfs_ro_file_exists(const char *name);
/**********************************************************************************************
* INTERNAL HELPERS FOR INLINES, DO NOT USE. *
**********************************************************************************************/
ssize_t _cbfs_boot_lookup(const char *name, bool force_ro, union cbfs_mdata *mdata);
void *_cbfs_load(const char *name, void *buf, size_t *size_inout, bool force_ro);
/**********************************************************************************************
* INLINE IMPLEMENTATIONS *
**********************************************************************************************/
static inline void *cbfs_map(const char *name, size_t *size_out)
{
return _cbfs_load(name, NULL, size_out, false);
}
static inline void *cbfs_ro_map(const char *name, size_t *size_out)
{
return _cbfs_load(name, NULL, size_out, true);
}
static inline size_t cbfs_load(const char *name, void *buf, size_t size)
{
if (_cbfs_load(name, buf, &size, false))
return size;
else
return 0;
}
static inline size_t cbfs_ro_load(const char *name, void *buf, size_t size)
{
if (_cbfs_load(name, buf, &size, true))
return size;
else
return 0;
}
static inline size_t cbfs_get_size(const char *name)
{
union cbfs_mdata mdata;
if (_cbfs_boot_lookup(name, false, &mdata) < 0)
return 0;
else
return be32toh(mdata.h.len);
}
static inline size_t cbfs_ro_get_size(const char *name)
{
union cbfs_mdata mdata;
if (_cbfs_boot_lookup(name, true, &mdata) < 0)
return 0;
else
return be32toh(mdata.h.len);
}
static inline enum cbfs_type cbfs_get_type(const char *name)
{
union cbfs_mdata mdata;
if (_cbfs_boot_lookup(name, false, &mdata) < 0)
return CBFS_TYPE_NULL;
else
return be32toh(mdata.h.type);
}
static inline enum cbfs_type cbfs_ro_get_type(const char *name)
{
union cbfs_mdata mdata;
if (_cbfs_boot_lookup(name, true, &mdata) < 0)
return CBFS_TYPE_NULL;
else
return be32toh(mdata.h.type);
}
static inline bool cbfs_file_exists(const char *name)
{
union cbfs_mdata mdata;
return _cbfs_boot_lookup(name, false, &mdata) >= 0;
}
static inline bool cbfs_ro_file_exists(const char *name)
{
union cbfs_mdata mdata;
return _cbfs_boot_lookup(name, true, &mdata) >= 0;
}
/* Legacy API. Designated for removal in the future. */
#include <cbfs_legacy.h>
#endif
|