ソースを参照

[efi] Add EFI time source

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9年前
コミット
6567511c3d

+ 1
- 1
src/config/defaults/efi.h ファイルの表示

@@ -20,7 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
20 20
 #define SANBOOT_NULL
21 21
 #define BOFM_EFI
22 22
 #define ENTROPY_EFI
23
-#define TIME_NULL
23
+#define TIME_EFI
24 24
 #define REBOOT_EFI
25 25
 
26 26
 #define	IMAGE_EFI		/* EFI image support */

+ 20
- 0
src/include/ipxe/efi/efi_time.h ファイルの表示

@@ -0,0 +1,20 @@
1
+#ifndef _IPXE_EFI_TIME_H
2
+#define _IPXE_EFI_TIME_H
3
+
4
+/** @file
5
+ *
6
+ * EFI time source
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#include <stdint.h>
13
+
14
+#ifdef TIME_EFI
15
+#define TIME_PREFIX_efi
16
+#else
17
+#define TIME_PREFIX_efi __efi_
18
+#endif
19
+
20
+#endif /* _IPXE_EFI_TIME_H */

+ 1
- 0
src/include/ipxe/errfile.h ファイルの表示

@@ -320,6 +320,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
320 320
 #define ERRFILE_efi_utils	      ( ERRFILE_OTHER | 0x00450000 )
321 321
 #define ERRFILE_efi_wrap	      ( ERRFILE_OTHER | 0x00460000 )
322 322
 #define ERRFILE_vmbus		      ( ERRFILE_OTHER | 0x00470000 )
323
+#define ERRFILE_efi_time	      ( ERRFILE_OTHER | 0x00480000 )
323 324
 
324 325
 /** @} */
325 326
 

+ 1
- 0
src/include/ipxe/time.h ファイルの表示

@@ -44,6 +44,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
44 44
 
45 45
 /* Include all architecture-independent time API headers */
46 46
 #include <ipxe/null_time.h>
47
+#include <ipxe/efi/efi_time.h>
47 48
 #include <ipxe/linux/linux_time.h>
48 49
 
49 50
 /* Include all architecture-dependent time API headers */

+ 75
- 0
src/interface/efi/efi_time.c ファイルの表示

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

読み込み中…
キャンセル
保存