Bladeren bron

[efi] Add "reboot" command for EFI

Abstract out the ability to reboot the system to a separate reboot()
function (with platform-specific implementations), add an EFI
implementation, and make the existing "reboot" command available under
EFI.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 jaren geleden
bovenliggende
commit
71cd508838

+ 14
- 0
src/arch/i386/include/bits/reboot.h Bestand weergeven

@@ -0,0 +1,14 @@
1
+#ifndef _BITS_REBOOT_H
2
+#define _BITS_REBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * i386-specific reboot API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#include <ipxe/bios_reboot.h>
13
+
14
+#endif /* _BITS_REBOOT_H */

+ 18
- 0
src/arch/i386/include/ipxe/bios_reboot.h Bestand weergeven

@@ -0,0 +1,18 @@
1
+#ifndef _IPXE_BIOS_REBOOT_H
2
+#define _IPXE_BIOS_REBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * Standard PC-BIOS reboot mechanism
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#ifdef REBOOT_PCBIOS
13
+#define REBOOT_PREFIX_pcbios
14
+#else
15
+#define REBOOT_PREFIX_pcbios __pcbios_
16
+#endif
17
+
18
+#endif /* _IPXE_BIOS_REBOOT_H */

+ 41
- 0
src/arch/i386/interface/pcbios/bios_reboot.c Bestand weergeven

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (C) 2010 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 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
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+/** @file
23
+ *
24
+ * Standard PC-BIOS reboot mechanism
25
+ *
26
+ */
27
+
28
+#include <ipxe/reboot.h>
29
+#include <realmode.h>
30
+
31
+/**
32
+ * Reboot system
33
+ *
34
+ */
35
+static void bios_reboot ( void ) {
36
+
37
+	/* Jump to system reset vector */
38
+	__asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : : );
39
+}
40
+
41
+PROVIDE_REBOOT ( pcbios, reboot, bios_reboot );

+ 12
- 0
src/arch/x86_64/include/bits/reboot.h Bestand weergeven

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_REBOOT_H
2
+#define _BITS_REBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * x86_64-specific reboot API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#endif /* _BITS_REBOOT_H */

+ 3
- 0
src/config/defaults/efi.h Bestand weergeven

@@ -19,8 +19,11 @@
19 19
 #define BOFM_EFI
20 20
 #define ENTROPY_NULL
21 21
 #define TIME_NULL
22
+#define REBOOT_EFI
22 23
 
23 24
 #define	IMAGE_EFI		/* EFI image support */
24 25
 #define	IMAGE_SCRIPT		/* iPXE script image support */
25 26
 
27
+#define	REBOOT_CMD		/* Reboot command */
28
+
26 29
 #endif /* CONFIG_DEFAULTS_EFI_H */

+ 1
- 0
src/config/defaults/linux.h Bestand weergeven

@@ -16,6 +16,7 @@
16 16
 #define SANBOOT_NULL
17 17
 #define ENTROPY_LINUX
18 18
 #define TIME_LINUX
19
+#define REBOOT_NULL
19 20
 
20 21
 #define DRIVERS_LINUX
21 22
 

+ 1
- 0
src/config/defaults/pcbios.h Bestand weergeven

@@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
20 20
 #define SANBOOT_PCBIOS
21 21
 #define ENTROPY_RTC
22 22
 #define TIME_RTC
23
+#define REBOOT_PCBIOS
23 24
 
24 25
 #define	IMAGE_ELF		/* ELF image support */
25 26
 #define	IMAGE_MULTIBOOT		/* MultiBoot image support */

+ 16
- 0
src/config/reboot.h Bestand weergeven

@@ -0,0 +1,16 @@
1
+#ifndef CONFIG_REBOOT_H
2
+#define CONFIG_REBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * Reboot API configuration
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#include <config/defaults.h>
13
+
14
+#include <config/local/reboot.h>
15
+
16
+#endif /* CONFIG_REBOOT_H */

+ 42
- 0
src/core/null_reboot.c Bestand weergeven

@@ -0,0 +1,42 @@
1
+/*
2
+ * Copyright (C) 2013 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 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
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+/**
23
+ * @file
24
+ *
25
+ * Null reboot mechanism
26
+ *
27
+ */
28
+
29
+#include <stdio.h>
30
+#include <ipxe/reboot.h>
31
+
32
+/**
33
+ * Reboot system
34
+ *
35
+ */
36
+static void null_reboot ( void ) {
37
+
38
+	printf ( "Cannot reboot; not implemented\n" );
39
+	while ( 1 ) {}
40
+}
41
+
42
+PROVIDE_REBOOT ( null, reboot, null_reboot );

src/arch/i386/hci/commands/reboot_cmd.c → src/hci/commands/reboot_cmd.c Bestand weergeven

