1 /** @file
2 Module produce Framework's EFI_PEI_FV_FILE_LOADER_PPI top of EFI_PEI_LOAD_FILE_PPI.
3
4 UEFI PI Spec supersedes Intel's Framework Specs.
5 EFI_PEI_FV_FILE_LOADER_PPI defined in Intel Framework Pkg is replaced by EFI_PEI_LOAD_FILE_PPI
6 in MdePkg.
7 This module produces EFI_PEI_FV_FILE_LOADER_PPI on top of EFI_PEI_LOAD_FILE_PPI .
8 This module is used on platform when both of these two conditions are true:
9 1) Framework module consumes EFI_PEI_FV_FILE_LOADER_PPI is present.
10 2) The platform has PI modules that produce EFI_PEI_LOAD_FILE_PPI.
11
12 Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
13
14 This program and the accompanying materials
15 are licensed and made available under the terms and conditions of the BSD License
16 which accompanies this distribution. The full text of the license may be found at
17 http://opensource.org/licenses/bsd-license.php
18
19 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
20 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 Module Name:
22
23 **/
24
25 #include <PiPei.h>
26 #include <Ppi/LoadFile.h>
27 #include <Ppi/FvLoadFile.h>
28 #include <Library/DebugLib.h>
29 #include <Library/PeiServicesLib.h>
30
31 /**
32
33 Wrap the call to PI's EFI_PEI_LOAD_FILE_PPI.
34
35 @param This A pointer to EFI_PEI_FV_FILE_LOADER_PPI.
36 @param FfsHeader Pointer to the FFS header of the file to load.
37 @param ImageAddress The loaded address of the Image.
38 @param ImageSize Pointer to the size of the loaded image.
39 @param EntryPoint Pointer to the entry point of the image.
40
41 @retval EFI_SUCCESS The image was loaded successfully.
42 @retval EFI_OUT_OF_RESOURCE There was not enought memory.
43 @retval EFI_INVALID_PARAMETER The contents of the FFS file did not contain a valid PE/COFF image that could be loaded.
44 **/
45 EFI_STATUS
46 EFIAPI
47 FrameworkLoadFile (
48 IN EFI_PEI_FV_FILE_LOADER_PPI *This,
49 IN EFI_FFS_FILE_HEADER *FfsHeader,
50 OUT EFI_PHYSICAL_ADDRESS *ImageAddress,
51 OUT UINT64 *ImageSize,
52 OUT EFI_PHYSICAL_ADDRESS *EntryPoint
53 );
54
55 EFI_PEI_FV_FILE_LOADER_PPI mLoadFilePpi = {
56 FrameworkLoadFile
57 };
58
59 EFI_PEI_PPI_DESCRIPTOR mPpiFrameworkLoadFile = {
60 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
61 &gEfiPeiFvFileLoaderPpiGuid,
62 &mLoadFilePpi
63 };
64
65 /**
66 Standard entry point of a PEIM.
67
68 @param FfsHeader The FFS file header
69 @param PeiServices General purpose services available to every PEIM.
70
71 @retval EFI_SUCCESS If the gEfiPeiReadOnlyVariablePpiGuid interface could be successfully installed.
72
73 **/
74 EFI_STATUS
75 EFIAPI
InitPeim(IN EFI_PEI_FILE_HANDLE FfsHeader,IN CONST EFI_PEI_SERVICES ** PeiServices)76 InitPeim (
77 IN EFI_PEI_FILE_HANDLE FfsHeader,
78 IN CONST EFI_PEI_SERVICES **PeiServices
79 )
80 {
81 //
82 // This thunk module can only be used together with a PI PEI core, as we
83 // assume PeiServices Pointer Table can be located in a standard way defined
84 // in PI spec.
85 //
86 ASSERT ((*PeiServices)->Hdr.Revision >= 0x00010000);
87 return (*PeiServices)->InstallPpi (PeiServices, &mPpiFrameworkLoadFile);
88 }
89
90
91 /**
92
93 Wrap the call to PI's EFI_PEI_LOAD_FILE_PPI.
94
95 @param This A pointer to EFI_PEI_FV_FILE_LOADER_PPI.
96 @param FfsHeader The pointer to the file header to be loaded by the Pe/Coff loader.
97 @param ImageAddress The loaded address of the Image.
98 @param ImageSize Pointer to the size of the loaded image.
99 @param EntryPoint Pointer to the entry point of the image.
100
101 @retval EFI_SUCCESS The image was loaded successfully.
102 @retval EFI_OUT_OF_RESOURCE There was not enought memory.
103 @retval EFI_INVALID_PARAMETER The contents of the FFS file did not contain a valid PE/COFF image that could be loaded.
104 **/
105 EFI_STATUS
106 EFIAPI
FrameworkLoadFile(IN EFI_PEI_FV_FILE_LOADER_PPI * This,IN EFI_FFS_FILE_HEADER * FfsHeader,OUT EFI_PHYSICAL_ADDRESS * ImageAddress,OUT UINT64 * ImageSize,OUT EFI_PHYSICAL_ADDRESS * EntryPoint)107 FrameworkLoadFile (
108 IN EFI_PEI_FV_FILE_LOADER_PPI *This,
109 IN EFI_FFS_FILE_HEADER *FfsHeader,
110 OUT EFI_PHYSICAL_ADDRESS *ImageAddress,
111 OUT UINT64 *ImageSize,
112 OUT EFI_PHYSICAL_ADDRESS *EntryPoint
113 )
114 {
115 EFI_STATUS Status;
116 EFI_PEI_LOAD_FILE_PPI *PiLoadFile;
117 UINT32 AuthenticationState;
118
119 Status = PeiServicesLocatePpi (
120 &gEfiPeiLoadFilePpiGuid,
121 0,
122 NULL,
123 (VOID **) &PiLoadFile
124 );
125 ASSERT_EFI_ERROR (Status);
126
127 return PiLoadFile->LoadFile (
128 PiLoadFile,
129 (EFI_PEI_FILE_HANDLE) FfsHeader,
130 ImageAddress,
131 ImageSize,
132 EntryPoint,
133 &AuthenticationState
134 );
135
136 }
137
138