]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Universal/Capsule/RuntimeDxe/CapsuleService.c
1)Add a new module CapsuleRuntime under EdkModulePkg\Universal\Capsule\RuntimeDxe...
[mirror_edk2.git] / EdkModulePkg / Universal / Capsule / RuntimeDxe / CapsuleService.c
CommitLineData
045f4521 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 CapsuleService.c\r
15\r
16Abstract:\r
17\r
18 Capsule Runtime Service.\r
19\r
20--*/\r
21\r
22#include "CapsuleService.h"\r
23\r
24\r
25STATIC EFI_GUID mEfiCapsuleHeaderGuid = EFI_CAPSULE_GUID;\r
26\r
27\r
28EFI_STATUS\r
29EFIAPI\r
30UpdateCapsule (\r
31 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
32 IN UINTN CapsuleCount,\r
33 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL\r
34 )\r
35/*++\r
36\r
37Routine Description:\r
38\r
39 This code finds whether the capsules need reset to update, if not, update immediately.\r
40\r
41Arguments:\r
42\r
43 CapsuleHeaderArray A array of pointers to capsule headers passed in\r
44 CapsuleCount The number of capsule\r
45 ScatterGatherList Physical address of datablock list points to capsule\r
46 \r
47Returns:\r
48\r
49 EFI STATUS\r
50 EFI_SUCCESS Valid capsule was passed.If CAPSULE_FLAG_PERSIT_ACROSS_RESET is\r
51 not set, the capsule has been successfully processed by the firmware.\r
52 If it set, the ScattlerGatherList is successfully to be set.\r
53 EFI_INVALID_PARAMETER CapsuleCount is less than 1,CapsuleGuid is not supported.\r
54 EFI_DEVICE_ERROR Failed to SetVariable or AllocatePool or ProcessFirmwareVolume. \r
55 \r
56--*/\r
57{\r
58 UINTN CapsuleSize;\r
59 UINTN ArrayNumber;\r
60 VOID *BufferPtr;\r
61 EFI_STATUS Status;\r
62 EFI_HANDLE FvHandle;\r
63 UEFI_CAPSULE_HEADER *CapsuleHeader;\r
64\r
65 if (CapsuleCount < 1) {\r
66 return EFI_INVALID_PARAMETER;\r
67 }\r
68\r
69 BufferPtr = NULL;\r
70 CapsuleHeader = NULL;\r
71\r
72 //\r
73 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET\r
74 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.\r
75 //\r
76 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
77 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
78 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) && !(CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET)) {\r
79 return EFI_INVALID_PARAMETER; \r
80 }\r
81 if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &mEfiCapsuleHeaderGuid)) {\r
82 if (!(CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) {\r
83 return EFI_UNSUPPORTED;\r
84 } \r
85 } \r
86 }\r
87\r
88 //\r
89 //Assume that capsules have the same flags on reseting or not. \r
90 //\r
91 CapsuleHeader = CapsuleHeaderArray[0];\r
92\r
93 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
94 //\r
95 //Check if the platform supports update capsule across a system reset\r
96 //\r
97 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest)) {\r
98 return EFI_UNSUPPORTED;\r
99 }\r
100 \r
101 if (ScatterGatherList == 0) {\r
102 return EFI_INVALID_PARAMETER;\r
103 } else {\r
104 Status = EfiSetVariable (\r
105 EFI_CAPSULE_VARIABLE_NAME, \r
106 &gEfiCapsuleVendorGuid, \r
107 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, \r
108 sizeof (UINTN), \r
109 (VOID *) &ScatterGatherList \r
110 );\r
111 if (Status != EFI_SUCCESS) { \r
112 return EFI_DEVICE_ERROR;\r
113 }\r
114 }\r
115 return EFI_SUCCESS;\r
116 }\r
117 \r
118 //\r
119 //The rest occurs in the condition of non-reset mode\r
120 //\r
121 if (EfiAtRuntime ()) { \r
122 return EFI_INVALID_PARAMETER;\r
123 }\r
124\r
125 //\r
126 //Here should be in the boot-time\r
127 //\r
128 for (ArrayNumber = 0; ArrayNumber < CapsuleCount ; ArrayNumber++) {\r
129 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
130 CapsuleSize = CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize;\r
131 Status = gBS->AllocatePool (EfiBootServicesData, CapsuleSize, &BufferPtr);\r
132 if (Status != EFI_SUCCESS) {\r
133 goto Done;\r
134 }\r
135 gBS->CopyMem (BufferPtr, (UINT8*)CapsuleHeader+ CapsuleHeader->HeaderSize, CapsuleSize);\r
136\r
137 //\r
138 //Call DXE service ProcessFirmwareVolume to process immediatelly \r
139 //\r
140 Status = gDS->ProcessFirmwareVolume (BufferPtr, CapsuleSize, &FvHandle);\r
141 if (Status != EFI_SUCCESS) {\r
142 gBS->FreePool (BufferPtr);\r
143 return EFI_DEVICE_ERROR;\r
144 }\r
145 gDS->Dispatch ();\r
146 gBS->FreePool (BufferPtr);\r
147 }\r
148 return EFI_SUCCESS;\r
149\r
150Done:\r
151 if (BufferPtr != NULL) {\r
152 gBS->FreePool (BufferPtr);\r
153 } \r
154 return EFI_DEVICE_ERROR;\r
155}\r
156\r
157\r
158 \r
159EFI_STATUS\r
160EFIAPI\r
161QueryCapsuleCapabilities (\r
162 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
163 IN UINTN CapsuleCount,\r
164 OUT UINT64 *MaxiumCapsuleSize,\r
165 OUT EFI_RESET_TYPE *ResetType\r
166 )\r
167/*++\r
168\r
169Routine Description:\r
170\r
171 This code is to query about capsule capability.\r
172\r
173Arguments:\r
174\r
175 CapsuleHeaderArray A array of pointers to capsule headers passed in\r
176 CapsuleCount The number of capsule\r
177 MaxiumCapsuleSize Max capsule size is supported\r
178 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.\r
179 If reset is needed, return EfiResetWarm.\r
180\r
181Returns:\r
182\r
183 EFI STATUS\r
184 EFI_SUCCESS Valid answer returned\r
185 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.\r
186 EFI_UNSUPPORTED The capsule type is not supported.\r
187\r
188--*/\r
189{\r
190 UINTN ArrayNumber;\r
191 UEFI_CAPSULE_HEADER *CapsuleHeader;\r
192\r
193 if (CapsuleCount < 1) {\r
194 return EFI_INVALID_PARAMETER;\r
195 }\r
196\r
197 if ((MaxiumCapsuleSize == NULL) ||(ResetType == NULL)) {\r
198 return EFI_INVALID_PARAMETER;\r
199 } \r
200\r
201 CapsuleHeader = NULL;\r
202 \r
203 //\r
204 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET\r
205 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.\r
206 //\r
207 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
208 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
209 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) && !(CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET)) {\r
210 return EFI_INVALID_PARAMETER; \r
211 }\r
212 if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &mEfiCapsuleHeaderGuid)) {\r
213 if (!(CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) {\r
214 return EFI_UNSUPPORTED;\r
215 }\r
216 } \r
217 }\r
218\r
219 //\r
220 //Assume that capsules have the same flags on reseting or not. \r
221 //\r
222 CapsuleHeader = CapsuleHeaderArray[0]; \r
223 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
224 //\r
225 //Check if the platform supports update capsule across a system reset\r
226 //\r
227 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest)) {\r
228 return EFI_UNSUPPORTED;\r
229 }\r
230 *ResetType = EfiResetWarm;\r
231 *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizePopulateCapsule); \r
232 } else {\r
233 *ResetType = EfiResetCold;\r
234 *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizeNonPopulateCapsule);\r
235 } \r
236 return EFI_SUCCESS;\r
237} \r
238\r