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
++) {
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
;
73 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) {
74 return EFI_UNSUPPORTED
;
79 //Assume that capsules have the same flags on reseting or not.
81 CapsuleHeader
= CapsuleHeaderArray
[0];
83 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
85 //Check if the platform supports update capsule across a system reset
87 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
88 return EFI_UNSUPPORTED
;
91 if (ScatterGatherList
== 0) {
92 return EFI_INVALID_PARAMETER
;
94 Status
= EfiSetVariable (
95 EFI_CAPSULE_VARIABLE_NAME
,
96 &gEfiCapsuleVendorGuid
,
97 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
99 (VOID
*) &ScatterGatherList
101 if (Status
!= EFI_SUCCESS
) {
102 return EFI_DEVICE_ERROR
;
109 //The rest occurs in the condition of non-reset mode
111 if (EfiAtRuntime ()) {
112 return EFI_INVALID_PARAMETER
;
116 //Here should be in the boot-time
118 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
119 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
120 CapsuleSize
= CapsuleHeader
->CapsuleImageSize
- CapsuleHeader
->HeaderSize
;
122 BufferPtr
= AllocatePool (CapsuleSize
);
123 if (BufferPtr
== NULL
) {
124 return EFI_DEVICE_ERROR
;
127 CopyMem (BufferPtr
, (UINT8
*)CapsuleHeader
+ CapsuleHeader
->HeaderSize
, CapsuleSize
);
130 //Call DXE service ProcessFirmwareVolume to process immediatelly
132 Status
= gDS
->ProcessFirmwareVolume (BufferPtr
, CapsuleSize
, &FvHandle
);
133 if (Status
!= EFI_SUCCESS
) {
134 FreePool (BufferPtr
);
135 return EFI_DEVICE_ERROR
;
138 FreePool (BufferPtr
);
148 QueryCapsuleCapabilities (
149 IN EFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
150 IN UINTN CapsuleCount
,
151 OUT UINT64
*MaxiumCapsuleSize
,
152 OUT EFI_RESET_TYPE
*ResetType
158 This code is to query about capsule capability.
162 CapsuleHeaderArray A array of pointers to capsule headers passed in
163 CapsuleCount The number of capsule
164 MaxiumCapsuleSize Max capsule size is supported
165 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.
166 If reset is needed, return EfiResetWarm.
171 EFI_SUCCESS Valid answer returned
172 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.
173 EFI_UNSUPPORTED The capsule type is not supported.
178 EFI_CAPSULE_HEADER
*CapsuleHeader
;
180 if (CapsuleCount
< 1) {
181 return EFI_INVALID_PARAMETER
;
184 if ((MaxiumCapsuleSize
== NULL
) ||(ResetType
== NULL
)) {
185 return EFI_INVALID_PARAMETER
;
188 CapsuleHeader
= NULL
;
190 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
191 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
192 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
193 return EFI_INVALID_PARAMETER
;
195 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) {
196 return EFI_UNSUPPORTED
;
201 //Assume that capsules have the same flags on reseting or not.
203 CapsuleHeader
= CapsuleHeaderArray
[0];
204 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
206 //Check if the platform supports update capsule across a system reset
208 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
209 return EFI_UNSUPPORTED
;
211 *ResetType
= EfiResetWarm
;
212 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizePopulateCapsule
);
214 *ResetType
= EfiResetCold
;
215 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizeNonPopulateCapsule
);
223 CapsuleServiceInitialize (
224 IN EFI_HANDLE ImageHandle
,
225 IN EFI_SYSTEM_TABLE
*SystemTable
231 This code is capsule runtime service initialization.
235 ImageHandle The image handle
236 SystemTable The system table.
245 EFI_HANDLE NewHandle
;
247 SystemTable
->RuntimeServices
->UpdateCapsule
= UpdateCapsule
;
248 SystemTable
->RuntimeServices
->QueryCapsuleCapabilities
= QueryCapsuleCapabilities
;
251 // Now install the Capsule Architectural Protocol on a new handle
255 Status
= gBS
->InstallMultipleProtocolInterfaces (
257 &gEfiCapsuleArchProtocolGuid
,
261 ASSERT_EFI_ERROR (Status
);