iPXE
efi_time.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <string.h>
00027 #include <errno.h>
00028 #include <time.h>
00029 #include <ipxe/time.h>
00030 #include <ipxe/efi/efi.h>
00031 
00032 /** @file
00033  *
00034  * EFI time source
00035  *
00036  */
00037 
00038 /**
00039  * Get current time in seconds
00040  *
00041  * @ret time            Time, in seconds
00042  */
00043 static time_t efi_get_time ( void ) {
00044         EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices;
00045         EFI_TIME time;
00046         struct tm tm;
00047         EFI_STATUS efirc;
00048         int rc;
00049 
00050         /* Get current time and date */
00051         if ( ( efirc = rs->GetTime ( &time, NULL ) ) != 0 ) {
00052                 rc = -EEFI ( efirc );
00053                 DBGC ( rs, "EFITIME could not get system time: %s\n",
00054                        strerror ( rc ) );
00055                 /* Nothing meaningful we can return */
00056                 return 0;
00057         }
00058 
00059         /* Construct broken-down time */
00060         memset ( &tm, 0, sizeof ( tm ) );
00061         tm.tm_sec = time.Second;
00062         tm.tm_min = time.Minute;
00063         tm.tm_hour = time.Hour;
00064         tm.tm_mday = time.Day;
00065         tm.tm_mon = ( time.Month - 1 );
00066         tm.tm_year = ( time.Year - 1900 );
00067         DBGC ( rs, "EFITIME is %04d-%02d-%02d %02d:%02d:%02d\n",
00068                ( tm.tm_year + 1900 ), ( tm.tm_mon + 1 ),
00069                tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec );
00070 
00071         /* Convert to seconds since the Epoch */
00072         return mktime ( &tm );
00073 }
00074 
00075 PROVIDE_TIME ( efi, time_now, efi_get_time );