]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Add "reboot" command for EFI
authorMichael Brown <mcb30@ipxe.org>
Fri, 22 Mar 2013 13:42:16 +0000 (13:42 +0000)
committerMichael Brown <mcb30@ipxe.org>
Fri, 22 Mar 2013 13:44:02 +0000 (13:44 +0000)
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>
14 files changed:
src/arch/i386/include/bits/reboot.h [new file with mode: 0644]
src/arch/i386/include/ipxe/bios_reboot.h [new file with mode: 0644]
src/arch/i386/interface/pcbios/bios_reboot.c [new file with mode: 0644]
src/arch/x86_64/include/bits/reboot.h [new file with mode: 0644]
src/config/defaults/efi.h
src/config/defaults/linux.h
src/config/defaults/pcbios.h
src/config/reboot.h [new file with mode: 0644]
src/core/null_reboot.c [new file with mode: 0644]
src/hci/commands/reboot_cmd.c [moved from src/arch/i386/hci/commands/reboot_cmd.c with 94% similarity]
src/include/ipxe/efi/efi_reboot.h [new file with mode: 0644]
src/include/ipxe/null_reboot.h [new file with mode: 0644]
src/include/ipxe/reboot.h [new file with mode: 0644]
src/interface/efi/efi_reboot.c [new file with mode: 0644]

diff --git a/src/arch/i386/include/bits/reboot.h b/src/arch/i386/include/bits/reboot.h
new file mode 100644 (file)
index 0000000..5b09e95
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _BITS_REBOOT_H
+#define _BITS_REBOOT_H
+
+/** @file
+ *
+ * i386-specific reboot API implementations
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <ipxe/bios_reboot.h>
+
+#endif /* _BITS_REBOOT_H */
diff --git a/src/arch/i386/include/ipxe/bios_reboot.h b/src/arch/i386/include/ipxe/bios_reboot.h
new file mode 100644 (file)
index 0000000..a084532
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef _IPXE_BIOS_REBOOT_H
+#define _IPXE_BIOS_REBOOT_H
+
+/** @file
+ *
+ * Standard PC-BIOS reboot mechanism
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#ifdef REBOOT_PCBIOS
+#define REBOOT_PREFIX_pcbios
+#else
+#define REBOOT_PREFIX_pcbios __pcbios_
+#endif
+
+#endif /* _IPXE_BIOS_REBOOT_H */
diff --git a/src/arch/i386/interface/pcbios/bios_reboot.c b/src/arch/i386/interface/pcbios/bios_reboot.c
new file mode 100644 (file)
index 0000000..86f4e3e
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+/** @file
+ *
+ * Standard PC-BIOS reboot mechanism
+ *
+ */
+
+#include <ipxe/reboot.h>
+#include <realmode.h>
+
+/**
+ * Reboot system
+ *
+ */
+static void bios_reboot ( void ) {
+
+       /* Jump to system reset vector */
+       __asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : : );
+}
+
+PROVIDE_REBOOT ( pcbios, reboot, bios_reboot );
diff --git a/src/arch/x86_64/include/bits/reboot.h b/src/arch/x86_64/include/bits/reboot.h
new file mode 100644 (file)
index 0000000..f1bce05
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _BITS_REBOOT_H
+#define _BITS_REBOOT_H
+
+/** @file
+ *
+ * x86_64-specific reboot API implementations
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#endif /* _BITS_REBOOT_H */
index 923360ae8088ff94c5d0f7c23812095b8ea7a579..c453e89a41e5b7f41526272661bd8f3ff9fe2b73 100644 (file)
 #define BOFM_EFI
 #define ENTROPY_NULL
 #define TIME_NULL
+#define REBOOT_EFI
 
 #define        IMAGE_EFI               /* EFI image support */
 #define        IMAGE_SCRIPT            /* iPXE script image support */
 
+#define        REBOOT_CMD              /* Reboot command */
+
 #endif /* CONFIG_DEFAULTS_EFI_H */
index 50897560d6dab58f7aca79c568cf39a1fd327479..666db6b826007e7aed138b2533531b7e4c0924b9 100644 (file)
@@ -16,6 +16,7 @@
 #define SANBOOT_NULL
 #define ENTROPY_LINUX
 #define TIME_LINUX
+#define REBOOT_NULL
 
 #define DRIVERS_LINUX
 
index c52fca972f6832e4e8e632ec6bb75a5fd0f240c9..7debc8d2f4f30b2e1c511b8d343e16922f553287 100644 (file)
@@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #define SANBOOT_PCBIOS
 #define ENTROPY_RTC
 #define TIME_RTC
+#define REBOOT_PCBIOS
 
 #define        IMAGE_ELF               /* ELF image support */
 #define        IMAGE_MULTIBOOT         /* MultiBoot image support */
