Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

efi_time.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <string.h>
  25. #include <errno.h>
  26. #include <time.h>
  27. #include <ipxe/time.h>
  28. #include <ipxe/efi/efi.h>
  29. /** @file
  30. *
  31. * EFI time source
  32. *
  33. */
  34. /**
  35. * Get current time in seconds
  36. *
  37. * @ret time Time, in seconds
  38. */
  39. static time_t efi_get_time ( void ) {
  40. EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices;
  41. EFI_TIME time;
  42. struct tm tm;
  43. EFI_STATUS efirc;
  44. int rc;
  45. /* Get current time and date */
  46. if ( ( efirc = rs->GetTime ( &time, NULL ) ) != 0 ) {
  47. rc = -EEFI ( efirc );
  48. DBGC ( rs, "EFITIME could not get system time: %s\n",
  49. strerror ( rc ) );
  50. /* Nothing meaningful we can return */
  51. return 0;
  52. }
  53. /* Construct broken-down time */
  54. memset ( &tm, 0, sizeof ( tm ) );
  55. tm.tm_sec = time.Second;
  56. tm.tm_min = time.Minute;
  57. tm.tm_hour = time.Hour;
  58. tm.tm_mday = time.Day;
  59. tm.tm_mon = ( time.Month - 1 );
  60. tm.tm_year = ( time.Year - 1900 );
  61. DBGC ( rs, "EFITIME is %04d-%02d-%02d %02d:%02d:%02d\n",
  62. ( tm.tm_year + 1900 ), ( tm.tm_mon + 1 ),
  63. tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec );
  64. /* Convert to seconds since the Epoch */
  65. return mktime ( &tm );
  66. }
  67. PROVIDE_TIME ( efi, time_now, efi_get_time );