3 * Copyright (c) 2011, 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 #include "BdsInternal.h"
17 //#include <Library/DxeServicesLib.h>
21 BdsLoadFileFromFirmwareVolume (
22 IN EFI_HANDLE FvHandle
,
24 IN EFI_FV_FILETYPE FileTypeFilter
,
25 OUT EFI_DEVICE_PATH
**EfiAppDevicePath
28 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
;
30 EFI_STATUS Status
, FileStatus
;
32 EFI_FV_FILETYPE FileType
;
33 EFI_FV_FILE_ATTRIBUTES Attributes
;
37 UINT32 Authentication
;
38 EFI_DEVICE_PATH
*FvDevicePath
;
39 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileDevicePath
;
41 Status
= gBS
->HandleProtocol (FvHandle
,&gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&FvProtocol
);
42 if (EFI_ERROR(Status
)) {
47 UiStringLen
= StrLen (FilePath
);
50 Key
= AllocatePool (FvProtocol
->KeySize
);
52 ZeroMem (Key
, FvProtocol
->KeySize
);
55 // Search in all files
56 FileType
= FileTypeFilter
;
58 Status
= FvProtocol
->GetNextFile (FvProtocol
, Key
, &FileType
, &NameGuid
, &Attributes
, &Size
);
59 if (!EFI_ERROR (Status
)) {
61 FileStatus
= FvProtocol
->ReadSection (
64 EFI_SECTION_USER_INTERFACE
,
70 if (!EFI_ERROR (FileStatus
)) {
71 if (StrnCmp (FilePath
, UiSection
, UiStringLen
) == 0) {
73 // We found a UiString match.
75 Status
= gBS
->HandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
77 // Generate the Device Path for the file
78 //DevicePath = DuplicateDevicePath(FvDevicePath);
79 EfiInitializeFwVolDevicepathNode (&FileDevicePath
, &NameGuid
);
80 *EfiAppDevicePath
= AppendDevicePathNode (FvDevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&FileDevicePath
);
89 } while (!EFI_ERROR (Status
));
96 Start an EFI Application from any Firmware Volume
98 @param EfiApp EFI Application Name
100 @retval EFI_SUCCESS All drivers have been connected
101 @retval EFI_NOT_FOUND The Linux kernel Device Path has not been found
102 @retval EFI_OUT_OF_RESOURCES There is not enough resource memory to store the matching results.
107 IN EFI_HANDLE ParentImageHandle
,
109 IN UINTN LoadOptionsSize
,
114 UINTN NoHandles
, HandleIndex
;
116 EFI_DEVICE_PATH
*EfiAppDevicePath
;
118 // Need to connect every drivers to ensure no dependencies are missing for the application
119 Status
= BdsConnectAllDrivers();
120 if (EFI_ERROR(Status
)) {
121 DEBUG ((EFI_D_ERROR
, "FAIL to connect all drivers\n"));
125 // Search the application in any Firmware Volume
126 Status
= gBS
->LocateHandleBuffer (ByProtocol
, &gEfiFirmwareVolume2ProtocolGuid
, NULL
, &NoHandles
, &Handles
);
127 if (EFI_ERROR (Status
) || (NoHandles
== 0)) {
128 DEBUG ((EFI_D_ERROR
, "FAIL to find Firmware Volume\n"));
132 // Search in all Firmware Volume for the EFI Application
133 for (HandleIndex
= 0; HandleIndex
< NoHandles
; HandleIndex
++) {
134 EfiAppDevicePath
= NULL
;
135 Status
= BdsLoadFileFromFirmwareVolume (Handles
[HandleIndex
], EfiApp
, EFI_FV_FILETYPE_APPLICATION
, &EfiAppDevicePath
);
136 if (!EFI_ERROR (Status
)) {
137 // Start the application
138 Status
= BdsStartEfiApplication (ParentImageHandle
, EfiAppDevicePath
, LoadOptionsSize
, LoadOptions
);