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"
19 IN BDS_FILE
*EfiAppFile
23 EFI_HANDLE ImageHandle
;
24 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH NewNode
;
25 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
27 // Only support loading from FV right now
28 ASSERT(EfiAppFile
->Type
== BDS_FILETYPE_FV
);
30 // Generate the Device Path for the file
31 DevicePath
= DuplicateDevicePath(EfiAppFile
->DevicePath
);
32 EfiInitializeFwVolDevicepathNode (&NewNode
, &(EfiAppFile
->File
.Fv
.Guid
));
33 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&NewNode
);
35 Status
= gBS
->LoadImage (TRUE
, gImageHandle
, DevicePath
, NULL
, 0, &ImageHandle
);
36 if (!EFI_ERROR (Status
)) {
38 // Before calling the image, enable the Watchdog Timer for
39 // the 5 Minute period
41 gBS
->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL
);
42 Status
= gBS
->StartImage (ImageHandle
, NULL
, NULL
);
44 // Clear the Watchdog Timer after the image returns
46 gBS
->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL
);
52 EFI_STATUS
BdsLoadApplicationFromPath(
58 // Need to connect every drivers to ensure no dependencies are missing for the application
59 Status
= BdsConnectAllDrivers();
60 if (EFI_ERROR(Status
)) {
61 DEBUG ((EFI_D_ERROR
, "FAIL to connect all drivers\n"));
65 // Locate the application from a device path
66 Status
= BdsLoadFilePath(EfiAppPath
, &EfiAppFile
);
67 if (EFI_ERROR(Status
)) {
68 DEBUG ((EFI_D_ERROR
, "ERROR: Do not find EFI application %s\n",EfiAppPath
));
72 // Start the application
73 Status
= BdsLoadPeCoff(&EfiAppFile
);
78 EFI_STATUS
BdsLoadApplication(
82 UINTN NoHandles
, HandleIndex
;
86 // Need to connect every drivers to ensure no dependencies are missing for the application
87 Status
= BdsConnectAllDrivers();
88 if (EFI_ERROR(Status
)) {
89 DEBUG ((EFI_D_ERROR
, "FAIL to connect all drivers\n"));
93 // Search the application in any Firmware Volume
94 Status
= gBS
->LocateHandleBuffer (ByProtocol
, &gEfiFirmwareVolume2ProtocolGuid
, NULL
, &NoHandles
, &Handles
);
95 if (EFI_ERROR (Status
) || (NoHandles
== 0)) {
96 DEBUG ((EFI_D_ERROR
, "FAIL to find Firmware Volume\n"));
100 // Search in all Firmware Volume for the EFI Application
101 for (HandleIndex
= 0; HandleIndex
< NoHandles
; HandleIndex
++) {
102 Status
= BdsLoadFileFromFirmwareVolume(Handles
[HandleIndex
],EfiApp
,EFI_FV_FILETYPE_APPLICATION
,&EfiAppFile
);
103 if (!EFI_ERROR (Status
)) {
104 // Start the application
105 Status
= BdsLoadPeCoff(&EfiAppFile
);