1 /** @file
2 *
3 * Copyright (c) 2016, Hisilicon Limited. All rights reserved.
4 * Copyright (c) 2016, Linaro Limited. All rights reserved.
5 *
6 * This program and the accompanying materials
7 * are licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
10 *
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 *
14 **/
15
16 #include <Uefi.h>
17 #include <PiPei.h>
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/HobLib.h>
23 #include <Library/PrintLib.h>
24 #include <Library/SerialPortLib.h>
25
26 #include <Guid/VersionInfoHobGuid.h>
27
28 struct MonthDescription {
29 CONST CHAR8* MonthStr;
30 UINT32 MonthInt;
31 } gMonthDescription[] = {
32 { "Jan", 1 },
33 { "Feb", 2 },
34 { "Mar", 3 },
35 { "Apr", 4 },
36 { "May", 5 },
37 { "Jun", 6 },
38 { "Jul", 7 },
39 { "Aug", 8 },
40 { "Sep", 9 },
41 { "Oct", 10 },
42 { "Nov", 11 },
43 { "Dec", 12 },
44 { "???", 1 }, // Use 1 as default month
45 };
46
GetReleaseTime(EFI_TIME * Time)47 VOID GetReleaseTime (EFI_TIME *Time)
48 {
49 CONST CHAR8 *ReleaseDate = __DATE__;
50 CONST CHAR8 *ReleaseTime = __TIME__;
51 UINTN i;
52
53 for(i=0;i<12;i++)
54 {
55 if(0 == AsciiStrnCmp(ReleaseDate, gMonthDescription[i].MonthStr, 3))
56 {
57 break;
58 }
59 }
60 Time->Month = gMonthDescription[i].MonthInt;
61 Time->Day = AsciiStrDecimalToUintn(ReleaseDate+4);
62 Time->Year = AsciiStrDecimalToUintn(ReleaseDate+7);
63 Time->Hour = AsciiStrDecimalToUintn(ReleaseTime);
64 Time->Minute = AsciiStrDecimalToUintn(ReleaseTime+3);
65 Time->Second = AsciiStrDecimalToUintn(ReleaseTime+6);
66
67 return;
68 }
69
70 EFI_STATUS
71 EFIAPI
VersionInfoEntry(IN EFI_PEI_FILE_HANDLE FileHandle,IN CONST EFI_PEI_SERVICES ** PeiServices)72 VersionInfoEntry (
73 IN EFI_PEI_FILE_HANDLE FileHandle,
74 IN CONST EFI_PEI_SERVICES **PeiServices
75 )
76 {
77 CHAR8 Buffer[100];
78 UINTN CharCount;
79 VERSION_INFO *VersionInfo;
80 EFI_TIME Time = {0};
81 CONST CHAR16 *ReleaseString =
82 (CHAR16 *) FixedPcdGetPtr (PcdFirmwareVersionString);
83
84 GetReleaseTime (&Time);
85
86 CharCount = AsciiSPrint (
87 Buffer,
88 sizeof (Buffer),
89 "\n\rBoot firmware (version %s built at %t)\n\r\n\r",
90 ReleaseString,
91 &Time
92 );
93 SerialPortWrite ((UINT8 *) Buffer, CharCount);
94
95 VersionInfo = BuildGuidHob (&gVersionInfoHobGuid,
96 sizeof (VERSION_INFO) -
97 sizeof (VersionInfo->String) +
98 StrSize (ReleaseString));
99 if (VersionInfo == NULL) {
100 DEBUG ((EFI_D_ERROR, "[%a]:[%d] Build HOB failed!\n", __FILE__, __LINE__));
101 return EFI_OUT_OF_RESOURCES;
102 }
103
104 CopyMem (&VersionInfo->BuildTime, &Time, sizeof (EFI_TIME));
105 CopyMem (VersionInfo->String, ReleaseString, StrSize (ReleaseString));
106
107 return EFI_SUCCESS;
108 }
109