@@ -17,9 +17,9 @@
17 17
  * 02110-1301, USA.
18 18
  */
19 19
 
20
-#include <realmode.h>
21 20
 #include <ipxe/command.h>
22 21
 #include <ipxe/parseopt.h>
22
+#include <ipxe/reboot.h>
23 23
 
24 24
 FILE_LICENCE ( GPL2_OR_LATER );
25 25
 
@@ -55,7 +55,7 @@ static int reboot_exec ( int argc, char **argv ) {
55 55
 		return rc;
56 56
 
57 57
 	/* Reboot system */
58
-	__asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : : );
58
+	reboot();
59 59
 
60 60
 	return 0;
61 61
 }

+ 18
- 0
src/include/ipxe/efi/efi_reboot.h Bestand weergeven

@@ -0,0 +1,18 @@
1
+#ifndef _IPXE_EFI_REBOOT_H
2
+#define _IPXE_EFI_REBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * iPXE reboot API for EFI
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#ifdef REBOOT_EFI
13
+#define REBOOT_PREFIX_efi
14
+#else
15
+#define REBOOT_PREFIX_efi __efi_
16
+#endif
17
+
18
+#endif /* _IPXE_EFI_REBOOT_H */

+ 18
- 0
src/include/ipxe/null_reboot.h Bestand weergeven

@@ -0,0 +1,18 @@
1
+#ifndef _IPXE_NULL_REBOOT_H
2
+#define _IPXE_NULL_REBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * iPXE do-nothing reboot API
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#ifdef REBOOT_NULL
13
+#define REBOOT_PREFIX_null
14
+#else
15
+#define REBOOT_PREFIX_null __null_
16
+#endif
17
+
18
+#endif /* _IPXE_NULL_REBOOT_H */

+ 57
- 0
src/include/ipxe/reboot.h Bestand weergeven

@@ -0,0 +1,57 @@
1
+#ifndef _IPXE_REBOOT_H
2
+#define _IPXE_REBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * iPXE reboot API
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#include <ipxe/api.h>
13
+#include <config/reboot.h>
14
+
15
+/**
16
+ * Calculate static inline reboot API function name
17
+ *
18
+ * @v _prefix		Subsystem prefix
19
+ * @v _api_func		API function
20
+ * @ret _subsys_func	Subsystem API function
21
+ */
22
+#define REBOOT_INLINE( _subsys, _api_func ) \
23
+	SINGLE_API_INLINE ( REBOOT_PREFIX_ ## _subsys, _api_func )
24
+
25
+/**
26
+ * Provide an reboot API implementation
27
+ *
28
+ * @v _prefix		Subsystem prefix
29
+ * @v _api_func		API function
30
+ * @v _func		Implementing function
31
+ */
32
+#define PROVIDE_REBOOT( _subsys, _api_func, _func ) \
33
+	PROVIDE_SINGLE_API ( REBOOT_PREFIX_ ## _subsys, _api_func, _func )
34
+
35
+/**
36
+ * Provide a static inline reboot API implementation
37
+ *
38
+ * @v _prefix		Subsystem prefix
39
+ * @v _api_func		API function
40
+ */
41
+#define PROVIDE_REBOOT_INLINE( _subsys, _api_func ) \
42
+	PROVIDE_SINGLE_API_INLINE ( REBOOT_PREFIX_ ## _subsys, _api_func )
43
+
44
+/* Include all architecture-independent reboot API headers */
45
+#include <ipxe/null_reboot.h>
46
+#include <ipxe/efi/efi_reboot.h>
47
+
48
+/* Include all architecture-dependent reboot API headers */
49
+#include <bits/reboot.h>
50
+
51
+/**
52
+ * Reboot system
53
+ *
54
+ */
55
+void reboot ( void );
56
+
57
+#endif /* _IPXE_REBOOT_H */

+ 43
- 0
src/interface/efi/efi_reboot.c Bestand weergeven

@@ -0,0 +1,43 @@
1
+/*
2
+ * Copyright (C) 2013 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 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
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+/**
23
+ * @file
24
+ *
25
+ * EFI reboot mechanism
26
+ *
27
+ */
28
+
29
+#include <ipxe/efi/efi.h>
30
+#include <ipxe/reboot.h>
31
+
32
+/**
33
+ * Reboot system
34
+ *
35
+ */
36
+static void efi_reboot ( void ) {
37
+	EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices;
38
+
39
+	/* Use runtime services to reset system */
40
+	rs->ResetSystem ( EfiResetCold, 0, 0, NULL );
41
+}
42
+
43
+PROVIDE_REBOOT ( efi, reboot, efi_reboot );

Laden…
Annuleren
Opslaan