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: "
51 BDS_LOADER_EFI_APPLICATION
= 0,
52 BDS_LOADER_KERNEL_LINUX_ATAG
,
53 BDS_LOADER_KERNEL_LINUX_FDT
,
54 } ARM_BDS_LOADER_TYPE
;
60 // These following fields have variable length and are packed:
62 //EFI_DEVICE_PATH_PROTOCOL *InitrdPathList;
63 } ARM_BDS_LINUX_ARGUMENTS
;
66 ARM_BDS_LINUX_ARGUMENTS LinuxArguments
;
67 } ARM_BDS_LOADER_ARGUMENTS
;
71 ARM_BDS_LOADER_TYPE LoaderType
;
72 } ARM_BDS_LOADER_OPTIONAL_DATA_HEADER
;
75 ARM_BDS_LOADER_OPTIONAL_DATA_HEADER Header
;
76 ARM_BDS_LOADER_ARGUMENTS Arguments
;
77 } ARM_BDS_LOADER_OPTIONAL_DATA
;
81 BDS_LOAD_OPTION
* BdsLoadOption
;
82 } BDS_LOAD_OPTION_ENTRY
;
85 BDS_DEVICE_FILESYSTEM
= 0,
90 } BDS_SUPPORTED_DEVICE_TYPE
;
94 CHAR16 Description
[BOOT_DEVICE_DESCRIPTION_MAX
];
95 EFI_DEVICE_PATH_PROTOCOL
* DevicePathProtocol
;
96 struct _BDS_LOAD_OPTION_SUPPORT
* Support
;
97 } BDS_SUPPORTED_DEVICE
;
99 #define SUPPORTED_BOOT_DEVICE_FROM_LINK(a) BASE_CR(a, BDS_SUPPORTED_DEVICE, Link)
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
, OUT BOOLEAN
*RequestBootType
);
106 EFI_STATUS (*UpdateDevicePathNode
)(IN EFI_DEVICE_PATH
*OldDevicePath
, IN CHAR16
* FileName
, OUT EFI_DEVICE_PATH_PROTOCOL
** NewDevicePath
, OUT BOOLEAN
*RequestBootType
);
107 } BDS_LOAD_OPTION_SUPPORT
;
109 #define LOAD_OPTION_ENTRY_FROM_LINK(a) BASE_CR(a, BDS_LOAD_OPTION_ENTRY, Link)
110 #define LOAD_OPTION_FROM_LINK(a) ((BDS_LOAD_OPTION_ENTRY*)BASE_CR(a, BDS_LOAD_OPTION_ENTRY, Link))->BdsLoadOption
113 BootDeviceListSupportedInit (
114 IN OUT LIST_ENTRY
*SupportedDeviceList
118 BootDeviceListSupportedFree (
119 IN LIST_ENTRY
*SupportedDeviceList
,
120 IN BDS_SUPPORTED_DEVICE
*Except
124 BootDeviceGetDeviceSupport (
125 IN EFI_DEVICE_PATH
*DevicePath
,
126 OUT BDS_LOAD_OPTION_SUPPORT
**DeviceSupport
131 IN OUT CHAR16
*CmdLine
,
137 IN OUT CHAR16
*CmdLine
,
143 IN OUT CHAR8
*CmdLine
,
149 IN OUT CHAR8
*CmdLine
,
155 IN OUT UINTN
*Integer
160 OUT EFI_IP_ADDRESS
*Ip
169 HasFilePathEfiExtension (
174 GetLastDevicePathNode (
175 IN EFI_DEVICE_PATH
* DevicePath
180 IN CHAR16
* BootOption
184 GetUnalignedDevicePathSize (
185 IN EFI_DEVICE_PATH
* DevicePath
189 GetAlignedDevicePath (
190 IN EFI_DEVICE_PATH
* DevicePath
194 GenerateDeviceDescriptionName (
195 IN EFI_HANDLE Handle
,
196 IN OUT CHAR16
* Description
201 IN OUT LIST_ENTRY
*BootOptionList
205 BootOptionParseLoadOption (
206 IN EFI_LOAD_OPTION EfiLoadOption
,
207 IN UINTN EfiLoadOptionSize
,
208 OUT BDS_LOAD_OPTION
**BdsLoadOption
213 IN BDS_LOAD_OPTION
*BootOption
218 IN UINT32 Attributes
,
219 IN CHAR16
* BootDescription
,
220 IN EFI_DEVICE_PATH_PROTOCOL
* DevicePath
,
221 IN ARM_BDS_LOADER_TYPE BootType
,
222 IN UINT8
* OptionalData
,
223 IN UINTN OptionalDataSize
,
224 OUT BDS_LOAD_OPTION
** BdsLoadOption
229 IN BDS_LOAD_OPTION
* BdsLoadOption
,
230 IN UINT32 Attributes
,
231 IN CHAR16
* BootDescription
,
232 IN EFI_DEVICE_PATH_PROTOCOL
* DevicePath
,
233 IN ARM_BDS_LOADER_TYPE BootType
,
234 IN UINT8
* OptionalData
,
235 IN UINTN OptionalDataSize
240 IN BDS_LOAD_OPTION
*BootOption
245 IN EFI_DEVICE_PATH
* DevicePath
,
246 OUT ARM_BDS_LOADER_TYPE
*BootType
,
247 OUT UINT32
*Attributes
261 * Try to detect if the given string is an ASCII or Unicode string
263 * There are actually few limitation to this function but it is mainly to give
264 * a user friendly output.
267 * - it only supports unicode string that use ASCII character (< 0x100)
268 * - single character ASCII strings are interpreted as Unicode string
269 * - string cannot be longer than 2 x BOOT_DEVICE_OPTION_MAX (600 bytes)
271 * @param String Buffer that might contain a Unicode or Ascii string
272 * @param IsUnicode If not NULL this boolean value returns if the string is an
273 * ASCII or Unicode string.
278 OUT BOOLEAN
*IsUnicode
281 #endif /* _BDSINTERNAL_H_ */