diff --git a/src/config/reboot.h b/src/config/reboot.h
new file mode 100644 (file)
index 0000000..240ef87
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef CONFIG_REBOOT_H
+#define CONFIG_REBOOT_H
+
+/** @file
+ *
+ * Reboot API configuration
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <config/defaults.h>
+
+#include <config/local/reboot.h>
+
+#endif /* CONFIG_REBOOT_H */
diff --git a/src/core/null_reboot.c b/src/core/null_reboot.c
new file mode 100644 (file)
index 0000000..b7e55bc
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+/**
+ * @file
+ *
+ * Null reboot mechanism
+ *
+ */
+
+#include <stdio.h>
+#include <ipxe/reboot.h>
+
+/**
+ * Reboot system
+ *
+ */
+static void null_reboot ( void ) {
+
+       printf ( "Cannot reboot; not implemented\n" );
+       while ( 1 ) {}
+}
+
+PROVIDE_REBOOT ( null, reboot, null_reboot );
similarity index 94%
rename from src/arch/i386/hci/commands/reboot_cmd.c
rename to src/hci/commands/reboot_cmd.c
index 74c69c94eec5729f28018e5e4142788a22b90e79..19d3d6df455591331c7560df6ed96457753eb4f4 100644 (file)
@@ -17,9 +17,9 @@
  * 02110-1301, USA.
  */
 
-#include <realmode.h>
 #include <ipxe/command.h>
 #include <ipxe/parseopt.h>
+#include <ipxe/reboot.h>
 
 FILE_LICENCE ( GPL2_OR_LATER );
 
@@ -55,7 +55,7 @@ static int reboot_exec ( int argc, char **argv ) {
                return rc;
 
        /* Reboot system */
-       __asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : : );
+       reboot();
 
        return 0;
 }
diff --git a/src/include/ipxe/efi/efi_reboot.h b/src/include/ipxe/efi/efi_reboot.h
new file mode 100644 (file)
index 0000000..33921b9
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef _IPXE_EFI_REBOOT_H
+#define _IPXE_EFI_REBOOT_H
+
+/** @file
+ *
+ * iPXE reboot API for EFI
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#ifdef REBOOT_EFI
+#define REBOOT_PREFIX_efi
+#else
+#define REBOOT_PREFIX_efi __efi_
+#endif
+
+#endif /* _IPXE_EFI_REBOOT_H */
diff --git a/src/include/ipxe/null_reboot.h b/src/include/ipxe/null_reboot.h
new file mode 100644 (file)
index 0000000..3de36c5
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef _IPXE_NULL_REBOOT_H
+#define _IPXE_NULL_REBOOT_H
+
+/** @file
+ *
+ * iPXE do-nothing reboot API
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#ifdef REBOOT_NULL
+#define REBOOT_PREFIX_null
+#else
+#define REBOOT_PREFIX_null __null_
+#endif
+
+#endif /* _IPXE_NULL_REBOOT_H */
diff --git a/src/include/ipxe/reboot.h b/src/include/ipxe/reboot.h
new file mode 100644 (file)
index 0000000..043c5e1
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef _IPXE_REBOOT_H
+#define _IPXE_REBOOT_H
+
+/** @file
+ *
+ * iPXE reboot API
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <ipxe/api.h>
+#include <config/reboot.h>
+
+/**
+ * Calculate static inline reboot API function name
+ *
+ * @v _prefix          Subsystem prefix
+ * @v _api_func                API function
+ * @ret _subsys_func   Subsystem API function
+ */
+#define REBOOT_INLINE( _subsys, _api_func ) \
+       SINGLE_API_INLINE ( REBOOT_PREFIX_ ## _subsys, _api_func )
+
+/**
+ * Provide an reboot API implementation
+ *
+ * @v _prefix          Subsystem prefix
+ * @v _api_func                API function
+ * @v _func            Implementing function
+ */
+#define PROVIDE_REBOOT( _subsys, _api_func, _func ) \
+       PROVIDE_SINGLE_API ( REBOOT_PREFIX_ ## _subsys, _api_func, _func )
+
+/**
+ * Provide a static inline reboot API implementation
+ *
+ * @v _prefix          Subsystem prefix
+ * @v _api_func                API function
+ */
+#define PROVIDE_REBOOT_INLINE( _subsys, _api_func ) \
+       PROVIDE_SINGLE_API_INLINE ( REBOOT_PREFIX_ ## _subsys, _api_func )
+
+/* Include all architecture-independent reboot API headers */
+#include <ipxe/null_reboot.h>
+#include <ipxe/efi/efi_reboot.h>
+
+/* Include all architecture-dependent reboot API headers */
+#include <bits/reboot.h>
+
+/**
+ * Reboot system
+ *
+ */
+void reboot ( void );
+
+#endif /* _IPXE_REBOOT_H */
diff --git a/src/interface/efi/efi_reboot.c b/src/interface/efi/efi_reboot.c
new file mode 100644 (file)
index 0000000..1ecccc4
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+/**
+ * @file
+ *
+ * EFI reboot mechanism
+ *
+ */
+
+#include <ipxe/efi/efi.h>
+#include <ipxe/reboot.h>
+
+/**
+ * Reboot system
+ *
+ */
+static void efi_reboot ( void ) {
+       EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices;
+
+       /* Use runtime services to reset system */
+       rs->ResetSystem ( EfiResetCold, 0, 0, NULL );
+}
+
+PROVIDE_REBOOT ( efi, reboot, efi_reboot );