]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/PlatformBdsDxe/Generic/Capsules.c
b1a6c6e7e92d59af155765c880cd71e8637bd3de
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / Generic / Capsules.c
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 Capsules.c
15
16 Abstract:
17
18 BDS routines to handle capsules.
19
20 --*/
21
22
23 //
24 // Include common header file for this module.
25 //
26 #include "CommonHeader.h"
27
28 #include <Common/FlashMap.H>
29
30 VOID
31 BdsLockFv (
32 IN EFI_CPU_IO_PROTOCOL *CpuIo,
33 IN EFI_FLASH_SUBAREA_ENTRY *FlashEntry
34 );
35
36 VOID
37 BdsLockFv (
38 IN EFI_CPU_IO_PROTOCOL *CpuIo,
39 IN EFI_FLASH_SUBAREA_ENTRY *FlashEntry
40 )
41 {
42 }
43
44 VOID
45 BdsLockNonUpdatableFlash (
46 VOID
47 )
48 {
49 }
50
51 EFI_STATUS
52 ProcessCapsules (
53 EFI_BOOT_MODE BootMode
54 )
55 /*++
56
57 Routine Description:
58
59 This routine is called to see if there are any capsules we need to process.
60 If the boot mode is not UPDATE, then we do nothing. Otherwise find the
61 capsule HOBS and produce firmware volumes for them via the DXE service.
62 Then call the dispatcher to dispatch drivers from them. Finally, check
63 the status of the updates.
64
65 Arguments:
66
67 BootMode - the current boot mode
68
69 Returns:
70
71 EFI_INVALID_PARAMETER - boot mode is not correct for an update
72
73 Note:
74
75 This function should be called by BDS in case we need to do some
76 sort of processing even if there is no capsule to process. We
77 need to do this if an earlier update went awry and we need to
78 clear the capsule variable so on the next reset PEI does not see it and
79 think there is a capsule available.
80
81 --*/
82 {
83 EFI_STATUS Status;
84 EFI_HOB_CAPSULE_VOLUME *CvHob;
85 EFI_PHYSICAL_ADDRESS BaseAddress;
86 UINT64 Length;
87 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
88 EFI_HANDLE FvProtocolHandle;
89
90 //
91 // We don't do anything else if the boot mode is not flash-update
92 //
93 if (BootMode != BOOT_ON_FLASH_UPDATE) {
94 return EFI_INVALID_PARAMETER;
95 }
96 //
97 // Only one capsule HOB allowed.
98 //
99 CvHob = GetFirstHob (EFI_HOB_TYPE_CV);
100 if (CvHob == NULL) {
101 //
102 // We didn't find a hob, so had no errors.
103 //
104 BdsLockNonUpdatableFlash ();
105 return EFI_SUCCESS;
106 }
107
108 BaseAddress = CvHob->BaseAddress;
109 Length = CvHob->Length;
110
111 Status = EFI_SUCCESS;
112 //
113 // Now walk the capsule and call the core to process each
114 // firmware volume in it.
115 //
116 while (Length != 0) {
117 //
118 // Point to the next firmware volume header, and then
119 // call the DXE service to process it.
120 //
121 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;
122 if (FwVolHeader->FvLength > Length) {
123 //
124 // Notes: need to stuff this status somewhere so that the
125 // error can be detected at OS runtime
126 //
127 Status = EFI_VOLUME_CORRUPTED;
128 break;
129 }
130
131 Status = gDS->ProcessFirmwareVolume (
132 (VOID *) (UINTN) BaseAddress,
133 (UINTN) FwVolHeader->FvLength,
134 &FvProtocolHandle
135 );
136 if (EFI_ERROR (Status)) {
137 break;
138 }
139 //
140 // Call the dispatcher to dispatch any drivers from the produced firmware volume
141 //
142 gDS->Dispatch ();
143 //
144 // On to the next FV in the capsule
145 //
146 Length -= FwVolHeader->FvLength;
147 BaseAddress = (EFI_PHYSICAL_ADDRESS) ((UINTN) BaseAddress + FwVolHeader->FvLength);
148 //
149 // Notes: when capsule spec is finalized, if the requirement is made to
150 // have each FV in a capsule aligned, then we will need to align the
151 // BaseAddress and Length here.
152 //
153 }
154
155
156 BdsLockNonUpdatableFlash ();
157
158 return Status;
159 }
160