]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/FvbRuntimeDxe/FvbInfo.c
d3b9145db01cddbe8be520c19ff8e8ed31536a4c
[mirror_edk2.git] / Vlv2TbltDevicePkg / FvbRuntimeDxe / FvbInfo.c
1 /**@file
2 Defines data structure that is the volume header found.
3 These data is intent to decouple FVB driver with FV header.
4
5 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9
10
11 **/
12
13 #include <PiDxe.h>
14 #include <Protocol/FirmwareVolumeBlock.h>
15 #include <Library/PcdLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/BaseLib.h>
18 #include <Guid/FirmwareFileSystem2.h>
19 #include <Guid/SystemNvDataGuid.h>
20
21 #define FIRMWARE_BLOCK_SIZE 0x8000
22 #define FVB_MEDIA_BLOCK_SIZE (FIRMWARE_BLOCK_SIZE * 2)
23
24 #define FV_RECOVERY_BASE_ADDRESS FixedPcdGet32(PcdFlashFvRecoveryBase)
25 #define RECOVERY_BIOS_BLOCK_NUM (FixedPcdGet32(PcdFlashFvRecoverySize) / FVB_MEDIA_BLOCK_SIZE)
26
27 #define FV_MAIN_BASE_ADDRESS FixedPcdGet32(PcdFlashFvMainBase)
28 #define MAIN_BIOS_BLOCK_NUM (FixedPcdGet32(PcdFlashFvMainSize) / FVB_MEDIA_BLOCK_SIZE)
29
30 #define NV_STORAGE_BASE_ADDRESS FixedPcdGet32(PcdFlashNvStorageVariableBase)
31 #define SYSTEM_NV_BLOCK_NUM ((FixedPcdGet32(PcdFlashNvStorageVariableSize)+ FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + FixedPcdGet32(PcdFlashNvStorageFtwSpareSize))/ FVB_MEDIA_BLOCK_SIZE)
32
33 typedef struct {
34 EFI_PHYSICAL_ADDRESS BaseAddress;
35 EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
36 EFI_FV_BLOCK_MAP_ENTRY End[1];
37 } EFI_FVB2_MEDIA_INFO;
38
39 //
40 // This data structure contains a template of all correct FV headers, which is used to restore
41 // Fv header if it's corrupted.
42 //
43 EFI_FVB2_MEDIA_INFO mPlatformFvbMediaInfo[] = {
44 //
45 // Main BIOS FVB
46 //
47 {
48 FV_MAIN_BASE_ADDRESS,
49 {
50 {0,}, //ZeroVector[16]
51 EFI_FIRMWARE_FILE_SYSTEM2_GUID,
52 FVB_MEDIA_BLOCK_SIZE * MAIN_BIOS_BLOCK_NUM,
53 EFI_FVH_SIGNATURE,
54 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
55 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
56 0, //CheckSum which will be calucated dynamically.
57 0, //ExtHeaderOffset
58 {0,}, //Reserved[1]
59 2, //Revision
60 {
61 {
62 MAIN_BIOS_BLOCK_NUM,
63 FVB_MEDIA_BLOCK_SIZE,
64 }
65 }
66 },
67 {
68 {
69 0,
70 0
71 }
72 }
73 },
74
75 //
76 // Systen NvStorage FVB
77 //
78 {
79 NV_STORAGE_BASE_ADDRESS,
80 {
81 {0,}, //ZeroVector[16]
82 EFI_SYSTEM_NV_DATA_FV_GUID,
83 FVB_MEDIA_BLOCK_SIZE * SYSTEM_NV_BLOCK_NUM,
84 EFI_FVH_SIGNATURE,
85 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
86 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
87 0, //CheckSum which will be calucated dynamically.
88 0, //ExtHeaderOffset
89 {0,}, //Reserved[1]
90 2, //Revision
91 {
92 {
93 SYSTEM_NV_BLOCK_NUM,
94 FVB_MEDIA_BLOCK_SIZE,
95 }
96 }
97 },
98 {
99 {
100 0,
101 0
102 }
103 }
104 },
105
106 //
107 // Recovery BIOS FVB
108 //
109 {
110 FV_RECOVERY_BASE_ADDRESS,
111 {
112 {0,}, //ZeroVector[16]
113 EFI_FIRMWARE_FILE_SYSTEM2_GUID,
114 FVB_MEDIA_BLOCK_SIZE * RECOVERY_BIOS_BLOCK_NUM,
115 EFI_FVH_SIGNATURE,
116 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
117 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
118 0, //CheckSum which will be calucated dynamically.
119 0, //ExtHeaderOffset
120 {0,}, //Reserved[1]
121 2, //Revision
122 {
123 {
124 RECOVERY_BIOS_BLOCK_NUM,
125 FVB_MEDIA_BLOCK_SIZE,
126 }
127 }
128 },
129 {
130 {
131 0,
132 0
133 }
134 }
135 }
136 };
137
138 EFI_STATUS
139 GetFvbInfo (
140 IN EFI_PHYSICAL_ADDRESS FvBaseAddress,
141 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
142 )
143 {
144 UINTN Index;
145 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
146
147 for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB2_MEDIA_INFO); Index += 1) {
148 if (mPlatformFvbMediaInfo[Index].BaseAddress == FvBaseAddress) {
149 FvHeader = &mPlatformFvbMediaInfo[Index].FvbInfo;
150
151 //
152 // Update the checksum value of FV header.
153 //
154 FvHeader->Checksum = CalculateCheckSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength);
155
156 *FvbInfo = FvHeader;
157
158 DEBUG ((EFI_D_INFO, "\nBaseAddr: 0x%lx \n", FvBaseAddress));
159 DEBUG ((EFI_D_INFO, "FvLength: 0x%lx \n", (*FvbInfo)->FvLength));
160 DEBUG ((EFI_D_INFO, "HeaderLength: 0x%x \n", (*FvbInfo)->HeaderLength));
161 DEBUG ((EFI_D_INFO, "FvBlockMap[0].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[0].NumBlocks));
162 DEBUG ((EFI_D_INFO, "FvBlockMap[0].BlockLength: 0x%x \n", (*FvbInfo)->BlockMap[0].Length));
163 DEBUG ((EFI_D_INFO, "FvBlockMap[1].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[1].NumBlocks));
164 DEBUG ((EFI_D_INFO, "FvBlockMap[1].BlockLength: 0x%x \n\n", (*FvbInfo)->BlockMap[1].Length));
165
166 return EFI_SUCCESS;
167 }
168 }
169 return EFI_NOT_FOUND;
170 }