3 Copyright (c) 2006, 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"
25 STATIC EFI_GUID mEfiCapsuleHeaderGuid
= EFI_CAPSULE_GUID
;
31 IN UEFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
32 IN UINTN CapsuleCount
,
33 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
39 This code finds whether the capsules need reset to update, if not, update immediately.
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
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.
63 UEFI_CAPSULE_HEADER
*CapsuleHeader
;
65 if (CapsuleCount
< 1) {
66 return EFI_INVALID_PARAMETER
;
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.
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
;
81 if (!CompareGuid (&CapsuleHeader
->CapsuleGuid
, &mEfiCapsuleHeaderGuid
)) {
82 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) {
83 return EFI_UNSUPPORTED
;
89 //Assume that capsules have the same flags on reseting or not.
91 CapsuleHeader
= CapsuleHeaderArray
[0];
93 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
95 //Check if the platform supports update capsule across a system reset
97 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
98 return EFI_UNSUPPORTED
;
101 if (ScatterGatherList
== 0) {
102 return EFI_INVALID_PARAMETER
;
104 Status
= EfiSetVariable (
105 EFI_CAPSULE_VARIABLE_NAME
,
106 &gEfiCapsuleVendorGuid
,
107 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
109 (VOID
*) &ScatterGatherList
111 if (Status
!= EFI_SUCCESS
) {
112 return EFI_DEVICE_ERROR
;
119 //The rest occurs in the condition of non-reset mode
121 if (EfiAtRuntime ()) {
122 return EFI_INVALID_PARAMETER
;
126 //Here should be in the boot-time
128 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
129 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
130 CapsuleSize
= CapsuleHeader
->CapsuleImageSize
- CapsuleHeader
->HeaderSize
;
131 Status
= gBS
->AllocatePool (EfiBootServicesData
, CapsuleSize
, &BufferPtr
);
132 if (Status
!= EFI_SUCCESS
) {
135 gBS
->CopyMem (BufferPtr
, (UINT8
*)CapsuleHeader
+ CapsuleHeader
->HeaderSize
, CapsuleSize
);
138 //Call DXE service ProcessFirmwareVolume to process immediatelly
140 Status
= gDS
->ProcessFirmwareVolume (BufferPtr
, CapsuleSize
, &FvHandle
);
141 if (Status
!= EFI_SUCCESS
) {
142 gBS
->FreePool (BufferPtr
);
143 return EFI_DEVICE_ERROR
;
146 gBS
->FreePool (BufferPtr
);
151 if (BufferPtr
!= NULL
) {
152 gBS
->FreePool (BufferPtr
);
154 return EFI_DEVICE_ERROR
;
161 QueryCapsuleCapabilities (
162 IN UEFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
163 IN UINTN CapsuleCount
,
164 OUT UINT64
*MaxiumCapsuleSize
,
165 OUT EFI_RESET_TYPE
*ResetType
171 This code is to query about capsule capability.
175 CapsuleHeaderArray A array of pointers to capsule headers passed in
176 CapsuleCount The number of capsule
177 MaxiumCapsuleSize Max capsule size is supported
178 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.
179 If reset is needed, return EfiResetWarm.
184 EFI_SUCCESS Valid answer returned
185 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.
186 EFI_UNSUPPORTED The capsule type is not supported.
191 UEFI_CAPSULE_HEADER
*CapsuleHeader
;
193 if (CapsuleCount
< 1) {
194 return EFI_INVALID_PARAMETER
;
197 if ((MaxiumCapsuleSize
== NULL
) ||(ResetType
== NULL
)) {
198 return EFI_INVALID_PARAMETER
;
201 CapsuleHeader
= NULL
;
204 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET
205 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.
207 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
208 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
209 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
210 return EFI_INVALID_PARAMETER
;
212 if (!CompareGuid (&CapsuleHeader
->CapsuleGuid
, &mEfiCapsuleHeaderGuid
)) {
213 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) {
214 return EFI_UNSUPPORTED
;
220 //Assume that capsules have the same flags on reseting or not.
222 CapsuleHeader
= CapsuleHeaderArray
[0];
223 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
225 //Check if the platform supports update capsule across a system reset
227 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
228 return EFI_UNSUPPORTED
;
230 *ResetType
= EfiResetWarm
;
231 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizePopulateCapsule
);
233 *ResetType
= EfiResetCold
;
234 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizeNonPopulateCapsule
);