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