]> git.proxmox.com Git - mirror_edk2.git/blob - FmpDevicePkg/Library/FmpPayloadHeaderLibV1/FmpPayloadHeaderLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / FmpDevicePkg / Library / FmpPayloadHeaderLibV1 / FmpPayloadHeaderLib.c
1 /** @file
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.
7
8 Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
9 Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
10
11 SPDX-License-Identifier: BSD-2-Clause-Patent
12
13 **/
14
15 #include <PiDxe.h>
16 #include <Library/FmpPayloadHeaderLib.h>
17
18 ///
19 /// Define FMP Payload Header structure here so it is not public
20 ///
21
22 #pragma pack(1)
23
24 typedef struct {
25 UINT32 Signature;
26 UINT32 HeaderSize;
27 UINT32 FwVersion;
28 UINT32 LowestSupportedVersion;
29 } FMP_PAYLOAD_HEADER;
30
31 #pragma pack()
32
33 ///
34 /// Identifier is used to make sure the data in the header is for this structure
35 /// and version. If the structure changes update the last digit.
36 ///
37 #define FMP_PAYLOAD_HEADER_SIGNATURE SIGNATURE_32 ('M', 'S', 'S', '1')
38
39 /**
40 Returns the FMP Payload Header size in bytes.
41
42 @param[in] Header FMP Payload Header to evaluate
43 @param[in] FmpPayloadSize Size of FMP payload
44 @param[out] Size The size, in bytes, of the FMP Payload Header.
45
46 @retval EFI_SUCCESS The firmware version was returned.
47 @retval EFI_INVALID_PARAMETER Header is NULL.
48 @retval EFI_INVALID_PARAMETER Size is NULL.
49 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
50
51 **/
52 EFI_STATUS
53 EFIAPI
54 GetFmpPayloadHeaderSize (
55 IN CONST VOID *Header,
56 IN CONST UINTN FmpPayloadSize,
57 OUT UINT32 *Size
58 )
59 {
60 FMP_PAYLOAD_HEADER *FmpPayloadHeader;
61
62 FmpPayloadHeader = NULL;
63
64 if ((Header == NULL) || (Size == NULL)) {
65 return EFI_INVALID_PARAMETER;
66 }
67
68 FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;
69 if (((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader) ||
70 ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize) ||
71 (FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)))
72 {
73 return EFI_INVALID_PARAMETER;
74 }
75
76 if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {
77 return EFI_INVALID_PARAMETER;
78 }
79
80 *Size = FmpPayloadHeader->HeaderSize;
81 return EFI_SUCCESS;
82 }
83
84 /**
85 Returns the version described in the FMP Payload Header.
86
87 @param[in] Header FMP Payload Header to evaluate
88 @param[in] FmpPayloadSize Size of FMP payload
89 @param[out] Version The firmware version described in the FMP Payload
90 Header.
91
92 @retval EFI_SUCCESS The firmware version was returned.
93 @retval EFI_INVALID_PARAMETER Header is NULL.
94 @retval EFI_INVALID_PARAMETER Version is NULL.
95 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
96
97 **/
98 EFI_STATUS
99 EFIAPI
100 GetFmpPayloadHeaderVersion (
101 IN CONST VOID *Header,
102 IN CONST UINTN FmpPayloadSize,
103 OUT UINT32 *Version
104 )
105 {
106 FMP_PAYLOAD_HEADER *FmpPayloadHeader;
107
108 FmpPayloadHeader = NULL;
109
110 if ((Header == NULL) || (Version == NULL)) {
111 return EFI_INVALID_PARAMETER;
112 }
113
114 FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;
115 if (((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader) ||
116 ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize) ||
117 (FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)))
118 {
119 return EFI_INVALID_PARAMETER;
120 }
121
122 if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {
123 return EFI_INVALID_PARAMETER;
124 }
125
126 *Version = FmpPayloadHeader->FwVersion;
127 return EFI_SUCCESS;
128 }
129
130 /**
131 Returns the lowest supported version described in the FMP Payload Header.
132
133 @param[in] Header FMP Payload Header to evaluate
134 @param[in] FmpPayloadSize Size of FMP payload
135 @param[out] LowestSupportedVersion The lowest supported version described in
136 the FMP Payload Header.
137
138 @retval EFI_SUCCESS The lowest support version was returned.
139 @retval EFI_INVALID_PARAMETER Header is NULL.
140 @retval EFI_INVALID_PARAMETER LowestSupportedVersion is NULL.
141 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 GetFmpPayloadHeaderLowestSupportedVersion (
147 IN CONST VOID *Header,
148 IN CONST UINTN FmpPayloadSize,
149 OUT UINT32 *LowestSupportedVersion
150 )
151 {
152 FMP_PAYLOAD_HEADER *FmpPayloadHeader;
153
154 FmpPayloadHeader = NULL;
155
156 if ((Header == NULL) || (LowestSupportedVersion == NULL)) {
157 return EFI_INVALID_PARAMETER;
158 }
159
160 FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;
161 if (((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader) ||
162 ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize) ||
163 (FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)))
164 {
165 return EFI_INVALID_PARAMETER;
166 }
167
168 if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {
169 return EFI_INVALID_PARAMETER;
170 }
171
172 *LowestSupportedVersion = FmpPayloadHeader->LowestSupportedVersion;
173 return EFI_SUCCESS;
174 }