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