]>
Commit | Line | Data |
---|---|---|
13d40edd | 1 | /** @file\r |
2 | Capsule Runtime Service.\r | |
74fea867 | 3 | \r |
13d40edd | 4 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r |
74fea867 | 5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13d40edd | 13 | **/\r |
74fea867 | 14 | \r |
15 | #include "CapsuleService.h"\r | |
16 | \r | |
17 | EFI_STATUS\r | |
18 | EFIAPI\r | |
19 | UpdateCapsule (\r | |
20 | IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r | |
21 | IN UINTN CapsuleCount,\r | |
22 | IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL\r | |
23 | )\r | |
24 | /*++\r | |
25 | \r | |
26 | Routine Description:\r | |
27 | \r | |
28 | This code finds whether the capsules need reset to update, if not, update immediately.\r | |
29 | \r | |
30 | Arguments:\r | |
31 | \r | |
32 | CapsuleHeaderArray A array of pointers to capsule headers passed in\r | |
33 | CapsuleCount The number of capsule\r | |
34 | ScatterGatherList Physical address of datablock list points to capsule\r | |
35 | \r | |
36 | Returns:\r | |
37 | \r | |
38 | EFI STATUS\r | |
39 | EFI_SUCCESS Valid capsule was passed.If CAPSULE_FLAG_PERSIT_ACROSS_RESET is\r | |
40 | not set, the capsule has been successfully processed by the firmware.\r | |
41 | If it set, the ScattlerGatherList is successfully to be set.\r | |
42 | EFI_INVALID_PARAMETER CapsuleCount is less than 1,CapsuleGuid is not supported.\r | |
6ee65722 | 43 | EFI_DEVICE_ERROR Failed to SetVariable or ProcessFirmwareVolume.\r |
74fea867 | 44 | \r |
45 | --*/\r | |
46 | {\r | |
74fea867 | 47 | UINTN ArrayNumber;\r |
74fea867 | 48 | EFI_STATUS Status;\r |
74fea867 | 49 | EFI_CAPSULE_HEADER *CapsuleHeader;\r |
50 | \r | |
51 | if (CapsuleCount < 1) {\r | |
52 | return EFI_INVALID_PARAMETER;\r | |
53 | }\r | |
54 | \r | |
74fea867 | 55 | CapsuleHeader = NULL;\r |
56 | \r | |
57 | for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r | |
d12f75fe LG |
58 | //\r |
59 | // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have\r | |
60 | // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r | |
61 | //\r | |
74fea867 | 62 | CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r |
63 | if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r | |
64 | return EFI_INVALID_PARAMETER;\r | |
65 | }\r | |
d12f75fe | 66 | //\r |
6ee65722 LG |
67 | // Check Capsule image without populate flag by firmware support capsule function \r |
68 | //\r | |
69 | if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r | |
70 | (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r | |
71 | return EFI_UNSUPPORTED;\r | |
72 | }\r | |
74fea867 | 73 | }\r |
74 | \r | |
d12f75fe | 75 | //\r |
6ee65722 | 76 | // Assume that capsules have the same flags on reseting or not.\r |
74fea867 | 77 | //\r |
78 | CapsuleHeader = CapsuleHeaderArray[0];\r | |
79 | \r | |
80 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r | |
81 | //\r | |
6ee65722 | 82 | // Check if the platform supports update capsule across a system reset\r |
74fea867 | 83 | //\r |
84 | if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest)) {\r | |
85 | return EFI_UNSUPPORTED;\r | |
86 | }\r | |
d12f75fe LG |
87 | //\r |
88 | // ScatterGatherList is only referenced if the capsules are defined to persist across\r | |
89 | // system reset. \r | |
90 | //\r | |
1be0dda6 | 91 | if (ScatterGatherList == (EFI_PHYSICAL_ADDRESS) (UINTN) NULL) {\r |
74fea867 | 92 | return EFI_INVALID_PARAMETER;\r |
93 | } else {\r | |
d12f75fe LG |
94 | //\r |
95 | // ScatterGatherList is only referenced if the capsules are defined to persist across\r | |
96 | // system reset. Set its value into NV storage to let pre-boot driver to pick it up \r | |
97 | // after coming through a system reset.\r | |
98 | //\r | |
74fea867 | 99 | Status = EfiSetVariable (\r |
100 | EFI_CAPSULE_VARIABLE_NAME,\r | |
101 | &gEfiCapsuleVendorGuid,\r | |
102 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
103 | sizeof (UINTN),\r | |
104 | (VOID *) &ScatterGatherList\r | |
105 | );\r | |
106 | if (Status != EFI_SUCCESS) {\r | |
d12f75fe | 107 | return Status;\r |
74fea867 | 108 | }\r |
6ee65722 LG |
109 | //\r |
110 | // Successfully set the capsule image address into variable.\r | |
111 | //\r | |
112 | return EFI_SUCCESS;\r | |
74fea867 | 113 | }\r |
74fea867 | 114 | }\r |
115 | \r | |
116 | //\r | |
d12f75fe | 117 | // The rest occurs in the condition of non-reset mode\r |
6ee65722 | 118 | // Now Runtime mode doesn't support the non-reset capsule image.\r |
74fea867 | 119 | //\r |
120 | if (EfiAtRuntime ()) {\r | |
17b87537 | 121 | return EFI_UNSUPPORTED;\r |
74fea867 | 122 | }\r |
123 | \r | |
124 | //\r | |
d12f75fe | 125 | // Here should be in the boot-time for non-reset capsule image\r |
6ee65722 | 126 | // Default process to Update Capsule image into Flash.\r |
74fea867 | 127 | //\r |
128 | for (ArrayNumber = 0; ArrayNumber < CapsuleCount ; ArrayNumber++) {\r | |
6ee65722 LG |
129 | Status = ProcessCapsuleImage (CapsuleHeaderArray[ArrayNumber]);\r |
130 | if (EFI_ERROR (Status)) {\r | |
d12f75fe | 131 | return Status;\r |
74fea867 | 132 | }\r |
74fea867 | 133 | }\r |
134 | \r | |
135 | return EFI_SUCCESS;\r | |
136 | }\r | |
137 | \r | |
138 | \r | |
139 | \r | |
140 | EFI_STATUS\r | |
141 | EFIAPI\r | |
142 | QueryCapsuleCapabilities (\r | |
143 | IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r | |
144 | IN UINTN CapsuleCount,\r | |
145 | OUT UINT64 *MaxiumCapsuleSize,\r | |
146 | OUT EFI_RESET_TYPE *ResetType\r | |
147 | )\r | |
148 | /*++\r | |
149 | \r | |
150 | Routine Description:\r | |
151 | \r | |
152 | This code is to query about capsule capability.\r | |
153 | \r | |
154 | Arguments:\r | |
155 | \r | |
156 | CapsuleHeaderArray A array of pointers to capsule headers passed in\r | |
157 | CapsuleCount The number of capsule\r | |
158 | MaxiumCapsuleSize Max capsule size is supported\r | |
159 | ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.\r | |
160 | If reset is needed, return EfiResetWarm.\r | |
161 | \r | |
162 | Returns:\r | |
163 | \r | |
164 | EFI STATUS\r | |
165 | EFI_SUCCESS Valid answer returned\r | |
166 | EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.\r | |
167 | EFI_UNSUPPORTED The capsule type is not supported.\r | |
168 | \r | |
169 | --*/\r | |
170 | {\r | |
171 | UINTN ArrayNumber;\r | |
172 | EFI_CAPSULE_HEADER *CapsuleHeader;\r | |
173 | \r | |
174 | if (CapsuleCount < 1) {\r | |
175 | return EFI_INVALID_PARAMETER;\r | |
176 | }\r | |
177 | \r | |
178 | if ((MaxiumCapsuleSize == NULL) ||(ResetType == NULL)) {\r | |
179 | return EFI_INVALID_PARAMETER;\r | |
180 | }\r | |
181 | \r | |
182 | CapsuleHeader = NULL;\r | |
183 | \r | |
184 | for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r | |
185 | CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r | |
d12f75fe LG |
186 | //\r |
187 | // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have\r | |
188 | // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.\r | |
189 | //\r | |
74fea867 | 190 | if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r |
191 | return EFI_INVALID_PARAMETER;\r | |
192 | }\r | |
d12f75fe | 193 | //\r |
6ee65722 LG |
194 | // Check Capsule image without populate flag by firmware support capsule function \r |
195 | //\r | |
196 | if (((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) && \r | |
197 | (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS)) {\r | |
198 | return EFI_UNSUPPORTED;\r | |
199 | }\r | |
74fea867 | 200 | }\r |
201 | \r | |
202 | //\r | |
203 | //Assume that capsules have the same flags on reseting or not.\r | |
204 | //\r | |
205 | CapsuleHeader = CapsuleHeaderArray[0];\r | |
206 | if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r | |
207 | //\r | |
208 | //Check if the platform supports update capsule across a system reset\r | |
209 | //\r | |
210 | if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest)) {\r | |
211 | return EFI_UNSUPPORTED;\r | |
212 | }\r | |
213 | *ResetType = EfiResetWarm;\r | |
214 | *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizePopulateCapsule);\r | |
215 | } else {\r | |
216 | *ResetType = EfiResetCold;\r | |
217 | *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizeNonPopulateCapsule);\r | |
218 | }\r | |
219 | return EFI_SUCCESS;\r | |
220 | }\r | |
221 | \r | |
222 | \r | |
223 | EFI_STATUS\r | |
224 | EFIAPI\r | |
225 | CapsuleServiceInitialize (\r | |
226 | IN EFI_HANDLE ImageHandle,\r | |
227 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
228 | )\r | |
229 | /*++\r | |
230 | \r | |
231 | Routine Description:\r | |
232 | \r | |
233 | This code is capsule runtime service initialization.\r | |
234 | \r | |
235 | Arguments:\r | |
236 | \r | |
237 | ImageHandle The image handle\r | |
238 | SystemTable The system table.\r | |
239 | \r | |
240 | Returns:\r | |
241 | \r | |
242 | EFI STATUS\r | |
243 | \r | |
244 | --*/\r | |
245 | {\r | |
246 | EFI_STATUS Status;\r | |
247 | EFI_HANDLE NewHandle;\r | |
248 | \r | |
249 | SystemTable->RuntimeServices->UpdateCapsule = UpdateCapsule;\r | |
250 | SystemTable->RuntimeServices->QueryCapsuleCapabilities = QueryCapsuleCapabilities;\r | |
251 | \r | |
252 | //\r | |
253 | // Now install the Capsule Architectural Protocol on a new handle\r | |
254 | //\r | |
255 | NewHandle = NULL;\r | |
256 | \r | |
257 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
258 | &NewHandle,\r | |
259 | &gEfiCapsuleArchProtocolGuid,\r | |
260 | NULL,\r | |
261 | NULL\r | |
262 | );\r | |
263 | ASSERT_EFI_ERROR (Status);\r | |
264 | \r | |
265 | return EFI_SUCCESS;\r | |
266 | }\r |