]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/BdsLib/BdsAppLoader.c
ARM Packages: Fixed line endings
[mirror_edk2.git] / ArmPkg / Library / BdsLib / BdsAppLoader.c
CommitLineData
1e57a462 1/** @file\r
2*\r
3* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include "BdsInternal.h"\r
16\r
17//#include <Library/DxeServicesLib.h>\r
18\r
19STATIC\r
20EFI_STATUS\r
21BdsLoadFileFromFirmwareVolume (\r
22 IN EFI_HANDLE FvHandle,\r
23 IN CHAR16 *FilePath,\r
24 IN EFI_FV_FILETYPE FileTypeFilter,\r
25 OUT EFI_DEVICE_PATH **EfiAppDevicePath\r
26 )\r
27{\r
28 EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;\r
29 VOID *Key;\r
30 EFI_STATUS Status, FileStatus;\r
31 EFI_GUID NameGuid;\r
32 EFI_FV_FILETYPE FileType;\r
33 EFI_FV_FILE_ATTRIBUTES Attributes;\r
34 UINTN Size;\r
35 UINTN UiStringLen;\r
36 CHAR16 *UiSection;\r
37 UINT32 Authentication;\r
38 EFI_DEVICE_PATH *FvDevicePath;\r
39 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileDevicePath;\r
40\r
41 Status = gBS->HandleProtocol (FvHandle,&gEfiFirmwareVolume2ProtocolGuid, (VOID **)&FvProtocol);\r
42 if (EFI_ERROR(Status)) {\r
43 return Status;\r
44 }\r
45\r
46 // Length of FilePath\r
47 UiStringLen = StrLen (FilePath);\r
48\r
49 // Allocate Key\r
50 Key = AllocatePool (FvProtocol->KeySize);\r
51 ASSERT (Key != NULL);\r
52 ZeroMem (Key, FvProtocol->KeySize);\r
53\r
54 do {\r
55 // Search in all files\r
56 FileType = FileTypeFilter;\r
57\r
58 Status = FvProtocol->GetNextFile (FvProtocol, Key, &FileType, &NameGuid, &Attributes, &Size);\r
59 if (!EFI_ERROR (Status)) {\r
60 UiSection = NULL;\r
61 FileStatus = FvProtocol->ReadSection (\r
62 FvProtocol,\r
63 &NameGuid,\r
64 EFI_SECTION_USER_INTERFACE,\r
65 0,\r
66 (VOID **)&UiSection,\r
67 &Size,\r
68 &Authentication\r
69 );\r
70 if (!EFI_ERROR (FileStatus)) {\r
71 if (StrnCmp (FilePath, UiSection, UiStringLen) == 0) {\r
72 //\r
73 // We found a UiString match.\r
74 //\r
75 Status = gBS->HandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r
76\r
77 // Generate the Device Path for the file\r
78 //DevicePath = DuplicateDevicePath(FvDevicePath);\r
79 EfiInitializeFwVolDevicepathNode (&FileDevicePath, &NameGuid);\r
80 *EfiAppDevicePath = AppendDevicePathNode (FvDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&FileDevicePath);\r
81\r
82 FreePool (Key);\r
83 FreePool (UiSection);\r
84 return FileStatus;\r
85 }\r
86 FreePool (UiSection);\r
87 }\r
88 }\r
89 } while (!EFI_ERROR (Status));\r
90\r
91 FreePool(Key);\r
92 return Status;\r
93}\r
94\r
95/**\r
96 Start an EFI Application from any Firmware Volume\r
97\r
98 @param EfiApp EFI Application Name\r
99\r
100 @retval EFI_SUCCESS All drivers have been connected\r
101 @retval EFI_NOT_FOUND The Linux kernel Device Path has not been found\r
102 @retval EFI_OUT_OF_RESOURCES There is not enough resource memory to store the matching results.\r
103\r
104**/\r
105EFI_STATUS\r
106BdsLoadApplication (\r
107 IN EFI_HANDLE ParentImageHandle,\r
108 IN CHAR16* EfiApp,\r
109 IN UINTN LoadOptionsSize,\r
110 IN VOID* LoadOptions\r
111 )\r
112{\r
113 EFI_STATUS Status;\r
114 UINTN NoHandles, HandleIndex;\r
115 EFI_HANDLE *Handles;\r
116 EFI_DEVICE_PATH *EfiAppDevicePath;\r
117\r
118 // Need to connect every drivers to ensure no dependencies are missing for the application\r
119 Status = BdsConnectAllDrivers();\r
120 if (EFI_ERROR(Status)) {\r
121 DEBUG ((EFI_D_ERROR, "FAIL to connect all drivers\n"));\r
122 return Status;\r
123 }\r
124\r
125 // Search the application in any Firmware Volume\r
126 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoHandles, &Handles);\r
127 if (EFI_ERROR (Status) || (NoHandles == 0)) {\r
128 DEBUG ((EFI_D_ERROR, "FAIL to find Firmware Volume\n"));\r
129 return Status;\r
130 }\r
131\r
132 // Search in all Firmware Volume for the EFI Application\r
133 for (HandleIndex = 0; HandleIndex < NoHandles; HandleIndex++) {\r
134 EfiAppDevicePath = NULL;\r
135 Status = BdsLoadFileFromFirmwareVolume (Handles[HandleIndex], EfiApp, EFI_FV_FILETYPE_APPLICATION, &EfiAppDevicePath);\r
136 if (!EFI_ERROR (Status)) {\r
137 // Start the application\r
138 Status = BdsStartEfiApplication (ParentImageHandle, EfiAppDevicePath, LoadOptionsSize, LoadOptions);\r
139 return Status;\r
140 }\r
141 }\r
142\r
143 return Status;\r
144}\r