]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/PlatformBds/Generic/Capsules.c
Add PcdComponentName2Disable and PcdDriverDiagnostics2Disable.
[mirror_edk2.git] / EdkNt32Pkg / Dxe / PlatformBds / Generic / Capsules.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 Capsules.c
15
16 Abstract:
17
18 BDS routines to handle capsules.
19
20 --*/
21
22
23 #include <Common/FlashMap.H>
24
25 VOID
26 BdsLockFv (
27 IN EFI_CPU_IO_PROTOCOL *CpuIo,
28 IN EFI_FLASH_SUBAREA_ENTRY *FlashEntry
29 );
30
31 VOID
32 BdsLockFv (
33 IN EFI_CPU_IO_PROTOCOL *CpuIo,
34 IN EFI_FLASH_SUBAREA_ENTRY *FlashEntry
35 )
36 {
37 EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
38 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
39 UINT64 BaseAddress;
40 UINT8 Data;
41 UINT32 BlockLength;
42 UINTN Index;
43
44 BaseAddress = FlashEntry->Base - 0x400000 + 2;
45 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (FlashEntry->Base));
46 BlockMap = &(FvHeader->FvBlockMap[0]);
47
48 while ((BlockMap->NumBlocks != 0) && (BlockMap->BlockLength != 0)) {
49 BlockLength = BlockMap->BlockLength;
50 for (Index = 0; Index < BlockMap->NumBlocks; Index++) {
51 CpuIo->Mem.Read (
52 CpuIo,
53 EfiCpuIoWidthUint8,
54 BaseAddress,
55 1,
56 &Data
57 );
58 Data = (UINT8) (Data | 0x3);
59 CpuIo->Mem.Write (
60 CpuIo,
61 EfiCpuIoWidthUint8,
62 BaseAddress,
63 1,
64 &Data
65 );
66 BaseAddress += BlockLength;
67 }
68
69 BlockMap++;
70 }
71 }
72
73 VOID
74 BdsLockNonUpdatableFlash (
75 VOID
76 )
77 {
78 EFI_FLASH_MAP_ENTRY_DATA *FlashMapEntryData;
79 EFI_PEI_HOB_POINTERS GuidHob;
80 EFI_STATUS Status;
81 EFI_CPU_IO_PROTOCOL *CpuIo;
82
83 Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &CpuIo);
84 ASSERT_EFI_ERROR (Status);
85
86 GuidHob.Raw = GetHobList ();
87 while ((GuidHob.Raw = GetNextGuidHob (&gEfiFlashMapHobGuid, GuidHob.Raw)) != NULL) {
88 FlashMapEntryData = (EFI_FLASH_MAP_ENTRY_DATA *) GET_GUID_HOB_DATA (GuidHob.Guid);
89
90 //
91 // Get the variable store area
92 //
93 if ((FlashMapEntryData->AreaType == EFI_FLASH_AREA_RECOVERY_BIOS) ||
94 (FlashMapEntryData->AreaType == EFI_FLASH_AREA_MAIN_BIOS)
95 ) {
96 BdsLockFv (CpuIo, &(FlashMapEntryData->Entries[0]));
97 }
98 GuidHob.Raw = GET_NEXT_HOB (GuidHob);
99 }
100
101 return ;
102 }
103
104 EFI_STATUS
105 ProcessCapsules (
106 EFI_BOOT_MODE BootMode
107 )
108 /*++
109
110 Routine Description:
111
112 This routine is called to see if there are any capsules we need to process.
113 If the boot mode is not UPDATE, then we do nothing. Otherwise find the
114 capsule HOBS and produce firmware volumes for them via the DXE service.
115 Then call the dispatcher to dispatch drivers from them. Finally, check
116 the status of the updates.
117
118 Arguments:
119
120 BootMode - the current boot mode
121
122 Returns:
123
124 EFI_INVALID_PARAMETER - boot mode is not correct for an update
125
126 Note:
127
128 This function should be called by BDS in case we need to do some
129 sort of processing even if there is no capsule to process. We
130 need to do this if an earlier update went awry and we need to
131 clear the capsule variable so on the next reset PEI does not see it and
132 think there is a capsule available.
133
134 --*/
135 {
136 EFI_STATUS Status;
137 EFI_HOB_CAPSULE_VOLUME *CvHob;
138 EFI_PHYSICAL_ADDRESS BaseAddress;
139 UINT64 Length;
140 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
141 EFI_HANDLE FvProtocolHandle;
142
143 //
144 // We don't do anything else if the boot mode is not flash-update
145 //
146 if (BootMode != BOOT_ON_FLASH_UPDATE) {
147 return EFI_INVALID_PARAMETER;
148 }
149 //
150 // Only one capsule HOB allowed.
151 //
152 CvHob = GetFirstHob (EFI_HOB_TYPE_CV);
153 if (CvHob == NULL) {
154 //
155 // We didn't find a hob, so had no errors.
156 //
157 BdsLockNonUpdatableFlash ();
158 return EFI_SUCCESS;
159 }
160
161 BaseAddress = CvHob->BaseAddress;
162 Length = CvHob->Length;
163
164 Status = EFI_SUCCESS;
165 //
166 // Now walk the capsule and call the core to process each
167 // firmware volume in it.
168 //
169 while (Length != 0) {
170 //
171 // Point to the next firmware volume header, and then
172 // call the DXE service to process it.
173 //
174 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;
175 if (FwVolHeader->FvLength > Length) {
176 //
177 // Notes: need to stuff this status somewhere so that the
178 // error can be detected at OS runtime
179 //
180 Status = EFI_VOLUME_CORRUPTED;
181 break;
182 }
183
184 Status = gDS->ProcessFirmwareVolume (
185 (VOID *) (UINTN) BaseAddress,
186 (UINTN) FwVolHeader->FvLength,
187 &FvProtocolHandle
188 );
189 if (EFI_ERROR (Status)) {
190 break;
191 }
192 //
193 // Call the dispatcher to dispatch any drivers from the produced firmware volume
194 //
195 gDS->Dispatch ();
196 //
197 // On to the next FV in the capsule
198 //
199 Length -= FwVolHeader->FvLength;
200 BaseAddress = (EFI_PHYSICAL_ADDRESS) ((UINTN) BaseAddress + FwVolHeader->FvLength);
201 //
202 // Notes: when capsule spec is finalized, if the requirement is made to
203 // have each FV in a capsule aligned, then we will need to align the
204 // BaseAddress and Length here.
205 //
206 }
207
208
209 BdsLockNonUpdatableFlash ();
210
211 return Status;
212 }
213