iPXE
Functions
efi_time.c File Reference

EFI time source. More...

#include <string.h>
#include <errno.h>
#include <time.h>
#include <ipxe/time.h>
#include <ipxe/efi/efi.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static time_t efi_get_time (void)
 Get current time in seconds.
 PROVIDE_TIME (efi, time_now, efi_get_time)

Detailed Description

EFI time source.

Definition in file efi_time.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static time_t efi_get_time ( void  ) [static]

Get current time in seconds.

Return values:
timeTime, in seconds

Definition at line 43 of file efi_time.c.

References EFI_TIME::Day, DBGC, EEFI, efi_systab, EFI_RUNTIME_SERVICES::GetTime, EFI_TIME::Hour, memset(), EFI_TIME::Minute, mktime(), EFI_TIME::Month, NULL, rc, EFI_SYSTEM_TABLE::RuntimeServices, EFI_TIME::Second, strerror(), time, tm::tm_hour, tm::tm_mday, tm::tm_min, tm::tm_mon, tm::tm_sec, tm::tm_year, and EFI_TIME::Year.

                                    {
        EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices;
        EFI_TIME time;
        struct tm tm;
        EFI_STATUS efirc;
        int rc;

        /* Get current time and date */
        if ( ( efirc = rs->GetTime ( &time, NULL ) ) != 0 ) {
                rc = -EEFI ( efirc );
                DBGC ( rs, "EFITIME could not get system time: %s\n",
                       strerror ( rc ) );
                /* Nothing meaningful we can return */
                return 0;
        }

        /* Construct broken-down time */
        memset ( &tm, 0, sizeof ( tm ) );
        tm.tm_sec = time.Second;
        tm.tm_min = time.Minute;
        tm.tm_hour = time.Hour;
        tm.tm_mday = time.Day;
        tm.tm_mon = ( time.Month - 1 );
        tm.tm_year = ( time.Year - 1900 );
        DBGC ( rs, "EFITIME is %04d-%02d-%02d %02d:%02d:%02d\n",
               ( tm.tm_year + 1900 ), ( tm.tm_mon + 1 ),
               tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec );

        /* Convert to seconds since the Epoch */
        return mktime ( &tm );
}
PROVIDE_TIME ( efi  ,
time_now  ,
efi_get_time   
)