]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Capsule/RuntimeDxe/CapsuleService.c
50de4c6c9d2a0c25a000c64d29bb03fc6920eb6b
[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
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_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {
79 return EFI_INVALID_PARAMETER;
80 }
81 if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &mEfiCapsuleHeaderGuid)) {
82 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {
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
132 BufferPtr = AllocatePool (CapsuleSize);
133 if (BufferPtr == NULL) {
134 return EFI_DEVICE_ERROR;
135 }
136
137 CopyMem (BufferPtr, (UINT8*)CapsuleHeader+ CapsuleHeader->HeaderSize, CapsuleSize);
138
139 //
140 //Call DXE service ProcessFirmwareVolume to process immediatelly
141 //
142 Status = gDS->ProcessFirmwareVolume (BufferPtr, CapsuleSize, &FvHandle);
143 if (Status != EFI_SUCCESS) {
144 FreePool (BufferPtr);
145 return EFI_DEVICE_ERROR;
146 }
147 gDS->Dispatch ();
148 FreePool (BufferPtr);
149 }
150
151 return EFI_SUCCESS;
152 }
153
154
155
156 EFI_STATUS
157 EFIAPI
158 QueryCapsuleCapabilities (
159 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,
160 IN UINTN CapsuleCount,
161 OUT UINT64 *MaxiumCapsuleSize,
162 OUT EFI_RESET_TYPE *ResetType
163 )
164 /*++
165
166 Routine Description:
167
168 This code is to query about capsule capability.
169
170 Arguments:
171
172 CapsuleHeaderArray A array of pointers to capsule headers passed in
173 CapsuleCount The number of capsule
174 MaxiumCapsuleSize Max capsule size is supported
175 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.
176 If reset is needed, return EfiResetWarm.
177
178 Returns:
179
180 EFI STATUS
181 EFI_SUCCESS Valid answer returned
182 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.
183 EFI_UNSUPPORTED The capsule type is not supported.
184
185 --*/
186 {
187 UINTN ArrayNumber;
188 UEFI_CAPSULE_HEADER *CapsuleHeader;
189
190 if (CapsuleCount < 1) {
191 return EFI_INVALID_PARAMETER;
192 }
193
194 if ((MaxiumCapsuleSize == NULL) ||(ResetType == NULL)) {
195 return EFI_INVALID_PARAMETER;
196 }
197
198 CapsuleHeader = NULL;
199
200 //
201 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET
202 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.
203 //
204 for (ArrayNumber = 0; ArrayNumber < CapsuleCount; ArrayNumber++) {
205 CapsuleHeader = CapsuleHeaderArray[ArrayNumber];
206 if ((CapsuleHeader->Flags & (CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) {
207 return EFI_INVALID_PARAMETER;
208 }
209 if (!CompareGuid (&CapsuleHeader->CapsuleGuid, &mEfiCapsuleHeaderGuid)) {
210 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {
211 return EFI_UNSUPPORTED;
212 }
213 }
214 }
215
216 //
217 //Assume that capsules have the same flags on reseting or not.
218 //
219 CapsuleHeader = CapsuleHeaderArray[0];
220 if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {
221 //
222 //Check if the platform supports update capsule across a system reset
223 //
224 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest)) {
225 return EFI_UNSUPPORTED;
226 }
227 *ResetType = EfiResetWarm;
228 *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizePopulateCapsule);
229 } else {
230 *ResetType = EfiResetCold;
231 *MaxiumCapsuleSize = FixedPcdGet32(PcdMaxSizeNonPopulateCapsule);
232 }
233 return EFI_SUCCESS;
234 }
235