2 Provides services to retrieve values from Version 1 of a capsule's FMP Payload
3 Header. The FMP Payload Header structure is not defined in the library class.
4 Instead, services are provided to retrieve information from the FMP Payload
5 Header. If information is added to the FMP Payload Header, then new services
6 may be added to this library class to retrieve the new information.
8 Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
9 Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 1. Redistributions of source code must retain the above copyright notice,
14 this list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <Library/FmpPayloadHeaderLib.h>
36 /// Define FMP Payload Header structure here so it is not public
45 UINT32 LowestSupportedVersion
;
51 /// Identifier is used to make sure the data in the header is for this structure
52 /// and version. If the structure changes update the last digit.
54 #define FMP_PAYLOAD_HEADER_SIGNATURE SIGNATURE_32 ('M', 'S', 'S', '1')
57 Returns the FMP Payload Header size in bytes.
59 @param[in] Header FMP Payload Header to evaluate
60 @param[in] FmpPayloadSize Size of FMP payload
61 @param[out] Size The size, in bytes, of the FMP Payload Header.
63 @retval EFI_SUCCESS The firmware version was returned.
64 @retval EFI_INVALID_PARAMETER Header is NULL.
65 @retval EFI_INVALID_PARAMETER Size is NULL.
66 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
71 GetFmpPayloadHeaderSize (
72 IN CONST VOID
*Header
,
73 IN CONST UINTN FmpPayloadSize
,
77 FMP_PAYLOAD_HEADER
*FmpPayloadHeader
;
79 FmpPayloadHeader
= NULL
;
81 if (Header
== NULL
|| Size
== NULL
) {
82 return EFI_INVALID_PARAMETER
;
85 FmpPayloadHeader
= (FMP_PAYLOAD_HEADER
*)Header
;
86 if ((UINTN
)FmpPayloadHeader
+ sizeof (FMP_PAYLOAD_HEADER
) < (UINTN
)FmpPayloadHeader
||
87 (UINTN
)FmpPayloadHeader
+ sizeof (FMP_PAYLOAD_HEADER
) >= (UINTN
)FmpPayloadHeader
+ FmpPayloadSize
||
88 FmpPayloadHeader
->HeaderSize
< sizeof (FMP_PAYLOAD_HEADER
)) {
89 return EFI_INVALID_PARAMETER
;
92 if (FmpPayloadHeader
->Signature
!= FMP_PAYLOAD_HEADER_SIGNATURE
) {
93 return EFI_INVALID_PARAMETER
;
96 *Size
= FmpPayloadHeader
->HeaderSize
;
101 Returns the version described in the FMP Payload Header.
103 @param[in] Header FMP Payload Header to evaluate
104 @param[in] FmpPayloadSize Size of FMP payload
105 @param[out] Version The firmware version described in the FMP Payload
108 @retval EFI_SUCCESS The firmware version was returned.
109 @retval EFI_INVALID_PARAMETER Header is NULL.
110 @retval EFI_INVALID_PARAMETER Version is NULL.
111 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
116 GetFmpPayloadHeaderVersion (
117 IN CONST VOID
*Header
,
118 IN CONST UINTN FmpPayloadSize
,
122 FMP_PAYLOAD_HEADER
*FmpPayloadHeader
;
124 FmpPayloadHeader
= NULL
;
126 if (Header
== NULL
|| Version
== NULL
) {
127 return EFI_INVALID_PARAMETER
;
130 FmpPayloadHeader
= (FMP_PAYLOAD_HEADER
*)Header
;
131 if ((UINTN
)FmpPayloadHeader
+ sizeof (FMP_PAYLOAD_HEADER
) < (UINTN
)FmpPayloadHeader
||
132 (UINTN
)FmpPayloadHeader
+ sizeof (FMP_PAYLOAD_HEADER
) >= (UINTN
)FmpPayloadHeader
+ FmpPayloadSize
||
133 FmpPayloadHeader
->HeaderSize
< sizeof (FMP_PAYLOAD_HEADER
)) {
134 return EFI_INVALID_PARAMETER
;
137 if (FmpPayloadHeader
->Signature
!= FMP_PAYLOAD_HEADER_SIGNATURE
) {
138 return EFI_INVALID_PARAMETER
;
141 *Version
= FmpPayloadHeader
->FwVersion
;
146 Returns the lowest supported version described in the FMP Payload Header.
148 @param[in] Header FMP Payload Header to evaluate
149 @param[in] FmpPayloadSize Size of FMP payload
150 @param[out] LowestSupportedVersion The lowest supported version described in
151 the FMP Payload Header.
153 @retval EFI_SUCCESS The lowest support version was returned.
154 @retval EFI_INVALID_PARAMETER Header is NULL.
155 @retval EFI_INVALID_PARAMETER LowestSupportedVersion is NULL.
156 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
161 GetFmpPayloadHeaderLowestSupportedVersion (
162 IN CONST VOID
*Header
,
163 IN CONST UINTN FmpPayloadSize
,
164 IN OUT UINT32
*LowestSupportedVersion
167 FMP_PAYLOAD_HEADER
*FmpPayloadHeader
;
169 FmpPayloadHeader
= NULL
;
171 if (Header
== NULL
|| LowestSupportedVersion
== NULL
) {
172 return EFI_INVALID_PARAMETER
;
175 FmpPayloadHeader
= (FMP_PAYLOAD_HEADER
*)Header
;
176 if ((UINTN
)FmpPayloadHeader
+ sizeof (FMP_PAYLOAD_HEADER
) < (UINTN
)FmpPayloadHeader
||
177 (UINTN
)FmpPayloadHeader
+ sizeof (FMP_PAYLOAD_HEADER
) >= (UINTN
)FmpPayloadHeader
+ FmpPayloadSize
||
178 FmpPayloadHeader
->HeaderSize
< sizeof (FMP_PAYLOAD_HEADER
)) {
179 return EFI_INVALID_PARAMETER
;
182 if (FmpPayloadHeader
->Signature
!= FMP_PAYLOAD_HEADER_SIGNATURE
) {
183 return EFI_INVALID_PARAMETER
;
186 *LowestSupportedVersion
= FmpPayloadHeader
->LowestSupportedVersion
;