ArmPlatformPkg/Bds: Added boot options reordering
[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 #define MOVE_BOOT_ENTRY L"Move entry: "
50
51 typedef enum {
52 BDS_LOADER_EFI_APPLICATION = 0,
53 BDS_LOADER_KERNEL_LINUX_ATAG,
54 BDS_LOADER_KERNEL_LINUX_FDT,
55 } ARM_BDS_LOADER_TYPE;
56
57 typedef struct {
58 UINT16 CmdLineSize;
59 UINT16 InitrdSize;
60
61 // These following fields have variable length and are packed:
62 //CHAR8 *CmdLine;
63 //EFI_DEVICE_PATH_PROTOCOL *InitrdPathList;
64 } ARM_BDS_LINUX_ARGUMENTS;
65
66 typedef union {
67 ARM_BDS_LINUX_ARGUMENTS LinuxArguments;
68 } ARM_BDS_LOADER_ARGUMENTS;
69
70 typedef struct {
71 UINT32 Signature;
72 ARM_BDS_LOADER_TYPE LoaderType;
73 } ARM_BDS_LOADER_OPTIONAL_DATA_HEADER;
74
75 typedef struct {
76 ARM_BDS_LOADER_OPTIONAL_DATA_HEADER Header;
77 ARM_BDS_LOADER_ARGUMENTS Arguments;
78 } ARM_BDS_LOADER_OPTIONAL_DATA;
79
80 typedef struct {
81 LIST_ENTRY Link;
82 BDS_LOAD_OPTION* BdsLoadOption;
83 } BDS_LOAD_OPTION_ENTRY;
84
85 typedef enum {
86 BDS_DEVICE_FILESYSTEM = 0,
87 BDS_DEVICE_MEMMAP,
88 BDS_DEVICE_PXE,
89 BDS_DEVICE_TFTP,
90 BDS_DEVICE_MAX
91 } BDS_SUPPORTED_DEVICE_TYPE;
92
93 typedef struct {
94 LIST_ENTRY Link;
95 CHAR16 Description[BOOT_DEVICE_DESCRIPTION_MAX];
96 EFI_DEVICE_PATH_PROTOCOL* DevicePathProtocol;
97 struct _BDS_LOAD_OPTION_SUPPORT* Support;
98 } BDS_SUPPORTED_DEVICE;
99
100 #define SUPPORTED_BOOT_DEVICE_FROM_LINK(a) BASE_CR(a, BDS_SUPPORTED_DEVICE, Link)
101
102 typedef struct _BDS_LOAD_OPTION_SUPPORT {
103 BDS_SUPPORTED_DEVICE_TYPE Type;
104 EFI_STATUS (*ListDevices)(IN OUT LIST_ENTRY* BdsLoadOptionList);
105 BOOLEAN (*IsSupported)(IN EFI_DEVICE_PATH *DevicePath);
106 EFI_STATUS (*CreateDevicePathNode)(IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes);
107 EFI_STATUS (*UpdateDevicePathNode)(IN EFI_DEVICE_PATH *OldDevicePath, IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath);
108
109 /// Define if the boot menu should request if the file is a EFI binary or a Linux kernel
110 /// Example: PXE boot always deliver a UEFI application.
111 BOOLEAN RequestBootType;
112 } BDS_LOAD_OPTION_SUPPORT;
113
114 #define LOAD_OPTION_ENTRY_FROM_LINK(a) BASE_CR(a, BDS_LOAD_OPTION_ENTRY, Link)
115 #define LOAD_OPTION_FROM_LINK(a) ((BDS_LOAD_OPTION_ENTRY*)BASE_CR(a, BDS_LOAD_OPTION_ENTRY, Link))->BdsLoadOption
116
117 EFI_STATUS
118 BootDeviceListSupportedInit (
119 IN OUT LIST_ENTRY *SupportedDeviceList
120 );
121
122 EFI_STATUS
123 BootDeviceListSupportedFree (
124 IN LIST_ENTRY *SupportedDeviceList,
125 IN BDS_SUPPORTED_DEVICE *Except
126 );
127
128 EFI_STATUS
129 BootDeviceGetDeviceSupport (
130 IN EFI_DEVICE_PATH *DevicePath,
131 OUT BDS_LOAD_OPTION_SUPPORT **DeviceSupport
132 );
133
134 EFI_STATUS
135 GetHIInputStr (
136 IN OUT CHAR16 *CmdLine,
137 IN UINTN MaxCmdLine
138 );
139
140 EFI_STATUS
141 EditHIInputStr (
142 IN OUT CHAR16 *CmdLine,
143 IN UINTN MaxCmdLine
144 );
145
146 EFI_STATUS
147 GetHIInputAscii (
148 IN OUT CHAR8 *CmdLine,
149 IN UINTN MaxCmdLine
150 );
151
152 EFI_STATUS
153 EditHIInputAscii (
154 IN OUT CHAR8 *CmdLine,
155 IN UINTN MaxCmdLine
156 );
157
158 EFI_STATUS
159 GetHIInputInteger (
160 IN OUT UINTN *Integer
161 );
162
163 EFI_STATUS
164 GetHIInputIP (
165 OUT EFI_IP_ADDRESS *Ip
166 );
167
168 EFI_STATUS
169 EditHIInputIP (
170 IN EFI_IP_ADDRESS *InIpAddr,
171 OUT EFI_IP_ADDRESS *OutIpAddr
172 );
173
174 EFI_STATUS
175 GetHIInputBoolean (
176 OUT BOOLEAN *Value
177 );
178
179 BOOLEAN
180 HasFilePathEfiExtension (
181 IN CHAR16* FilePath
182 );
183
184 EFI_DEVICE_PATH*
185 GetLastDevicePathNode (
186 IN EFI_DEVICE_PATH* DevicePath
187 );
188
189 EFI_STATUS
190 BdsStartBootOption (
191 IN CHAR16* BootOption
192 );
193
194 UINTN
195 GetUnalignedDevicePathSize (
196 IN EFI_DEVICE_PATH* DevicePath
197 );
198
199 EFI_DEVICE_PATH*
200 GetAlignedDevicePath (
201 IN EFI_DEVICE_PATH* DevicePath
202 );
203
204 EFI_STATUS
205 GenerateDeviceDescriptionName (
206 IN EFI_HANDLE Handle,
207 IN OUT CHAR16* Description
208 );
209
210 EFI_STATUS
211 BootOptionList (
212 IN OUT LIST_ENTRY *BootOptionList
213 );
214
215 EFI_STATUS
216 BootOptionParseLoadOption (
217 IN EFI_LOAD_OPTION EfiLoadOption,
218 IN UINTN EfiLoadOptionSize,
219 OUT BDS_LOAD_OPTION **BdsLoadOption
220 );
221
222 EFI_STATUS
223 BootOptionStart (
224 IN BDS_LOAD_OPTION *BootOption
225 );
226
227 EFI_STATUS
228 BootOptionCreate (
229 IN UINT32 Attributes,
230 IN CHAR16* BootDescription,
231 IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
232 IN ARM_BDS_LOADER_TYPE BootType,
233 IN UINT8* OptionalData,
234 IN UINTN OptionalDataSize,
235 OUT BDS_LOAD_OPTION** BdsLoadOption
236 );
237
238 EFI_STATUS
239 BootOptionUpdate (
240 IN BDS_LOAD_OPTION* BdsLoadOption,
241 IN UINT32 Attributes,
242 IN CHAR16* BootDescription,
243 IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
244 IN ARM_BDS_LOADER_TYPE BootType,
245 IN UINT8* OptionalData,
246 IN UINTN OptionalDataSize
247 );
248
249 EFI_STATUS
250 BootOptionDelete (
251 IN BDS_LOAD_OPTION *BootOption
252 );
253
254 EFI_STATUS
255 BootDeviceGetType (
256 IN EFI_DEVICE_PATH* DevicePath,
257 OUT ARM_BDS_LOADER_TYPE *BootType,
258 OUT UINT32 *Attributes
259 );
260
261 EFI_STATUS
262 BootMenuMain (
263 VOID
264 );
265
266 BOOLEAN
267 IsUnicodeString (
268 IN VOID* String
269 );
270
271 /*
272 * Try to detect if the given string is an ASCII or Unicode string
273 *
274 * There are actually few limitation to this function but it is mainly to give
275 * a user friendly output.
276 *
277 * Some limitations:
278 * - it only supports unicode string that use ASCII character (< 0x100)
279 * - single character ASCII strings are interpreted as Unicode string
280 * - string cannot be longer than 2 x BOOT_DEVICE_OPTION_MAX (600 bytes)
281 *
282 * @param String Buffer that might contain a Unicode or Ascii string
283 * @param IsUnicode If not NULL this boolean value returns if the string is an
284 * ASCII or Unicode string.
285 */
286 BOOLEAN
287 IsPrintableString (
288 IN VOID* String,
289 OUT BOOLEAN *IsUnicode
290 );
291
292 #endif /* _BDSINTERNAL_H_ */