Skip to content

Commit 7de15a2

Browse files
huanglx729apop5
authored andcommitted
[Cherry-Pick] Add Standalone Mm BiosIdLib and format code with Uncrustify.
Cc: Eric Dong <eric.dong@intel.com> Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com> Signed-off-by: Lixia Huang <lisa.huang@intel.com>
1 parent 620d3ae commit 7de15a2

File tree

8 files changed

+245
-202
lines changed

8 files changed

+245
-202
lines changed

BoardModulePkg/BoardModulePkg.dsc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@
8484

8585
BoardModulePkg/Library/BiosIdLib/DxeBiosIdLib.inf
8686
BoardModulePkg/Library/BiosIdLib/PeiBiosIdLib.inf
87+
BoardModulePkg/Library/BiosIdLib/StandaloneMmBiosIdLib.inf
8788

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/** @file
2+
Boot service common BIOS ID library implementation.
3+
4+
These functions in this file can be called during DXE and cannot be called during runtime
5+
or in SMM which should use a RT or SMM library.
6+
7+
8+
Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
9+
SPDX-License-Identifier: BSD-2-Clause-Patent
10+
11+
**/
12+
13+
#include <PiDxe.h>
14+
#include <Library/BaseMemoryLib.h>
15+
#include <Library/BiosIdLib.h>
16+
#include <Guid/BiosId.h>
17+
18+
/**
19+
This function returns the BIOS Version & Release Date and Time by getting and converting BIOS ID.
20+
21+
@param[out] BiosVersion The Bios Version out of the conversion.
22+
@param[out] BiosReleaseDate The Bios Release Date out of the conversion.
23+
@param[out] BiosReleaseTime The Bios Release Time out of the conversion.
24+
25+
@retval EFI_SUCCESS BIOS Version & Release Date and Time have been got successfully.
26+
@retval EFI_NOT_FOUND BIOS ID image is not found, and no parameter will be modified.
27+
@retval EFI_INVALID_PARAMETER All the parameters are NULL.
28+
29+
**/
30+
EFI_STATUS
31+
EFIAPI
32+
GetBiosVersionDateTime (
33+
OUT CHAR16 *BiosVersion OPTIONAL,
34+
OUT CHAR16 *BiosReleaseDate OPTIONAL,
35+
OUT CHAR16 *BiosReleaseTime OPTIONAL
36+
)
37+
{
38+
EFI_STATUS Status;
39+
BIOS_ID_IMAGE BiosIdImage;
40+
41+
if ((BiosVersion == NULL) && (BiosReleaseDate == NULL) && (BiosReleaseTime == NULL)) {
42+
return EFI_INVALID_PARAMETER;
43+
}
44+
45+
Status = GetBiosId (&BiosIdImage);
46+
if (EFI_ERROR (Status)) {
47+
return EFI_NOT_FOUND;
48+
}
49+
50+
if (BiosVersion != NULL) {
51+
//
52+
// Fill the BiosVersion data from the BIOS ID.
53+
//
54+
CopyMem (BiosVersion, &(BiosIdImage.BiosIdString), sizeof (BIOS_ID_STRING));
55+
}
56+
57+
if (BiosReleaseDate != NULL) {
58+
//
59+
// Fill the build timestamp date from the BIOS ID in the "MM/DD/YY" format.
60+
//
61+
BiosReleaseDate[0] = BiosIdImage.BiosIdString.TimeStamp[2];
62+
BiosReleaseDate[1] = BiosIdImage.BiosIdString.TimeStamp[3];
63+
BiosReleaseDate[2] = (CHAR16)((UINT8)('/'));
64+
65+
BiosReleaseDate[3] = BiosIdImage.BiosIdString.TimeStamp[4];
66+
BiosReleaseDate[4] = BiosIdImage.BiosIdString.TimeStamp[5];
67+
BiosReleaseDate[5] = (CHAR16)((UINT8)('/'));
68+
69+
//
70+
// Add 20 for SMBIOS table
71+
// Current Linux kernel will misjudge 09 as year 0, so using 2009 for SMBIOS table
72+
//
73+
BiosReleaseDate[6] = '2';
74+
BiosReleaseDate[7] = '0';
75+
BiosReleaseDate[8] = BiosIdImage.BiosIdString.TimeStamp[0];
76+
BiosReleaseDate[9] = BiosIdImage.BiosIdString.TimeStamp[1];
77+
78+
BiosReleaseDate[10] = (CHAR16)((UINT8)('\0'));
79+
}
80+
81+
if (BiosReleaseTime != NULL) {
82+
//
83+
// Fill the build timestamp time from the BIOS ID in the "HH:MM" format.
84+
//
85+
BiosReleaseTime[0] = BiosIdImage.BiosIdString.TimeStamp[6];
86+
BiosReleaseTime[1] = BiosIdImage.BiosIdString.TimeStamp[7];
87+
BiosReleaseTime[2] = (CHAR16)((UINT8)(':'));
88+
89+
BiosReleaseTime[3] = BiosIdImage.BiosIdString.TimeStamp[8];
90+
BiosReleaseTime[4] = BiosIdImage.BiosIdString.TimeStamp[9];
91+
92+
BiosReleaseTime[5] = (CHAR16)((UINT8)('\0'));
93+
}
94+
95+
return EFI_SUCCESS;
96+
}

