]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/BdsDxe/Capsules.c
1. PI SMBIOS Checkin. Major change include:
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / Capsules.c
1 /** @file
2 BDS routines to handle capsules.
3
4 Copyright (c) 2004 - 2009, 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 BdsProcessCapsules (
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
55 CapsuleNumber = 0;
56 CapsuleTotalNumber = 0;
57 CacheIndex = 0;
58 CacheNumber = 0;
59 CapsulePtr = NULL;
60 CapsulePtrCache = NULL;
61 CapsuleGuidCache = NULL;
62
63 //
64 // We don't do anything else if the boot mode is not flash-update
65 //
66 if (BootMode != BOOT_ON_FLASH_UPDATE) {
67 return EFI_INVALID_PARAMETER;
68 }
69
70 Status = EFI_SUCCESS;
71 //
72 // Find all capsule images from hob
73 //
74 HobPointer.Raw = GetHobList ();
75 while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) {
76 CapsuleTotalNumber ++;
77 HobPointer.Raw = GET_NEXT_HOB (HobPointer);
78 }
79
80 if (CapsuleTotalNumber == 0) {
81 //
82 // We didn't find a hob, so had no errors.
83 //
84 PlatformBdsLockNonUpdatableFlash ();
85 return EFI_SUCCESS;
86 }
87
88 //
89 // Init temp Capsule Data table.
90 //
91 CapsulePtr = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);
92 ASSERT (CapsulePtr != NULL);
93 CapsulePtrCache = (VOID **) AllocateZeroPool (sizeof (VOID *) * CapsuleTotalNumber);
94 ASSERT (CapsulePtrCache != NULL);
95 CapsuleGuidCache = (EFI_GUID *) AllocateZeroPool (sizeof (EFI_GUID) * CapsuleTotalNumber);
96 ASSERT (CapsuleGuidCache != NULL);
97
98 //
99 // Find all capsule images from hob
100 //
101 HobPointer.Raw = GetHobList ();
102 while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE, HobPointer.Raw)) != NULL) {
103 CapsulePtr [CapsuleNumber++] = (VOID *) (UINTN) HobPointer.Capsule->BaseAddress;
104 HobPointer.Raw = GET_NEXT_HOB (HobPointer);
105 }
106
107 //
108 //Check the capsule flags,if contains CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE, install
109 //capsuleTable to configure table with EFI_CAPSULE_GUID
110 //
111
112 //
113 // Capsules who have CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE always are used for operating
114 // System to have information persist across a system reset. EFI System Table must
115 // point to an array of capsules that contains the same CapsuleGuid value. And agents
116 // searching for this type capsule will look in EFI System Table and search for the
117 // capsule's Guid and associated pointer to retrieve the data. Two steps below describes
118 // how to sorting the capsules by the unique guid and install the array to EFI System Table.
119 // Firstly, Loop for all coalesced capsules, record unique CapsuleGuids and cache them in an
120 // array for later sorting capsules by CapsuleGuid.
121 //
122 for (Index = 0; Index < CapsuleTotalNumber; Index++) {
123 CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];
124 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {
125 //
126 // For each capsule, we compare it with known CapsuleGuid in the CacheArray.
127 // If already has the Guid, skip it. Whereas, record it in the CacheArray as
128 // an additional one.
129 //
130 CacheIndex = 0;
131 while (CacheIndex < CacheNumber) {
132 if (CompareGuid(&CapsuleGuidCache[CacheIndex],&CapsuleHeader->CapsuleGuid)) {
133 break;
134 }
135 CacheIndex++;
136 }
137 if (CacheIndex == CacheNumber) {
138 CopyMem(&CapsuleGuidCache[CacheNumber++],&CapsuleHeader->CapsuleGuid,sizeof(EFI_GUID));
139 }
140 }
141 }
142
143 //
144 // Secondly, for each unique CapsuleGuid in CacheArray, gather all coalesced capsules
145 // whose guid is the same as it, and malloc memory for an array which preceding
146 // with UINT32. The array fills with entry point of capsules that have the same
147 // CapsuleGuid, and UINT32 represents the size of the array of capsules. Then install
148 // this array into EFI System Table, so that agents searching for this type capsule
149 // will look in EFI System Table and search for the capsule's Guid and associated
150 // pointer to retrieve the data.
151 //
152 CacheIndex = 0;
153 while (CacheIndex < CacheNumber) {
154 CapsuleNumber = 0;
155 for (Index = 0; Index < CapsuleTotalNumber; Index++) {
156 CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];
157 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) != 0) {
158 if (CompareGuid (&CapsuleGuidCache[CacheIndex], &CapsuleHeader->CapsuleGuid)) {
159 //
160 // Cache Caspuleheader to the array, this array is uniqued with certain CapsuleGuid.
161 //
162 CapsulePtrCache[CapsuleNumber++] = (VOID*)CapsuleHeader;
163 }
164 }
165 }
166 if (CapsuleNumber != 0) {
167 Size = sizeof(EFI_CAPSULE_TABLE) + (CapsuleNumber - 1) * sizeof(VOID*);
168 CapsuleTable = AllocateRuntimePool (Size);
169 ASSERT (CapsuleTable != NULL);
170 CapsuleTable->CapsuleArrayNumber = CapsuleNumber;
171 CopyMem(&CapsuleTable->CapsulePtr[0], CapsulePtrCache, CapsuleNumber * sizeof(VOID*));
172 Status = gBS->InstallConfigurationTable (&CapsuleGuidCache[CacheIndex], (VOID*)CapsuleTable);
173 ASSERT_EFI_ERROR (Status);
174 }
175 CacheIndex++;
176 }
177
178 //
179 // Besides ones with CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag, all capsules left are
180 // recognized by platform with CapsuleGuid. For general platform driver, UpdateFlash
181 // type is commonly supported, so here only deal with encapsuled FVs capsule. Additional
182 // type capsule transaction could be extended. It depends on platform policy.
183 //
184 for (Index = 0; Index < CapsuleTotalNumber; Index++) {
185 CapsuleHeader = (EFI_CAPSULE_HEADER*) CapsulePtr [Index];
186 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {
187 //
188 // Call capsule library to process capsule image.
189 //
190 ProcessCapsuleImage (CapsuleHeader);
191 }
192 }
193
194 PlatformBdsLockNonUpdatableFlash ();
195
196 //
197 // Free the allocated temp memory space.
198 //
199 FreePool (CapsuleGuidCache);
200 FreePool (CapsulePtrCache);
201 FreePool (CapsulePtr);
202
203 return Status;
204 }
205