This repository was archived by the owner on Aug 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLinuxLoaderLib.h
More file actions
197 lines (173 loc) · 7.43 KB
/
LinuxLoaderLib.h
File metadata and controls
197 lines (173 loc) · 7.43 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __LINUXLOADERLIB_H__
#define __LINUXLOADERLIB_H__
#include <Uefi.h>
#include "DeviceInfo.h"
#include <Guid/FileInfo.h>
#include <Guid/FileSystemInfo.h>
#include <Guid/Gpt.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/EfiFileLib.h>
#include <Library/IoLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/PrintLib.h>
#include <Library/TimerLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <PiDxe.h>
#include <Protocol/BlockIo.h>
#include <Protocol/DevicePath.h>
#include <Protocol/EFIEraseBlock.h>
#include <Protocol/EFIMdtp.h>
#include <Protocol/EFIVerifiedBoot.h>
#include <Protocol/EFINandPartiGuid.h>
#include <Protocol/FirmwareVolume2.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/SerialIo.h>
#include <Protocol/SimpleFileSystem.h>
/**
gQcomTokenSpaceGuid GUID definition.
*/
#define QCOM_TOKEN_SPACE_GUID \
{ \
0x882f8c2b, 0x9646, 0x435f, \
{ \
0x8d, 0xe5, 0xf2, 0x08, 0xff, 0x80, 0xc1, 0xbd \
} \
}
/* Selection attributes for selecting the BlkIo handles */
#define BLK_IO_SEL_MEDIA_TYPE_REMOVABLE 0x0001
#define BLK_IO_SEL_MEDIA_TYPE_NON_REMOVABLE 0x0002
#define BLK_IO_SEL_PARTITIONED_GPT 0x0004
#define BLK_IO_SEL_PARTITIONED_MBR 0x0008
#define BLK_IO_SEL_MATCH_PARTITION_TYPE_GUID 0x0010
#define BLK_IO_SEL_SELECT_MOUNTED_FILESYSTEM 0x0020
#define BLK_IO_SEL_SELECT_BY_VOLUME_NAME 0x0040
/* Select only the root device handle indicated. Doesn't return
* any partitions within.
* Currently this filter applies only for eMMC device, not the external
* device connected via USB */
#define BLK_IO_SEL_SELECT_ROOT_DEVICE_ONLY 0x0080
/* Select the handle that's on the indicated root device.
* Currently this filter applies only for eMMC device, not the external
* device connected via USB */
#define BLK_IO_SEL_MATCH_ROOT_DEVICE 0x0100
/* Select through partition name*/
#define BLK_IO_SEL_MATCH_PARTITION_LABEL 0x0200
/* Do case insensetive string comparisons */
#define BLK_IO_SEL_STRING_CASE_INSENSITIVE 0x0400
/* Partitioning scheme types for selecting the BlkIo handles */
#define PARTITIONED_TYPE_MBR 0x01
#define PARTITIONED_TYPE_GPT 0x02
#define ZERO 0
#define ARRAY_SIZE(a) sizeof (a) / sizeof (*a)
#define MAX_HANDLE_INFO_LIST 128
/* Macro to avoid integer overflow */
#define ADD_OF(a, b) (MAX_UINT32 - b > a) ? (a + b) : ZERO
#define BOOT_DEV_MAX_LEN 32
#define BOOT_DEV_NAME_SIZE_MAX 10
/* Allocate unsafe stack size of 128KB to address worst case,
* which is same as the normal stack size */
#define BOOT_LOADER_MAX_UNSAFE_STACK_SIZE (1 << 17)
/* Any data specific to additional attributes can be added here. */
typedef struct {
EFI_GUID *RootDeviceType; /* GUID Selecting the root device type */
EFI_GUID *PartitionType; /* Partition Type to match */
CHAR8 *VolumeName; /* Mounted filesystem volume name to match */
CHAR16 *PartitionLabel; /* Partition label to match */
} PartiSelectFilter;
/* Output data providing more information about the device handle */
typedef struct {
/* Handle that has BlkIO protocol installed, returned for all type of filters
*/
EFI_HANDLE *Handle;
/* Block IO protocol interface is returned for all type of filters */
EFI_BLOCK_IO_PROTOCOL *BlkIo;
/* This HDD dev path is returned only if Matching Partition type is requested
* It should be noted that the contents of this memory should NOT be changed
*/
const HARDDRIVE_DEVICE_PATH *PartitionInfo;
} HandleInfo;
/* Load image from partition to buffer */
EFI_STATUS
LoadImageFromPartition (VOID *ImageBuffer, UINT32 *ImageSize, CHAR16 *Pname);
EFI_STATUS
ReadWriteDeviceInfo (vb_device_state_op_t Mode, void *DevInfo, UINT32 Sz);
EFI_STATUS
GetNandOemPartiGuid (EFI_GUID *Ptype);
EFI_STATUS
GetNandMiscPartiGuid (EFI_GUID *Ptype);
/**
Returns a list of BlkIo handles based on required criteria
SelectionAttrib : Bitmask representing the conditions that need
to be met for the handles returned. Based on the
selections filter members should have valid values.
FilterData : Instance of Partition Select Filter structure that
needs extended data for certain type flags. For example
Partition type and/or Volume name can be specified.
HandleInfoPtr : Pointer Handle info where the information can be returned
MaxBlkIopCnt : On input, max number of handles the buffer can hold,
On output, the number of handles returned.
@retval EFI_SUCCESS if the operation was successful
*/
EFI_STATUS
EFIAPI
GetBlkIOHandles (IN UINT32 SelectionAttrib,
IN PartiSelectFilter *FilterData,
OUT HandleInfo *HandleInfoPtr,
IN OUT UINT32 *MaxBlkIopCnt);
VOID
ToLower (CHAR8 *Str);
UINT64 GetTimerCountms (VOID);
EFI_STATUS
WriteToPartition (EFI_GUID *Ptype, VOID *Msg, UINT32 MsgSize);
BOOLEAN IsSecureBootEnabled (VOID);
EFI_STATUS ResetDeviceState (VOID);
EFI_STATUS
ErasePartition (EFI_BLOCK_IO_PROTOCOL *BlockIo, EFI_HANDLE *Handle);
EFI_STATUS
GetBootDevice (CHAR8 *BootDevBuf, UINT32 Len);
/* Returns whether MDTP is active or not,
* or whether it should be considered active for
* bootloader flows. */
EFI_STATUS
IsMdtpActive (BOOLEAN *IsActive);
EFI_STATUS
WriteBlockToPartition (EFI_BLOCK_IO_PROTOCOL *BlockIo,
IN EFI_HANDLE *Handle,
IN UINT64 Offset,
IN UINT64 Size,
IN VOID *Image);
#endif