]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/BdsDxe/Capsules.c
Remove extra #Include
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / Capsules.c
1 /** @file
2 BDS routines to handle capsules.
3
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 #include "Bds.h"
15
16 /**
17
18 This routine is called to see if there are any capsules we need to process.
19 If the boot mode is not UPDATE, then we do nothing. Otherwise find the
20 capsule HOBS and produce firmware volumes for them via the DXE service.
21 Then call the dispatcher to dispatch drivers from them. Finally, check
22 the status of the updates.
23
24 This function should be called by BDS in case we need to do some
25 sort of processing even if there is no capsule to process. We
26 need to do this if an earlier update went away and we need to
27 clear the capsule variable so on the next reset PEI does not see it and
28 think there is a capsule available.
29
30 @param BootMode the current boot mode
31
32 @retval EFI_INVALID_PARAMETER boot mode is not correct for an update
33 @retval EFI_SUCCESS There is no error when processing capsule
34
35 **/
36 EFI_STATUS
37 ProcessCapsules (
38 EFI_BOOT_MODE BootMode
39 )
40 {
41 EFI_STATUS Status;
42 EFI_PEI_HOB_POINTERS HobPointer;
43 EFI_CAPSULE_HEADER *CapsuleHeader;
44 UINT32 Size;
45 UINT32 CapsuleNumber;
46 UINT32 CapsuleTotalNumber;
47 EFI_CAPSULE_TABLE *CapsuleTable;
48 UINT32 Index;
49 UINT32 CacheIndex;
50 UINT32 CacheNumber;
51 VOID **CapsulePtr;
52 VOID **CapsulePtrCache;
53 EFI_GUID *CapsuleGuidCache;
54 CAPSULE_HOB_INFO *CapsuleHobInfo;
55
56 CapsuleNumber = 0;
57 CapsuleTotalNumber = 0;
58 CacheIndex = 0;
59 CacheNumber = 0;
60 CapsulePtr = NULL;
61 CapsulePtrCache = NULL;
62 CapsuleGuidCache = NULL;
63
64 //
65 // We don't do anything else if the boot mode is not flash-update
66 //
67 if (BootMode != BOOT_ON_FLASH_UPDATE) {
68 return EFI_INVALID_PARAMETER;
69 }
70
71 Status = EFI_SUCCESS;
72 //
73 // Find all capsule images from hob
74 //
75 HobPointer.Raw = GetHobList ();
76 while ((HobPointer.Raw = GetNextGuidHob (&gEfiCapsuleVendorGuid, HobPointer.Raw)) != NULL) {
77 CapsuleTotalNumber ++;
78
79 HobPointer.Raw = GET_NEXT_HOB (HobPointer);
80 }
81
82 if (CapsuleTotalNumber == 0) {
83 //
84 // We didn't find a hob, so had no errors.
85 //
86 PlatformBdsLockNonUpdatableFlash ();
87 return EFI_SUCCESS;
88 }
89
90 //
91 // Init temp Capsule Data table.
92 //
93 CapsulePtr = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);
94 ASSERT (CapsulePtr != NULL);
95 CapsulePtrCache = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);
96 ASSERT (CapsulePtrCache != NULL);
97 CapsuleGuidCache = (EFI_GUID *) AllocateZeroPool (sizeof (EFI_GUID) * CapsuleTotalNumber);
98 ASSERT (CapsuleGuidCache != NULL);
99
100 //
101 // Find all capsule images from hob
102 //
103 HobPointer.Raw = GetHobList ();
104 while ((HobPointer.Raw = GetNextGuidHob (&gEfiCapsuleVendorGuid, HobPointer.Raw)) != NULL) {
105 CapsuleHobInfo = GET_GUID_HOB_DATA (HobPointer.Guid);
106 CapsulePtr [CapsuleNumber++] = (VOID *)(UINTN)(CapsuleHobInfo->BaseAddress);
107
108 HobPointer.Raw = GET_NEXT_HOB (HobPointer);
109 }
110
111 //
112 //Check the capsule flags,if contains CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE, install
113 //capsuleTable to configure table with EFI_CAPSULE_GUID
114 //
115
116 //
117 // Capsules who have CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE always are used for operating
118 // System to have information persist across a system reset. EFI System Table must
119 // point to an array of capsules that contains the same CapsuleGuid value. And agents
120 // searching for this type capsule will look in EFI System Table and search for the
121 // capsule's Guid and associated pointer to retrieve the data. Two steps below describes
122 // how to sorting the capsules by the unique guid and install the array to EFI System Table.
123 // Firstly, Loop for all coalesced capsules, record unique CapsuleGuids and cache them in an
124 // array for later sorting capsules by CapsuleGuid.
125 //
126 for (Index = 0; Index < CapsuleTotalNumber; Index++) {
127 CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];
128 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {
129 //
130 // For each capsule, we compare it with known CapsuleGuid in the CacheArray.
131 // If already has the Guid, skip it. Whereas, record it in the CacheArray as
132 // an additional one.
133 //
134 CacheIndex = 0;
135 while (CacheIndex < CacheNumber) {
136 if (CompareGuid(&CapsuleGuidCache[CacheIndex],&CapsuleHeader->CapsuleGuid)) {
137 break;
138 }
139 CacheIndex++;
140 }
141 if (CacheIndex == CacheNumber) {
142 CopyMem(&CapsuleGuidCache[CacheNumber++],&CapsuleHeader->CapsuleGuid,sizeof(EFI_GUID));
143 }
144 }
145 }
146
147 //
148 // Secondly, for each unique CapsuleGuid in CacheArray, gather all coalesced capsules
149 // whose guid is the same as it, and malloc memory for an array which preceding
150 // with UINT32. The array fills with entry point of capsules that have the same
151 // CapsuleGuid, and UINT32 represents the size of the array of capsules. Then install
152 // this array into EFI System Table, so that agents searching for this type capsule
153 // will look in EFI System Table and search for the capsule's Guid and associated
154 // pointer to retrieve the data.
155 //
156 CacheIndex = 0;
157 while (CacheIndex < CacheNumber) {
158 CapsuleNumber = 0;
159 for (Index = 0; Index < CapsuleTotalNumber; Index++) {
160 CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];
161 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {
162 if (CompareGuid (&CapsuleGuidCache[CacheIndex], &CapsuleHeader->CapsuleGuid)) {
163 //
164 // Cache Caspuleheader to the array, this array is uniqued with certain CapsuleGuid.
165 //
166 CapsulePtrCache[CapsuleNumber++] = (VOID*)CapsuleHeader;
167 }
168 }
169 }
170 if (CapsuleNumber != 0) {
171 Size = sizeof(EFI_CAPSULE_TABLE) + (CapsuleNumber - 1) * sizeof(VOID*);
172 CapsuleTable = AllocateRuntimePool (Size);
173 ASSERT (CapsuleTable != NULL);
174 CapsuleTable->CapsuleArrayNumber = CapsuleNumber;
175 CopyMem(&CapsuleTable->CapsulePtr[0], CapsulePtrCache, CapsuleNumber * sizeof(VOID*));
176 Status = gBS->InstallConfigurationTable (&CapsuleGuidCache[CacheIndex], (VOID*)CapsuleTable);
177 ASSERT_EFI_ERROR (Status);
178 }
179 CacheIndex++;
180 }
181
182 //
183 // Besides ones with CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag, all capsules left are
184 // recognized by platform with CapsuleGuid. For general platform driver, UpdateFlash
185 // type is commonly supported, so here only deal with encapsuled FVs capsule. Additional
186 // type capsule transaction could be extended. It depends on platform policy.
187 //
188 for (Index = 0; Index < CapsuleTotalNumber; Index++) {
189 CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];
190 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {
191 //
192 // Call capsule library to process capsule image.
193 //
194 ProcessCapsuleImage (CapsuleHeader);
195 }
196 }
197
198 PlatformBdsLockNonUpdatableFlash ();
199
200 //
201 // Free the allocated temp memory space.
202 //
203 FreePool (CapsuleGuidCache);
204 FreePool (CapsulePtrCache);
205 FreePool (CapsulePtr);
206
207 return Status;
208 }