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"
24 extern EFI_GUID gEfiCapsuleGuid
;
29 IN UEFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
30 IN UINTN CapsuleCount
,
31 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
37 This code finds whether the capsules need reset to update, if not, update immediately.
41 CapsuleHeaderArray A array of pointers to capsule headers passed in
42 CapsuleCount The number of capsule
43 ScatterGatherList Physical address of datablock list points to capsule
48 EFI_SUCCESS Valid capsule was passed.If CAPSULE_FLAG_PERSIT_ACROSS_RESET is
49 not set, the capsule has been successfully processed by the firmware.
50 If it set, the ScattlerGatherList is successfully to be set.
51 EFI_INVALID_PARAMETER CapsuleCount is less than 1,CapsuleGuid is not supported.
52 EFI_DEVICE_ERROR Failed to SetVariable or AllocatePool or ProcessFirmwareVolume.
61 UEFI_CAPSULE_HEADER
*CapsuleHeader
;
63 if (CapsuleCount
< 1) {
64 return EFI_INVALID_PARAMETER
;
71 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET
72 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.
74 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
75 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
76 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
77 return EFI_INVALID_PARAMETER
;
79 if (!CompareGuid (&CapsuleHeader
->CapsuleGuid
, &gEfiCapsuleGuid
)) {
80 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) {
81 return EFI_UNSUPPORTED
;
87 //Assume that capsules have the same flags on reseting or not.
89 CapsuleHeader
= CapsuleHeaderArray
[0];
91 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
93 //Check if the platform supports update capsule across a system reset
95 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
96 return EFI_UNSUPPORTED
;
99 if (ScatterGatherList
== 0) {
100 return EFI_INVALID_PARAMETER
;
102 Status
= EfiSetVariable (
103 EFI_CAPSULE_VARIABLE_NAME
,
104 &gEfiCapsuleVendorGuid
,
105 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
107 (VOID
*) &ScatterGatherList
109 if (Status
!= EFI_SUCCESS
) {
110 return EFI_DEVICE_ERROR
;
117 //The rest occurs in the condition of non-reset mode
119 if (EfiAtRuntime ()) {
120 return EFI_INVALID_PARAMETER
;
124 //Here should be in the boot-time
126 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
127 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
128 CapsuleSize
= CapsuleHeader
->CapsuleImageSize
- CapsuleHeader
->HeaderSize
;
130 BufferPtr
= AllocatePool (CapsuleSize
);
131 if (BufferPtr
== NULL
) {
132 return EFI_DEVICE_ERROR
;
135 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 FreePool (BufferPtr
);
143 return EFI_DEVICE_ERROR
;
146 FreePool (BufferPtr
);
156 QueryCapsuleCapabilities (
157 IN UEFI_CAPSULE_HEADER
**CapsuleHeaderArray
,
158 IN UINTN CapsuleCount
,
159 OUT UINT64
*MaxiumCapsuleSize
,
160 OUT EFI_RESET_TYPE
*ResetType
166 This code is to query about capsule capability.
170 CapsuleHeaderArray A array of pointers to capsule headers passed in
171 CapsuleCount The number of capsule
172 MaxiumCapsuleSize Max capsule size is supported
173 ResetType Reset type the capsule indicates, if reset is not needed,return EfiResetCold.
174 If reset is needed, return EfiResetWarm.
179 EFI_SUCCESS Valid answer returned
180 EFI_INVALID_PARAMETER MaxiumCapsuleSize is NULL,ResetType is NULL.CapsuleCount is less than 1,CapsuleGuid is not supported.
181 EFI_UNSUPPORTED The capsule type is not supported.
186 UEFI_CAPSULE_HEADER
*CapsuleHeader
;
188 if (CapsuleCount
< 1) {
189 return EFI_INVALID_PARAMETER
;
192 if ((MaxiumCapsuleSize
== NULL
) ||(ResetType
== NULL
)) {
193 return EFI_INVALID_PARAMETER
;
196 CapsuleHeader
= NULL
;
199 //Compare GUIDs with EFI_CAPSULE_GUID, if capsule header contains CAPSULE_FLAGS_PERSIST_ACROSS_RESET
200 //and CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE flags,whatever the GUID is ,the service supports.
202 for (ArrayNumber
= 0; ArrayNumber
< CapsuleCount
; ArrayNumber
++) {
203 CapsuleHeader
= CapsuleHeaderArray
[ArrayNumber
];
204 if ((CapsuleHeader
->Flags
& (CAPSULE_FLAGS_PERSIST_ACROSS_RESET
| CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
)) == CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) {
205 return EFI_INVALID_PARAMETER
;
207 if (!CompareGuid (&CapsuleHeader
->CapsuleGuid
, &gEfiCapsuleGuid
)) {
208 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE
) == 0) {
209 return EFI_UNSUPPORTED
;
215 //Assume that capsules have the same flags on reseting or not.
217 CapsuleHeader
= CapsuleHeaderArray
[0];
218 if ((CapsuleHeader
->Flags
& CAPSULE_FLAGS_PERSIST_ACROSS_RESET
) != 0) {
220 //Check if the platform supports update capsule across a system reset
222 if (!FeaturePcdGet(PcdSupportUpdateCapsuleRest
)) {
223 return EFI_UNSUPPORTED
;
225 *ResetType
= EfiResetWarm
;
226 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizePopulateCapsule
);
228 *ResetType
= EfiResetCold
;
229 *MaxiumCapsuleSize
= FixedPcdGet32(PcdMaxSizeNonPopulateCapsule
);