3 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
4 Copyright (c) 2016 - 2018, ARM Limited. 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.
15 #include "StandaloneMmCore.h"
16 #include <Library/FvLib.h>
17 #include <Library/ExtractGuidedSectionLib.h>
20 // List of file types supported by dispatcher
22 EFI_FV_FILETYPE mMmFileTypes
[] = {
24 0xE, //EFI_FV_FILETYPE_MM_STANDALONE,
26 // Note: DXE core will process the FV image file, so skip it in MM core
27 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
33 IN EFI_HANDLE FvHandle
,
35 IN UINTN Pe32DataSize
,
38 IN EFI_GUID
*DriverName
43 IN EFI_HANDLE FvHandle
48 IN EFI_HANDLE FvHandle
52 MmCoreFfsFindMmDriver (
53 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
58 Given the pointer to the Firmware Volume Header find the
59 MM driver and return it's PE32 image.
62 FwVolHeader - Pointer to memory mapped FV
70 EFI_STATUS DepexStatus
;
71 EFI_FFS_FILE_HEADER
*FileHeader
;
72 EFI_FV_FILETYPE FileType
;
78 EFI_COMMON_SECTION_HEADER
*Section
;
80 UINTN SectionDataSize
;
83 UINT32 ScratchBufferSize
;
85 UINT16 SectionAttribute
;
86 UINT32 AuthenticationStatus
;
87 EFI_FIRMWARE_VOLUME_HEADER
*InnerFvHeader
;
89 DEBUG ((DEBUG_INFO
, "MmCoreFfsFindMmDriver - 0x%x\n", FwVolHeader
));
91 if (FvHasBeenProcessed (FwVolHeader
)) {
95 FvIsBeingProcesssed (FwVolHeader
);
98 // First check for encapsulated compressed firmware volumes
102 Status
= FfsFindNextFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
,
103 FwVolHeader
, &FileHeader
);
104 if (EFI_ERROR (Status
)) {
107 Status
= FfsFindSectionData (EFI_SECTION_GUID_DEFINED
, FileHeader
,
108 &SectionData
, &SectionDataSize
);
109 if (EFI_ERROR (Status
)) {
112 Section
= (EFI_COMMON_SECTION_HEADER
*)(FileHeader
+ 1);
113 Status
= ExtractGuidedSectionGetInfo (Section
, &DstBufferSize
,
114 &ScratchBufferSize
, &SectionAttribute
);
115 if (EFI_ERROR (Status
)) {
120 // Allocate scratch buffer
122 ScratchBuffer
= (VOID
*)(UINTN
)AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize
));
123 if (ScratchBuffer
== NULL
) {
124 return EFI_OUT_OF_RESOURCES
;
128 // Allocate destination buffer, extra one page for adjustment
130 DstBuffer
= (VOID
*)(UINTN
)AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize
));
131 if (DstBuffer
== NULL
) {
132 return EFI_OUT_OF_RESOURCES
;
136 // Call decompress function
138 Status
= ExtractGuidedSectionDecode (Section
, &DstBuffer
, ScratchBuffer
,
139 &AuthenticationStatus
);
140 FreePages (ScratchBuffer
, EFI_SIZE_TO_PAGES (ScratchBufferSize
));
141 if (EFI_ERROR (Status
)) {
146 "Processing compressed firmware volume (AuthenticationStatus == %x)\n",
147 AuthenticationStatus
));
149 Status
= FindFfsSectionInSections (DstBuffer
, DstBufferSize
,
150 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
, &Section
);
151 if (EFI_ERROR (Status
)) {
155 InnerFvHeader
= (VOID
*)(Section
+ 1);
156 Status
= MmCoreFfsFindMmDriver (InnerFvHeader
);
157 if (EFI_ERROR (Status
)) {
162 for (Index
= 0; Index
< sizeof (mMmFileTypes
) / sizeof (mMmFileTypes
[0]); Index
++) {
163 DEBUG ((DEBUG_INFO
, "Check MmFileTypes - 0x%x\n", mMmFileTypes
[Index
]));
164 FileType
= mMmFileTypes
[Index
];
167 Status
= FfsFindNextFile (FileType
, FwVolHeader
, &FileHeader
);
168 if (!EFI_ERROR (Status
)) {
169 Status
= FfsFindSectionData (EFI_SECTION_PE32
, FileHeader
, &Pe32Data
, &Pe32DataSize
);
170 DEBUG ((DEBUG_INFO
, "Find PE data - 0x%x\n", Pe32Data
));
171 DepexStatus
= FfsFindSectionData (EFI_SECTION_MM_DEPEX
, FileHeader
, &Depex
, &DepexSize
);
172 if (!EFI_ERROR (DepexStatus
)) {
173 MmAddToDriverList (FwVolHeader
, Pe32Data
, Pe32DataSize
, Depex
, DepexSize
, &FileHeader
->Name
);
176 } while (!EFI_ERROR (Status
));
182 FreePages (DstBuffer
, EFI_SIZE_TO_PAGES (DstBufferSize
));