]>
Commit | Line | Data |
---|---|---|
1bfda055 | 1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2011, 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 | EFI_STATUS\r | |
18 | BdsLoadPeCoff (\r | |
19 | IN BDS_FILE *EfiAppFile\r | |
20 | )\r | |
21 | {\r | |
22 | EFI_STATUS Status;\r | |
23 | EFI_HANDLE ImageHandle;\r | |
24 | MEDIA_FW_VOL_FILEPATH_DEVICE_PATH NewNode;\r | |
25 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
26 | \r | |
27 | // Only support loading from FV right now\r | |
28 | ASSERT(EfiAppFile->Type == BDS_FILETYPE_FV);\r | |
29 | \r | |
30 | // Generate the Device Path for the file\r | |
31 | DevicePath = DuplicateDevicePath(EfiAppFile->DevicePath);\r | |
32 | EfiInitializeFwVolDevicepathNode (&NewNode, &(EfiAppFile->File.Fv.Guid));\r | |
33 | DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&NewNode);\r | |
34 | \r | |
35 | Status = gBS->LoadImage (TRUE, gImageHandle, DevicePath, NULL, 0, &ImageHandle);\r | |
36 | if (!EFI_ERROR (Status)) {\r | |
bad880b1 | 37 | //\r |
38 | // Before calling the image, enable the Watchdog Timer for\r | |
39 | // the 5 Minute period\r | |
40 | //\r | |
41 | gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r | |
1bfda055 | 42 | Status = gBS->StartImage (ImageHandle, NULL, NULL);\r |
bad880b1 | 43 | //\r |
44 | // Clear the Watchdog Timer after the image returns\r | |
45 | //\r | |
46 | gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r | |
1bfda055 | 47 | }\r |
48 | \r | |
49 | return Status;\r | |
50 | }\r | |
51 | \r | |
52 | EFI_STATUS BdsLoadApplicationFromPath(\r | |
53 | IN CHAR16* EfiAppPath\r | |
54 | ) {\r | |
55 | EFI_STATUS Status;\r | |
56 | BDS_FILE EfiAppFile;\r | |
57 | \r | |
58 | // Need to connect every drivers to ensure no dependencies are missing for the application\r | |
59 | Status = BdsConnectAllDrivers();\r | |
60 | if (EFI_ERROR(Status)) {\r | |
61 | DEBUG ((EFI_D_ERROR, "FAIL to connect all drivers\n"));\r | |
62 | return Status;\r | |
63 | }\r | |
64 | \r | |
65 | // Locate the application from a device path\r | |
66 | Status = BdsLoadFilePath(EfiAppPath, &EfiAppFile);\r | |
67 | if (EFI_ERROR(Status)) {\r | |
68 | DEBUG ((EFI_D_ERROR, "ERROR: Do not find EFI application %s\n",EfiAppPath));\r | |
69 | return Status;\r | |
70 | }\r | |
71 | \r | |
72 | // Start the application\r | |
73 | Status = BdsLoadPeCoff(&EfiAppFile);\r | |
74 | \r | |
75 | return Status;\r | |
76 | }\r | |
77 | \r | |
78 | EFI_STATUS BdsLoadApplication(\r | |
79 | IN CHAR16* EfiApp\r | |
80 | ) {\r | |
81 | EFI_STATUS Status;\r | |
82 | UINTN NoHandles, HandleIndex;\r | |
83 | EFI_HANDLE *Handles;\r | |
84 | BDS_FILE EfiAppFile;\r | |
85 | \r | |
86 | // Need to connect every drivers to ensure no dependencies are missing for the application\r | |
87 | Status = BdsConnectAllDrivers();\r | |
88 | if (EFI_ERROR(Status)) {\r | |
89 | DEBUG ((EFI_D_ERROR, "FAIL to connect all drivers\n"));\r | |
90 | return Status;\r | |
91 | }\r | |
92 | \r | |
93 | // Search the application in any Firmware Volume\r | |
94 | Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoHandles, &Handles);\r | |
95 | if (EFI_ERROR (Status) || (NoHandles == 0)) {\r | |
96 | DEBUG ((EFI_D_ERROR, "FAIL to find Firmware Volume\n"));\r | |
97 | return Status;\r | |
98 | }\r | |
99 | \r | |
100 | // Search in all Firmware Volume for the EFI Application\r | |
101 | for (HandleIndex = 0; HandleIndex < NoHandles; HandleIndex++) {\r | |
102 | Status = BdsLoadFileFromFirmwareVolume(Handles[HandleIndex],EfiApp,EFI_FV_FILETYPE_APPLICATION,&EfiAppFile);\r | |
103 | if (!EFI_ERROR (Status)) {\r | |
104 | // Start the application\r | |
105 | Status = BdsLoadPeCoff(&EfiAppFile);\r | |
106 | return Status;\r | |
107 | }\r | |
108 | }\r | |
109 | \r | |
110 | return Status;\r | |
111 | }\r |