]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbInfo.c
BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[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 <Pi/PiFirmwareVolume.h>
28
29 //
30 // The protocols, PPI and GUID defintions for this module
31 //
32 #include <Guid/SystemNvDataGuid.h>
33 //
34 // The Library classes this module consumes
35 //
36 #include <Library/BaseLib.h>
37 #include <Library/PcdLib.h>
38
39 typedef struct {
40 UINT64 FvLength;
41 EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
42 //
43 // EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
44 //
45 EFI_FV_BLOCK_MAP_ENTRY End[1];
46 } EFI_FVB_MEDIA_INFO;
47
48 EFI_FVB_MEDIA_INFO mPlatformFvbMediaInfo[] = {
49 //
50 // Systen NvStorage FVB
51 //
52 {
53 FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
54 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
55 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
56 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),
57 {
58 {
59 0,
60 }, // ZeroVector[16]
61 EFI_SYSTEM_NV_DATA_FV_GUID,
62 FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
63 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
64 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
65 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),
66 EFI_FVH_SIGNATURE,
67 EFI_FVB2_MEMORY_MAPPED |
68 EFI_FVB2_READ_ENABLED_CAP |
69 EFI_FVB2_READ_STATUS |
70 EFI_FVB2_WRITE_ENABLED_CAP |
71 EFI_FVB2_WRITE_STATUS |
72 EFI_FVB2_ERASE_POLARITY |
73 EFI_FVB2_ALIGNMENT_16,
74 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
75 0, // CheckSum
76 0, // ExtHeaderOffset
77 {
78 0,
79 }, // Reserved[1]
80 2, // Revision
81 {
82 {
83 (FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
84 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
85 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
86 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize)) /
87 FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
88 FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
89 }
90 } // BlockMap[1]
91 },
92 {
93 {
94 0,
95 0
96 }
97 } // End[1]
98 }
99 };
100
101 EFI_STATUS
102 GetFvbInfo (
103 IN UINT64 FvLength,
104 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
105 )
106 {
107 STATIC BOOLEAN Checksummed = FALSE;
108 UINTN Index;
109
110 if (!Checksummed) {
111 for (Index = 0;
112 Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO);
113 Index += 1) {
114 UINT16 Checksum;
115 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = 0;
116 Checksum = CalculateCheckSum16 (
117 (UINT16*) &mPlatformFvbMediaInfo[Index].FvbInfo,
118 mPlatformFvbMediaInfo[Index].FvbInfo.HeaderLength
119 );
120 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = Checksum;
121 }
122 Checksummed = TRUE;
123 }
124
125 for (Index = 0;
126 Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO);
127 Index += 1) {
128 if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {
129 *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;
130 return EFI_SUCCESS;
131 }
132 }
133
134 return EFI_NOT_FOUND;
135 }