]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c
ArmPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPkg / Library / LinuxBootBootManagerLib / LinuxBootBm.c
1 /** @file
2 Implementation for PlatformBootManagerLib library class interfaces.
3
4 Copyright (C) 2015-2016, Red Hat, Inc.
5 Copyright (c) 2014 - 2019, ARM Ltd. All rights reserved.<BR>
6 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
7 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
8 Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
9
10 SPDX-License-Identifier: BSD-2-Clause-Patent
11
12 **/
13
14 #include <Uefi.h>
15
16 #include <Guid/EventGroup.h>
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/DevicePathLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/PcdLib.h>
23 #include <Library/UefiBootManagerLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/UefiRuntimeServicesTableLib.h>
27 #include <Protocol/LoadedImage.h>
28 #include <Protocol/PlatformBootManager.h>
29
30 /**
31 Register a boot option using a file GUID in the FV.
32
33 @param FileGuid The file GUID name in the FV.
34 @param Description The description of the boot option.
35 @param Attributes The attributes of the boot option.
36
37 **/
38 STATIC
39 VOID
40 PlatformRegisterFvBootOption (
41 CONST EFI_GUID *FileGuid,
42 CHAR16 *Description,
43 UINT32 Attributes
44 )
45 {
46 EFI_STATUS Status;
47 INTN OptionIndex;
48 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
49 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
50 UINTN BootOptionCount;
51 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;
52 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
53 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
54
55 Status = gBS->HandleProtocol (
56 gImageHandle,
57 &gEfiLoadedImageProtocolGuid,
58 (VOID **)&LoadedImage
59 );
60 ASSERT_EFI_ERROR (Status);
61
62 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
63 DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);
64 ASSERT (DevicePath != NULL);
65 DevicePath = AppendDevicePathNode (
66 DevicePath,
67 (EFI_DEVICE_PATH_PROTOCOL *)&FileNode
68 );
69 ASSERT (DevicePath != NULL);
70
71 Status = EfiBootManagerInitializeLoadOption (
72 &NewOption,
73 LoadOptionNumberUnassigned,
74 LoadOptionTypeBoot,
75 Attributes,
76 Description,
77 DevicePath,
78 NULL,
79 0
80 );
81 ASSERT_EFI_ERROR (Status);
82 FreePool (DevicePath);
83
84 BootOptions = EfiBootManagerGetLoadOptions (
85 &BootOptionCount,
86 LoadOptionTypeBoot
87 );
88
89 OptionIndex = EfiBootManagerFindLoadOption (
90 &NewOption,
91 BootOptions,
92 BootOptionCount
93 );
94
95 if (OptionIndex == -1) {
96 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN);
97 ASSERT_EFI_ERROR (Status);
98 }
99
100 EfiBootManagerFreeLoadOption (&NewOption);
101 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
102 }
103
104 /**
105 Do the platform specific action before the console is connected.
106
107 Such as:
108 Update console variable;
109 Register new Driver#### or Boot####;
110 Signal ReadyToLock event.
111 **/
112 VOID
113 EFIAPI
114 PlatformBootManagerBeforeConsole (
115 VOID
116 )
117 {
118 //
119 // Signal EndOfDxe PI Event
120 //
121 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
122 }
123
124 /**
125 Do the platform specific action after the console is connected.
126
127 Such as:
128 Dynamically switch output mode;
129 Signal console ready platform customized event;
130 Run diagnostics like memory testing;
131 Connect certain devices;
132 Dispatch additional option roms.
133 **/
134 VOID
135 EFIAPI
136 PlatformBootManagerAfterConsole (
137 VOID
138 )
139 {
140 EFI_GUID LinuxBootFileGuid;
141
142 CopyGuid (&LinuxBootFileGuid, PcdGetPtr (PcdLinuxBootFileGuid));
143
144 if (!CompareGuid (&LinuxBootFileGuid, &gZeroGuid)) {
145 //
146 // Register LinuxBoot
147 //
148 PlatformRegisterFvBootOption (
149 &LinuxBootFileGuid,
150 L"LinuxBoot",
151 LOAD_OPTION_ACTIVE
152 );
153 } else {
154 DEBUG ((DEBUG_ERROR, "%a: PcdLinuxBootFileGuid was not set!\n", __FUNCTION__));
155 }
156 }
157
158 /**
159 This function is called each second during the boot manager waits the
160 timeout.
161
162 @param TimeoutRemain The remaining timeout.
163 **/
164 VOID
165 EFIAPI
166 PlatformBootManagerWaitCallback (
167 UINT16 TimeoutRemain
168 )
169 {
170 return;
171 }
172
173 /**
174 The function is called when no boot option could be launched,
175 including platform recovery options and options pointing to applications
176 built into firmware volumes.
177
178 If this function returns, BDS attempts to enter an infinite loop.
179 **/
180 VOID
181 EFIAPI
182 PlatformBootManagerUnableToBoot (
183 VOID
184 )
185 {
186 return;
187 }