]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbInfo.c
OvmfPkg: QemuFlashFvbServicesRuntimeDxe: split out runtime DXE specifics
[mirror_edk2.git] / OvmfPkg / QemuFlashFvbServicesRuntimeDxe / FvbInfo.c
1 /**@file
2
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 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 Module Name:
14
15 FvbInfo.c
16
17 Abstract:
18
19 Defines data structure that is the volume header found.These data is intent
20 to decouple FVB driver with FV header.
21
22 **/
23
24 //
25 // The package level header files this module uses
26 //
27 #include <PiDxe.h>
28 //
29 // The protocols, PPI and GUID defintions for this module
30 //
31 #include <Guid/EventGroup.h>
32 #include <Guid/FirmwareFileSystem2.h>
33 #include <Guid/SystemNvDataGuid.h>
34 #include <Protocol/FirmwareVolumeBlock.h>
35 #include <Protocol/DevicePath.h>
36 //
37 // The Library classes this module consumes
38 //
39 #include <Library/UefiLib.h>
40 #include <Library/UefiDriverEntryPoint.h>
41 #include <Library/BaseLib.h>
42 #include <Library/DxeServicesTableLib.h>
43 #include <Library/UefiRuntimeLib.h>
44 #include <Library/DebugLib.h>
45 #include <Library/HobLib.h>
46 #include <Library/BaseMemoryLib.h>
47 #include <Library/MemoryAllocationLib.h>
48 #include <Library/UefiBootServicesTableLib.h>
49 #include <Library/PcdLib.h>
50
51 typedef struct {
52 UINT64 FvLength;
53 EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
54 //
55 // EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
56 //
57 EFI_FV_BLOCK_MAP_ENTRY End[1];
58 } EFI_FVB_MEDIA_INFO;
59
60 EFI_FVB_MEDIA_INFO mPlatformFvbMediaInfo[] = {
61 //
62 // Systen NvStorage FVB
63 //
64 {
65 FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
66 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
67 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
68 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),
69 {
70 {
71 0,
72 }, // ZeroVector[16]
73 EFI_SYSTEM_NV_DATA_FV_GUID,
74 FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
75 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
76 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
77 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),
78 EFI_FVH_SIGNATURE,
79 EFI_FVB2_MEMORY_MAPPED |
80 EFI_FVB2_READ_ENABLED_CAP |
81 EFI_FVB2_READ_STATUS |
82 EFI_FVB2_WRITE_ENABLED_CAP |
83 EFI_FVB2_WRITE_STATUS |
84 EFI_FVB2_ERASE_POLARITY |
85 EFI_FVB2_ALIGNMENT_16,
86 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
87 0, // CheckSum
88 0, // ExtHeaderOffset
89 {
90 0,
91 }, // Reserved[1]
92 2, // Revision
93 {
94 {
95 (FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
96 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
97 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
98 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize)) /
99 FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
100 FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
101 }
102 } // BlockMap[1]
103 },
104 {
105 {
106 0,
107 0
108 }
109 } // End[1]
110 }
111 };
112
113 EFI_STATUS
114 GetFvbInfo (
115 IN UINT64 FvLength,
116 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
117 )
118 {
119 STATIC BOOLEAN Checksummed = FALSE;
120 UINTN Index;
121
122 if (!Checksummed) {
123 for (Index = 0;
124 Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO);
125 Index += 1) {
126 UINT16 Checksum;
127 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = 0;
128 Checksum = CalculateCheckSum16 (
129 (UINT16*) &mPlatformFvbMediaInfo[Index].FvbInfo,
130 mPlatformFvbMediaInfo[Index].FvbInfo.HeaderLength
131 );
132 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = Checksum;
133 }
134 Checksummed = TRUE;
135 }
136
137 for (Index = 0;
138 Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO);
139 Index += 1) {
140 if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {
141 *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;
142 return EFI_SUCCESS;
143 }
144 }
145
146 return EFI_NOT_FOUND;
147 }