]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/BdsLib/BdsAppLoader.c
Patch from open source community for CryptoPkg to allow it to build for ARM using...
[mirror_edk2.git] / ArmPkg / Library / BdsLib / BdsAppLoader.c
1 /** @file
2 *
3 * Copyright (c) 2011, ARM Limited. All rights reserved.
4 *
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
9 *
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.
12 *
13 **/
14
15 #include "BdsInternal.h"
16
17 EFI_STATUS
18 BdsLoadPeCoff (
19 IN BDS_FILE *EfiAppFile
20 )
21 {
22 EFI_STATUS Status;
23 EFI_HANDLE ImageHandle;
24 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH NewNode;
25 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
26
27 // Only support loading from FV right now
28 ASSERT(EfiAppFile->Type == BDS_FILETYPE_FV);
29
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);
34
35 Status = gBS->LoadImage (TRUE, gImageHandle, DevicePath, NULL, 0, &ImageHandle);
36 if (!EFI_ERROR (Status)) {
37 //
38 // Before calling the image, enable the Watchdog Timer for
39 // the 5 Minute period
40 //
41 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
42 Status = gBS->StartImage (ImageHandle, NULL, NULL);
43 //
44 // Clear the Watchdog Timer after the image returns
45 //
46 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
47 }
48
49 return Status;
50 }
51
52 EFI_STATUS BdsLoadApplicationFromPath(
53 IN CHAR16* EfiAppPath
54 ) {
55 EFI_STATUS Status;
56 BDS_FILE EfiAppFile;
57
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"));
62 return Status;
63 }
64
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));
69 return Status;
70 }
71
72 // Start the application
73 Status = BdsLoadPeCoff(&EfiAppFile);
74
75 return Status;
76 }
77
78 EFI_STATUS BdsLoadApplication(
79 IN CHAR16* EfiApp
80 ) {
81 EFI_STATUS Status;
82 UINTN NoHandles, HandleIndex;
83 EFI_HANDLE *Handles;
84 BDS_FILE EfiAppFile;
85
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"));
90 return Status;
91 }
92
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"));
97 return Status;
98 }
99
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);
106 return Status;
107 }
108 }
109
110 return Status;
111 }