xref: /aosp_15_r20/external/vboot_reference/firmware/include/vboot_api.h (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1 /* Copyright 2013 The ChromiumOS Authors
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  *
5  * APIs provided by firmware to vboot_reference.
6  *
7  * General notes:
8  *
9  * All verified boot functions now start with "Vb" for namespace clarity.  This
10  * fixes the problem where uboot and vboot both defined assert().
11  *
12  * Verified boot APIs to be implemented by the calling firmware and exported to
13  * vboot_reference start with "VbEx".
14  *
15  * TODO: split this file into a vboot_entry_points.h file which contains the
16  * entry points for the firmware to call vboot_reference, and a
17  * vboot_firmware_exports.h which contains the APIs to be implemented by the
18  * calling firmware and exported to vboot_reference.
19  */
20 
21 #ifndef VBOOT_REFERENCE_VBOOT_API_H_
22 #define VBOOT_REFERENCE_VBOOT_API_H_
23 
24 #include <stdint.h>
25 #include <stdlib.h>
26 
27 #include "../2lib/include/2constants.h"
28 #include "../2lib/include/2return_codes.h"
29 #include "gpt.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif  /* __cplusplus */
34 
35 struct vb2_context;
36 struct vb2_disk_info;
37 typedef struct VbSharedDataHeader VbSharedDataHeader;
38 
39 /*****************************************************************************/
40 /* Disk access (previously in boot_device.h) */
41 
42 /**
43  * Read lba_count LBA sectors, starting at sector lba_start, from the disk,
44  * into the buffer.
45  *
46  * This is used for random access to the GPT. It is not for the partition
47  * contents. The upper limit is lba_count.
48  *
49  * If the disk handle is invalid (for example, the handle refers to a disk
50  * which as been removed), the function must return error but must not
51  * crash.
52  */
53 vb2_error_t VbExDiskRead(vb2ex_disk_handle_t handle, uint64_t lba_start,
54 			 uint64_t lba_count, void *buffer);
55 
56 /**
57  * Write lba_count LBA sectors, starting at sector lba_start, to the disk, from
58  * the buffer.
59  *
60  * This is used for random access to the GPT. It does not (necessarily) access
61  * the streaming portion of the device.
62  *
63  * If the disk handle is invalid (for example, the handle refers to a disk
64  * which as been removed), the function must return error but must not
65  * crash.
66  */
67 vb2_error_t VbExDiskWrite(vb2ex_disk_handle_t handle, uint64_t lba_start,
68 			  uint64_t lba_count, const void *buffer);
69 
70 /* Streaming read interface */
71 typedef void *VbExStream_t;
72 
73 /**
74  * Open a stream on a disk
75  *
76  * @param handle	Disk to open the stream against
77  * @param lba_start	Starting sector offset within the disk to stream from
78  * @param lba_count	Maximum extent of the stream in sectors
79  * @param stream	out-paramter for the generated stream
80  *
81  * @return Error code, or VB2_SUCCESS.
82  *
83  * This is used for access to the contents of the actual partitions on the
84  * device. It is not used to access the GPT. The size of the content addressed
85  * is within streaming_lba_count.
86  */
87 vb2_error_t VbExStreamOpen(vb2ex_disk_handle_t handle, uint64_t lba_start,
88 			   uint64_t lba_count, VbExStream_t *stream_ptr);
89 
90 /**
91  * Read from a stream on a disk
92  *
93  * @param stream	Stream to read from
94  * @param bytes		Number of bytes to read
95  * @param buffer	Destination to read into
96  *
97  * @return Error code, or VB2_SUCCESS. Failure to read as much data as
98  * requested is an error.
99  *
100  * This is used for access to the contents of the actual partitions on the
101  * device. It is not used to access the GPT.
102  */
103 vb2_error_t VbExStreamRead(VbExStream_t stream, uint32_t bytes, void *buffer);
104 
105 /**
106  * Close a stream
107  *
108  * @param stream	Stream to close
109  */
110 void VbExStreamClose(VbExStream_t stream);
111 
112 #ifdef __cplusplus
113 }
114 #endif  /* __cplusplus */
115 
116 #endif  /* VBOOT_REFERENCE_VBOOT_API_H_ */
117