]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/FvbRuntimeDxe/FvbInfo.c
BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[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 This program and the accompanying materials are licensed and made available under
8 the terms and conditions of the BSD License that accompanies this distribution.
9 The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15
16 **/
17
18 #include <PiDxe.h>
19 #include <Protocol/FirmwareVolumeBlock.h>
20 #include <Library/PcdLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseLib.h>
23 #include <Guid/FirmwareFileSystem2.h>
24 #include <Guid/SystemNvDataGuid.h>
25
26 #define FIRMWARE_BLOCK_SIZE 0x8000
27 #define FVB_MEDIA_BLOCK_SIZE (FIRMWARE_BLOCK_SIZE * 2)
28
29 #define FV_RECOVERY_BASE_ADDRESS FixedPcdGet32(PcdFlashFvRecoveryBase)
30 #define RECOVERY_BIOS_BLOCK_NUM (FixedPcdGet32(PcdFlashFvRecoverySize) / FVB_MEDIA_BLOCK_SIZE)
31
32 #define FV_MAIN_BASE_ADDRESS FixedPcdGet32(PcdFlashFvMainBase)
33 #define MAIN_BIOS_BLOCK_NUM (FixedPcdGet32(PcdFlashFvMainSize) / FVB_MEDIA_BLOCK_SIZE)
34
35 #define NV_STORAGE_BASE_ADDRESS FixedPcdGet32(PcdFlashNvStorageVariableBase)
36 #define SYSTEM_NV_BLOCK_NUM ((FixedPcdGet32(PcdFlashNvStorageVariableSize)+ FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + FixedPcdGet32(PcdFlashNvStorageFtwSpareSize))/ FVB_MEDIA_BLOCK_SIZE)
37
38 typedef struct {
39 EFI_PHYSICAL_ADDRESS BaseAddress;
40 EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
41 EFI_FV_BLOCK_MAP_ENTRY End[1];
42 } EFI_FVB2_MEDIA_INFO;
43
44 //
45 // This data structure contains a template of all correct FV headers, which is used to restore
46 // Fv header if it's corrupted.
47 //
48 EFI_FVB2_MEDIA_INFO mPlatformFvbMediaInfo[] = {
49 //
50 // Main BIOS FVB
51 //
52 {
53 FV_MAIN_BASE_ADDRESS,
54 {
55 {0,}, //ZeroVector[16]
56 EFI_FIRMWARE_FILE_SYSTEM2_GUID,
57 FVB_MEDIA_BLOCK_SIZE * MAIN_BIOS_BLOCK_NUM,
58 EFI_FVH_SIGNATURE,
59 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
60 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
61 0, //CheckSum which will be calucated dynamically.
62 0, //ExtHeaderOffset
63 {0,}, //Reserved[1]
64 2, //Revision
65 {
66 {
67 MAIN_BIOS_BLOCK_NUM,
68 FVB_MEDIA_BLOCK_SIZE,
69 }
70 }
71 },
72 {
73 {
74 0,
75 0
76 }
77 }
78 },
79
80 //
81 // Systen NvStorage FVB
82 //
83 {
84 NV_STORAGE_BASE_ADDRESS,
85 {
86 {0,}, //ZeroVector[16]
87 EFI_SYSTEM_NV_DATA_FV_GUID,
88 FVB_MEDIA_BLOCK_SIZE * SYSTEM_NV_BLOCK_NUM,
89 EFI_FVH_SIGNATURE,
90 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
91 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
92 0, //CheckSum which will be calucated dynamically.
93 0, //ExtHeaderOffset
94 {0,}, //Reserved[1]
95 2, //Revision
96 {
97 {
98 SYSTEM_NV_BLOCK_NUM,
99 FVB_MEDIA_BLOCK_SIZE,
100 }
101 }
102 },
103 {
104 {
105 0,
106 0
107 }
108 }
109 },
110
111 //
112 // Recovery BIOS FVB
113 //
114 {
115 FV_RECOVERY_BASE_ADDRESS,
116 {
117 {0,}, //ZeroVector[16]
118 EFI_FIRMWARE_FILE_SYSTEM2_GUID,
119 FVB_MEDIA_BLOCK_SIZE * RECOVERY_BIOS_BLOCK_NUM,
120 EFI_FVH_SIGNATURE,
121 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
122 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
123 0, //CheckSum which will be calucated dynamically.
124 0, //ExtHeaderOffset
125 {0,}, //Reserved[1]
126 2, //Revision
127 {
128 {
129 RECOVERY_BIOS_BLOCK_NUM,
130 FVB_MEDIA_BLOCK_SIZE,
131 }
132 }
133 },
134 {
135 {
136 0,
137 0
138 }
139 }
140 }
141 };
142
143 EFI_STATUS
144 GetFvbInfo (
145 IN EFI_PHYSICAL_ADDRESS FvBaseAddress,
146 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
147 )
148 {
149 UINTN Index;
150 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
151
152 for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB2_MEDIA_INFO); Index += 1) {
153 if (mPlatformFvbMediaInfo[Index].BaseAddress == FvBaseAddress) {
154 FvHeader = &mPlatformFvbMediaInfo[Index].FvbInfo;
155
156 //
157 // Update the checksum value of FV header.
158 //
159 FvHeader->Checksum = CalculateCheckSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength);
160
161 *FvbInfo = FvHeader;
162
163 DEBUG ((EFI_D_INFO, "\nBaseAddr: 0x%lx \n", FvBaseAddress));
164 DEBUG ((EFI_D_INFO, "FvLength: 0x%lx \n", (*FvbInfo)->FvLength));
165 DEBUG ((EFI_D_INFO, "HeaderLength: 0x%x \n", (*FvbInfo)->HeaderLength));
166 DEBUG ((EFI_D_INFO, "FvBlockMap[0].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[0].NumBlocks));
167 DEBUG ((EFI_D_INFO, "FvBlockMap[0].BlockLength: 0x%x \n", (*FvbInfo)->BlockMap[0].Length));
168 DEBUG ((EFI_D_INFO, "FvBlockMap[1].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[1].NumBlocks));
169 DEBUG ((EFI_D_INFO, "FvBlockMap[1].BlockLength: 0x%x \n\n", (*FvbInfo)->BlockMap[1].Length));
170
171 return EFI_SUCCESS;
172 }
173 }
174 return EFI_NOT_FOUND;
175 }