]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Bds/BdsInternal.h
32e4b65d2bab1bd371dc62dd1bc2ce8c0f186c70
[mirror_edk2.git] / ArmPlatformPkg / Bds / BdsInternal.h
1 /** @file
2 *
3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
4 *
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
9 *
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 *
13 **/
14
15 #ifndef _BDSINTERNAL_H_
16 #define _BDSINTERNAL_H_
17
18 #include <PiDxe.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/BdsLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/DevicePathLib.h>
23 #include <Library/UefiLib.h>
24 #include <Library/PrintLib.h>
25 #include <Library/PcdLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/UefiRuntimeServicesTableLib.h>
29
30 #include <Protocol/DevicePathFromText.h>
31 #include <Protocol/DevicePathToText.h>
32
33 #include <Guid/GlobalVariable.h>
34
35 #define BOOT_DEVICE_DESCRIPTION_MAX 100
36 #define BOOT_DEVICE_FILEPATH_MAX 100
37 #define BOOT_DEVICE_OPTION_MAX 300
38 #define BOOT_DEVICE_ADDRESS_MAX (sizeof(L"0x0000000000000000"))
39
40 #define ARM_BDS_OPTIONAL_DATA_SIGNATURE SIGNATURE_32('a', 'b', 'o', 'd')
41
42 #define IS_ARM_BDS_BOOTENTRY(ptr) \
43 (((ptr)->OptionalData != NULL) && \
44 (ReadUnaligned32 ((CONST UINT32*)&((ARM_BDS_LOADER_OPTIONAL_DATA*)((ptr)->OptionalData))->Header.Signature) \
45 == ARM_BDS_OPTIONAL_DATA_SIGNATURE))
46
47 #define UPDATE_BOOT_ENTRY L"Update entry: "
48 #define DELETE_BOOT_ENTRY L"Delete entry: "
49
50 typedef enum {
51 BDS_LOADER_EFI_APPLICATION = 0,
52 BDS_LOADER_KERNEL_LINUX_ATAG,
53 BDS_LOADER_KERNEL_LINUX_FDT,
54 } ARM_BDS_LOADER_TYPE;
55
56 typedef struct {
57 UINT16 CmdLineSize;
58 UINT16 InitrdSize;
59
60 // These following fields have variable length and are packed:
61 //CHAR8 *CmdLine;
62 //EFI_DEVICE_PATH_PROTOCOL *InitrdPathList;
63 } ARM_BDS_LINUX_ARGUMENTS;
64
65 typedef union {
66 ARM_BDS_LINUX_ARGUMENTS LinuxArguments;
67 } ARM_BDS_LOADER_ARGUMENTS;
68
69 typedef struct {
70 UINT32 Signature;
71 ARM_BDS_LOADER_TYPE LoaderType;
72 } ARM_BDS_LOADER_OPTIONAL_DATA_HEADER;
73
74 typedef struct {
75 ARM_BDS_LOADER_OPTIONAL_DATA_HEADER Header;
76 ARM_BDS_LOADER_ARGUMENTS Arguments;
77 } ARM_BDS_LOADER_OPTIONAL_DATA;
78
79 typedef struct {
80 LIST_ENTRY Link;
81 BDS_LOAD_OPTION* BdsLoadOption;
82 } BDS_LOAD_OPTION_ENTRY;
83
84 typedef enum {
85 BDS_DEVICE_FILESYSTEM = 0,
86 BDS_DEVICE_MEMMAP,
87 BDS_DEVICE_PXE,
88 BDS_DEVICE_TFTP,
89 BDS_DEVICE_MAX
90 } BDS_SUPPORTED_DEVICE_TYPE;
91
92 typedef struct {
93 LIST_ENTRY Link;
94 CHAR16 Description[BOOT_DEVICE_DESCRIPTION_MAX];
95 EFI_DEVICE_PATH_PROTOCOL* DevicePathProtocol;
96 struct _BDS_LOAD_OPTION_SUPPORT* Support;
97 } BDS_SUPPORTED_DEVICE;
98
99 #define SUPPORTED_BOOT_DEVICE_FROM_LINK(a) BASE_CR(a, BDS_SUPPORTED_DEVICE, Link)
100
101 typedef struct _BDS_LOAD_OPTION_SUPPORT {
102 BDS_SUPPORTED_DEVICE_TYPE Type;
103 EFI_STATUS (*ListDevices)(IN OUT LIST_ENTRY* BdsLoadOptionList);
104 BOOLEAN (*IsSupported)(IN EFI_DEVICE_PATH *DevicePath);
105 EFI_STATUS (*CreateDevicePathNode)(IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes);
106 EFI_STATUS (*UpdateDevicePathNode)(IN EFI_DEVICE_PATH *OldDevicePath, IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath);
107
108 /// Define if the boot menu should request if the file is a EFI binary or a Linux kernel
109 /// Example: PXE boot always deliver a UEFI application.
110 BOOLEAN RequestBootType;
111 } BDS_LOAD_OPTION_SUPPORT;
112
113 #define LOAD_OPTION_ENTRY_FROM_LINK(a) BASE_CR(a, BDS_LOAD_OPTION_ENTRY, Link)
114 #define LOAD_OPTION_FROM_LINK(a) ((BDS_LOAD_OPTION_ENTRY*)BASE_CR(a, BDS_LOAD_OPTION_ENTRY, Link))->BdsLoadOption
115
116 EFI_STATUS
117 BootDeviceListSupportedInit (
118 IN OUT LIST_ENTRY *SupportedDeviceList
119 );
120
121 EFI_STATUS
122 BootDeviceListSupportedFree (
123 IN LIST_ENTRY *SupportedDeviceList,
124 IN BDS_SUPPORTED_DEVICE *Except
125 );
126
127 EFI_STATUS
128 BootDeviceGetDeviceSupport (
129 IN EFI_DEVICE_PATH *DevicePath,
130 OUT BDS_LOAD_OPTION_SUPPORT **DeviceSupport
131 );
132
133 EFI_STATUS
134 GetHIInputStr (
135 IN OUT CHAR16 *CmdLine,
136 IN UINTN MaxCmdLine
137 );
138
139 EFI_STATUS
140 EditHIInputStr (
141 IN OUT CHAR16 *CmdLine,
142 IN UINTN MaxCmdLine
143 );
144
145 EFI_STATUS
146 GetHIInputAscii (
147 IN OUT CHAR8 *CmdLine,
148 IN UINTN MaxCmdLine
149 );
150
151 EFI_STATUS
152 EditHIInputAscii (
153 IN OUT CHAR8 *CmdLine,
154 IN UINTN MaxCmdLine
155 );
156
157 EFI_STATUS
158 GetHIInputInteger (
159 IN OUT UINTN *Integer
160 );
161
162 EFI_STATUS
163 GetHIInputIP (
164 OUT EFI_IP_ADDRESS *Ip
165 );
166
167 EFI_STATUS
168 EditHIInputIP (
169 IN EFI_IP_ADDRESS *InIpAddr,
170 OUT EFI_IP_ADDRESS *OutIpAddr
171 );
172
173 EFI_STATUS
174 GetHIInputBoolean (
175 OUT BOOLEAN *Value
176 );
177
178 BOOLEAN
179 HasFilePathEfiExtension (
180 IN CHAR16* FilePath
181 );
182
183 EFI_DEVICE_PATH*
184 GetLastDevicePathNode (
185 IN EFI_DEVICE_PATH* DevicePath
186 );
187
188 EFI_STATUS
189 BdsStartBootOption (
190 IN CHAR16* BootOption
191 );
192
193 UINTN
194 GetUnalignedDevicePathSize (
195 IN EFI_DEVICE_PATH* DevicePath
196 );
197
198 EFI_DEVICE_PATH*
199 GetAlignedDevicePath (
200 IN EFI_DEVICE_PATH* DevicePath
201 );
202
203 EFI_STATUS
204 GenerateDeviceDescriptionName (
205 IN EFI_HANDLE Handle,
206 IN OUT CHAR16* Description
207 );
208
209 EFI_STATUS
210 BootOptionList (
211 IN OUT LIST_ENTRY *BootOptionList
212 );
213
214 EFI_STATUS
215 BootOptionParseLoadOption (
216 IN EFI_LOAD_OPTION EfiLoadOption,
217 IN UINTN EfiLoadOptionSize,
218 OUT BDS_LOAD_OPTION **BdsLoadOption
219 );
220
221 EFI_STATUS
222 BootOptionStart (
223 IN BDS_LOAD_OPTION *BootOption
224 );
225
226 EFI_STATUS
227 BootOptionCreate (
228 IN UINT32 Attributes,
229 IN CHAR16* BootDescription,
230 IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
231 IN ARM_BDS_LOADER_TYPE BootType,
232 IN UINT8* OptionalData,
233 IN UINTN OptionalDataSize,
234 OUT BDS_LOAD_OPTION** BdsLoadOption
235 );
236
237 EFI_STATUS
238 BootOptionUpdate (
239 IN BDS_LOAD_OPTION* BdsLoadOption,
240 IN UINT32 Attributes,
241 IN CHAR16* BootDescription,
242 IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
243 IN ARM_BDS_LOADER_TYPE BootType,
244 IN UINT8* OptionalData,
245 IN UINTN OptionalDataSize
246 );
247
248 EFI_STATUS
249 BootOptionDelete (
250 IN BDS_LOAD_OPTION *BootOption
251 );
252
253 EFI_STATUS
254 BootDeviceGetType (
255 IN EFI_DEVICE_PATH* DevicePath,
256 OUT ARM_BDS_LOADER_TYPE *BootType,
257 OUT UINT32 *Attributes
258 );
259
260 EFI_STATUS
261 BootMenuMain (
262 VOID
263 );
264
265 BOOLEAN
266 IsUnicodeString (
267 IN VOID* String
268 );
269
270 /*
271 * Try to detect if the given string is an ASCII or Unicode string
272 *
273 * There are actually few limitation to this function but it is mainly to give
274 * a user friendly output.
275 *
276 * Some limitations:
277 * - it only supports unicode string that use ASCII character (< 0x100)
278 * - single character ASCII strings are interpreted as Unicode string
279 * - string cannot be longer than 2 x BOOT_DEVICE_OPTION_MAX (600 bytes)
280 *
281 * @param String Buffer that might contain a Unicode or Ascii string
282 * @param IsUnicode If not NULL this boolean value returns if the string is an
283 * ASCII or Unicode string.
284 */
285 BOOLEAN
286 IsPrintableString (
287 IN VOID* String,
288 OUT BOOLEAN *IsUnicode
289 );
290
291 #endif /* _BDSINTERNAL_H_ */