]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/DxeCapsuleLib/DxeCapsuleLib.c
Update code to pass build on VS2008 with /Od compiler option.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / DxeCapsuleLib / DxeCapsuleLib.c
1 /** @file
2 Capsule Library instance to update capsule image to flash.
3
4 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15 #include <PiDxe.h>
16 #include <Guid/Capsule.h>
17 #include <Library/DebugLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DxeServicesTableLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/CapsuleLib.h>
22
23 /**
24 Those capsules supported by the firmwares.
25
26 @param CapsuleHeader Points to a capsule header.
27
28 @retval EFI_SUCESS Input capsule is supported by firmware.
29 @retval EFI_UNSUPPORTED Input capsule is not supported by the firmware.
30 **/
31 EFI_STATUS
32 EFIAPI
33 SupportCapsuleImage (
34 IN EFI_CAPSULE_HEADER *CapsuleHeader
35 )
36 {
37 if (CompareGuid (&gEfiCapsuleGuid, &CapsuleHeader->CapsuleGuid)) {
38 return EFI_SUCCESS;
39 }
40
41 return EFI_UNSUPPORTED;
42 }
43
44 /**
45 The firmware implements to process the capsule image.
46
47 @param CapsuleHeader Points to a capsule header.
48
49 @retval EFI_SUCESS Process Capsule Image successfully.
50 @retval EFI_UNSUPPORTED Capsule image is not supported by the firmware.
51 @retval EFI_VOLUME_CORRUPTED FV volume in the capsule is corrupted.
52 @retval EFI_OUT_OF_RESOURCES Not enough memory.
53 **/
54 EFI_STATUS
55 EFIAPI
56 ProcessCapsuleImage (
57 IN EFI_CAPSULE_HEADER *CapsuleHeader
58 )
59 {
60 UINT32 Length;
61 EFI_FIRMWARE_VOLUME_HEADER *FvImage;
62 EFI_FIRMWARE_VOLUME_HEADER *ProcessedFvImage;
63 EFI_STATUS Status;
64 EFI_HANDLE FvProtocolHandle;
65 UINT32 FvAlignment;
66
67 FvImage = NULL;
68 ProcessedFvImage = NULL;
69 Status = EFI_SUCCESS;
70
71 if (SupportCapsuleImage (CapsuleHeader) != EFI_SUCCESS) {
72 return EFI_UNSUPPORTED;
73 }
74
75 //
76 // Skip the capsule header, move to the Firware Volume
77 //
78 FvImage = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINT8 *) CapsuleHeader + CapsuleHeader->HeaderSize);
79 Length = CapsuleHeader->CapsuleImageSize - CapsuleHeader->HeaderSize;
80
81 while (Length != 0) {
82 //
83 // Point to the next firmware volume header, and then
84 // call the DXE service to process it.
85 //
86 if (FvImage->FvLength > (UINTN) Length) {
87 //
88 // Notes: need to stuff this status somewhere so that the
89 // error can be detected at OS runtime
90 //
91 Status = EFI_VOLUME_CORRUPTED;
92 break;
93 }
94
95 FvAlignment = 1 << ((FvImage->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
96 //
97 // FvAlignment must be more than 8 bytes required by FvHeader structure.
98 //
99 if (FvAlignment < 8) {
100 FvAlignment = 8;
101 }
102 //
103 // Check FvImage Align is required.
104 //
105 if (((UINTN) FvImage % FvAlignment) == 0) {
106 ProcessedFvImage = FvImage;
107 } else {
108 //
109 // Allocate new aligned buffer to store FvImage.
110 //
111 ProcessedFvImage = (EFI_FIRMWARE_VOLUME_HEADER *) AllocateAlignedPages ((UINTN) EFI_SIZE_TO_PAGES ((UINTN) FvImage->FvLength), (UINTN) FvAlignment);
112 if (ProcessedFvImage == NULL) {
113 Status = EFI_OUT_OF_RESOURCES;
114 break;
115 }
116 CopyMem (ProcessedFvImage, FvImage, (UINTN) FvImage->FvLength);
117 }
118
119 Status = gDS->ProcessFirmwareVolume (
120 (VOID *) ProcessedFvImage,
121 (UINTN) ProcessedFvImage->FvLength,
122 &FvProtocolHandle
123 );
124 if (EFI_ERROR (Status)) {
125 break;
126 }
127 //
128 // Call the dispatcher to dispatch any drivers from the produced firmware volume
129 //
130 gDS->Dispatch ();
131 //
132 // On to the next FV in the capsule
133 //
134 Length -= (UINT32) FvImage->FvLength;
135 FvImage = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINT8 *) FvImage + FvImage->FvLength);
136 }
137
138 return Status;
139 }
140
141