2 Section Extraction PEIM
4 Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
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.
16 #include <Ppi/GuidedSectionExtraction.h>
17 #include <Library/DebugLib.h>
18 #include <Library/ExtractGuidedSectionLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/PeiServicesLib.h>
23 // Function prototype for Section Extraction PPI service
27 CustomGuidedSectionExtract (
28 IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*This
,
29 IN CONST VOID
*InputSection
,
30 OUT VOID
**OutputBuffer
,
31 OUT UINTN
*OutputSize
,
32 OUT UINT32
*AuthenticationStatus
36 // Module global for the Section Extraction PPI instance
38 CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi
= {
39 CustomGuidedSectionExtract
43 The ExtractSection() function processes the input section and
44 returns a pointer to the section contents. If the section being
45 extracted does not require processing (if the section
46 GuidedSectionHeader.Attributes has the
47 EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then
48 OutputBuffer is just updated to point to the start of the
49 section's contents. Otherwise, *Buffer must be allocated
50 from PEI permanent memory.
52 @param This Indicates the
53 EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.
54 Buffer containing the input GUIDed section to be
55 processed. OutputBuffer OutputBuffer is
56 allocated from PEI permanent memory and contains
57 the new section stream.
58 @param InputSection A pointer to the input buffer, which contains
59 the input section to be processed.
60 @param OutputBuffer A pointer to a caller-allocated buffer, whose
61 size is specified by the contents of OutputSize.
62 @param OutputSize A pointer to a caller-allocated
63 UINTN in which the size of *OutputBuffer
64 allocation is stored. If the function
65 returns anything other than EFI_SUCCESS,
66 the value of OutputSize is undefined.
67 @param AuthenticationStatus A pointer to a caller-allocated
68 UINT32 that indicates the
69 authentication status of the
70 output buffer. If the input
71 section's GuidedSectionHeader.
72 Attributes field has the
73 EFI_GUIDED_SECTION_AUTH_STATUS_VALID
75 AuthenticationStatus must return
76 zero. These bits reflect the
77 status of the extraction
78 operation. If the function
79 returns anything other than
80 EFI_SUCCESS, the value of
81 AuthenticationStatus is
84 @retval EFI_SUCCESS The InputSection was
85 successfully processed and the
86 section contents were returned.
88 @retval EFI_OUT_OF_RESOURCES The system has insufficient
89 resources to process the request.
91 @retval EFI_INVALID_PARAMETER The GUID in InputSection does
92 not match this instance of the
93 GUIDed Section Extraction PPI.
98 CustomGuidedSectionExtract (
99 IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI
*This
,
100 IN CONST VOID
*InputSection
,
101 OUT VOID
**OutputBuffer
,
102 OUT UINTN
*OutputSize
,
103 OUT UINT32
*AuthenticationStatus
107 UINT8
*ScratchBuffer
;
108 UINT32 ScratchBufferSize
;
109 UINT32 OutputBufferSize
;
110 UINT16 SectionAttribute
;
113 // Init local variable
115 ScratchBuffer
= NULL
;
118 // Call GetInfo to get the size and attribute of input guided section data.
120 Status
= ExtractGuidedSectionGetInfo (
127 if (EFI_ERROR (Status
)) {
128 DEBUG ((DEBUG_ERROR
, "GetInfo from guided section Failed - %r\n", Status
));
132 if (ScratchBufferSize
!= 0) {
134 // Allocate scratch buffer
136 ScratchBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize
));
137 if (ScratchBuffer
== NULL
) {
138 return EFI_OUT_OF_RESOURCES
;
142 if (((SectionAttribute
& EFI_GUIDED_SECTION_PROCESSING_REQUIRED
) != 0) && OutputBufferSize
> 0) {
144 // Allocate output buffer
146 *OutputBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize
) + 1);
147 if (*OutputBuffer
== NULL
) {
148 return EFI_OUT_OF_RESOURCES
;
150 DEBUG ((DEBUG_INFO
, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize
, *OutputBuffer
));
152 // *OutputBuffer still is one section. Adjust *OutputBuffer offset,
153 // skip EFI section header to make section data at page alignment.
155 *OutputBuffer
= (VOID
*)((UINT8
*) *OutputBuffer
+ EFI_PAGE_SIZE
- sizeof (EFI_COMMON_SECTION_HEADER
));
158 Status
= ExtractGuidedSectionDecode (
164 if (EFI_ERROR (Status
)) {
168 DEBUG ((DEBUG_ERROR
, "Extract guided section Failed - %r\n", Status
));
172 *OutputSize
= (UINTN
) OutputBufferSize
;
178 Main entry for Section Extraction PEIM driver.
180 This routine registers the Section Extraction PPIs that have been registered
181 with the Section Extraction Library.
183 @param FileHandle Handle of the file being invoked.
184 @param PeiServices Describes the list of possible PEI Services.
186 @retval EFI_SUCCESS The entry point is executed successfully.
187 @retval other Some error occurs when executing this entry point.
192 SectionExtractionPeiEntry (
193 IN EFI_PEI_FILE_HANDLE FileHandle
,
194 IN CONST EFI_PEI_SERVICES
**PeiServices
198 EFI_GUID
*ExtractHandlerGuidTable
;
199 UINTN ExtractHandlerNumber
;
200 EFI_PEI_PPI_DESCRIPTOR
*GuidPpi
;
203 // Get custom extract guided section method guid list
205 ExtractHandlerNumber
= ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable
);
208 // Install custom extraction guid PPI
210 if (ExtractHandlerNumber
> 0) {
211 GuidPpi
= (EFI_PEI_PPI_DESCRIPTOR
*) AllocatePool (ExtractHandlerNumber
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
212 ASSERT (GuidPpi
!= NULL
);
213 while (ExtractHandlerNumber
-- > 0) {
214 GuidPpi
->Flags
= EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
215 GuidPpi
->Ppi
= (VOID
*) &mCustomGuidedSectionExtractionPpi
;
216 GuidPpi
->Guid
= &ExtractHandlerGuidTable
[ExtractHandlerNumber
];
217 Status
= PeiServicesInstallPpi (GuidPpi
++);
218 ASSERT_EFI_ERROR (Status
);