Add EBC, FTW, Crc32SectionExtract, NullMemoryTest modules.
[mirror_edk2.git] / MdeModulePkg / Universal / Capsule / RuntimeDxe / CapsuleService.c
CommitLineData
513f3f44 1/*++\r
2\r
3Copyright (c) 2006 - 2007, 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
24EFI_STATUS\r
25EFIAPI\r
26UpdateCapsule (\r
27 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
28 IN UINTN CapsuleCount,\r
29 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL\r
30 )\r
31/*++\r
32\r
33Routine Description:\r
34\r
35 This code finds whether the capsules need reset to update, if not, update immediately.\r
36\r
37Arguments:\r
38\r
39 CapsuleHeaderArray A array of pointers to capsule headers passed in\r
40 CapsuleCount The number of capsule\r
41 ScatterGatherList Physical address of datablock list points to capsule\r
42\r
43Returns:\r
44\r
45 EFI STATUS\r
46 EFI_SUCCESS Valid capsule was passed.If CAPSULE_FLAG_PERSIT_ACROSS_RESET is\r
47 not set, the capsule has been successfully processed by the firmware.\r
48 If it set, the ScattlerGatherList is successfully to be set.\r
49 EFI_INVALID_PARAMETER CapsuleCount is less than 1,CapsuleGuid is not supported.\r
50 EFI_DEVICE_ERROR Failed to SetVariable or AllocatePool or ProcessFirmwareVolume.\r
51\r
52--*/\r
53{\r
54 UINTN CapsuleSize;\r
55 UINTN ArrayNumber;\r
56 VOID *BufferPtr;\r
57 EFI_STATUS Status;\r
58 EFI_HANDLE FvHandle;\r
59 UEFI_CAPSULE_HEADER *CapsuleHeader;\r
60\r
61 if (CapsuleCount < 1) {\r
62 return EFI_INVALID_PARAMETER;\r
63 }\r
64\r
65 BufferPtr = NULL;\r
66 CapsuleHeader = NULL;\r
67\r
68 //\r
69 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET\r
70 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.\r
71 //\r
72 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
73 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
74 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r
75 return EFI_INVALID_PARAMETER;\r
76 }\r
77 if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiCapsuleGuid)) {\r
78 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
79 return EFI_UNSUPPORTED;\r
80 }\r
81 }\r
82 }\r
83\r
84 //\r
85 //Assume that capsules have the same flags on reseting or not.\r
86 //\r
87 CapsuleHeader = CapsuleHeaderArray[0];\r
88\r
89 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
90 //\r
91 //Check if the platform supports update capsule across a system reset\r
92 //\r
93 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest)) {\r
94 return EFI_UNSUPPORTED;\r
95 }\r
96\r
97 if (ScatterGatherList == 0) {\r
98 return EFI_INVALID_PARAMETER;\r
99 } else {\r
100 Status = EfiSetVariable (\r
101 EFI_CAPSULE_VARIABLE_NAME,\r
102 &gEfiCapsuleVendorGuid,\r
103 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
104 sizeof (UINTN),\r
105 (VOID *) &ScatterGatherList\r
106 );\r
107 if (Status != EFI_SUCCESS) {\r
108 return EFI_DEVICE_ERROR;\r
109 }\r
110 }\r
111 return EFI_SUCCESS;\r
112 }\r
113\r
114 //\r
115 //The rest occurs in the condition of non-reset mode\r
116 //\r
117 if (EfiAtRuntime ()) {\r
118 return EFI_INVALID_PARAMETER;\r
119 }\r
120\r
121 //\r
122 //Here should be in the boot-time\r
123 //\r
124 for (ArrayNumber = 0; ArrayNumber < CapsuleCount ; ArrayNumber++) {\r
125 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
126 CapsuleSize = CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize;\r
127\r
128 BufferPtr = AllocatePool (CapsuleSize);\r
129 if (BufferPtr == NULL) {\r
130 return EFI_DEVICE_ERROR;\r
131 }\r
132\r
133 CopyMem (BufferPtr, (UINT8*)CapsuleHeader+ CapsuleHeader->HeaderSize, CapsuleSize);\r
134\r
135 //\r
136 //Call DXE service ProcessFirmwareVolume to process immediatelly\r
137 //\r
138 Status = gDS->ProcessFirmwareVolume (BufferPtr, CapsuleSize, &FvHandle);\r
139 if (Status != EFI_SUCCESS) {\r
140 FreePool (BufferPtr);\r
141 return EFI_DEVICE_ERROR;\r
142 }\r
143 gDS->Dispatch ();\r
144 FreePool (BufferPtr);\r
145 }\r
146\r
147 return EFI_SUCCESS;\r
148}\r
149\r
150\r
151\r
152EFI_STATUS\r
153EFIAPI\r
154QueryCapsuleCapabilities (\r
155 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
156 IN UINTN CapsuleCount,\r
157 OUT UINT64 *MaxiumCapsuleSize,\r
158 OUT EFI_RESET_TYPE *ResetType\r
159 )\r
160/*++\r
161\r
162Routine Description:\r
163\r
164 This code is to query about capsule capability.\r
165\r
166Arguments:\r
167\r
168 CapsuleHeaderArray A array of pointers to capsule headers passed in\r
169 CapsuleCount The number of capsule\r
170 MaxiumCapsuleSize Max capsule size is supported\r
171 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.\r
172 If reset is needed, return EfiResetWarm.\r
173\r
174Returns:\r
175\r
176 EFI STATUS\r
177 EFI_SUCCESS Valid answer returned\r
178 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.\r
179 EFI_UNSUPPORTED The capsule type is not supported.\r
180\r
181--*/\r
182{\r
183 UINTN ArrayNumber;\r
184 UEFI_CAPSULE_HEADER *CapsuleHeader;\r
185\r
186 if (CapsuleCount < 1) {\r
187 return EFI_INVALID_PARAMETER;\r
188 }\r
189\r
190 if ((MaxiumCapsuleSize == NULL) ||(ResetType == NULL)) {\r
191 return EFI_INVALID_PARAMETER;\r
192 }\r
193\r
194 CapsuleHeader = NULL;\r
195\r
196 //\r
197 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET\r
198 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.\r
199 //\r
200 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {\r
201 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];\r
202 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {\r
203 return EFI_INVALID_PARAMETER;\r
204 }\r
205 if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiCapsuleGuid)) {\r
206 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {\r
207 return EFI_UNSUPPORTED;\r
208 }\r
209 }\r
210 }\r
211\r
212 //\r
213 //Assume that capsules have the same flags on reseting or not.\r
214 //\r
215 CapsuleHeader = CapsuleHeaderArray[0];\r
216 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {\r
217 //\r
218 //Check if the platform supports update capsule across a system reset\r
219 //\r
220 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest)) {\r
221 return EFI_UNSUPPORTED;\r
222 }\r
223 *ResetType = EfiResetWarm;\r
224 *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizePopulateCapsule);\r
225 } else {\r
226 *ResetType = EfiResetCold;\r
227 *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizeNonPopulateCapsule);\r
228 }\r
229 return EFI_SUCCESS;\r
230}\r
231\r