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"
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
;
132 BufferPtr
= AllocatePool (CapsuleSize
);
133 if (BufferPtr
== NULL
) {
134 return EFI_DEVICE_ERROR
;
137 CopyMem (BufferPtr
, (UINT8
*)CapsuleHeader
+ CapsuleHeader
->HeaderSize
, CapsuleSize
);
140 //Call DXE service ProcessFirmwareVolume to process immediatelly
142 Status
= gDS
->ProcessFirmwareVolume (BufferPtr
, CapsuleSize
, &FvHandle
);
143 if (Status
!= EFI_SUCCESS
) {
144 FreePool (BufferPtr
);
145 return EFI_DEVICE_ERROR
;
148 FreePool (BufferPtr
);
158 QueryCapsuleCapabilities (
159 IN UEFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
160 IN UINTN CapsuleCount
,
161 OUT UINT64
*MaxiumCapsuleSize
,
162 OUT EFI_RESET_TYPE
*ResetType
168 This code is to query about capsule capability.
172 CapsuleHeaderArray A array of pointers to capsule headers passed in
173 CapsuleCount The number of capsule
174 MaxiumCapsuleSize Max capsule size is supported
175 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.
176 If reset is needed, return EfiResetWarm.
181 EFI_SUCCESS Valid answer returned
182 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.
183 EFI_UNSUPPORTED The capsule type is not supported.
188 UEFI_CAPSULE_HEADER
*CapsuleHeader
;
190 if (CapsuleCount
< 1) {
191 return EFI_INVALID_PARAMETER
;
194 if ((MaxiumCapsuleSize
== NULL
) ||(ResetType
== NULL
)) {
195 return EFI_INVALID_PARAMETER
;
198 CapsuleHeader
= NULL
;
201 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET
202 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.
204 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
205 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
206 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
207 return EFI_INVALID_PARAMETER
;
209 if (!CompareGuid (&CapsuleHeader
->CapsuleGuid
, &mEfiCapsuleHeaderGuid
)) {
210 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) {
211 return EFI_UNSUPPORTED
;
217 //Assume that capsules have the same flags on reseting or not.
219 CapsuleHeader
= CapsuleHeaderArray
[0];
220 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
222 //Check if the platform supports update capsule across a system reset
224 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
225 return EFI_UNSUPPORTED
;
227 *ResetType
= EfiResetWarm
;
228 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizePopulateCapsule
);
230 *ResetType
= EfiResetCold
;
231 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizeNonPopulateCapsule
);