2 Capsule Runtime Driver produces two UEFI capsule runtime services.
3 (UpdateCapsule, QueryCapsuleCapabilities)
4 It installs the Capsule Architectural Protocol defined in PI1.0a to signify
5 the capsule runtime services are ready.
7 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <Protocol/Capsule.h>
21 #include <Guid/CapsuleVendor.h>
23 #include <Library/DebugLib.h>
24 #include <Library/PcdLib.h>
25 #include <Library/CapsuleLib.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/UefiRuntimeServicesTableLib.h>
29 #include <Library/UefiRuntimeLib.h>
32 Passes capsules to the firmware with both virtual and physical mapping. Depending on the intended
33 consumption, the firmware may process the capsule immediately. If the payload should persist
34 across a system reset, the reset value returned from EFI_QueryCapsuleCapabilities must
35 be passed into ResetSystem() and will cause the capsule to be processed by the firmware as
36 part of the reset process.
38 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules
39 being passed into update capsule.
40 @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in
42 @param ScatterGatherList Physical pointer to a set of
43 EFI_CAPSULE_BLOCK_DESCRIPTOR that describes the
44 location in physical memory of a set of capsules.
46 @retval EFI_SUCCESS Valid capsule was passed. If
47 CAPSULE_FLAGS_PERSIT_ACROSS_RESET is not set, the
48 capsule has been successfully processed by the firmware.
49 @retval EFI_DEVICE_ERROR The capsule update was started, but failed due to a device error.
50 @retval EFI_INVALID_PARAMETER CapsuleCount is Zero, or CapsuleImage is not valid.
51 For across reset capsule image, ScatterGatherList is NULL.
52 @retval EFI_UNSUPPORTED CapsuleImage is not recognized by the firmware.
58 IN EFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
59 IN UINTN CapsuleCount
,
60 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
65 EFI_CAPSULE_HEADER
*CapsuleHeader
;
69 // Capsule Count can't be less than one.
71 if (CapsuleCount
< 1) {
72 return EFI_INVALID_PARAMETER
;
77 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
79 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have
80 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.
82 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
83 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
84 return EFI_INVALID_PARAMETER
;
87 // Check Capsule image without populate flag by firmware support capsule function
89 if (((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) &&
90 (SupportCapsuleImage (CapsuleHeader
) != EFI_SUCCESS
)) {
91 return EFI_UNSUPPORTED
;
96 // Walk through all capsules, record whether there is a capsule
97 // needs reset. And then process capsules which has no reset flag directly.
99 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
100 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
102 // Here should be in the boot-time for non-reset capsule image
103 // Platform specific update for the non-reset capsule image.
105 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) == 0) {
106 if (EfiAtRuntime ()) {
107 Status
= EFI_UNSUPPORTED
;
109 Status
= ProcessCapsuleImage(CapsuleHeader
);
111 if (EFI_ERROR(Status
)) {
120 // After launching all capsules who has no reset flag, if no more capsules claims
121 // for a system reset just return.
128 // ScatterGatherList is only referenced if the capsules are defined to persist across
131 if (ScatterGatherList
== (EFI_PHYSICAL_ADDRESS
) (UINTN
) NULL
) {
132 return EFI_INVALID_PARAMETER
;
136 // Check if the platform supports update capsule across a system reset
138 if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset
)) {
139 return EFI_UNSUPPORTED
;
143 // ScatterGatherList is only referenced if the capsules are defined to persist across
144 // system reset. Set its value into NV storage to let pre-boot driver to pick it up
145 // after coming through a system reset.
147 Status
= gRT
->SetVariable (
148 EFI_CAPSULE_VARIABLE_NAME
,
149 &gEfiCapsuleVendorGuid
,
150 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
152 (VOID
*) &ScatterGatherList
159 Returns if the capsule can be supported via UpdateCapsule().
161 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules
162 being passed into update capsule.
163 @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in
165 @param MaxiumCapsuleSize On output the maximum size that UpdateCapsule() can
166 support as an argument to UpdateCapsule() via
167 CapsuleHeaderArray and ScatterGatherList.
168 @param ResetType Returns the type of reset required for the capsule update.
170 @retval EFI_SUCCESS Valid answer returned.
171 @retval EFI_UNSUPPORTED The capsule image is not supported on this platform, and
172 MaximumCapsuleSize and ResetType are undefined.
173 @retval EFI_INVALID_PARAMETER MaximumCapsuleSize is NULL, or ResetTyep is NULL,
174 Or CapsuleCount is Zero, or CapsuleImage is not valid.
179 QueryCapsuleCapabilities (
180 IN EFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
181 IN UINTN CapsuleCount
,
182 OUT UINT64
*MaxiumCapsuleSize
,
183 OUT EFI_RESET_TYPE
*ResetType
187 EFI_CAPSULE_HEADER
*CapsuleHeader
;
190 // Capsule Count can't be less than one.
192 if (CapsuleCount
< 1) {
193 return EFI_INVALID_PARAMETER
;
197 // Check whether input paramter is valid
199 if ((MaxiumCapsuleSize
== NULL
) ||(ResetType
== NULL
)) {
200 return EFI_INVALID_PARAMETER
;
203 CapsuleHeader
= NULL
;
205 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
206 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
208 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have
209 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.
211 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
212 return EFI_INVALID_PARAMETER
;
215 // Check Capsule image without populate flag is supported by firmware
217 if (((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) &&
218 (SupportCapsuleImage (CapsuleHeader
) != EFI_SUCCESS
)) {
219 return EFI_UNSUPPORTED
;
224 // Assume that capsules have the same flags on reseting or not.
226 CapsuleHeader
= CapsuleHeaderArray
[0];
227 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
229 //Check if the platform supports update capsule across a system reset
231 if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset
)) {
232 return EFI_UNSUPPORTED
;
234 *ResetType
= EfiResetWarm
;
237 // For non-reset capsule image.
239 *ResetType
= EfiResetCold
;
243 // The support max capsule image size
245 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) != 0) {
246 *MaxiumCapsuleSize
= PcdGet32(PcdMaxSizePopulateCapsule
);
248 *MaxiumCapsuleSize
= PcdGet32(PcdMaxSizeNonPopulateCapsule
);
257 This code installs UEFI capsule runtime service.
259 @param ImageHandle The firmware allocated handle for the EFI image.
260 @param SystemTable A pointer to the EFI System Table.
262 @retval EFI_SUCCESS UEFI Capsule Runtime Services are installed successfully.
267 CapsuleServiceInitialize (
268 IN EFI_HANDLE ImageHandle
,
269 IN EFI_SYSTEM_TABLE
*SystemTable
273 EFI_HANDLE NewHandle
;
276 // Install capsule runtime services into UEFI runtime service tables.
278 gRT
->UpdateCapsule
= UpdateCapsule
;
279 gRT
->QueryCapsuleCapabilities
= QueryCapsuleCapabilities
;
282 // Install the Capsule Architectural Protocol on a new handle
283 // to signify the capsule runtime services are ready.
287 Status
= gBS
->InstallMultipleProtocolInterfaces (
289 &gEfiCapsuleArchProtocolGuid
,
293 ASSERT_EFI_ERROR (Status
);