iPXE
efi_time.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 FILE_SECBOOT ( PERMITTED );
26 
27 #include <string.h>
28 #include <errno.h>
29 #include <time.h>
30 #include <ipxe/time.h>
31 #include <ipxe/efi/efi.h>
32 
33 /** @file
34  *
35  * EFI time source
36  *
37  */
38 
39 /**
40  * Get current time in seconds
41  *
42  * @ret time Time, in seconds
43  */
44 static time_t efi_get_time ( void ) {
46  EFI_TIME time;
47  struct tm tm;
48  EFI_STATUS efirc;
49  int rc;
50 
51  /* Get current time and date */
52  if ( ( efirc = rs->GetTime ( &time, NULL ) ) != 0 ) {
53  rc = -EEFI ( efirc );
54  DBGC ( rs, "EFITIME could not get system time: %s\n",
55  strerror ( rc ) );
56  /* Nothing meaningful we can return */
57  return 0;
58  }
59 
60  /* Construct broken-down time */
61  memset ( &tm, 0, sizeof ( tm ) );
62  tm.tm_sec = time.Second;
63  tm.tm_min = time.Minute;
64  tm.tm_hour = time.Hour;
65  tm.tm_mday = time.Day;
66  tm.tm_mon = ( time.Month - 1 );
67  tm.tm_year = ( time.Year - 1900 );
68  DBGC ( rs, "EFITIME is %04d-%02d-%02d %02d:%02d:%02d\n",
69  ( tm.tm_year + 1900 ), ( tm.tm_mon + 1 ),
71 
72  /* Convert to seconds since the Epoch */
73  return mktime ( &tm );
74 }
75 
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int tm_min
Minutes [0,59].
Definition: time.h:20
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:175
Error codes.
int tm_mday
Day of month [1,31].
Definition: time.h:24
#define DBGC(...)
Definition: compiler.h:505
PROVIDE_TIME(efi, time_now, efi_get_time)
int tm_year
Years since 1900.
Definition: time.h:28
time_t time_now(void)
Get current time in seconds (ignoring system clock offset)
UINT8 Day
Definition: UefiBaseType.h:74
UINT8 Minute
Definition: UefiBaseType.h:76
int tm_mon
Month of year [0,11].
Definition: time.h:26
UINT8 Second
Definition: UefiBaseType.h:77
UINT8 Hour
Definition: UefiBaseType.h:75
time_t mktime(struct tm *tm)
Calculate seconds since the Epoch.
Definition: time.c:118
EFI Runtime Services Table.
Definition: UefiSpec.h:1880
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
UINT16 Year
Definition: UefiBaseType.h:72
EFI_GET_TIME GetTime
Definition: UefiSpec.h:1889
UINT8 Month
Definition: UefiBaseType.h:73
Broken-down time.
Definition: time.h:16
EFI API.
EFI Time Abstraction: Year: 1900 - 9999 Month: 1 - 12 Day: 1 - 31 Hour: 0 - 23 Minute: 0 - 59 Second:...
Definition: UefiBaseType.h:71
FILE_SECBOOT(PERMITTED)
EFI_RUNTIME_SERVICES * RuntimeServices
A pointer to the EFI Runtime Services Table.
Definition: UefiSpec.h:2095
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:32
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int tm_sec
Seconds [0,60].
Definition: time.h:18
EFI_SYSTEM_TABLE * efi_systab
static time_t efi_get_time(void)
Get current time in seconds.
Definition: efi_time.c:44
int tm_hour
Hour [0,23].
Definition: time.h:22
int64_t time_t
Seconds since the Epoch.
Definition: time.h:19
Time source.
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
String functions.
void * memset(void *dest, int character, size_t len) __nonnull