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