BoardModulePkg/Library/BiosIdLib/DxeBiosIdLib.c

Lines changed: 14 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
or in SMM which should use a RT or SMM library.
66
77
8-
Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
8+
Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.<BR>
99
SPDX-License-Identifier: BSD-2-Clause-Patent
1010
1111
**/
@@ -15,7 +15,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
1515
#include <Library/HobLib.h>
1616
#include <Library/DxeServicesLib.h>
1717
#include <Library/BaseMemoryLib.h>
18-
#include <Library/HobLib.h>
1918
#include <Library/MemoryAllocationLib.h>
2019
#include <Library/DebugLib.h>
2120
#include <Library/BiosIdLib.h>
@@ -36,16 +35,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
3635
EFI_STATUS
3736
EFIAPI
3837
GetBiosId (
39-
OUT BIOS_ID_IMAGE *BiosIdImage OPTIONAL
38+
OUT BIOS_ID_IMAGE *BiosIdImage OPTIONAL
4039
)
4140
{
42-
EFI_STATUS Status;
43-
BIOS_ID_IMAGE TempBiosIdImage;
44-
VOID *Address;
45-
UINTN Size;
41+
EFI_STATUS Status;
42+
BIOS_ID_IMAGE TempBiosIdImage;
43+
VOID *Address;
44+
UINTN Size;
4645

4746
Address = NULL;
48-
Size = 0;
47+
Size = 0;
4948

5049
if (BiosIdImage == NULL) {
5150
//
@@ -58,10 +57,10 @@ GetBiosId (
5857
Address = GetFirstGuidHob (&gBiosIdGuid);
5958
if (Address != NULL) {
6059
Size = sizeof (BIOS_ID_IMAGE);
61-
CopyMem ((VOID *) BiosIdImage, GET_GUID_HOB_DATA (Address), Size);
60+
CopyMem ((VOID *)BiosIdImage, GET_GUID_HOB_DATA (Address), Size);
6261

63-
DEBUG ((EFI_D_INFO, "DXE get BIOS ID from HOB successfully\n"));
64-
DEBUG ((EFI_D_INFO, "BIOS ID: %s\n", (CHAR16 *) (&(BiosIdImage->BiosIdString))));
62+
DEBUG ((DEBUG_INFO, "DXE get BIOS ID from HOB successfully\n"));
63+
DEBUG ((DEBUG_INFO, "BIOS ID: %s\n", (CHAR16 *)(&(BiosIdImage->BiosIdString))));
6564
return EFI_SUCCESS;
6665
}
6766

@@ -77,99 +76,17 @@ GetBiosId (
7776
// BIOS ID image is present in FV.
7877
//
7978
Size = sizeof (BIOS_ID_IMAGE);
80-
CopyMem ((VOID *) BiosIdImage, Address, Size);
79+
CopyMem ((VOID *)BiosIdImage, Address, Size);
8180
//
8281
// GetSectionFromAnyFv () allocated buffer for Address, now free it.
8382
//
8483
FreePool (Address);
8584

86-
DEBUG ((EFI_D_INFO, "DXE get BIOS ID from FV successfully\n"));
87-
DEBUG ((EFI_D_INFO, "BIOS ID: %s\n", (CHAR16 *) (&(BiosIdImage->BiosIdString))));
85+
DEBUG ((DEBUG_INFO, "DXE get BIOS ID from FV successfully\n"));
86+
DEBUG ((DEBUG_INFO, "BIOS ID: %s\n", (CHAR16 *)(&(BiosIdImage->BiosIdString))));
8887
return EFI_SUCCESS;
8988
}
9089

91-
DEBUG ((EFI_D_ERROR, "DXE get BIOS ID failed: %r\n", EFI_NOT_FOUND));
90+
DEBUG ((DEBUG_ERROR, "DXE get BIOS ID failed: %r\n", EFI_NOT_FOUND));
9291
return EFI_NOT_FOUND;
9392
}
94-
95-
/**
96-
This function returns the BIOS Version & Release Date and Time by getting and converting BIOS ID.
97-
98-
@param[out] BiosVersion The Bios Version out of the conversion.
99-
@param[out] BiosReleaseDate The Bios Release Date out of the conversion.
100-
@param[out] BiosReleaseTime The Bios Release Time out of the conversion.
101-
102-
@retval EFI_SUCCESS BIOS Version & Release Date and Time have been got successfully.
103-
@retval EFI_NOT_FOUND BIOS ID image is not found, and no parameter will be modified.
104-
@retval EFI_INVALID_PARAMETER All the parameters are NULL.
105-
106-
**/
107-
EFI_STATUS
108-
EFIAPI
109-
GetBiosVersionDateTime (
110-
OUT CHAR16 *BiosVersion, OPTIONAL
111-
OUT CHAR16 *BiosReleaseDate, OPTIONAL
112-
OUT CHAR16 *BiosReleaseTime OPTIONAL
113-
)
114-
{
115-
EFI_STATUS Status;
116-
BIOS_ID_IMAGE BiosIdImage;
117-
118-
if ((BiosVersion == NULL) && (BiosReleaseDate == NULL) && (BiosReleaseTime == NULL)) {
119-
return EFI_INVALID_PARAMETER;
120-
}
121-
122-
Status = GetBiosId (&BiosIdImage);
123-
if (EFI_ERROR (Status)) {
124-
return EFI_NOT_FOUND;
125-
}
126-
127-
if (BiosVersion != NULL) {
128-
//
129-
// Fill the BiosVersion data from the BIOS ID.
130-
//
131-
CopyMem (BiosVersion, &(BiosIdImage.BiosIdString), sizeof (BIOS_ID_STRING));
132-
}
133-
134-
if (BiosReleaseDate != NULL) {
135-
//
136-
// Fill the build timestamp date from the BIOS ID in the "MM/DD/YY" format.
137-
//
138-
BiosReleaseDate[0] = BiosIdImage.BiosIdString.TimeStamp[2];
139-
BiosReleaseDate[1] = BiosIdImage.BiosIdString.TimeStamp[3];
140-
BiosReleaseDate[2] = (CHAR16) ((UINT8) ('/'));
141-
142-
BiosReleaseDate[3] = BiosIdImage.BiosIdString.TimeStamp[4];
143-
BiosReleaseDate[4] = BiosIdImage.BiosIdString.TimeStamp[5];
144-
BiosReleaseDate[5] = (CHAR16) ((UINT8) ('/'));
145-
146-
//
147-
// Add 20 for SMBIOS table
148-
// Current Linux kernel will misjudge 09 as year 0, so using 2009 for SMBIOS table
149-
//
150-
BiosReleaseDate[6] = '2';
151-
BiosReleaseDate[7] = '0';
152-
BiosReleaseDate[8] = BiosIdImage.BiosIdString.TimeStamp[0];
153-
BiosReleaseDate[9] = BiosIdImage.BiosIdString.TimeStamp[1];
154-
155-
BiosReleaseDate[10] = (CHAR16) ((UINT8) ('\0'));
156-
}
157-
158-
if (BiosReleaseTime != NULL) {
159-
160-
//
161-
// Fill the build timestamp time from the BIOS ID in the "HH:MM" format.
162-
//
163-
BiosReleaseTime[0] = BiosIdImage.BiosIdString.TimeStamp[6];
164-
BiosReleaseTime[1] = BiosIdImage.BiosIdString.TimeStamp[7];
165-
BiosReleaseTime[2] = (CHAR16) ((UINT8) (':'));
166-
167-
BiosReleaseTime[3] = BiosIdImage.BiosIdString.TimeStamp[8];
168-
BiosReleaseTime[4] = BiosIdImage.BiosIdString.TimeStamp[9];
169-
170-
BiosReleaseTime[5] = (CHAR16) ((UINT8) ('\0'));
171-
}
172-
173-
return EFI_SUCCESS;
174-
}
175-

BoardModulePkg/Library/BiosIdLib/DxeBiosIdLib.inf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### @file
22
# DXE BIOS ID library.
33
#
4-
# Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
4+
# Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
55
#
66
# SPDX-License-Identifier: BSD-2-Clause-Patent
77
#
@@ -22,10 +22,11 @@
2222

2323
[Sources.common]
2424
DxeBiosIdLib.c
25+
BiosIdCommon.c
2526

2627
[Packages]
2728
MdePkg/MdePkg.dec
28-
BoardModulePkg/BoardModulePkg.dec
29+
BoardModulePkg/BoardModulePkg.dec
2930

3031
[LibraryClasses]
3132
BaseLib

0 commit comments

Comments
 (0)