]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbInfo.c
OvmfPkg: Add QemuFlashFvbServicesRuntimeDxe driver
[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 (FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
94 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
95 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
96 FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize)) / FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
97 FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
98 }
99 },
100 {
101 0,
102 0
103 }
104 }
105 };
106
107 EFI_STATUS
108 GetFvbInfo (
109 IN UINT64 FvLength,
110 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
111 )
112 {
113 STATIC BOOLEAN Checksummed = FALSE;
114 UINTN Index;
115
116 if (!Checksummed) {
117 for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {
118 UINT16 Checksum;
119 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = 0;
120 Checksum = CalculateCheckSum16 (
121 (UINT16*) &mPlatformFvbMediaInfo[Index].FvbInfo,
122 mPlatformFvbMediaInfo[Index].FvbInfo.HeaderLength
123 );
124 mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = Checksum;
125 }
126 Checksummed = TRUE;
127 }
128
129 for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {
130 if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {
131 *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;
132 return EFI_SUCCESS;
133 }
134 }
135
136 return EFI_NOT_FOUND;
137 }