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 AllocatePool or ProcessFirmwareVolume.
59 EFI_CAPSULE_HEADER
*CapsuleHeader
;
61 if (CapsuleCount
< 1) {
62 return EFI_INVALID_PARAMETER
;
68 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
70 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have
71 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.
73 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
74 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
75 return EFI_INVALID_PARAMETER
;
78 // To remove this check. Capsule update supports non reset image.
80 // if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {
81 // return EFI_UNSUPPORTED;
86 // Check capsule guid is suppored by this platform. To do
90 //Assume that capsules have the same flags on reseting or not.
92 CapsuleHeader
= CapsuleHeaderArray
[0];
94 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
96 //Check if the platform supports update capsule across a system reset
98 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
99 return EFI_UNSUPPORTED
;
102 // ScatterGatherList is only referenced if the capsules are defined to persist across
105 if (ScatterGatherList
== (EFI_PHYSICAL_ADDRESS
) NULL
) {
106 return EFI_INVALID_PARAMETER
;
109 // ScatterGatherList is only referenced if the capsules are defined to persist across
110 // system reset. Set its value into NV storage to let pre-boot driver to pick it up
111 // after coming through a system reset.
113 Status
= EfiSetVariable (
114 EFI_CAPSULE_VARIABLE_NAME
,
115 &gEfiCapsuleVendorGuid
,
116 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
118 (VOID
*) &ScatterGatherList
120 if (Status
!= EFI_SUCCESS
) {
128 // The rest occurs in the condition of non-reset mode
129 // Current Runtime mode doesn't support the non-reset capsule image.
131 if (EfiAtRuntime ()) {
132 return EFI_INVALID_PARAMETER
;
136 // Here should be in the boot-time for non-reset capsule image
137 // Default process to Update Capsule image into Flash for any guid image.
139 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
140 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
141 CapsuleSize
= CapsuleHeader
->CapsuleImageSize
- CapsuleHeader
->HeaderSize
;
143 BufferPtr
= AllocatePool (CapsuleSize
);
144 if (BufferPtr
== NULL
) {
145 return EFI_OUT_OF_RESOURCES
;
148 CopyMem (BufferPtr
, (UINT8
*)CapsuleHeader
+ CapsuleHeader
->HeaderSize
, CapsuleSize
);
151 //Call DXE service ProcessFirmwareVolume to process immediatelly
153 Status
= gDS
->ProcessFirmwareVolume (BufferPtr
, CapsuleSize
, &FvHandle
);
154 if (Status
!= EFI_SUCCESS
) {
155 FreePool (BufferPtr
);
159 FreePool (BufferPtr
);
169 QueryCapsuleCapabilities (
170 IN EFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
171 IN UINTN CapsuleCount
,
172 OUT UINT64
*MaxiumCapsuleSize
,
173 OUT EFI_RESET_TYPE
*ResetType
179 This code is to query about capsule capability.
183 CapsuleHeaderArray A array of pointers to capsule headers passed in
184 CapsuleCount The number of capsule
185 MaxiumCapsuleSize Max capsule size is supported
186 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.
187 If reset is needed, return EfiResetWarm.
192 EFI_SUCCESS Valid answer returned
193 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.
194 EFI_UNSUPPORTED The capsule type is not supported.
199 EFI_CAPSULE_HEADER
*CapsuleHeader
;
201 if (CapsuleCount
< 1) {
202 return EFI_INVALID_PARAMETER
;
205 if ((MaxiumCapsuleSize
== NULL
) ||(ResetType
== NULL
)) {
206 return EFI_INVALID_PARAMETER
;
209 CapsuleHeader
= NULL
;
211 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
212 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
214 // A capsule which has the CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flag must have
215 // CAPSULE_FLAGS_PERSIST_ACROSS_RESET set in its header as well.
217 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
218 return EFI_INVALID_PARAMETER
;
221 // To remove this check. Capsule update supports non reset image.
223 // if ((CapsuleHeader->Flags & CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE) == 0) {
224 // return EFI_UNSUPPORTED;
229 //Assume that capsules have the same flags on reseting or not.
231 CapsuleHeader
= CapsuleHeaderArray
[0];
232 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
234 //Check if the platform supports update capsule across a system reset
236 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
237 return EFI_UNSUPPORTED
;
239 *ResetType
= EfiResetWarm
;
240 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizePopulateCapsule
);
242 *ResetType
= EfiResetCold
;
243 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizeNonPopulateCapsule
);
251 CapsuleServiceInitialize (
252 IN EFI_HANDLE ImageHandle
,
253 IN EFI_SYSTEM_TABLE
*SystemTable
259 This code is capsule runtime service initialization.
263 ImageHandle The image handle
264 SystemTable The system table.
273 EFI_HANDLE NewHandle
;
275 SystemTable
->RuntimeServices
->UpdateCapsule
= UpdateCapsule
;
276 SystemTable
->RuntimeServices
->QueryCapsuleCapabilities
= QueryCapsuleCapabilities
;
279 // Now install the Capsule Architectural Protocol on a new handle
283 Status
= gBS
->InstallMultipleProtocolInterfaces (
285 &gEfiCapsuleArchProtocolGuid
,
289 ASSERT_EFI_ERROR (Status
);