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