]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbInfo.c
OvmfPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / OvmfPkg / QemuFlashFvbServicesRuntimeDxe / FvbInfo.c
1 /**@file
2
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 Module Name:
8
9 FvbInfo.c
10
11 Abstract:
12
13 Defines data structure that is the volume header found.These data is intent
14 to decouple FVB driver with FV header.
15
16 **/
17
18 //
19 // The package level header files this module uses
20 //
21 #include <Pi/PiFirmwareVolume.h>
22
23 //
24 // The protocols, PPI and GUID defintions for this module
25 //
26 #include <Guid/SystemNvDataGuid.h>
27 //
28 // The Library classes this module consumes
29 //
30 #include <Library/BaseLib.h>
31 #include <Library/PcdLib.h>
32
33 typedef struct {
34 UINT64 FvLength;
35 EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
36 //
37 // EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
38 //
39 EFI_FV_BLOCK_MAP_ENTRY End[1];
40 } EFI_FVB_MEDIA_INFO;
41
42 EFI_FVB_MEDIA_INFO mPlatformFvbMediaInfo[] = {
43 //
44 // Systen NvStorage FVB
45 //
46 {
47 FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
48 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
49 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
50 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),
51 {
52 {
53 0,
54 }, // ZeroVector[16]
55 EFI_SYSTEM_NV_DATA_FV_GUID,
56 FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
57 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
58 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
59 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),
60 EFI_FVH_SIGNATURE,
61 EFI_FVB2_MEMORY_MAPPED |
62 EFI_FVB2_READ_ENABLED_CAP |
63 EFI_FVB2_READ_STATUS |
64 EFI_FVB2_WRITE_ENABLED_CAP |
65 EFI_FVB2_WRITE_STATUS |
66 EFI_FVB2_ERASE_POLARITY |
67 EFI_FVB2_ALIGNMENT_16,
68 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
69 0, // CheckSum
70 0, // ExtHeaderOffset
71 {
72 0,
73 }, // Reserved[1]
74 2, // Revision
75 {
76 {
77 (FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
78 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
79 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
80 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize)) /
81 FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
82 FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
83 }
84 } // BlockMap[1]
85 },
86 {
87 {
88 0,
89 0
90 }
91 } // End[1]
92 }
93 };
94
95 EFI_STATUS
96 GetFvbInfo (
97 IN UINT64 FvLength,
98 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
99 )
100 {
101 STATIC BOOLEAN Checksummed = FALSE;
102 UINTN Index;
103
104 if (!Checksummed) {
105 for (Index = 0;
106 Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO);
107 Index += 1) {
108 UINT16 Checksum;
109 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = 0;
110 Checksum = CalculateCheckSum16 (
111 (UINT16*) &mPlatformFvbMediaInfo[Index].FvbInfo,
112 mPlatformFvbMediaInfo[Index].FvbInfo.HeaderLength
113 );
114 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = Checksum;
115 }
116 Checksummed = TRUE;
117 }
118
119 for (Index = 0;
120 Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO);
121 Index += 1) {
122 if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {
123 *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;
124 return EFI_SUCCESS;
125 }
126 }
127
128 return EFI_NOT_FOUND;
129 }