VirtualBox

source: vbox/trunk/include/iprt/efi.h@ 108695

Last change on this file since 108695 was 108554, checked in by vboxsync, 6 weeks ago

Runtime/common/efi,Main: Fix creating NVRAM files for ARM VMs, the previous ones where incompatible to what the UEFI firmware expected causing a hang during boot under certain circumstances, bugref:10872

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
1/** @file
2 * IPRT - EFI related utilities.
3 */
4
5/*
6 * Copyright (C) 2021-2024 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_efi_h
37#define IPRT_INCLUDED_efi_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/cdefs.h>
43#include <iprt/types.h>
44#include <iprt/time.h>
45#include <iprt/vfs.h>
46
47#include <iprt/formats/efi-common.h>
48
49
50RT_C_DECLS_BEGIN
51
52/** @defgroup grp_rt_efi RTEfi - EFI utilities
53 * @ingroup grp_rt
54 * @{
55 */
56
57
58#ifdef IN_RING3
59
60/**
61 * Converts an EFI time to a time spec (UTC).
62 *
63 * @returns pTimeSpec on success.
64 * @returns NULL if the pEfiTime data is invalid.
65 * @param pTimeSpec Where to store the converted time.
66 * @param pEfiTime Pointer to the EFI time struct.
67 */
68RTDECL(PRTTIMESPEC) RTEfiTimeToTimeSpec(PRTTIMESPEC pTimeSpec, PCEFI_TIME pEfiTime);
69
70
71/**
72 * Converts a time spec (UTC) to an EFI time.
73 *
74 * @returns pEfiTime on success.
75 * @returns NULL if the pTimeSpec data is invalid.
76 * @param pEfiTime Pointer to the EFI time struct.
77 * @param pTimeSpec The time spec to convert.
78 */
79RTDECL(PEFI_TIME) RTEfiTimeFromTimeSpec(PEFI_TIME pEfiTime, PCRTTIMESPEC pTimeSpec);
80
81
82/**
83 * Converts the given EFI GUID to the IPRT UUID representation.
84 *
85 * @returns pUuid.
86 * @param pUuid Where to store the converted GUID.
87 * @param pEfiGuid The EFI GUID to convert.
88 */
89RTDECL(PRTUUID) RTEfiGuidToUuid(PRTUUID pUuid, PCEFI_GUID pEfiGuid);
90
91
92/**
93 * Converts the given EFI GUID to the IPRT UUID representation.
94 *
95 * @returns pEfiGuid.
96 * @param pEfiGuid Where to store the converted UUID.
97 * @param pUuid The UUID to convert.
98 */
99RTDECL(PEFI_GUID) RTEfiGuidFromUuid(PEFI_GUID pEfiGuid, PCRTUUID pUuid);
100
101
102/**
103 * Compares two EFI GUID values.
104 *
105 * @returns 0 if eq, < 0 or > 0.
106 * @param pGuid1 First value to compare.
107 * @param pGuid2 Second value to compare.
108 */
109RTDECL(int) RTEfiGuidCompare(PCEFI_GUID pGuid1, PCEFI_GUID pGuid2);
110
111
112/**
113 * Opens an EFI variable store.
114 *
115 * @returns IPRT status code.
116 * @param hVfsFileIn The file or device backing the store.
117 * @param fMntFlags RTVFSMNT_F_XXX.
118 * @param fVarStoreFlags Reserved, MBZ.
119 * @param phVfs Where to return the virtual file system handle.
120 * @param pErrInfo Where to return additional error information.
121 */
122RTDECL(int) RTEfiVarStoreOpenAsVfs(RTVFSFILE hVfsFileIn, uint32_t fMntFlags, uint32_t fVarStoreFlags, PRTVFS phVfs, PRTERRINFO pErrInfo);
123
124
125/** @name RTEFIVARSTORE_CREATE_F_XXX - RTEfiVarStoreCreate flags
126 * @{ */
127/** Use default options. */
128#define RTEFIVARSTORE_CREATE_F_DEFAULT UINT32_C(0)
129/** Don't create a fault tolerant write working space.
130 * The default is to create one reducing the size of the variable store. */
131#define RTEFIVARSTORE_CREATE_F_NO_FTW_WORKING_SPACE RT_BIT_32(0)
132/** Mask containing all valid flags. */
133#define RTEFIVARSTORE_CREATE_F_VALID_MASK UINT32_C(0x00000001)
134/** @} */
135
136/**
137 * EFI variable store config.
138 */
139typedef struct RTEFIVARSTORECFG
140{
141 /** The size of the firmware volume. */
142 uint32_t cbFv;
143 /** The block size. */
144 uint32_t cbBlock;
145 /** Size of the variable store in bytes (minus metadata overhead). */
146 uint32_t cbVarStore;
147 /** Size of the NV event log area following the variable store - 0 if no NV event log area is configured. */
148 uint32_t cbNvEventLog;
149 /** Size of the fault tolerant working space - 0 to disable the FTW area. */
150 uint32_t cbFtw;
151 /** Write queue size in bytes of the FTW area. */
152 uint64_t cbWriteQueue;
153} RTEFIVARSTORECFG;
154/** Pointer to an EFI variable store config. */
155typedef RTEFIVARSTORECFG *PRTEFIVARSTORECFG;
156/** Pointer to a const EFI variable store config. */
157typedef const RTEFIVARSTORECFG *PCRTEFIVARSTORECFG;
158
159
160/**
161 * Creates a new EFI variable store.
162 *
163 * @returns IRPT status code.
164 * @param hVfsFile The store file.
165 * @param offStore The offset into @a hVfsFile of the file.
166 * Typically 0.
167 * @param pCfg The firmware volume config for the variable store.
168 * @param pErrInfo Additional error information, maybe. Optional.
169 */
170RTDECL(int) RTEfiVarStoreCreate(RTVFSFILE hVfsFile, uint64_t offStore, PCRTEFIVARSTORECFG pCfg, PRTERRINFO pErrInfo);
171
172
173/**
174 * EFI signature type.
175 */
176typedef enum RTEFISIGTYPE
177{
178 /** Invalid type, do not use. */
179 RTEFISIGTYPE_INVALID = 0,
180 /** First valid signature type. */
181 RTEFISIGTYPE_FIRST_VALID,
182 /** Signature contains a SHA256 hash. */
183 RTEFISIGTYPE_SHA256 = RTEFISIGTYPE_FIRST_VALID,
184 /** Signature contains a RSA2048 key (only the modulus in big endian form,
185 * the exponent is always 65537/0x10001). */
186 RTEFISIGTYPE_RSA2048,
187 /** Signature contains a RSA2048 signature of a SHA256 hash. */
188 RTEFISIGTYPE_RSA2048_SHA256,
189 /** Signature contains a SHA1 hash. */
190 RTEFISIGTYPE_SHA1,
191 /** Signature contains a RSA2048 signature of a SHA1 hash. */
192 RTEFISIGTYPE_RSA2048_SHA1,
193 /** Signature contains a DER encoded X.509 certificate. */
194 RTEFISIGTYPE_X509,
195 /** First invalid type (do not use). */
196 RTEFISIGTYPE_FIRST_INVALID,
197 /** 32bit blowup hack.*/
198 RTEFISIGTYPE_32BIT_HACK = 0x7fffffff
199} RTEFISIGTYPE;
200
201
202/**
203 * EFI signature database enumeration callback.
204 *
205 * @returns IPRT status code, any status code other than VINF_SUCCESS will abort the enumeration.
206 * @param hEfiSigDb Handle to the EFI signature database this callback is called on.
207 * @param enmSigType The signature type.
208 * @param pUuidOwner Signature owner UUID.
209 * @param pvSig The signature data (dependent on the type).
210 * @param cbSig Size of the signature in bytes.
211 * @param pvUser Opaque user data passed in RTEfiSigDbEnum().
212 */
213typedef DECLCALLBACKTYPE(int, FNRTEFISIGDBENUMSIG,(RTEFISIGDB hEfiSigDb, RTEFISIGTYPE enmSigType, PCRTUUID pUuidOwner,
214 const void *pvSig, size_t cbSig, void *pvUser));
215/** Pointer to a EFI signature database enumeration callback. */
216typedef FNRTEFISIGDBENUMSIG *PFNRTEFISIGDBENUMSIG;
217
218
219/**
220 * Creates an empty EFI signature database.
221 *
222 * @returns IPRT status code.
223 * @param phEfiSigDb Where to store the handle to the empty EFI signature database on success.
224 */
225RTDECL(int) RTEfiSigDbCreate(PRTEFISIGDB phEfiSigDb);
226
227
228/**
229 * Destroys the given EFI signature database handle.
230 *
231 * @returns IPRT status code.
232 * @param hEfiSigDb The EFI signature database handle to destroy.
233 */
234RTDECL(int) RTEfiSigDbDestroy(RTEFISIGDB hEfiSigDb);
235
236
237/**
238 * Adds the signatures from an existing signature database contained in the given file.
239 *
240 * @returns IPRT status code.
241 * @param hEfiSigDb The EFI signature database handle.
242 * @param hVfsFileIn The file handle containing the existing signature database.
243 */
244RTDECL(int) RTEfiSigDbAddFromExistingDb(RTEFISIGDB hEfiSigDb, RTVFSFILE hVfsFileIn);
245
246
247/**
248 * Adds a new signature to the given signature database from the given file.
249 *
250 * @returns IPRT status code.
251 * @param hEfiSigDb The EFI signature database handle.
252 * @param enmSigType Type of the signature.
253 * @param pUuidOwner The UUID of the signature owner.
254 * @param hVfsFileIn File handle containing the signature data.
255 */
256RTDECL(int) RTEfiSigDbAddSignatureFromFile(RTEFISIGDB hEfiSigDb, RTEFISIGTYPE enmSigType, PCRTUUID pUuidOwner, RTVFSFILE hVfsFileIn);
257
258
259/**
260 * Adds a new signature to the given signature database from the given buffer.
261 *
262 * @returns IPRT status code.
263 * @param hEfiSigDb The EFI signature database handle.
264 * @param enmSigType Type of the signature.
265 * @param pUuidOwner The UUID of the signature owner.
266 * @param pvBuf Pointer to the signature data.
267 * @param cbBuf Size of the signature data in bytes.
268 */
269RTDECL(int) RTEfiSigDbAddSignatureFromBuf(RTEFISIGDB hEfiSigDb, RTEFISIGTYPE enmSigType, PCRTUUID pUuidOwner,
270 const void *pvBuf, size_t cbBuf);
271
272
273/**
274 * Writes the given EFI signature database to the given file.
275 *
276 * @returns IPRT status code.
277 * @param hEfiSigDb The EFI signature database handle.
278 * @param hVfsFileOut The file handle to write the signature database to.
279 */
280RTDECL(int) RTEfiSigDbWriteToFile(RTEFISIGDB hEfiSigDb, RTVFSFILE hVfsFileOut);
281
282
283/**
284 * Enumerate all signatures in the given EFI signature database.
285 *
286 * @returns IPRT status code.
287 * @param hEfiSigDb The EFI signature database handle.
288 * @param pfnEnumSig The callback to call for each signature.
289 * @param pvUser Opaque user data to pass to the callback.
290 */
291RTDECL(int) RTEfiSigDbEnum(RTEFISIGDB hEfiSigDb, PFNRTEFISIGDBENUMSIG pfnEnumSig, void *pvUser);
292
293
294/**
295 * Returns a human readable string of the given signature type.
296 *
297 * @returns Human readable string.
298 * @param enmSigType The signature type.
299 */
300RTDECL(const char *) RTEfiSigDbTypeStringify(RTEFISIGTYPE enmSigType);
301
302
303/**
304 * Returns a pointer to the EFI GUID identifying the given signature type.
305 *
306 * @returns Pointer to the EFI GUID.
307 * @param enmSigType The signature type.
308 */
309RTDECL(PCEFI_GUID) RTEfiSigDbTypeGetGuid(RTEFISIGTYPE enmSigType);
310
311#endif /* IN_RING3 */
312
313/** @} */
314
315RT_C_DECLS_END
316
317#endif /* !IPRT_INCLUDED_efi_h */
318
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette