]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - FmpDevicePkg/Library/FmpPayloadHeaderLibV1/FmpPayloadHeaderLib.c
FmpDevicePkg: Add library instances
[mirror_edk2.git] / FmpDevicePkg / Library / FmpPayloadHeaderLibV1 / FmpPayloadHeaderLib.c
... / ...
CommitLineData
1/** @file\r
2 Provides services to retrieve values from Version 1 of a capsule's FMP Payload\r
3 Header. The FMP Payload Header structure is not defined in the library class.\r
4 Instead, services are provided to retrieve information from the FMP Payload\r
5 Header. If information is added to the FMP Payload Header, then new services\r
6 may be added to this library class to retrieve the new information.\r
7\r
8 Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>\r
9 Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
10\r
11 Redistribution and use in source and binary forms, with or without\r
12 modification, are permitted provided that the following conditions are met:\r
13 1. Redistributions of source code must retain the above copyright notice,\r
14 this list of conditions and the following disclaimer.\r
15 2. Redistributions in binary form must reproduce the above copyright notice,\r
16 this list of conditions and the following disclaimer in the documentation\r
17 and/or other materials provided with the distribution.\r
18\r
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
22 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\r
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\r
27 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
28 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
29\r
30**/\r
31\r
32#include <PiDxe.h>\r
33#include <Library/FmpPayloadHeaderLib.h>\r
34\r
35///\r
36/// Define FMP Payload Header structure here so it is not public\r
37///\r
38\r
39#pragma pack(1)\r
40\r
41typedef struct {\r
42 UINT32 Signature;\r
43 UINT32 HeaderSize;\r
44 UINT32 FwVersion;\r
45 UINT32 LowestSupportedVersion;\r
46} FMP_PAYLOAD_HEADER;\r
47\r
48#pragma pack()\r
49\r
50///\r
51/// Identifier is used to make sure the data in the header is for this structure\r
52/// and version. If the structure changes update the last digit.\r
53///\r
54#define FMP_PAYLOAD_HEADER_SIGNATURE SIGNATURE_32 ('M', 'S', 'S', '1')\r
55\r
56/**\r
57 Returns the FMP Payload Header size in bytes.\r
58\r
59 @param[in] Header FMP Payload Header to evaluate\r
60 @param[in] FmpPayloadSize Size of FMP payload\r
61 @param[out] Size The size, in bytes, of the FMP Payload Header.\r
62\r
63 @retval EFI_SUCCESS The firmware version was returned.\r
64 @retval EFI_INVALID_PARAMETER Header is NULL.\r
65 @retval EFI_INVALID_PARAMETER Size is NULL.\r
66 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.\r
67\r
68**/\r
69EFI_STATUS\r
70EFIAPI\r
71GetFmpPayloadHeaderSize (\r
72 IN CONST VOID *Header,\r
73 IN CONST UINTN FmpPayloadSize,\r
74 OUT UINT32 *Size\r
75 )\r
76{\r
77 FMP_PAYLOAD_HEADER *FmpPayloadHeader;\r
78\r
79 FmpPayloadHeader = NULL;\r
80\r
81 if (Header == NULL || Size == NULL) {\r
82 return EFI_INVALID_PARAMETER;\r
83 }\r
84\r
85 FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;\r
86 if ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader ||\r
87 (UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize ||\r
88 FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)) {\r
89 return EFI_INVALID_PARAMETER;\r
90 }\r
91\r
92 if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {\r
93 return EFI_INVALID_PARAMETER;\r
94 }\r
95\r
96 *Size = FmpPayloadHeader->HeaderSize;\r
97 return EFI_SUCCESS;\r
98}\r
99\r
100/**\r
101 Returns the version described in the FMP Payload Header.\r
102\r
103 @param[in] Header FMP Payload Header to evaluate\r
104 @param[in] FmpPayloadSize Size of FMP payload\r
105 @param[out] Version The firmware version described in the FMP Payload\r
106 Header.\r
107\r
108 @retval EFI_SUCCESS The firmware version was returned.\r
109 @retval EFI_INVALID_PARAMETER Header is NULL.\r
110 @retval EFI_INVALID_PARAMETER Version is NULL.\r
111 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.\r
112\r
113**/\r
114EFI_STATUS\r
115EFIAPI\r
116GetFmpPayloadHeaderVersion (\r
117 IN CONST VOID *Header,\r
118 IN CONST UINTN FmpPayloadSize,\r
119 OUT UINT32 *Version\r
120 )\r
121{\r
122 FMP_PAYLOAD_HEADER *FmpPayloadHeader;\r
123\r
124 FmpPayloadHeader = NULL;\r
125\r
126 if (Header == NULL || Version == NULL) {\r
127 return EFI_INVALID_PARAMETER;\r
128 }\r
129\r
130 FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;\r
131 if ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader ||\r
132 (UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize ||\r
133 FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)) {\r
134 return EFI_INVALID_PARAMETER;\r
135 }\r
136\r
137 if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {\r
138 return EFI_INVALID_PARAMETER;\r
139 }\r
140\r
141 *Version = FmpPayloadHeader->FwVersion;\r
142 return EFI_SUCCESS;\r
143}\r
144\r
145/**\r
146 Returns the lowest supported version described in the FMP Payload Header.\r
147\r
148 @param[in] Header FMP Payload Header to evaluate\r
149 @param[in] FmpPayloadSize Size of FMP payload\r
150 @param[out] LowestSupportedVersion The lowest supported version described in\r
151 the FMP Payload Header.\r
152\r
153 @retval EFI_SUCCESS The lowest support version was returned.\r
154 @retval EFI_INVALID_PARAMETER Header is NULL.\r
155 @retval EFI_INVALID_PARAMETER LowestSupportedVersion is NULL.\r
156 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.\r
157\r
158**/\r
159EFI_STATUS\r
160EFIAPI\r
161GetFmpPayloadHeaderLowestSupportedVersion (\r
162 IN CONST VOID *Header,\r
163 IN CONST UINTN FmpPayloadSize,\r
164 IN OUT UINT32 *LowestSupportedVersion\r
165 )\r
166{\r
167 FMP_PAYLOAD_HEADER *FmpPayloadHeader;\r
168\r
169 FmpPayloadHeader = NULL;\r
170\r
171 if (Header == NULL || LowestSupportedVersion == NULL) {\r
172 return EFI_INVALID_PARAMETER;\r
173 }\r
174\r
175 FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;\r
176 if ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader ||\r
177 (UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize ||\r
178 FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)) {\r
179 return EFI_INVALID_PARAMETER;\r
180 }\r
181\r
182 if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {\r
183 return EFI_INVALID_PARAMETER;\r
184 }\r
185\r
186 *LowestSupportedVersion = FmpPayloadHeader->LowestSupportedVersion;\r
187 return EFI_SUCCESS;\r
188}\r