2 Defines data structure that is the volume header found.These data is intent
3 to decouple FVB driver with FV header.
5 Copyright (c) 2013 Intel Corporation.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "FwBlockService.h"
16 //#define FVB_MEDIA_BLOCK_SIZE PcdGet32(PcdFlashMinEraseSize)
17 #define FVB_MEDIA_BLOCK_SIZE 0x1000
20 EFI_PHYSICAL_ADDRESS BaseAddress
;
21 EFI_FIRMWARE_VOLUME_HEADER FvbInfo
;
23 //EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
25 EFI_FV_BLOCK_MAP_ENTRY End
[1];
26 } EFI_FVB2_MEDIA_INFO
;
29 // This data structure contains a template of all correct FV headers, which is used to restore
30 // Fv header if it's corrupted.
32 EFI_FVB2_MEDIA_INFO mPlatformFvbMediaInfo
[] = {
39 {0,}, //ZeroVector[16]
40 EFI_FIRMWARE_FILE_SYSTEM2_GUID
,
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.
64 // Systen NvStorage FVB
69 {0,}, //ZeroVector[16]
70 EFI_SYSTEM_NV_DATA_FV_GUID
,
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.
99 {0,}, //ZeroVector[16]
100 EFI_FIRMWARE_FILE_SYSTEM2_GUID
,
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.
129 {0,}, //ZeroVector[16]
130 EFI_FIRMWARE_FILE_SYSTEM2_GUID
,
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
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.
160 EFI_FVB2_MEDIA_INFO mPlatformFtwFvbInfo
[] = {
162 // System variable FTW working FVB
167 {0,}, //ZeroVector[16]
168 EFI_SYSTEM_NV_DATA_FV_GUID
,
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.
192 // Systen NV variable FTW spare FVB
197 {0,}, //ZeroVector[16]
198 EFI_SYSTEM_NV_DATA_FV_GUID
,
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.
227 IN EFI_PHYSICAL_ADDRESS FvBaseAddress
,
228 OUT EFI_FIRMWARE_VOLUME_HEADER
**FvbInfo
232 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
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);
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);
249 for (Index
=0; Index
< sizeof (mPlatformFtwFvbInfo
)/sizeof (mPlatformFtwFvbInfo
[0]); Index
+= 1) {
250 if (mPlatformFtwFvbInfo
[Index
].BaseAddress
== FvBaseAddress
) {
251 FvHeader
= &mPlatformFtwFvbInfo
[Index
].FvbInfo
;
253 // Update the checksum value of FV header.
255 FvHeader
->Checksum
= CalculateCheckSum16 ((UINT16
*) FvHeader
, FvHeader
->HeaderLength
/ sizeof (UINT16
));
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
));
270 return EFI_NOT_FOUND
;
276 IN EFI_PHYSICAL_ADDRESS FvBaseAddress
,
277 OUT EFI_FIRMWARE_VOLUME_HEADER
**FvbInfo
281 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
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);
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);
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);
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);
310 for (Index
=0; Index
< sizeof (mPlatformFvbMediaInfo
)/sizeof (mPlatformFvbMediaInfo
[0]); Index
+= 1) {
311 if (mPlatformFvbMediaInfo
[Index
].BaseAddress
== FvBaseAddress
) {
312 FvHeader
= &mPlatformFvbMediaInfo
[Index
].FvbInfo
;
314 // Update the checksum value of FV header.
316 FvHeader
->Checksum
= CalculateCheckSum16 ((UINT16
*) FvHeader
, FvHeader
->HeaderLength
/ sizeof (UINT16
));
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
));
331 return EFI_NOT_FOUND
;