blob: 5668b5472cc344117c568acadc402bd1cc7a331d [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/*++ @file
2 Defines data structure that is the volume header found.These data is intent
3 to decouple FVB driver with FV header.
4
5Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
6Portions copyright (c) 2011, Apple Inc. All rights reserved.
7This program and the accompanying materials
8are licensed and made available under the terms and conditions of the BSD License
9which accompanies this distribution. The full text of the license may be found at
10http://opensource.org/licenses/bsd-license.php
11
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15
16**/
17
18#include <PiDxe.h>
19
20#include <Guid/EventGroup.h>
21#include <Guid/FirmwareFileSystem2.h>
22#include <Guid/SystemNvDataGuid.h>
23
24#include <Protocol/FirmwareVolumeBlock.h>
25#include <Protocol/DevicePath.h>
26
27#include <Library/UefiLib.h>
28#include <Library/UefiDriverEntryPoint.h>
29#include <Library/BaseLib.h>
30#include <Library/DxeServicesTableLib.h>
31#include <Library/UefiRuntimeLib.h>
32#include <Library/DebugLib.h>
33#include <Library/HobLib.h>
34#include <Library/BaseMemoryLib.h>
35#include <Library/MemoryAllocationLib.h>
36#include <Library/UefiBootServicesTableLib.h>
37#include <Library/PcdLib.h>
38#include <Library/DevicePathLib.h>
39
40
41typedef struct {
42 UINT64 FvLength;
43 EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
44 //
45 // EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
46 //
47 EFI_FV_BLOCK_MAP_ENTRY End[1];
48} EFI_FVB_MEDIA_INFO;
49
50EFI_FVB_MEDIA_INFO mPlatformFvbMediaInfo[] = {
51 //
52 // Recovery BOIS FVB
53 //
54 {
55 FixedPcdGet32 (PcdEmuFlashFvRecoverySize),
56 {
57 {
58 0,
59 }, // ZeroVector[16]
60 EFI_FIRMWARE_FILE_SYSTEM2_GUID,
61 FixedPcdGet32 (PcdEmuFlashFvRecoverySize),
62 EFI_FVH_SIGNATURE,
63 EFI_FVB2_READ_ENABLED_CAP |
64 EFI_FVB2_READ_STATUS |
65 EFI_FVB2_WRITE_ENABLED_CAP |
66 EFI_FVB2_WRITE_STATUS |
67 EFI_FVB2_ERASE_POLARITY,
68 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
69 0, // CheckSum
70 0, // ExtHeaderOffset
71 {
72 0,
73 }, // Reserved[1]
74 2, // Revision
75 {
76 {
77 FixedPcdGet32 (PcdEmuFlashFvRecoverySize)/FixedPcdGet32 (PcdEmuFirmwareBlockSize),
78 FixedPcdGet32 (PcdEmuFirmwareBlockSize),
79 }
80 }
81 },
82 {
83 {
84 0,
85 0
86 }
87 }
88 },
89 //
90 // Systen NvStorage FVB
91 //
92 {
93 FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
94 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
95 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
96 FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize),
97 {
98 {
99 0,
100 }, // ZeroVector[16]
101 EFI_SYSTEM_NV_DATA_FV_GUID,
102 FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
103 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
104 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
105 FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize),
106 EFI_FVH_SIGNATURE,
107 EFI_FVB2_READ_ENABLED_CAP |
108 EFI_FVB2_READ_STATUS |
109 EFI_FVB2_WRITE_ENABLED_CAP |
110 EFI_FVB2_WRITE_STATUS |
111 EFI_FVB2_ERASE_POLARITY,
112 sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
113 0, // CheckSum
114 0, // ExtHeaderOffset
115 {
116 0,
117 }, // Reserved[1]
118 2, // Revision
119 {
120 {
121 (FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
122 FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
123 FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
124 FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize)) / FixedPcdGet32 (PcdEmuFirmwareBlockSize),
125 FixedPcdGet32 (PcdEmuFirmwareBlockSize),
126 }
127 }
128 },
129 {
130 {
131 0,
132 0
133 }
134 }
135 }
136};
137
138EFI_STATUS
139GetFvbInfo (
140 IN UINT64 FvLength,
141 OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
142 )
143{
144 UINTN Index;
145
146 for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {
147 if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {
148 *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;
149 return EFI_SUCCESS;
150 }
151 }
152
153 return EFI_NOT_FOUND;
154}