mirror of https://github.com/ipxe/ipxe.git
[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>pull/13/head
parent
11ad0bafbf
commit
71cd508838
|
@ -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 */
|
|
@ -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 */
|
|
@ -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 );
|
|
@ -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 */
|
|
@ -19,8 +19,11 @@
|
|||
#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 */
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define SANBOOT_NULL
|
||||
#define ENTROPY_LINUX
|
||||
#define TIME_LINUX
|
||||
#define REBOOT_NULL
|
||||
|
||||
#define DRIVERS_LINUX
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
|
@ -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 );
|
|
@ -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;
|
||||
}
|
|
@ -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 */
|
|
@ -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 */
|
|
@ -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 */
|
|
@ -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 );
|
Loading…
Reference in New Issue