]> git.proxmox.com Git - mirror_edk2.git/blob - StandaloneMmPkg/Core/FwVol.c
StandaloneMmPkg/Core: Implementation of Standalone MM Core Module.
[mirror_edk2.git] / StandaloneMmPkg / Core / FwVol.c
1 /**@file
2
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
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 "StandaloneMmCore.h"
16 #include <Library/FvLib.h>
17
18 //
19 // List of file types supported by dispatcher
20 //
21 EFI_FV_FILETYPE mMmFileTypes[] = {
22 EFI_FV_FILETYPE_MM,
23 0xE, //EFI_FV_FILETYPE_MM_STANDALONE,
24 //
25 // Note: DXE core will process the FV image file, so skip it in MM core
26 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
27 //
28 };
29
30 EFI_STATUS
31 MmAddToDriverList (
32 IN EFI_HANDLE FvHandle,
33 IN VOID *Pe32Data,
34 IN UINTN Pe32DataSize,
35 IN VOID *Depex,
36 IN UINTN DepexSize,
37 IN EFI_GUID *DriverName
38 );
39
40 BOOLEAN
41 FvHasBeenProcessed (
42 IN EFI_HANDLE FvHandle
43 );
44
45 VOID
46 FvIsBeingProcesssed (
47 IN EFI_HANDLE FvHandle
48 );
49
50 EFI_STATUS
51 MmCoreFfsFindMmDriver (
52 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader
53 )
54 /*++
55
56 Routine Description:
57 Given the pointer to the Firmware Volume Header find the
58 MM driver and return it's PE32 image.
59
60 Arguments:
61 FwVolHeader - Pointer to memory mapped FV
62
63 Returns:
64 other - Failure
65
66 --*/
67 {
68 EFI_STATUS Status;
69 EFI_STATUS DepexStatus;
70 EFI_FFS_FILE_HEADER *FileHeader;
71 EFI_FV_FILETYPE FileType;
72 VOID *Pe32Data;
73 UINTN Pe32DataSize;
74 VOID *Depex;
75 UINTN DepexSize;
76 UINTN Index;
77
78 DEBUG ((DEBUG_INFO, "MmCoreFfsFindMmDriver - 0x%x\n", FwVolHeader));
79
80 if (FvHasBeenProcessed (FwVolHeader)) {
81 return EFI_SUCCESS;
82 }
83
84 FvIsBeingProcesssed (FwVolHeader);
85
86 for (Index = 0; Index < sizeof (mMmFileTypes) / sizeof (mMmFileTypes[0]); Index++) {
87 DEBUG ((DEBUG_INFO, "Check MmFileTypes - 0x%x\n", mMmFileTypes[Index]));
88 FileType = mMmFileTypes[Index];
89 FileHeader = NULL;
90 do {
91 Status = FfsFindNextFile (FileType, FwVolHeader, &FileHeader);
92 if (!EFI_ERROR (Status)) {
93 Status = FfsFindSectionData (EFI_SECTION_PE32, FileHeader, &Pe32Data, &Pe32DataSize);
94 DEBUG ((DEBUG_INFO, "Find PE data - 0x%x\n", Pe32Data));
95 DepexStatus = FfsFindSectionData (EFI_SECTION_MM_DEPEX, FileHeader, &Depex, &DepexSize);
96 if (!EFI_ERROR (DepexStatus)) {
97 MmAddToDriverList (FwVolHeader, Pe32Data, Pe32DataSize, Depex, DepexSize, &FileHeader->Name);
98 }
99 }
100 } while (!EFI_ERROR (Status));
101 }
102
103 return Status;
104 }