2 Defines data structure that is the volume header found.
3 These data is intent to decouple FVB driver with FV header.
5 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
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.
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.
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>
26 #define FIRMWARE_BLOCK_SIZE 0x8000
27 #define FVB_MEDIA_BLOCK_SIZE (FIRMWARE_BLOCK_SIZE * 2)
29 #define FV_RECOVERY_BASE_ADDRESS FixedPcdGet32(PcdFlashFvRecoveryBase)
30 #define RECOVERY_BIOS_BLOCK_NUM (FixedPcdGet32(PcdFlashFvRecoverySize) / FVB_MEDIA_BLOCK_SIZE)
32 #define FV_MAIN_BASE_ADDRESS FixedPcdGet32(PcdFlashFvMainBase)
33 #define MAIN_BIOS_BLOCK_NUM (FixedPcdGet32(PcdFlashFvMainSize) / FVB_MEDIA_BLOCK_SIZE)
35 #define NV_STORAGE_BASE_ADDRESS FixedPcdGet32(PcdFlashNvStorageVariableBase)
36 #define SYSTEM_NV_BLOCK_NUM ((FixedPcdGet32(PcdFlashNvStorageVariableSize)+ FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + FixedPcdGet32(PcdFlashNvStorageFtwSpareSize))/ FVB_MEDIA_BLOCK_SIZE)
39 EFI_PHYSICAL_ADDRESS BaseAddress
;
40 EFI_FIRMWARE_VOLUME_HEADER FvbInfo
;
41 EFI_FV_BLOCK_MAP_ENTRY End
[1];
42 } EFI_FVB2_MEDIA_INFO
;
45 // This data structure contains a template of all correct FV headers, which is used to restore
46 // Fv header if it's corrupted.
48 EFI_FVB2_MEDIA_INFO mPlatformFvbMediaInfo
[] = {
55 {0,}, //ZeroVector[16]
56 EFI_FIRMWARE_FILE_SYSTEM2_GUID
,
57 FVB_MEDIA_BLOCK_SIZE
* MAIN_BIOS_BLOCK_NUM
,
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.
81 // Systen NvStorage FVB
84 NV_STORAGE_BASE_ADDRESS
,
86 {0,}, //ZeroVector[16]
87 EFI_SYSTEM_NV_DATA_FV_GUID
,
88 FVB_MEDIA_BLOCK_SIZE
* SYSTEM_NV_BLOCK_NUM
,
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.
115 FV_RECOVERY_BASE_ADDRESS
,
117 {0,}, //ZeroVector[16]
118 EFI_FIRMWARE_FILE_SYSTEM2_GUID
,
119 FVB_MEDIA_BLOCK_SIZE
* RECOVERY_BIOS_BLOCK_NUM
,
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.
129 RECOVERY_BIOS_BLOCK_NUM
,
130 FVB_MEDIA_BLOCK_SIZE
,
145 IN EFI_PHYSICAL_ADDRESS FvBaseAddress
,
146 OUT EFI_FIRMWARE_VOLUME_HEADER
**FvbInfo
150 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
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
;
157 // Update the checksum value of FV header.
159 FvHeader
->Checksum
= CalculateCheckSum16 ((UINT16
*) FvHeader
, FvHeader
->HeaderLength
);
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
));
174 return EFI_NOT_FOUND
;