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