]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.c
Rename Crc32GuidedSectionExtractLib to DxeCrc32GuidedSectionExtractLib.
[mirror_edk2.git] / MdeModulePkg / Library / DxeCrc32GuidedSectionExtractLib / DxeCrc32GuidedSectionExtractLib.c
CommitLineData
d51ffc1f
LG
1/*++\r
2\r
3Copyright (c) 2007, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 DxeCrc32GuidedSectionExtractLib.c\r
15\r
16Abstract:\r
17\r
18 Implements GUIDed section extraction protocol interface with \r
19 a specific GUID: CRC32.\r
20\r
21 Please refer to the Framewokr Firmware Volume Specification 0.9.\r
22\r
23--*/\r
24\r
25#include <PiDxe.h>\r
26#include <Protocol/Crc32GuidedSectionExtraction.h>\r
27#include <Protocol/SecurityPolicy.h>\r
28#include <Library/ExtractGuidedSectionLib.h>\r
29#include <Library/DebugLib.h>\r
30#include <Library/UefiBootServicesTableLib.h>\r
31\r
32typedef struct {\r
33 EFI_GUID_DEFINED_SECTION GuidedSectionHeader;\r
34 UINT32 CRC32Checksum;\r
35} CRC32_SECTION_HEADER;\r
36\r
37EFI_STATUS\r
38EFIAPI\r
39Crc32GuidedSectionGetInfo (\r
40 IN CONST VOID *InputSection,\r
41 OUT UINT32 *OutputBufferSize,\r
42 OUT UINT32 *ScratchBufferSize,\r
43 OUT UINT16 *SectionAttribute\r
44 )\r
45/*++\r
46\r
47Routine Description:\r
48\r
49 The implementation of Crc32 guided section GetInfo().\r
50\r
51Arguments:\r
52 InputSection Buffer containing the input GUIDed section to be processed. \r
53 OutputBufferSize The size of OutputBuffer.\r
54 ScratchBufferSize The size of ScratchBuffer.\r
55 SectionAttribute The attribute of the input guided section.\r
56\r
57Returns:\r
58\r
59 EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.\r
60 EFI_INVALID_PARAMETER - The source data is corrupted\r
61\r
62--*/\r
63{\r
64 //\r
65 // Retrieve the size and attribute of the input section data.\r
66 //\r
67 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
68 *ScratchBufferSize = 0;\r
69 *OutputBufferSize = *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff;\r
70 *OutputBufferSize -= ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset;\r
71\r
72 return EFI_SUCCESS;\r
73}\r
74\r
75EFI_STATUS\r
76EFIAPI\r
77Crc32GuidedSectionHandler (\r
78 IN CONST VOID *InputSection,\r
79 OUT VOID **OutputBuffer,\r
80 IN VOID *ScratchBuffer, OPTIONAL\r
81 OUT UINT32 *AuthenticationStatus\r
82 )\r
83/*++\r
84\r
85Routine Description:\r
86\r
87 The implementation of Crc32 Guided section extraction.\r
88\r
89Arguments:\r
90 InputSection Buffer containing the input GUIDed section to be processed. \r
91 OutputBuffer OutputBuffer to point to the start of the section's contents.\r
92 if guided data is not prcessed. Otherwise,\r
93 OutputBuffer to contain the output data, which is allocated by the caller.\r
94 ScratchBuffer A pointer to a caller-allocated buffer for function internal use. \r
95 AuthenticationStatus A pointer to a caller-allocated UINT32 that indicates the\r
96 authentication status of the output buffer.
97\r
98Returns:\r
99\r
100 EFI_SUCCESS - Decompression is successfull\r
101 EFI_INVALID_PARAMETER - The source data is corrupted\r
102\r
103--*/\r
104{\r
105 EFI_STATUS Status;\r
106 CRC32_SECTION_HEADER *Crc32SectionHeader;\r
107 UINT32 Crc32Checksum;\r
108 UINT32 OutputBufferSize;\r
109 VOID *DummyInterface;\r
110\r
111 Crc32Checksum = 0;\r
112 //\r
113 // Points to the Crc32 section header\r
114 //\r
115 Crc32SectionHeader = (CRC32_SECTION_HEADER *) InputSection;\r
116 *OutputBuffer = (UINT8 *) InputSection + Crc32SectionHeader->GuidedSectionHeader.DataOffset;\r
117 OutputBufferSize = *(UINT32 *) (((EFI_COMMON_SECTION_HEADER *) InputSection)->Size) & 0x00ffffff; \r
118 OutputBufferSize -= Crc32SectionHeader->GuidedSectionHeader.DataOffset;\r
119\r
120 //\r
121 // Implictly CRC32 GUIDed section should have STATUS_VALID bit set\r
122 //\r
123 ASSERT (Crc32SectionHeader->GuidedSectionHeader.Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID);\r
124 *AuthenticationStatus = EFI_AUTH_STATUS_IMAGE_SIGNED;\r
125\r
126 //\r
127 // Check whether there exists EFI_SECURITY_POLICY_PROTOCOL_GUID.\r
128 //\r
129 Status = gBS->LocateProtocol (&gEfiSecurityPolicyProtocolGuid, NULL, &DummyInterface);\r
130 if (!EFI_ERROR (Status)) {\r
131 *AuthenticationStatus |= EFI_AUTH_STATUS_PLATFORM_OVERRIDE;\r
132 } else {\r
133 //\r
134 // Calculate CRC32 Checksum of Image\r
135 //\r
136 Status = gBS->CalculateCrc32 (*OutputBuffer, OutputBufferSize, &Crc32Checksum);\r
137 if (Status == EFI_SUCCESS) {\r
138 if (Crc32Checksum != Crc32SectionHeader->CRC32Checksum) {\r
139 *AuthenticationStatus |= EFI_AUTH_STATUS_TEST_FAILED;\r
140 }\r
141 } else {\r
142 *AuthenticationStatus |= EFI_AUTH_STATUS_NOT_TESTED;\r
143 }\r
144 }\r
145\r
146 return EFI_SUCCESS;\r
147}\r
148\r
149/**
150 Register Crc32 section handler.\r
151
152 @retval RETURN_SUCCESS Register successfully.\r
153 @retval RETURN_OUT_OF_RESOURCES No enough memory to store this handler.
154**/\r
155EFI_STATUS\r
156EFIAPI\r
157DxeCrc32GuidedSectionExtractLibConstructor (\r
158 )\r
159{\r
160 return ExtractGuidedSectionRegisterHandlers (\r
161 &gEfiCrc32GuidedSectionExtractionProtocolGuid,\r
162 Crc32GuidedSectionGetInfo,\r
163 Crc32GuidedSectionHandler\r
164 );\r
165}\r
166\r