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