3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
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
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.
15 #ifndef _BDSINTERNAL_H_
16 #define _BDSINTERNAL_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>
30 #include <Protocol/DevicePathFromText.h>
31 #include <Protocol/DevicePathToText.h>
33 #include <Guid/GlobalVariable.h>
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"))
40 #define ARM_BDS_OPTIONAL_DATA_SIGNATURE SIGNATURE_32('a', 'b', 'o', 'd')
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))
47 #define UPDATE_BOOT_ENTRY L"Update entry: "
48 #define DELETE_BOOT_ENTRY L"Delete entry: "
49 #define MOVE_BOOT_ENTRY L"Move entry: "
52 BDS_LOADER_EFI_APPLICATION
= 0,
53 BDS_LOADER_KERNEL_LINUX_ATAG
,
54 BDS_LOADER_KERNEL_LINUX_FDT
,
55 } ARM_BDS_LOADER_TYPE
;
61 // These following fields have variable length and are packed:
63 //EFI_DEVICE_PATH_PROTOCOL *InitrdPathList;
64 } ARM_BDS_LINUX_ARGUMENTS
;
67 ARM_BDS_LINUX_ARGUMENTS LinuxArguments
;
68 } ARM_BDS_LOADER_ARGUMENTS
;
72 ARM_BDS_LOADER_TYPE LoaderType
;
73 } ARM_BDS_LOADER_OPTIONAL_DATA_HEADER
;
76 ARM_BDS_LOADER_OPTIONAL_DATA_HEADER Header
;
77 ARM_BDS_LOADER_ARGUMENTS Arguments
;
78 } ARM_BDS_LOADER_OPTIONAL_DATA
;
82 BDS_LOAD_OPTION
* BdsLoadOption
;
83 } BDS_LOAD_OPTION_ENTRY
;
86 BDS_DEVICE_FILESYSTEM
= 0,
91 } BDS_SUPPORTED_DEVICE_TYPE
;
95 CHAR16 Description
[BOOT_DEVICE_DESCRIPTION_MAX
];
96 EFI_DEVICE_PATH_PROTOCOL
* DevicePathProtocol
;
97 struct _BDS_LOAD_OPTION_SUPPORT
* Support
;
98 } BDS_SUPPORTED_DEVICE
;
100 #define SUPPORTED_BOOT_DEVICE_FROM_LINK(a) BASE_CR(a, BDS_SUPPORTED_DEVICE, Link)
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
);
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
;
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
118 BootDeviceListSupportedInit (
119 IN OUT LIST_ENTRY
*SupportedDeviceList
123 BootDeviceListSupportedFree (
124 IN LIST_ENTRY
*SupportedDeviceList
,
125 IN BDS_SUPPORTED_DEVICE
*Except
129 BootDeviceGetDeviceSupport (
130 IN EFI_DEVICE_PATH
*DevicePath
,
131 OUT BDS_LOAD_OPTION_SUPPORT
**DeviceSupport
136 IN OUT CHAR16
*CmdLine
,
142 IN OUT CHAR16
*CmdLine
,
148 IN OUT CHAR8
*CmdLine
,
154 IN OUT CHAR8
*CmdLine
,
160 IN OUT UINTN
*Integer
165 OUT EFI_IP_ADDRESS
*Ip
170 IN EFI_IP_ADDRESS
*InIpAddr
,
171 OUT EFI_IP_ADDRESS
*OutIpAddr
180 HasFilePathEfiExtension (
185 GetLastDevicePathNode (
186 IN EFI_DEVICE_PATH
* DevicePath
191 IN CHAR16
* BootOption
195 GetUnalignedDevicePathSize (
196 IN EFI_DEVICE_PATH
* DevicePath
200 GetAlignedDevicePath (
201 IN EFI_DEVICE_PATH
* DevicePath
205 GenerateDeviceDescriptionName (
206 IN EFI_HANDLE Handle
,
207 IN OUT CHAR16
* Description
212 IN OUT LIST_ENTRY
*BootOptionList
216 BootOptionParseLoadOption (
217 IN EFI_LOAD_OPTION EfiLoadOption
,
218 IN UINTN EfiLoadOptionSize
,
219 OUT BDS_LOAD_OPTION
**BdsLoadOption
224 IN BDS_LOAD_OPTION
*BootOption
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
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
251 IN BDS_LOAD_OPTION
*BootOption
256 IN EFI_DEVICE_PATH
* DevicePath
,
257 OUT ARM_BDS_LOADER_TYPE
*BootType
,
258 OUT UINT32
*Attributes
272 * Try to detect if the given string is an ASCII or Unicode string
274 * There are actually few limitation to this function but it is mainly to give
275 * a user friendly output.
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)
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.
289 OUT BOOLEAN
*IsUnicode
293 An empty function to pass error checking of CreateEventEx ().
295 @param Event Event whose notification function is being invoked.
296 @param Context Pointer to the notification function's context,
297 which is implementation-dependent.
302 EmptyCallbackFunction (
307 #endif /* _BDSINTERNAL_H_ */