]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Library/HalRuntimeServicesExampleLib/Capsule.c
Add the beginning of a GDB based Debug Agent. IA-32 and X64 don't have low level...
[mirror_edk2.git] / EmbeddedPkg / Library / HalRuntimeServicesExampleLib / Capsule.c
CommitLineData
2ef2b01e
A
1/** @file\r
2 Generic Capsule services\r
3\r
4 Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
5 \r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Common/CapsuleName.h>\r
17\r
18\r
19//\r
20//Max size capsule services support are platform policy,to populate capsules we just need\r
21//memory to maintain them across reset,it is not a problem. And to special capsules ,for\r
22//example,update flash,it is mostly decided by the platform. Here is a sample size for \r
23//different type capsules.\r
24//\r
25#define MAX_SIZE_POPULATE (0)\r
26#define MAX_SIZE_NON_POPULATE (0)\r
27#define MAX_SUPPORT_CAPSULE_NUM 0x10\r
28\r
29\r
30BOOLEAN\r
31EFIAPI\r
32SupportUpdateCapsuleRest (\r
33 VOID\r
34 )\r
35{\r
36 //\r
37 //If the platform has a way to guarantee the memory integrity across a system reset, return \r
38 //TRUE, else FALSE. \r
39 //\r
40 return FALSE;\r
41}\r
42\r
43\r
44\r
45VOID\r
46EFIAPI\r
47SupportCapsuleSize (\r
48 IN OUT UINT32 *MaxSizePopulate,\r
49 IN OUT UINT32 *MaxSizeNonPopulate\r
50 )\r
51{\r
52 //\r
53 //Here is a sample size, different platforms have different sizes.\r
54 //\r
55 *MaxSizePopulate = MAX_SIZE_POPULATE;\r
56 *MaxSizeNonPopulate = MAX_SIZE_NON_POPULATE;\r
57 return; \r
58}\r
59\r
60\r
61\r
62\r
63EFI_STATUS\r
64LibUpdateCapsule (\r
65 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
66 IN UINTN CapsuleCount,\r
67 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL\r
68 )\r
69/*++\r
70\r
71Routine Description:\r
72\r
73 This code finds if the capsule needs reset to update, if no, update immediately.\r
74\r
75Arguments:\r
76\r
77 CapsuleHeaderArray A array of pointers to capsule headers passed in\r
78 CapsuleCount The number of capsule\r
79 ScatterGatherList Physical address of datablock list points to capsule\r
80 \r
81Returns:\r
82\r
83 EFI STATUS\r
84 EFI_SUCCESS Valid capsule was passed.If CAPSULE_FLAG_PERSIT_ACROSS_RESET is\r
85 not set, the capsule has been successfully processed by the firmware.\r
86 If it set, the ScattlerGatherList is successfully to be set.\r
87 EFI_INVALID_PARAMETER CapsuleCount is less than 1,CapsuleGuid is not supported.\r
88 EFI_DEVICE_ERROR Failed to SetVariable or AllocatePool or ProcessFirmwareVolume. \r
89 \r
90--*/\r
91{\r
92 UINTN CapsuleSize;\r
93 UINTN ArrayNumber;\r
94 VOID *BufferPtr;\r
95 EFI_STATUS Status;\r
96 EFI_HANDLE FvHandle;\r
97 UEFI_CAPSULE_HEADER *CapsuleHeader;\r
98\r
99 if ((CapsuleCount < 1) || (CapsuleCount > MAX_SUPPORT_CAPSULE_NUM)){\r
100 return EFI_INVALID_PARAMETER;\r
101 }\r
102\r
103 BufferPtr = NULL;\r
104 CapsuleHeader = NULL;\r
105\r
106 //\r
107 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET\r
108 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.\r
109 //\r
110 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
111 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
112 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r
113 return EFI_INVALID_PARAMETER; \r
114 }\r
115 if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiCapsuleGuid)) {\r
116 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
117 return EFI_UNSUPPORTED;\r
118 } \r
119 } \r
120 }\r
121\r
122 //\r
123 //Assume that capsules have the same flags on reseting or not. \r
124 //\r
125 CapsuleHeader = CapsuleHeaderArray[0];\r
126\r
127 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
128 //\r
129 //Check if the platform supports update capsule across a system reset\r
130 //\r
131 if (!SupportUpdateCapsuleRest()) {\r
132 return EFI_UNSUPPORTED;\r
133 }\r
134 \r
135 if (ScatterGatherList == 0) {\r
136 return EFI_INVALID_PARAMETER;\r
137 } else {\r
138 Status = EfiSetVariable (\r
139 EFI_CAPSULE_VARIABLE_NAME, \r
140 &gEfiCapsuleVendorGuid, \r
141 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, \r
142 sizeof (UINTN), \r
143 (VOID *) &ScatterGatherList \r
144 );\r
145 if (Status != EFI_SUCCESS) { \r
146 return EFI_DEVICE_ERROR;\r
147 }\r
148 }\r
149 return EFI_SUCCESS;\r
150 }\r
151 \r
152 //\r
153 //The rest occurs in the condition of non-reset mode\r
154 //\r
155 if (EfiAtRuntime ()) { \r
156 return EFI_INVALID_PARAMETER;\r
157 }\r
158\r
159 //\r
160 //Here should be in the boot-time\r
161 //\r
162 for (ArrayNumber = 0; ArrayNumber < CapsuleCount ; ArrayNumber++) {\r
163 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
164 CapsuleSize = CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize;\r
165 Status = gBS->AllocatePool (EfiBootServicesData, CapsuleSize, &BufferPtr);\r
166 if (Status != EFI_SUCCESS) {\r
167 goto Done;\r
168 }\r
169 gBS->CopyMem (BufferPtr, (UINT8*)CapsuleHeader+ CapsuleHeader->HeaderSize, CapsuleSize);\r
170\r
171 //\r
172 //Call DXE service ProcessFirmwareVolume to process immediatelly \r
173 //\r
174 Status = gDS->ProcessFirmwareVolume (BufferPtr, CapsuleSize, &FvHandle);\r
175 if (Status != EFI_SUCCESS) {\r
176 gBS->FreePool (BufferPtr);\r
177 return EFI_DEVICE_ERROR;\r
178 }\r
179 gDS->Dispatch ();\r
180 gBS->FreePool (BufferPtr);\r
181 }\r
182 return EFI_SUCCESS;\r
183\r
184Done:\r
185 if (BufferPtr != NULL) {\r
186 gBS->FreePool (BufferPtr);\r
187 } \r
188 return EFI_DEVICE_ERROR;\r
189}\r
190\r
191\r
192EFI_STATUS\r
193QueryCapsuleCapabilities (\r
194 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
195 IN UINTN CapsuleCount,\r
196 OUT UINT64 *MaxiumCapsuleSize,\r
197 OUT EFI_RESET_TYPE *ResetType\r
198 )\r
199/*++\r
200\r
201Routine Description:\r
202\r
203 This code is query about capsule capability.\r
204\r
205Arguments:\r
206\r
207 CapsuleHeaderArray A array of pointers to capsule headers passed in\r
208 CapsuleCount The number of capsule\r
209 MaxiumCapsuleSize Max capsule size is supported\r
210 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.\r
211 If reset is needed, return EfiResetWarm.\r
212\r
213Returns:\r
214\r
215 EFI STATUS\r
216 EFI_SUCCESS Valid answer returned\r
217 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.\r
218 EFI_UNSUPPORTED The capsule type is not supported.\r
219\r
220--*/\r
221{\r
222 UINTN ArrayNumber;\r
223 UEFI_CAPSULE_HEADER *CapsuleHeader;\r
224 UINT32 MaxSizePopulate;\r
225 UINT32 MaxSizeNonPopulate;\r
226\r
227\r
228 if ((CapsuleCount < 1) || (CapsuleCount > MAX_SUPPORT_CAPSULE_NUM)){\r
229 return EFI_INVALID_PARAMETER;\r
230 }\r
231\r
232 if ((MaxiumCapsuleSize == NULL) ||(ResetType == NULL)) {\r
233 return EFI_INVALID_PARAMETER;\r
234 } \r
235\r
236 CapsuleHeader = NULL;\r
237 \r
238 //\r
239 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET\r
240 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.\r
241 //\r
242 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
243 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
244 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r
245 return EFI_INVALID_PARAMETER; \r
246 }\r
247 if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiCapsuleGuid)) {\r
248 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
249 return EFI_UNSUPPORTED;\r
250 }\r
251 } \r
252 }\r
253\r
254 SupportCapsuleSize(&MaxSizePopulate,&MaxSizeNonPopulate);\r
255 //\r
256 //Assume that capsules have the same flags on reseting or not. \r
257 //\r
258 CapsuleHeader = CapsuleHeaderArray[0]; \r
259 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
260 //\r
261 //Check if the platform supports update capsule across a system reset\r
262 //\r
263 if (!SupportUpdateCapsuleRest()) {\r
264 return EFI_UNSUPPORTED;\r
265 }\r
266 *ResetType = EfiResetWarm;\r
267 *MaxiumCapsuleSize = MaxSizePopulate; \r
268 } else {\r
269 *ResetType = EfiResetCold;\r
270 *MaxiumCapsuleSize = MaxSizeNonPopulate;\r
271 } \r
272 return EFI_SUCCESS;\r
273}\r
274\r
275\r
276VOID\r
277LibCapsuleVirtualAddressChangeEvent (\r
278 VOID\r
279 )\r
280{\r
281}\r
282\r
283VOID\r
284LibCapsuleInitialize (\r
285 VOID\r
286 )\r
287{\r
288}\r