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
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.
18 Capsule Runtime Service.
22 #include "CapsuleService.h"
27 IN EFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
28 IN UINTN CapsuleCount
,
29 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
35 This code finds whether the capsules need reset to update, if not, update immediately.
39 CapsuleHeaderArray A array of pointers to capsule headers passed in
40 CapsuleCount The number of capsule
41 ScatterGatherList Physical address of datablock list points to capsule
46 EFI_SUCCESS Valid capsule was passed.If CAPSULE_FLAG_PERSIT_ACROSS_RESET is
47 not set, the capsule has been successfully processed by the firmware.
48 If it set, the ScattlerGatherList is successfully to be set.
49 EFI_INVALID_PARAMETER CapsuleCount is less than 1,CapsuleGuid is not supported.
50 EFI_DEVICE_ERROR Failed to SetVariable or ProcessFirmwareVolume.
56 EFI_CAPSULE_HEADER
*CapsuleHeader
;
58 if (CapsuleCount
< 1) {
59 return EFI_INVALID_PARAMETER
;
64 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
66 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have
67 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.
69 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
70 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
71 return EFI_INVALID_PARAMETER
;
74 // Check Capsule image without populate flag by firmware support capsule function
76 if (((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) &&
77 (SupportCapsuleImage (CapsuleHeader
) != EFI_SUCCESS
)) {
78 return EFI_UNSUPPORTED
;
83 // Assume that capsules have the same flags on reseting or not.
85 CapsuleHeader
= CapsuleHeaderArray
[0];
87 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
89 // Check if the platform supports update capsule across a system reset
91 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
92 return EFI_UNSUPPORTED
;
95 // ScatterGatherList is only referenced if the capsules are defined to persist across
98 if (ScatterGatherList
== (EFI_PHYSICAL_ADDRESS
) (UINTN
) NULL
) {
99 return EFI_INVALID_PARAMETER
;
102 // ScatterGatherList is only referenced if the capsules are defined to persist across
103 // system reset. Set its value into NV storage to let pre-boot driver to pick it up
104 // after coming through a system reset.
106 Status
= EfiSetVariable (
107 EFI_CAPSULE_VARIABLE_NAME
,
108 &gEfiCapsuleVendorGuid
,
109 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
111 (VOID
*) &ScatterGatherList
113 if (Status
!= EFI_SUCCESS
) {
117 // Successfully set the capsule image address into variable.
124 // The rest occurs in the condition of non-reset mode
125 // Now Runtime mode doesn't support the non-reset capsule image.
127 if (EfiAtRuntime ()) {
128 return EFI_UNSUPPORTED
;
132 // Here should be in the boot-time for non-reset capsule image
133 // Default process to Update Capsule image into Flash.
135 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
136 Status
= ProcessCapsuleImage (CapsuleHeaderArray
[ArrayNumber
]);
137 if (EFI_ERROR (Status
)) {
149 QueryCapsuleCapabilities (
150 IN EFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
151 IN UINTN CapsuleCount
,
152 OUT UINT64
*MaxiumCapsuleSize
,
153 OUT EFI_RESET_TYPE
*ResetType
159 This code is to query about capsule capability.
163 CapsuleHeaderArray A array of pointers to capsule headers passed in
164 CapsuleCount The number of capsule
165 MaxiumCapsuleSize Max capsule size is supported
166 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.
167 If reset is needed, return EfiResetWarm.
172 EFI_SUCCESS Valid answer returned
173 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.
174 EFI_UNSUPPORTED The capsule type is not supported.
179 EFI_CAPSULE_HEADER
*CapsuleHeader
;
181 if (CapsuleCount
< 1) {
182 return EFI_INVALID_PARAMETER
;
185 if ((MaxiumCapsuleSize
== NULL
) ||(ResetType
== NULL
)) {
186 return EFI_INVALID_PARAMETER
;
189 CapsuleHeader
= NULL
;
191 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
192 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
194 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have
195 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.
197 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
198 return EFI_INVALID_PARAMETER
;
201 // Check Capsule image without populate flag by firmware support capsule function
203 if (((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) &&
204 (SupportCapsuleImage (CapsuleHeader
) != EFI_SUCCESS
)) {
205 return EFI_UNSUPPORTED
;
210 //Assume that capsules have the same flags on reseting or not.
212 CapsuleHeader
= CapsuleHeaderArray
[0];
213 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
215 //Check if the platform supports update capsule across a system reset
217 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
218 return EFI_UNSUPPORTED
;
220 *ResetType
= EfiResetWarm
;
221 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizePopulateCapsule
);
223 *ResetType
= EfiResetCold
;
224 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizeNonPopulateCapsule
);
232 CapsuleServiceInitialize (
233 IN EFI_HANDLE ImageHandle
,
234 IN EFI_SYSTEM_TABLE
*SystemTable
240 This code is capsule runtime service initialization.
244 ImageHandle The image handle
245 SystemTable The system table.
254 EFI_HANDLE NewHandle
;
256 SystemTable
->RuntimeServices
->UpdateCapsule
= UpdateCapsule
;
257 SystemTable
->RuntimeServices
->QueryCapsuleCapabilities
= QueryCapsuleCapabilities
;
260 // Now install the Capsule Architectural Protocol on a new handle
264 Status
= gBS
->InstallMultipleProtocolInterfaces (
266 &gEfiCapsuleArchProtocolGuid
,
270 ASSERT_EFI_ERROR (Status
);