]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkPlatformPkg/Platform/SpiFvbServices/FvbInfo.c
QuarkPlatformPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / QuarkPlatformPkg / Platform / SpiFvbServices / FvbInfo.c
1 /** @file
2 Defines data structure that is the volume header found.These data is intent
3 to decouple FVB driver with FV header.
4
5 Copyright (c) 2013 Intel Corporation.
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9
10 **/
11
12 #include <PiDxe.h>
13 #include "FwBlockService.h"
14
15
16 //#define FVB_MEDIA_BLOCK_SIZE PcdGet32(PcdFlashMinEraseSize)
17 #define FVB_MEDIA_BLOCK_SIZE 0x1000
18
19 typedef struct {
20 EFI_PHYSICAL_ADDRESS BaseAddress;
21 EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
22 //
23 //EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
24 //
25 EFI_FV_BLOCK_MAP_ENTRY End[1];
26 } EFI_FVB2_MEDIA_INFO;
27
28 //
29 // This data structure contains a template of all correct FV headers, which is used to restore
30 // Fv header if it's corrupted.
31 //
32 EFI_FVB2_MEDIA_INFO mPlatformFvbMediaInfo[] = {
33 //
34 // Main BIOS FVB
35 //
36 {
37 0,
38 {
39 {0,}, //ZeroVector[16]
40 EFI_FIRMWARE_FILE_SYSTEM2_GUID,
41 0,
42 EFI_FVH_SIGNATURE,
43 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
44 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
45 0, //CheckSum, check the FD for the value.
46 0, //ExtHeaderOffset
47 {0,}, //Reserved[1]
48 2, //Revision
49 {
50 {
51 0,
52 0,
53 }
54 }
55 },
56 {
57 {
58 0,
59 0
60 }
61 }
62 },
63 //
64 // Systen NvStorage FVB
65 //
66 {
67 0,
68 {
69 {0,}, //ZeroVector[16]
70 EFI_SYSTEM_NV_DATA_FV_GUID,
71 0,
72 EFI_FVH_SIGNATURE,
73 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
74 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
75 0, //CheckSum which will be calucated dynamically.
76 0, //ExtHeaderOffset
77 {0,}, //Reserved[1]
78 2, //Revision
79 {
80 {
81 0,
82 0,
83 }
84 }
85 },
86 {
87 {
88 0,
89 0
90 }
91 }
92 },
93 //
94 // Recovery BIOS FVB
95 //
96 {
97 0,
98 {
99 {0,}, //ZeroVector[16]
100 EFI_FIRMWARE_FILE_SYSTEM2_GUID,
101 0,
102 EFI_FVH_SIGNATURE,
103 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
104 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
105 0, //CheckSum which will be calucated dynamically.
106 0, //ExtHeaderOffset
107 {0,}, //Reserved[1]
108 2, //Revision
109 {
110 {
111 0,
112 0,
113 }
114 }
115 },
116 {
117 {
118 0,
119 0
120 }
121 }
122 },
123 //
124 // Payload FVB
125 //
126 {
127 0,
128 {
129 {0,}, //ZeroVector[16]
130 EFI_FIRMWARE_FILE_SYSTEM2_GUID,
131 0,
132 EFI_FVH_SIGNATURE,
133 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
134 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
135 0, //CheckSum which will be calucated dynamically.
136 0x60, //ExtHeaderOffset
137 {0,}, //Reserved[1]
138 2, //Revision
139 {
140 {
141 0,
142 0,
143 }
144 }
145 },
146 {
147 {
148 0,
149 0
150 }
151 }
152 }
153 };
154
155
156 //
157 // FTW working space and FTW spare space don't have FV header.
158 // We need create one for them and use it for FVB protocol.
159 //
160 EFI_FVB2_MEDIA_INFO mPlatformFtwFvbInfo[] = {
161 //
162 // System variable FTW working FVB
163 //
164 {
165 0,
166 {
167 {0,}, //ZeroVector[16]
168 EFI_SYSTEM_NV_DATA_FV_GUID,
169 0,
170 EFI_FVH_SIGNATURE,
171 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
172 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
173 0, //CheckSum which will be calucated dynamically.
174 0, //ExtHeaderOffset
175 {0,}, //Reserved[1]
176 2, //Revision
177 {
178 {
179 0,
180 0,
181 }
182 }
183 },
184 {
185 {
186 0,
187 0
188 }
189 }
190 },
191 //
192 // Systen NV variable FTW spare FVB
193 //
194 {
195 0,
196 {
197 {0,}, //ZeroVector[16]
198 EFI_SYSTEM_NV_DATA_FV_GUID,
199 0,
200 EFI_FVH_SIGNATURE,
201 0x0004feff, // check MdePkg/Include/Pi/PiFirmwareVolume.h for details on EFI_FVB_ATTRIBUTES_2
202 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
203 0, //CheckSum which will be calucated dynamically.
204 0, //ExtHeaderOffset
205 {0,}, //Reserved[1]
206 2, //Revision
207 {
208 {
209 0,
210 0,
211 }
212 }
213 },
214 {
215 {
216 0,
217 0
218 }
219 }
220 }
221 };
222
223
224
225 EFI_STATUS
226 GetFtwFvbInfo (
227 IN EFI_PHYSICAL_ADDRESS FvBaseAddress,
228 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
229 )
230 {
231 UINTN Index;
232 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
233
234 //
235 // Init Fvb data
236 //
237 mPlatformFtwFvbInfo[0].BaseAddress = PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
238 mPlatformFtwFvbInfo[0].FvbInfo.FvLength = PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
239 mPlatformFtwFvbInfo[0].FvbInfo.BlockMap[0].NumBlocks = PcdGet32 (PcdFlashNvStorageFtwWorkingSize) / FVB_MEDIA_BLOCK_SIZE;
240 mPlatformFtwFvbInfo[0].FvbInfo.BlockMap[0].Length = FVB_MEDIA_BLOCK_SIZE;
241 ASSERT ((PcdGet32 (PcdFlashNvStorageFtwWorkingSize) % FVB_MEDIA_BLOCK_SIZE) == 0);
242
243 mPlatformFtwFvbInfo[1].BaseAddress = PcdGet32 (PcdFlashNvStorageFtwSpareBase);
244 mPlatformFtwFvbInfo[1].FvbInfo.FvLength = PcdGet32 (PcdFlashNvStorageFtwSpareSize);
245 mPlatformFtwFvbInfo[1].FvbInfo.BlockMap[0].NumBlocks = PcdGet32 (PcdFlashNvStorageFtwSpareSize) / FVB_MEDIA_BLOCK_SIZE;
246 mPlatformFtwFvbInfo[1].FvbInfo.BlockMap[0].Length = FVB_MEDIA_BLOCK_SIZE;
247 ASSERT ((PcdGet32 (PcdFlashNvStorageFtwSpareSize) % FVB_MEDIA_BLOCK_SIZE) == 0);
248
249 for (Index=0; Index < sizeof (mPlatformFtwFvbInfo)/sizeof (mPlatformFtwFvbInfo[0]); Index += 1) {
250 if (mPlatformFtwFvbInfo[Index].BaseAddress == FvBaseAddress) {
251 FvHeader = &mPlatformFtwFvbInfo[Index].FvbInfo;
252 //
253 // Update the checksum value of FV header.
254 //
255 FvHeader->Checksum = CalculateCheckSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));
256
257 *FvbInfo = FvHeader;
258
259 DEBUG ((EFI_D_INFO, "\nFTW BaseAddr: 0x%lx \n", FvBaseAddress));
260 DEBUG ((EFI_D_INFO, "FvLength: 0x%lx \n", (*FvbInfo)->FvLength));
261 DEBUG ((EFI_D_INFO, "HeaderLength: 0x%x \n", (*FvbInfo)->HeaderLength));
262 DEBUG ((EFI_D_INFO, "FvBlockMap[0].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[0].NumBlocks));
263 DEBUG ((EFI_D_INFO, "FvBlockMap[0].BlockLength: 0x%x \n", (*FvbInfo)->BlockMap[0].Length));
264 DEBUG ((EFI_D_INFO, "FvBlockMap[1].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[1].NumBlocks));
265 DEBUG ((EFI_D_INFO, "FvBlockMap[1].BlockLength: 0x%x \n\n", (*FvbInfo)->BlockMap[1].Length));
266
267 return EFI_SUCCESS;
268 }
269 }
270 return EFI_NOT_FOUND;
271 }
272
273
274 EFI_STATUS
275 GetFvbInfo (
276 IN EFI_PHYSICAL_ADDRESS FvBaseAddress,
277 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
278 )
279 {
280 UINTN Index;
281 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
282
283 //
284 // Init Fvb data
285 //
286 mPlatformFvbMediaInfo[0].BaseAddress = PcdGet32 (PcdFlashFvMainBase);
287 mPlatformFvbMediaInfo[0].FvbInfo.FvLength = PcdGet32 (PcdFlashFvMainSize);
288 mPlatformFvbMediaInfo[0].FvbInfo.BlockMap[0].NumBlocks = PcdGet32 (PcdFlashFvMainSize) / FVB_MEDIA_BLOCK_SIZE;
289 mPlatformFvbMediaInfo[0].FvbInfo.BlockMap[0].Length = FVB_MEDIA_BLOCK_SIZE;
290 ASSERT ((PcdGet32 (PcdFlashFvMainSize) % FVB_MEDIA_BLOCK_SIZE) == 0);
291
292 mPlatformFvbMediaInfo[1].BaseAddress = PcdGet32 (PcdFlashNvStorageVariableBase);
293 mPlatformFvbMediaInfo[1].FvbInfo.FvLength = PcdGet32 (PcdFlashNvStorageVariableSize);
294 mPlatformFvbMediaInfo[1].FvbInfo.BlockMap[0].NumBlocks = PcdGet32 (PcdFlashNvStorageVariableSize) / FVB_MEDIA_BLOCK_SIZE;
295 mPlatformFvbMediaInfo[1].FvbInfo.BlockMap[0].Length = FVB_MEDIA_BLOCK_SIZE;
296 ASSERT ((PcdGet32 (PcdFlashNvStorageVariableSize) % FVB_MEDIA_BLOCK_SIZE) == 0);
297
298 mPlatformFvbMediaInfo[2].BaseAddress = PcdGet32 (PcdFlashFvRecoveryBase);
299 mPlatformFvbMediaInfo[2].FvbInfo.FvLength = PcdGet32 (PcdFlashFvRecoverySize);
300 mPlatformFvbMediaInfo[2].FvbInfo.BlockMap[0].NumBlocks = PcdGet32 (PcdFlashFvRecoverySize) / FVB_MEDIA_BLOCK_SIZE;
301 mPlatformFvbMediaInfo[2].FvbInfo.BlockMap[0].Length = FVB_MEDIA_BLOCK_SIZE;
302 ASSERT ((PcdGet32 (PcdFlashFvRecoverySize) % FVB_MEDIA_BLOCK_SIZE) == 0);
303
304 mPlatformFvbMediaInfo[3].BaseAddress = PcdGet32 (PcdFlashFvPayloadBase);
305 mPlatformFvbMediaInfo[3].FvbInfo.FvLength = PcdGet32 (PcdFlashFvPayloadSize);
306 mPlatformFvbMediaInfo[3].FvbInfo.BlockMap[0].NumBlocks = PcdGet32 (PcdFlashFvPayloadSize) / FVB_MEDIA_BLOCK_SIZE;
307 mPlatformFvbMediaInfo[3].FvbInfo.BlockMap[0].Length = FVB_MEDIA_BLOCK_SIZE;
308 ASSERT ((PcdGet32 (PcdFlashFvPayloadSize) % FVB_MEDIA_BLOCK_SIZE) == 0);
309
310 for (Index=0; Index < sizeof (mPlatformFvbMediaInfo)/sizeof (mPlatformFvbMediaInfo[0]); Index += 1) {
311 if (mPlatformFvbMediaInfo[Index].BaseAddress == FvBaseAddress) {
312 FvHeader = &mPlatformFvbMediaInfo[Index].FvbInfo;
313 //
314 // Update the checksum value of FV header.
315 //
316 FvHeader->Checksum = CalculateCheckSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));
317
318 *FvbInfo = FvHeader;
319
320 DEBUG ((EFI_D_INFO, "\nBaseAddr: 0x%lx \n", FvBaseAddress));
321 DEBUG ((EFI_D_INFO, "FvLength: 0x%lx \n", (*FvbInfo)->FvLength));
322 DEBUG ((EFI_D_INFO, "HeaderLength: 0x%x \n", (*FvbInfo)->HeaderLength));
323 DEBUG ((EFI_D_INFO, "FvBlockMap[0].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[0].NumBlocks));
324 DEBUG ((EFI_D_INFO, "FvBlockMap[0].BlockLength: 0x%x \n", (*FvbInfo)->BlockMap[0].Length));
325 DEBUG ((EFI_D_INFO, "FvBlockMap[1].NumBlocks: 0x%x \n", (*FvbInfo)->BlockMap[1].NumBlocks));
326 DEBUG ((EFI_D_INFO, "FvBlockMap[1].BlockLength: 0x%x \n\n", (*FvbInfo)->BlockMap[1].Length));
327
328 return EFI_SUCCESS;
329 }
330 }
331 return EFI_NOT_FOUND;
332 }