]> 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 return EFI_INVALID_PARAMETER;
73 }
74
75 if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {
76 return EFI_INVALID_PARAMETER;
77 }
78
79 *Size = FmpPayloadHeader->HeaderSize;
80 return EFI_SUCCESS;
81 }
82
83 /**
84 Returns the version described in the FMP Payload Header.
85
86 @param[in] Header FMP Payload Header to evaluate
87 @param[in] FmpPayloadSize Size of FMP payload
88 @param[out] Version The firmware version described in the FMP Payload
89 Header.
90
91 @retval EFI_SUCCESS The firmware version was returned.
92 @retval EFI_INVALID_PARAMETER Header is NULL.
93 @retval EFI_INVALID_PARAMETER Version is NULL.
94 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
95
96 **/
97 EFI_STATUS
98 EFIAPI
99 GetFmpPayloadHeaderVersion (
100 IN CONST VOID *Header,
101 IN CONST UINTN FmpPayloadSize,
102 OUT UINT32 *Version
103 )
104 {
105 FMP_PAYLOAD_HEADER *FmpPayloadHeader;
106
107 FmpPayloadHeader = NULL;
108
109 if (Header == NULL || Version == NULL) {
110 return EFI_INVALID_PARAMETER;
111 }
112
113 FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;
114 if ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader ||
115 (UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize ||
116 FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)) {
117 return EFI_INVALID_PARAMETER;
118 }
119
120 if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {
121 return EFI_INVALID_PARAMETER;
122 }
123
124 *Version = FmpPayloadHeader->FwVersion;
125 return EFI_SUCCESS;
126 }
127
128 /**
129 Returns the lowest supported version described in the FMP Payload Header.
130
131 @param[in] Header FMP Payload Header to evaluate
132 @param[in] FmpPayloadSize Size of FMP payload
133 @param[out] LowestSupportedVersion The lowest supported version described in
134 the FMP Payload Header.
135
136 @retval EFI_SUCCESS The lowest support version was returned.
137 @retval EFI_INVALID_PARAMETER Header is NULL.
138 @retval EFI_INVALID_PARAMETER LowestSupportedVersion is NULL.
139 @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
140
141 **/
142 EFI_STATUS
143 EFIAPI
144 GetFmpPayloadHeaderLowestSupportedVersion (
145 IN CONST VOID *Header,
146 IN CONST UINTN FmpPayloadSize,
147 OUT UINT32 *LowestSupportedVersion
148 )
149 {
150 FMP_PAYLOAD_HEADER *FmpPayloadHeader;
151
152 FmpPayloadHeader = NULL;
153
154 if (Header == NULL || LowestSupportedVersion == NULL) {
155 return EFI_INVALID_PARAMETER;
156 }
157
158 FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;
159 if ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader ||
160 (UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize ||
161 FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)) {
162 return EFI_INVALID_PARAMETER;
163 }
164
165 if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {
166 return EFI_INVALID_PARAMETER;
167 }
168
169 *LowestSupportedVersion = FmpPayloadHeader->LowestSupportedVersion;
170 return EFI_SUCCESS;
171 }